diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-05-06 18:27:50 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-05-06 18:38:26 +0200 |
commit | 67a10829cc62090325e1f3f9bcc57edc8d5c5965 (patch) | |
tree | 97005e798438884c312c39afad7ec44b6d495e16 | |
parent | fa6147b879add9ad4db0f2bc8d4c47f7fd92f41c (diff) | |
download | ghdl-67a10829cc62090325e1f3f9bcc57edc8d5c5965.tar.gz ghdl-67a10829cc62090325e1f3f9bcc57edc8d5c5965.tar.bz2 ghdl-67a10829cc62090325e1f3f9bcc57edc8d5c5965.zip |
synth-expr.adb: handle negative values. Fix ghdl/ghdl-yosys-plugin#115
-rw-r--r-- | src/synth/synth-expr.adb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb index e24a4959d..c8bfd6b24 100644 --- a/src/synth/synth-expr.adb +++ b/src/synth/synth-expr.adb @@ -1340,11 +1340,27 @@ package body Synth.Expr is case Pfx_Bnd.Dir is when Dir_To => - Off := Uns32 (L_Add - Pfx_Bnd.Left); Width := Uns32 (R_Add - L_Add + 1); + Off := Uns32 (L_Add - Pfx_Bnd.Left); when Dir_Downto => - Off := Uns32 (R_Add - Pfx_Bnd.Right); Width := Uns32 (L_Add - R_Add + 1); + if R_Add >= Pfx_Bnd.Right then + Off := Uns32 (R_Add - Pfx_Bnd.Right); + else + -- Handle biased values. + declare + Bias : constant Uns32 := + (Uns32 (Pfx_Bnd.Right - R_Add) + Step - 1) / Step; + Bias_Net : Net; + begin + -- Add bias to INP and adjust the offset. + Bias_Net := Build2_Const_Uns + (Ctxt, Uns64 (Bias), Get_Width (Inp)); + Inp := Build_Dyadic (Ctxt, Id_Add, Inp, Bias_Net); + Set_Location (Inp, Loc); + Off := Uns32 (Int32 (Bias * Step) + R_Add - Pfx_Bnd.Right); + end; + end if; end case; end Synth_Extract_Dyn_Suffix; |