aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth/netlists-memories.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-07-24 06:22:16 +0200
committerTristan Gingold <tgingold@free.fr>2020-07-24 06:22:16 +0200
commit921398c1dac0979723374afc01b9feb6e01fa98e (patch)
tree2d4fa3122f13edba041eae0529f30951d3c1ef85 /src/synth/netlists-memories.adb
parent01c82f09be0baaa84cc189255b47fb1326da7424 (diff)
downloadghdl-921398c1dac0979723374afc01b9feb6e01fa98e.tar.gz
ghdl-921398c1dac0979723374afc01b9feb6e01fa98e.tar.bz2
ghdl-921398c1dac0979723374afc01b9feb6e01fa98e.zip
synth: fix handling of multi-dim ROM. Fix #1390
Document index order for memidx.
Diffstat (limited to 'src/synth/netlists-memories.adb')
-rw-r--r--src/synth/netlists-memories.adb29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/synth/netlists-memories.adb b/src/synth/netlists-memories.adb
index 704c96e8b..f9e5c124c 100644
--- a/src/synth/netlists-memories.adb
+++ b/src/synth/netlists-memories.adb
@@ -165,10 +165,10 @@ package body Netlists.Memories is
when Id_Dyn_Extract =>
-- Extract step from memidx gate.
Idx := Get_Net_Parent (Get_Input_Net (Extr_Inst, 1));
- if Get_Id (Idx) = Id_Addidx then
- -- Multi-dim arrays, lowest index is the first one.
- Idx := Get_Net_Parent (Get_Input_Net (Idx, 0));
- end if;
+ while Get_Id (Idx) = Id_Addidx loop
+ -- Multi-dim arrays, lowest index is the last one.
+ Idx := Get_Net_Parent (Get_Input_Net (Idx, 1));
+ end loop;
pragma Assert (Get_Id (Idx) = Id_Memidx);
Step := Get_Param_Uns32 (Idx, 0);
@@ -316,7 +316,7 @@ package body Netlists.Memories is
pragma Unreferenced (Mem_Depth);
-- Do checks on memidx.
- Last_Size := 0;
+ Last_Size := Mem_Size;
for I in Indexes'Range loop
declare
Inst : constant Instance := Indexes (I).Inst;
@@ -326,17 +326,18 @@ package body Netlists.Memories is
Max : constant Uns32 := Get_Param_Uns32 (Inst, 1);
Max_W : constant Width := Clog2 (Max + 1);
Sub_Addr1 : Net;
+ Sz : Uns32;
begin
-- Check max (from previous dimension).
+ -- Check the memidx can index its whole input.
pragma Assert (Max /= 0);
- if I /= Indexes'First then
- if Last_Size /= Step then
- raise Internal_Error;
- end if;
+ Sz := (Max + 1) * Step;
+ if Sz /= Last_Size then
+ raise Internal_Error;
end if;
- Last_Size := (Max + 1) * Step;
+ Last_Size := Step;
- if I = Indexes'First then
+ if I = Indexes'Last then
if Step /= Val_Wd then
raise Internal_Error;
end if;
@@ -357,16 +358,12 @@ package body Netlists.Memories is
end;
end loop;
- if Last_Size /= Mem_Size then
- raise Internal_Error;
- end if;
-
-- Lower (just concat addresses).
declare
use Netlists.Concats;
Concat : Concat_Type;
begin
- for I in Indexes'Range loop
+ for I in reverse Indexes'Range loop
Append (Concat, Indexes (I).Addr);
end loop;