diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-11-16 10:22:31 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-11-16 10:22:31 +0100 |
commit | 244a972901e539098fca2f120e53119f4a28724e (patch) | |
tree | 0a54bd73eaad3a6d69abab4cba4f804d4bce6881 /src/synth | |
parent | 0da6f5cda834b7c1898aa0b85202d81e3a72b068 (diff) | |
download | ghdl-244a972901e539098fca2f120e53119f4a28724e.tar.gz ghdl-244a972901e539098fca2f120e53119f4a28724e.tar.bz2 ghdl-244a972901e539098fca2f120e53119f4a28724e.zip |
synth: handle static add uns nat.
Diffstat (limited to 'src/synth')
-rw-r--r-- | src/synth/synth-ieee-numeric_std.adb | 31 | ||||
-rw-r--r-- | src/synth/synth-ieee-numeric_std.ads | 2 | ||||
-rw-r--r-- | src/synth/synth-static_oper.adb | 18 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/synth/synth-ieee-numeric_std.adb b/src/synth/synth-ieee-numeric_std.adb index 4d8aa46a9..5319a3113 100644 --- a/src/synth/synth-ieee-numeric_std.adb +++ b/src/synth/synth-ieee-numeric_std.adb @@ -112,4 +112,35 @@ package body Synth.Ieee.Numeric_Std is end loop; return Res; end Add_Sgn_Int; + + function Add_Uns_Nat (L : Std_Logic_Vector; R : Uns64) + 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 := 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 (V, 1); + end loop; + return Res; + end Add_Uns_Nat; end Synth.Ieee.Numeric_Std; diff --git a/src/synth/synth-ieee-numeric_std.ads b/src/synth/synth-ieee-numeric_std.ads index 824c3fe00..340dac3d6 100644 --- a/src/synth/synth-ieee-numeric_std.ads +++ b/src/synth/synth-ieee-numeric_std.ads @@ -27,4 +27,6 @@ package Synth.Ieee.Numeric_Std is function Add_Sgn_Int (L : Std_Logic_Vector; R : Int64) return Std_Logic_Vector; + function Add_Uns_Nat (L : Std_Logic_Vector; R : Uns64) + 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 fb79af54c..645456db0 100644 --- a/src/synth/synth-static_oper.adb +++ b/src/synth/synth-static_oper.adb @@ -123,6 +123,21 @@ package body Synth.Static_Oper is end; end Synth_Add_Sgn_Int; + function Synth_Add_Uns_Nat (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 Uns64 := Uns64 (R.Scal); + begin + To_Std_Logic_Vector (L, L_Arr); + declare + Res_Arr : constant Std_Logic_Vector := Add_Uns_Nat (L_Arr, R_Val); + begin + return To_Value_Acc (Res_Arr, L.Typ.Vec_El); + end; + end Synth_Add_Uns_Nat; + function Synth_Static_Dyadic_Predefined (Syn_Inst : Synth_Instance_Acc; Imp : Node; Left : Value_Acc; @@ -224,6 +239,9 @@ package body Synth.Static_Oper is when Iir_Predefined_Ieee_Numeric_Std_Add_Sgn_Int => return Synth_Add_Sgn_Int (Left, Right, Expr); + when Iir_Predefined_Ieee_Numeric_Std_Add_Uns_Nat => + return Synth_Add_Uns_Nat (Left, Right, Expr); + when others => Error_Msg_Synth (+Expr, "synth_static_dyadic_predefined: unhandled " |