aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-11-05 19:03:08 +0100
committerTristan Gingold <tgingold@free.fr>2019-11-05 19:03:08 +0100
commit103e373e194fa782770cae50573f924b78b0bdf2 (patch)
tree08136be7ca856569fe5b739037dbc1e7f7de3c1f
parent448fc4b63b3ffcb8d64b2ef1ff52ae2f800ea494 (diff)
downloadghdl-103e373e194fa782770cae50573f924b78b0bdf2.tar.gz
ghdl-103e373e194fa782770cae50573f924b78b0bdf2.tar.bz2
ghdl-103e373e194fa782770cae50573f924b78b0bdf2.zip
netlists: add build2_sresize, simplify code.
-rw-r--r--src/synth/netlists-folds.adb23
-rw-r--r--src/synth/netlists-folds.ads10
-rw-r--r--src/synth/synth-oper.adb68
3 files changed, 53 insertions, 48 deletions
diff --git a/src/synth/netlists-folds.adb b/src/synth/netlists-folds.adb
index a360c2a49..fd35ed8ed 100644
--- a/src/synth/netlists-folds.adb
+++ b/src/synth/netlists-folds.adb
@@ -147,6 +147,29 @@ package body Netlists.Folds is
end if;
end Build2_Uresize;
+ function Build2_Sresize (Ctxt : Context_Acc;
+ I : Net;
+ W : Width;
+ Loc : Location_Type := No_Location)
+ return Net
+ is
+ Wn : constant Width := Get_Width (I);
+ Res : Net;
+ begin
+ if Wn = W then
+ return I;
+ else
+ if Wn > W then
+ Res := Build_Trunc (Ctxt, Id_Strunc, I, W);
+ else
+ pragma Assert (Wn < W);
+ Res := Build_Extend (Ctxt, Id_Sextend, I, W);
+ end if;
+ Locations.Set_Location (Res, Loc);
+ return Res;
+ end if;
+ end Build2_Sresize;
+
function Build2_Extract
(Ctxt : Context_Acc; I : Net; Off, W : Width) return Net is
begin
diff --git a/src/synth/netlists-folds.ads b/src/synth/netlists-folds.ads
index bd417162f..22ab60949 100644
--- a/src/synth/netlists-folds.ads
+++ b/src/synth/netlists-folds.ads
@@ -42,7 +42,15 @@ package Netlists.Folds is
W : Width;
Loc : Location_Type := No_Location)
return Net;
- -- Same as Build_Extract, but return I iff extract all the bits.
+
+ -- Sign extend, noop or truncate I so that its width is W.
+ function Build2_Sresize (Ctxt : Context_Acc;
+ I : Net;
+ W : Width;
+ Loc : Location_Type := No_Location)
+ return Net;
+
+-- Same as Build_Extract, but return I iff extract all the bits.
function Build2_Extract
(Ctxt : Context_Acc; I : Net; Off, W : Width) return Net;
end Netlists.Folds;
diff --git a/src/synth/synth-oper.adb b/src/synth/synth-oper.adb
index 19e376444..8f929d7bb 100644
--- a/src/synth/synth-oper.adb
+++ b/src/synth/synth-oper.adb
@@ -51,23 +51,9 @@ package body Synth.Oper is
return Build2_Uresize (Build_Context, N, W, Get_Location (Loc));
end Synth_Uresize;
- function Synth_Sresize (N : Net; W : Width; Loc : Node) return Net
- is
- Wn : constant Width := Get_Width (N);
- Res : Net;
+ function Synth_Sresize (N : Net; W : Width; Loc : Node) return Net is
begin
- if Wn = W then
- return N;
- else
- if Wn > W then
- Res := Build_Trunc (Build_Context, Id_Strunc, N, W);
- else
- pragma Assert (Wn < W);
- Res := Build_Extend (Build_Context, Id_Sextend, N, W);
- end if;
- Set_Location (Res, Loc);
- return Res;
- end if;
+ return Build2_Sresize (Build_Context, N, W, Get_Location (Loc));
end Synth_Sresize;
function Synth_Uresize (Val : Value_Acc; W : Width; Loc : Node) return Net
@@ -297,9 +283,7 @@ package body Synth.Oper is
function Synth_Dyadic_Uns (Id : Dyadic_Module_Id; Is_Res_Vec : Boolean)
return Value_Acc
is
- L : constant Net := Get_Net (Left);
- R : constant Net := Get_Net (Right);
- W : constant Width := Width'Max (Get_Width (L), Get_Width (R));
+ W : constant Width := Width'Max (Left.Typ.W, Right.Typ.W);
Rtype : Type_Acc;
L1, R1 : Net;
N : Net;
@@ -309,8 +293,8 @@ package body Synth.Oper is
else
Rtype := Left.Typ;
end if;
- L1 := Synth_Uresize (L, W, Expr);
- R1 := Synth_Uresize (R, W, Expr);
+ L1 := Synth_Uresize (Left, W, Expr);
+ R1 := Synth_Uresize (Right, W, Expr);
N := Build_Dyadic (Build_Context, Id, L1, R1);
Set_Location (N, Expr);
return Create_Value_Net (N, Rtype);
@@ -319,9 +303,7 @@ package body Synth.Oper is
function Synth_Dyadic_Sgn (Id : Dyadic_Module_Id; Is_Res_Vec : Boolean)
return Value_Acc
is
- L : constant Net := Get_Net (Left);
- R : constant Net := Get_Net (Right);
- W : constant Width := Width'Max (Get_Width (L), Get_Width (R));
+ W : constant Width := Width'Max (Left.Typ.W, Right.Typ.W);
Rtype : Type_Acc;
L1, R1 : Net;
N : Net;
@@ -331,8 +313,8 @@ package body Synth.Oper is
else
Rtype := Left.Typ;
end if;
- L1 := Synth_Sresize (L, W, Expr);
- R1 := Synth_Sresize (R, W, Expr);
+ L1 := Synth_Sresize (Left, W, Expr);
+ R1 := Synth_Sresize (Right, W, Expr);
N := Build_Dyadic (Build_Context, Id, L1, R1);
Set_Location (N, Expr);
return Create_Value_Net (N, Rtype);
@@ -341,14 +323,12 @@ package body Synth.Oper is
function Synth_Compare_Uns_Uns (Id : Compare_Module_Id)
return Value_Acc
is
- L : constant Net := Get_Net (Left);
- R : constant Net := Get_Net (Right);
- W : constant Width := Width'Max (Get_Width (L), Get_Width (R));
+ W : constant Width := Width'Max (Left.Typ.W, Right.Typ.W);
L1, R1 : Net;
N : Net;
begin
- L1 := Synth_Uresize (L, W, Expr);
- R1 := Synth_Uresize (R, W, Expr);
+ L1 := Synth_Uresize (Left, W, Expr);
+ R1 := Synth_Uresize (Right, W, Expr);
N := Build_Compare (Build_Context, Id, L1, R1);
Set_Location (N, Expr);
return Create_Value_Net (N, Boolean_Type);
@@ -381,14 +361,12 @@ package body Synth.Oper is
function Synth_Compare_Sgn_Sgn (Id : Compare_Module_Id)
return Value_Acc
is
- L : constant Net := Get_Net (Left);
- R : constant Net := Get_Net (Right);
- W : constant Width := Width'Max (Get_Width (L), Get_Width (R));
+ W : constant Width := Width'Max (Left.Typ.W, Right.Typ.W);
L1, R1 : Net;
N : Net;
begin
- L1 := Synth_Sresize (L, W, Expr);
- R1 := Synth_Sresize (R, W, Expr);
+ L1 := Synth_Sresize (Left, W, Expr);
+ R1 := Synth_Sresize (Right, W, Expr);
N := Build_Compare (Build_Context, Id, L1, R1);
Set_Location (N, Expr);
return Create_Value_Net (N, Boolean_Type);
@@ -565,16 +543,14 @@ package body Synth.Oper is
end;
when Iir_Predefined_Ieee_Numeric_Std_Mul_Uns_Nat =>
declare
- L : constant Net := Get_Net (Left);
- R : constant Net := Get_Net (Right);
- Lw : constant Width := Get_Width (L);
+ Lw : constant Width := Left.Typ.W;
W : constant Width := 2 * Lw;
L1, R1 : Net;
Rtype : Type_Acc;
N : Net;
begin
- L1 := Synth_Uresize (L, W, Expr);
- R1 := Synth_Uresize (R, W, Expr);
+ L1 := Synth_Uresize (Left, W, Expr);
+ R1 := Synth_Uresize (Right, W, Expr);
Rtype := Create_Vec_Type_By_Length (W, Left.Typ.Vec_El);
N := Build_Dyadic (Build_Context, Id_Umul, L1, R1);
Set_Location (N, Expr);
@@ -583,16 +559,14 @@ package body Synth.Oper is
when Iir_Predefined_Ieee_Numeric_Std_Div_Uns_Nat =>
declare
- L : constant Net := Get_Net (Left);
- R : constant Net := Get_Net (Right);
- Lw : constant Width := Get_Width (L);
- W : constant Width := Width'Max (Lw, Get_Width (R));
+ Lw : constant Width := Left.Typ.W;
+ W : constant Width := Width'Max (Lw, Right.Typ.W);
L1, R1 : Net;
Rtype : Type_Acc;
N : Net;
begin
- L1 := Synth_Uresize (L, W, Expr);
- R1 := Synth_Uresize (R, W, Expr);
+ L1 := Synth_Uresize (Left, W, Expr);
+ R1 := Synth_Uresize (Right, W, Expr);
Rtype := Create_Vec_Type_By_Length (Lw, Left.Typ.Vec_El);
N := Build_Dyadic (Build_Context, Id_Udiv, L1, R1);
Set_Location (N, Expr);