aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth/synth-ieee-numeric_std.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-04-26 16:46:43 +0200
committerTristan Gingold <tgingold@free.fr>2020-04-26 16:46:43 +0200
commit6a375b0d724d9f04b56857675827c9cf6bab6498 (patch)
tree96b105219ae9f2fd52cfd0b4925f2ee76a33f3fa /src/synth/synth-ieee-numeric_std.adb
parentfa0964793ae49a40f13d1592ddc4ca50a1895b76 (diff)
downloadghdl-6a375b0d724d9f04b56857675827c9cf6bab6498.tar.gz
ghdl-6a375b0d724d9f04b56857675827c9cf6bab6498.tar.bz2
ghdl-6a375b0d724d9f04b56857675827c9cf6bab6498.zip
synth: implement static sub_sgn_int. Fix #1265
Diffstat (limited to 'src/synth/synth-ieee-numeric_std.adb')
-rw-r--r--src/synth/synth-ieee-numeric_std.adb31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/synth/synth-ieee-numeric_std.adb b/src/synth/synth-ieee-numeric_std.adb
index 96a228bb3..7c132dd8e 100644
--- a/src/synth/synth-ieee-numeric_std.adb
+++ b/src/synth/synth-ieee-numeric_std.adb
@@ -211,6 +211,37 @@ package body Synth.Ieee.Numeric_Std is
return Res;
end Sub_Uns_Nat;
+ function Sub_Sgn_Int (L : Std_Logic_Vector; R : Int64)
+ return Std_Logic_Vector
+ is
+ pragma Assert (L'First = 1);
+ Res : Std_Logic_Vector (1 .. L'Last);
+ V : Uns64;
+ Lb, Rb, Carry : Sl_X01;
+ begin
+ if L'Last < 1 then
+ return Null_Vec;
+ end if;
+ V := To_Uns64 (R);
+ Carry := '1';
+ for I in reverse Res'Range loop
+ Lb := Sl_To_X01 (L (I));
+ Rb := Uns_To_01 (V and 1);
+ Rb := Not_Table (Rb);
+ if Lb = 'X' then
+ --assert NO_WARNING
+ -- report "NUMERIC_STD.""+"": non logical value detected"
+ -- severity warning;
+ Res := (others => 'X');
+ exit;
+ end if;
+ Res (I) := Compute_Sum (Carry, Rb, Lb);
+ Carry := Compute_Carry (Carry, Rb, Lb);
+ V := Shift_Right_Arithmetic (V, 1);
+ end loop;
+ return Res;
+ end Sub_Sgn_Int;
+
function Mul_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector
is
pragma Assert (L'First = 1);