aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth/synth-ieee-numeric_std.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-12-03 07:15:32 +0100
committerTristan Gingold <tgingold@free.fr>2019-12-03 07:15:32 +0100
commitd3f43030f21cc5a983bf23697d7c5c311e45f9b1 (patch)
tree7a7512b5b23d4d22d6875bf6d1c20437b75f2de5 /src/synth/synth-ieee-numeric_std.adb
parente6a643ea1db47dc5fcf3893a81b3193869edbc38 (diff)
downloadghdl-d3f43030f21cc5a983bf23697d7c5c311e45f9b1.tar.gz
ghdl-d3f43030f21cc5a983bf23697d7c5c311e45f9b1.tar.bz2
ghdl-d3f43030f21cc5a983bf23697d7c5c311e45f9b1.zip
synth: add static neg for signed.
Diffstat (limited to 'src/synth/synth-ieee-numeric_std.adb')
-rw-r--r--src/synth/synth-ieee-numeric_std.adb28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/synth/synth-ieee-numeric_std.adb b/src/synth/synth-ieee-numeric_std.adb
index 738146014..0a75d0576 100644
--- a/src/synth/synth-ieee-numeric_std.adb
+++ b/src/synth/synth-ieee-numeric_std.adb
@@ -238,4 +238,32 @@ package body Synth.Ieee.Numeric_Std is
return Res;
end Mul_Sgn_Sgn;
+ function Neg_Sgn (V : Std_Logic_Vector) return Std_Logic_Vector
+ is
+ pragma Assert (V'First = 1);
+ Len : constant Integer := V'Last;
+ subtype Res_Type is Std_Logic_Vector (1 .. Len);
+ Res : Res_Type;
+ Vb, Carry : Sl_X01;
+ begin
+ if Len < 1 then
+ return Null_Vec;
+ end if;
+ Carry := '1';
+ for I in 0 .. Len - 1 loop
+ Vb := Sl_To_X01 (V (V'Last - I));
+ if Vb = 'X' then
+ --assert NO_WARNING
+ -- report "NUMERIC_STD.""+"": non logical value detected"
+ -- severity warning;
+ Res := (others => 'X');
+ exit;
+ end if;
+ Vb := Not_Table (Vb);
+ Res (Res'Last - I) := Xor_Table (Carry, Vb);
+ Carry := And_Table (Carry, Vb);
+ end loop;
+ return Res;
+ end Neg_Sgn;
+
end Synth.Ieee.Numeric_Std;