diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-03-02 21:03:47 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-03-02 21:10:33 +0100 |
commit | 319c63804dee35360865f53aca93a80af02e99b6 (patch) | |
tree | 3063771942e49c477a49686bc2aa7a77d31ef931 | |
parent | 32db0bb23303a8d1165a1a613f47bfadd5c128d5 (diff) | |
download | ghdl-319c63804dee35360865f53aca93a80af02e99b6.tar.gz ghdl-319c63804dee35360865f53aca93a80af02e99b6.tar.bz2 ghdl-319c63804dee35360865f53aca93a80af02e99b6.zip |
synth: fix conversion of net to constant for physical values. Fix #1148
-rw-r--r-- | src/synth/netlists-folds.adb | 4 | ||||
-rw-r--r-- | src/synth/synth-context.adb | 13 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/synth/netlists-folds.adb b/src/synth/netlists-folds.adb index 6b8a57fb8..ef5cfdd2c 100644 --- a/src/synth/netlists-folds.adb +++ b/src/synth/netlists-folds.adb @@ -39,7 +39,7 @@ package body Netlists.Folds is Inst := Build_Const_Bit (Ctxt, W); Set_Param_Uns32 (Inst, 0, Uns32 (Val and 16#ffff_ffff#)); Set_Param_Uns32 (Inst, 1, Uns32 (Shift_Right (Val, 32))); - for I in 2 .. (W + 31) / 32 loop + for I in 2 .. (W + 31) / 32 - 1 loop Set_Param_Uns32 (Inst, Param_Idx (I), 0); end loop; return Get_Output (Inst, 0); @@ -81,7 +81,7 @@ package body Netlists.Folds is Inst := Build_Const_Bit (Ctxt, W); Set_Param_Uns32 (Inst, 0, Uns32 (V and 16#ffff_ffff#)); Set_Param_Uns32 (Inst, 1, Uns32 (Shift_Right (V, 32))); - for I in 2 .. (W + 31) / 32 loop + for I in 2 .. (W + 31) / 32 - 1 loop Set_Param_Uns32 (Inst, Param_Idx (I), S); end loop; return Get_Output (Inst, 0); diff --git a/src/synth/synth-context.adb b/src/synth/synth-context.adb index 8aea87ea9..e5e5479a8 100644 --- a/src/synth/synth-context.adb +++ b/src/synth/synth-context.adb @@ -29,6 +29,7 @@ with Vhdl.Errors; use Vhdl.Errors; with Vhdl.Utils; with Netlists.Builders; use Netlists.Builders; +with Netlists.Folds; use Netlists.Folds; with Netlists.Concats; with Synth.Expr; use Synth.Expr; @@ -445,12 +446,16 @@ package body Synth.Context is return Res; end; when Type_Discrete => - if Val.Typ.W <= 32 then + if Val.Typ.W <= 64 then declare - V : Uns32; + Sh : constant Natural := 64 - Natural (Val.Typ.W); + V : Uns64; begin - V := Uns32 (To_Uns64 (Val.Scal) and 16#ffff_ffff#); - return Build_Const_UB32 (Build_Context, V, Val.Typ.W); + V := To_Uns64 (Val.Scal); + -- Keep only Val.Typ.W bits of the value. + V := Shift_Right (Shift_Left (V, Sh), Sh); + return Build2_Const_Uns + (Build_Context, V, Val.Typ.W); end; else raise Internal_Error; |