aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-11-01 18:34:46 +0100
committerTristan Gingold <tgingold@free.fr>2019-11-01 18:34:46 +0100
commit150a5c6e886cb5a5e5da3194f02481781fba027b (patch)
tree1da90345df4f2623cc79685d37e31a4c8a59c667
parentd4b148035ddbf84657d18d927a28885c494d5875 (diff)
downloadghdl-150a5c6e886cb5a5e5da3194f02481781fba027b.tar.gz
ghdl-150a5c6e886cb5a5e5da3194f02481781fba027b.tar.bz2
ghdl-150a5c6e886cb5a5e5da3194f02481781fba027b.zip
netlits: fix memidx order.
-rw-r--r--src/synth/netlists-expands.adb87
-rw-r--r--src/synth/netlists-memories.adb4
2 files changed, 52 insertions, 39 deletions
diff --git a/src/synth/netlists-expands.adb b/src/synth/netlists-expands.adb
index 8c17e2313..a759e08f3 100644
--- a/src/synth/netlists-expands.adb
+++ b/src/synth/netlists-expands.adb
@@ -30,6 +30,55 @@ with Netlists.Concats; use Netlists.Concats;
package body Netlists.Expands is
type Memidx_Array_Type is array (Natural range <>) of Instance;
+ -- Extract Memidx from ADDR_NET and return the number of elements NBR_ELS
+ -- (which is usually 2**width(ADDR_NET)).
+ -- Memidx are ordered from the one with the largest step to the one with
+ -- the smallest step.
+ procedure Gather_Memidx (Addr_Net : Net;
+ Memidx_Arr : out Memidx_Array_Type;
+ Nbr_Els : out Natural)
+ is
+ N : Net;
+ P : Natural;
+ Ninst : Instance;
+ Memidx : Instance;
+ Max : Uns32;
+ begin
+ N := Addr_Net;
+ Nbr_Els := 1;
+ P := Memidx_Arr'Last;
+ loop
+ Ninst := Get_Net_Parent (N);
+ case Get_Id (Ninst) is
+ when Id_Memidx =>
+ Memidx := Ninst;
+ when Id_Addidx =>
+ -- Extract memidx.
+ Memidx := Get_Net_Parent (Get_Input_Net (Ninst, 1));
+ pragma Assert (Get_Id (Memidx) = Id_Memidx);
+ N := Get_Input_Net (Ninst, 0);
+ when others =>
+ raise Internal_Error;
+ end case;
+
+ Memidx_Arr (P) := Memidx;
+
+ -- Check memidx are ordered by decreasing step.
+ pragma Assert
+ (P = Memidx_Arr'Last
+ or else (Get_Param_Uns32 (Memidx, 0)
+ >= Get_Param_Uns32 (Memidx_Arr (P + 1), 0)));
+
+ P := P - 1;
+
+ Max := Get_Param_Uns32 (Memidx, 1);
+ pragma Assert (Max /= 0);
+ Nbr_Els := Nbr_Els * Natural (Max + 1);
+
+ exit when Memidx = Ninst;
+ end loop;
+ end Gather_Memidx;
+
-- IDX is the next index to be fill in ELS.
-- OFF is offset for extraction from VAL.
-- ADDR_OFF is the address offset.
@@ -125,44 +174,6 @@ package body Netlists.Expands is
end if;
end Truncate_Address;
- procedure Gather_Memidx (Addr_Net : Net;
- Memidx_Arr : out Memidx_Array_Type;
- Nbr_Els : out Natural)
- is
- N : Net;
- P : Natural;
- Ninst : Instance;
- Memidx : Instance;
- Max : Uns32;
- begin
- N := Addr_Net;
- Nbr_Els := 1;
- P := Memidx_Arr'Last;
- loop
- Ninst := Get_Net_Parent (N);
- case Get_Id (Ninst) is
- when Id_Memidx =>
- Memidx := Ninst;
- when Id_Addidx =>
- -- Extract memidx.
- Memidx := Get_Net_Parent (Get_Input_Net (Ninst, 1));
- pragma Assert (Get_Id (Memidx) = Id_Memidx);
- N := Get_Input_Net (Ninst, 0);
- when others =>
- raise Internal_Error;
- end case;
-
- Memidx_Arr (P) := Memidx;
- P := P - 1;
-
- Max := Get_Param_Uns32 (Memidx, 1);
- pragma Assert (Max /= 0);
- Nbr_Els := Nbr_Els * Natural (Max + 1);
-
- exit when Memidx = Ninst;
- end loop;
- end Gather_Memidx;
-
procedure Expand_Dyn_Extract (Ctxt : Context_Acc; Inst : Instance)
is
Val : constant Net := Get_Input_Net (Inst, 0);
diff --git a/src/synth/netlists-memories.adb b/src/synth/netlists-memories.adb
index 4904e0cec..4163e4878 100644
--- a/src/synth/netlists-memories.adb
+++ b/src/synth/netlists-memories.adb
@@ -674,11 +674,13 @@ package body Netlists.Memories is
end if;
-- Merge id_dyn_extract.
+ -- The order for Addix is important: from larger steps
+ -- to smaller ones.
Disconnect (Get_Input (Inst, 0));
Connect (Get_Input (Inst, 0), Get_Input_Net (Data, 0));
Disconnect (Get_Input (Data, 0));
Add := Build_Addidx
- (Ctxt, Get_Input_Net (Inst, 1), Get_Input_Net (Data, 1));
+ (Ctxt, Get_Input_Net (Data, 1), Get_Input_Net (Inst, 1));
Disconnect (Get_Input (Data, 1));
Disconnect (Get_Input (Inst, 1));
Connect (Get_Input (Inst, 1), Add);