diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-01-13 06:20:00 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-01-13 06:20:00 +0100 |
commit | bcc88a45ddffd2cc54b9fcbfe7313f624478f873 (patch) | |
tree | e775aba2579b3d2e29388810acd832a9b24546a0 /src/synth | |
parent | c3e17a99f3369ec5e63433dbee6819b6aadae4cd (diff) | |
download | ghdl-bcc88a45ddffd2cc54b9fcbfe7313f624478f873.tar.gz ghdl-bcc88a45ddffd2cc54b9fcbfe7313f624478f873.tar.bz2 ghdl-bcc88a45ddffd2cc54b9fcbfe7313f624478f873.zip |
synth: handle static "-" for unsigned. For of #1087
Diffstat (limited to 'src/synth')
-rw-r--r-- | src/synth/synth-ieee-numeric_std.adb | 38 | ||||
-rw-r--r-- | src/synth/synth-ieee-numeric_std.ads | 2 | ||||
-rw-r--r-- | src/synth/synth-static_oper.adb | 19 |
3 files changed, 59 insertions, 0 deletions
diff --git a/src/synth/synth-ieee-numeric_std.adb b/src/synth/synth-ieee-numeric_std.adb index 0a75d0576..f308a2cc5 100644 --- a/src/synth/synth-ieee-numeric_std.adb +++ b/src/synth/synth-ieee-numeric_std.adb @@ -142,6 +142,44 @@ package body Synth.Ieee.Numeric_Std is return Res; end Add_Uns_Nat; + function Sub_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector + is + pragma Assert (L'First = 1); + pragma Assert (R'First = 1); + Len : constant Integer := Integer'Max (L'Last, R'Last); + subtype Res_Type is Std_Logic_Vector (1 .. Len); + Res : Res_Type; + Lb, Rb, Carry : Sl_X01; + begin + if L'Last < 1 or R'Last < 1 then + return Null_Vec; + end if; + Carry := '1'; + for I in 0 .. Len - 1 loop + if I >= L'Last then + Lb := '0'; + else + Lb := Sl_To_X01 (L (L'Last - I)); + end if; + if I >= R'Last then + Rb := '1'; + else + Rb := Sl_To_X01 (R (R'Last - I)); + Rb := Not_Table (Rb); + end if; + if Lb = 'X' or Rb = 'X' then + --assert NO_WARNING + -- report "NUMERIC_STD.""+"": non logical value detected" + -- severity warning; + Res := (others => 'X'); + exit; + end if; + Res (Res'Last - I) := Compute_Sum (Carry, Rb, Lb); + Carry := Compute_Carry (Carry, Rb, Lb); + end loop; + return Res; + end Sub_Uns_Uns; + function Mul_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector is pragma Assert (L'First = 1); diff --git a/src/synth/synth-ieee-numeric_std.ads b/src/synth/synth-ieee-numeric_std.ads index 1d8dacd7b..1490bf9d1 100644 --- a/src/synth/synth-ieee-numeric_std.ads +++ b/src/synth/synth-ieee-numeric_std.ads @@ -34,6 +34,8 @@ package Synth.Ieee.Numeric_Std is function Add_Uns_Nat (L : Std_Logic_Vector; R : Uns64) return Std_Logic_Vector; + function Sub_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector; + function Mul_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector; function Mul_Sgn_Sgn (L, R : Std_Logic_Vector) return Std_Logic_Vector; diff --git a/src/synth/synth-static_oper.adb b/src/synth/synth-static_oper.adb index 02662ab1e..7d5e24fa4 100644 --- a/src/synth/synth-static_oper.adb +++ b/src/synth/synth-static_oper.adb @@ -212,6 +212,22 @@ package body Synth.Static_Oper is end; end Synth_Add_Uns_Nat; + function Synth_Sub_Uns_Uns (L, R : Value_Acc; Loc : Syn_Src) + return Value_Acc + is + pragma Unreferenced (Loc); + L_Arr : Std_Logic_Vector (1 .. Natural (L.Arr.Len)); + R_Arr : Std_Logic_Vector (1 .. Natural (R.Arr.Len)); + begin + To_Std_Logic_Vector (L, L_Arr); + To_Std_Logic_Vector (R, R_Arr); + declare + Res_Arr : constant Std_Logic_Vector := Sub_Uns_Uns (L_Arr, R_Arr); + begin + return To_Value_Acc (Res_Arr, L.Typ.Vec_El); + end; + end Synth_Sub_Uns_Uns; + function Synth_Mul_Uns_Uns (L, R : Value_Acc; Loc : Syn_Src) return Value_Acc is @@ -402,6 +418,9 @@ package body Synth.Static_Oper is when Iir_Predefined_Ieee_Numeric_Std_Add_Uns_Nat => return Synth_Add_Uns_Nat (Left, Right, Expr); + when Iir_Predefined_Ieee_Numeric_Std_Sub_Uns_Uns => + return Synth_Sub_Uns_Uns (Left, Right, Expr); + when Iir_Predefined_Ieee_Numeric_Std_Mul_Uns_Uns => return Synth_Mul_Uns_Uns (Left, Right, Expr); |