diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-11-16 09:13:59 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-11-16 09:13:59 +0100 |
commit | 0da6f5cda834b7c1898aa0b85202d81e3a72b068 (patch) | |
tree | 7cf826531cf8632d185e559af72930b0c45f9de6 | |
parent | 706fd3a64ca9d55591542d0488b87698e3835c21 (diff) | |
download | ghdl-0da6f5cda834b7c1898aa0b85202d81e3a72b068.tar.gz ghdl-0da6f5cda834b7c1898aa0b85202d81e3a72b068.tar.bz2 ghdl-0da6f5cda834b7c1898aa0b85202d81e3a72b068.zip |
synth: handle static add sgn int.
-rw-r--r-- | src/synth/synth-ieee-numeric_std.adb | 36 | ||||
-rw-r--r-- | src/synth/synth-ieee-numeric_std.ads | 5 | ||||
-rw-r--r-- | src/synth/synth-static_oper.adb | 18 |
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 56e8742c4..4d8aa46a9 100644 --- a/src/synth/synth-ieee-numeric_std.adb +++ b/src/synth/synth-ieee-numeric_std.adb @@ -18,6 +18,8 @@ -- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, -- MA 02110-1301, USA. +with Types_Utils; use Types_Utils; + package body Synth.Ieee.Numeric_Std is Null_Vec : constant Std_Logic_Vector (1 .. 0) := (others => '0'); @@ -40,6 +42,9 @@ package body Synth.Ieee.Numeric_Std is Sl_To_X01 : constant Sl_To_X01_Array := ('0' | 'L' => '0', '1' | 'H' => '1', others => 'X'); + type Uns_To_01_Array is array (Uns64 range 0 .. 1) of Sl_X01; + Uns_To_01 : constant Uns_To_01_Array := (0 => '0', 1 => '1'); + function Add_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector is pragma Assert (L'First = 1); @@ -76,4 +81,35 @@ package body Synth.Ieee.Numeric_Std is end loop; return Res; end Add_Uns_Uns; + + function Add_Sgn_Int (L : Std_Logic_Vector; R : Int64) + return Std_Logic_Vector + is + pragma Assert (L'First = 1); + subtype Res_Type is Std_Logic_Vector (1 .. L'Last); + V : Uns64; + Res : Res_Type; + Lb, Rb, Carry : Sl_X01; + begin + if L'Last < 1 then + return Null_Vec; + end if; + V := To_Uns64 (R); + Carry := '0'; + for I in Res'Range loop + Lb := Sl_To_X01 (L (I)); + Rb := Uns_To_01 (V and 1); + 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 Add_Sgn_Int; end Synth.Ieee.Numeric_Std; diff --git a/src/synth/synth-ieee-numeric_std.ads b/src/synth/synth-ieee-numeric_std.ads index 051881d0e..824c3fe00 100644 --- a/src/synth/synth-ieee-numeric_std.ads +++ b/src/synth/synth-ieee-numeric_std.ads @@ -18,8 +18,13 @@ -- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, -- MA 02110-1301, USA. +with Types; use Types; + with Synth.Ieee.Std_Logic_1164; use Synth.Ieee.Std_Logic_1164; package Synth.Ieee.Numeric_Std is function Add_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector; + + function Add_Sgn_Int (L : Std_Logic_Vector; R : Int64) + return Std_Logic_Vector; end Synth.Ieee.Numeric_Std; diff --git a/src/synth/synth-static_oper.adb b/src/synth/synth-static_oper.adb index c25775bae..fb79af54c 100644 --- a/src/synth/synth-static_oper.adb +++ b/src/synth/synth-static_oper.adb @@ -108,6 +108,21 @@ package body Synth.Static_Oper is end; end Synth_Add_Uns_Uns; + function Synth_Add_Sgn_Int (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_Val : constant Int64 := R.Scal; + begin + To_Std_Logic_Vector (L, L_Arr); + declare + Res_Arr : constant Std_Logic_Vector := Add_Sgn_Int (L_Arr, R_Val); + begin + return To_Value_Acc (Res_Arr, L.Typ.Vec_El); + end; + end Synth_Add_Sgn_Int; + function Synth_Static_Dyadic_Predefined (Syn_Inst : Synth_Instance_Acc; Imp : Node; Left : Value_Acc; @@ -206,6 +221,9 @@ package body Synth.Static_Oper is when Iir_Predefined_Ieee_Numeric_Std_Add_Uns_Uns => return Synth_Add_Uns_Uns (Left, Right, Expr); + when Iir_Predefined_Ieee_Numeric_Std_Add_Sgn_Int => + return Synth_Add_Sgn_Int (Left, Right, Expr); + when others => Error_Msg_Synth (+Expr, "synth_static_dyadic_predefined: unhandled " |