aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-12-31 18:55:44 +0100
committerTristan Gingold <tgingold@free.fr>2019-12-31 18:57:44 +0100
commit3485a2054df425a54796ce69f28d19b6eea2b868 (patch)
tree58293caff9f2426c061cd621432cc56fa9ecabd4 /src
parent03e71f74ace9dbd543435b5f94df87b83bb7d54f (diff)
downloadghdl-3485a2054df425a54796ce69f28d19b6eea2b868.tar.gz
ghdl-3485a2054df425a54796ce69f28d19b6eea2b868.tar.bz2
ghdl-3485a2054df425a54796ce69f28d19b6eea2b868.zip
synth-environment: also optimize mux merge for sub-nets.
Diffstat (limited to 'src')
-rw-r--r--src/synth/netlists-utils.adb28
-rw-r--r--src/synth/netlists-utils.ads5
-rw-r--r--src/synth/synth-environment.adb2
3 files changed, 34 insertions, 1 deletions
diff --git a/src/synth/netlists-utils.adb b/src/synth/netlists-utils.adb
index 4a189b39e..59eb086d5 100644
--- a/src/synth/netlists-utils.adb
+++ b/src/synth/netlists-utils.adb
@@ -230,6 +230,34 @@ package body Netlists.Utils is
Free_Instance (Inst);
end Disconnect_And_Free;
+ function Same_Net (L, R : Net) return Boolean
+ is
+ Linst : Instance;
+ Rinst : Instance;
+ begin
+ if L = R then
+ -- Obvious case.
+ return True;
+ end if;
+
+ if Get_Width (L) /= Get_Width (R) then
+ -- Must have the same width.
+ return False;
+ end if;
+
+ -- Handle extract.
+ Linst := Get_Net_Parent (L);
+ if Get_Id (Linst) /= Id_Extract then
+ return False;
+ end if;
+ Rinst := Get_Net_Parent (R);
+ if Get_Id (Rinst) /= Id_Extract then
+ return False;
+ end if;
+ return Get_Input_Net (Linst, 0) = Get_Input_Net (Rinst, 0)
+ and then Get_Param_Uns32 (Linst, 0) = Get_Param_Uns32 (Rinst, 0);
+ end Same_Net;
+
function Clog2 (W : Width) return Width is
begin
return Uns32 (Mutils.Clog2 (Uns64 (W)));
diff --git a/src/synth/netlists-utils.ads b/src/synth/netlists-utils.ads
index 6a29e0034..79838b614 100644
--- a/src/synth/netlists-utils.ads
+++ b/src/synth/netlists-utils.ads
@@ -74,6 +74,11 @@ package Netlists.Utils is
-- disconnect and free it.
procedure Disconnect_And_Free (I : Input);
+ -- Return true IFF L and R is the same net.
+ -- Either because L = R (obvious case) or because both are the same
+ -- selection of the same net.
+ function Same_Net (L, R : Net) return Boolean;
+
function Clog2 (W : Width) return Width;
-- Used at many places.
diff --git a/src/synth/synth-environment.adb b/src/synth/synth-environment.adb
index 11c4b505d..0f5d8816e 100644
--- a/src/synth/synth-environment.adb
+++ b/src/synth/synth-environment.adb
@@ -1018,7 +1018,7 @@ package body Synth.Environment is
-- Build mux.
N1_Inst := Get_Net_Parent (N (1));
if Get_Id (N1_Inst) = Id_Mux2
- and then Get_Driver (Get_Mux2_I0 (N1_Inst)) = N (0)
+ and then Same_Net (Get_Driver (Get_Mux2_I0 (N1_Inst)), N (0))
then
Res := Build_Mux2
(Ctxt, Build_Dyadic (Ctxt, Id_And,