aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-10-28 20:07:46 +0100
committerTristan Gingold <tgingold@free.fr>2019-10-28 20:07:46 +0100
commitfce8f04ce5aef77c597ea3f97f84ec5ffb08a3da (patch)
tree33d971a255b7bb533e5316fd4460cc70b01ed405 /src
parent13a28fa63e8dca2b31e09c2b393a6440b64d05b8 (diff)
downloadghdl-fce8f04ce5aef77c597ea3f97f84ec5ffb08a3da.tar.gz
ghdl-fce8f04ce5aef77c597ea3f97f84ec5ffb08a3da.tar.bz2
ghdl-fce8f04ce5aef77c597ea3f97f84ec5ffb08a3da.zip
synth: adjust computation of max for dyn_extract.
Diffstat (limited to 'src')
-rw-r--r--src/synth/netlists-expands.adb4
-rw-r--r--src/synth/netlists-memories.adb6
-rw-r--r--src/synth/synth-expr.adb8
3 files changed, 10 insertions, 8 deletions
diff --git a/src/synth/netlists-expands.adb b/src/synth/netlists-expands.adb
index ebc51670d..3438ee132 100644
--- a/src/synth/netlists-expands.adb
+++ b/src/synth/netlists-expands.adb
@@ -52,7 +52,7 @@ package body Netlists.Expands is
Max := Get_Param_Uns32 (Inst1, 1);
pragma Assert (Max /= 0);
- Res := Res * Natural (Max);
+ Res := Res * Natural (Max + 1);
exit when Inst1 = Inst;
end loop;
@@ -99,7 +99,7 @@ package body Netlists.Expands is
begin
pragma Assert (Max /= 0);
- for I in 0 .. Max - 1 loop
+ for I in 0 .. Max loop
if Sub_Inst /= No_Instance then
-- recurse.
raise Internal_Error;
diff --git a/src/synth/netlists-memories.adb b/src/synth/netlists-memories.adb
index e56990c03..4904e0cec 100644
--- a/src/synth/netlists-memories.adb
+++ b/src/synth/netlists-memories.adb
@@ -342,10 +342,8 @@ package body Netlists.Memories is
begin
-- Check max
Max := Get_Param_Uns32 (Inst, 1);
- if Max = 0 then
- Max := Last_Size / Step;
- end if;
- if Max * Step /= Last_Size then
+ pragma Assert (Max /= 0);
+ if (Max + 1) * Step /= Last_Size then
raise Internal_Error;
end if;
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb
index d16dedffe..e58cfce74 100644
--- a/src/synth/synth-expr.adb
+++ b/src/synth/synth-expr.adb
@@ -964,7 +964,7 @@ package body Synth.Expr is
Off := Index_To_Offset (Bnd, Idx_Val.Scal, Name) * W;
else
Voff := Dyn_Index_To_Offset (Bnd, Idx_Val, Name);
- Voff := Build_Memidx (Get_Build (Syn_Inst), Voff, W, Bnd.Len,
+ Voff := Build_Memidx (Get_Build (Syn_Inst), Voff, W, Bnd.Len - 1,
Width (Clog2 (Uns64 (W * Bnd.Len))));
Set_Location (Voff, Name);
Off := 0;
@@ -1260,7 +1260,11 @@ package body Synth.Expr is
(Name, Pfx_Bnd, Get_Net (Left), Get_Net (Right),
Inp, Step, Off, Wd);
-- FIXME: convert range to offset.
- Max := (Pfx_Bnd.Len - Off) / Step;
+ -- example: len=128 wd=8 step=8 => max=16
+ -- len=8 wd=4 step=1 => max=4
+ -- max so that max*step+wd <= len - off
+ -- max <= (len - off - wd) / step
+ Max := (Pfx_Bnd.Len - Off - Wd) / Step;
Inp := Build_Memidx
(Get_Build (Syn_Inst),
Inp, Step * El_Wd, Max,