aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-05-16 08:09:27 +0200
committerTristan Gingold <tgingold@free.fr>2020-05-16 08:17:51 +0200
commitad87210f34671ab9454b581965a15f67eb39cdcf (patch)
treeec8b4aa8c68e2f2ebae0caa90fd437c812777f64 /src/synth
parent2412f7355e029905cdac0883982fd3927f493e3a (diff)
downloadghdl-ad87210f34671ab9454b581965a15f67eb39cdcf.tar.gz
ghdl-ad87210f34671ab9454b581965a15f67eb39cdcf.tar.bz2
ghdl-ad87210f34671ab9454b581965a15f67eb39cdcf.zip
synth: handle static calls to signed numeric_std + -. Fix #1313
Diffstat (limited to 'src/synth')
-rw-r--r--src/synth/synth-ieee-numeric_std.adb79
-rw-r--r--src/synth/synth-ieee-numeric_std.ads9
-rw-r--r--src/synth/synth-static_oper.adb34
3 files changed, 119 insertions, 3 deletions
diff --git a/src/synth/synth-ieee-numeric_std.adb b/src/synth/synth-ieee-numeric_std.adb
index 7c132dd8e..e7cc2ef65 100644
--- a/src/synth/synth-ieee-numeric_std.adb
+++ b/src/synth/synth-ieee-numeric_std.adb
@@ -82,6 +82,45 @@ package body Synth.Ieee.Numeric_Std is
return Res;
end Add_Uns_Uns;
+ function Add_Sgn_Sgn (L, R : Std_Logic_Vector) return Std_Logic_Vector
+ is
+ pragma Assert (L'First = 1);
+ pragma Assert (R'First = 1);
+ Len : constant Integer := Integer'Max (L'Last, R'Last);
+ subtype Res_Type is Std_Logic_Vector (1 .. Len);
+ Res : Res_Type;
+ Lb, Rb, Carry : Sl_X01;
+ begin
+ if L'Last < 1 or R'Last < 1 then
+ return Null_Vec;
+ end if;
+ Carry := '0';
+ for I in 0 .. Len - 1 loop
+ if I >= L'Last then
+ Lb := L (1);
+ else
+ Lb := L (L'Last - I);
+ end if;
+ Lb := Sl_To_X01 (Lb);
+ if I >= R'Last then
+ Rb := R (1);
+ else
+ Rb := R (R'Last - I);
+ end if;
+ Rb := Sl_To_X01 (Rb);
+ if Lb = 'X' or Rb = 'X' then
+ --assert NO_WARNING
+ -- report "NUMERIC_STD.""+"": non logical value detected"
+ -- severity warning;
+ Res := (others => 'X');
+ exit;
+ end if;
+ Res (Res'Last - I) := Compute_Sum (Carry, Rb, Lb);
+ Carry := Compute_Carry (Carry, Rb, Lb);
+ end loop;
+ return Res;
+ end Add_Sgn_Sgn;
+
function Add_Sgn_Int (L : Std_Logic_Vector; R : Int64)
return Std_Logic_Vector
is
@@ -211,6 +250,46 @@ package body Synth.Ieee.Numeric_Std is
return Res;
end Sub_Uns_Nat;
+ function Sub_Sgn_Sgn (L, R : Std_Logic_Vector) return Std_Logic_Vector
+ is
+ pragma Assert (L'First = 1);
+ pragma Assert (R'First = 1);
+ Len : constant Integer := Integer'Max (L'Last, R'Last);
+ subtype Res_Type is Std_Logic_Vector (1 .. Len);
+ Res : Res_Type;
+ Lb, Rb, Carry : Sl_X01;
+ begin
+ if L'Last < 1 or R'Last < 1 then
+ return Null_Vec;
+ end if;
+ Carry := '1';
+ for I in 0 .. Len - 1 loop
+ if I >= L'Last then
+ Lb := L (1);
+ else
+ Lb := L (L'Last - I);
+ end if;
+ Lb := Sl_To_X01 (Lb);
+ if I >= R'Last then
+ Rb := R (1);
+ else
+ Rb := R (R'Last - I);
+ end if;
+ Rb := Sl_To_X01 (Rb);
+ Rb := Not_Table (Rb);
+ if Lb = 'X' or Rb = 'X' then
+ --assert NO_WARNING
+ -- report "NUMERIC_STD.""+"": non logical value detected"
+ -- severity warning;
+ Res := (others => 'X');
+ exit;
+ end if;
+ Res (Res'Last - I) := Compute_Sum (Carry, Rb, Lb);
+ Carry := Compute_Carry (Carry, Rb, Lb);
+ end loop;
+ return Res;
+ end Sub_Sgn_Sgn;
+
function Sub_Sgn_Int (L : Std_Logic_Vector; R : Int64)
return Std_Logic_Vector
is
diff --git a/src/synth/synth-ieee-numeric_std.ads b/src/synth/synth-ieee-numeric_std.ads
index 31beea86f..280be3da5 100644
--- a/src/synth/synth-ieee-numeric_std.ads
+++ b/src/synth/synth-ieee-numeric_std.ads
@@ -27,20 +27,23 @@ package Synth.Ieee.Numeric_Std is
function Neg_Sgn (V : Std_Logic_Vector) return Std_Logic_Vector;
+ -- "+"
function Add_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector;
-
function Add_Sgn_Int (L : Std_Logic_Vector; R : Int64)
return Std_Logic_Vector;
function Add_Uns_Nat (L : Std_Logic_Vector; R : Uns64)
return Std_Logic_Vector;
+ function Add_Sgn_Sgn (L, R : Std_Logic_Vector) return Std_Logic_Vector;
+ -- "-"
function Sub_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector;
-
function Sub_Sgn_Int (L : Std_Logic_Vector; R : Int64)
return Std_Logic_Vector;
function Sub_Uns_Nat (L : Std_Logic_Vector; R : Uns64)
- return Std_Logic_Vector;
+ return Std_Logic_Vector;
+ function Sub_Sgn_Sgn (L, R : Std_Logic_Vector) return Std_Logic_Vector;
+ -- "*"
function Mul_Uns_Uns (L, R : Std_Logic_Vector) return Std_Logic_Vector;
function Mul_Nat_Uns (L : Uns64; R : Std_Logic_Vector)
return Std_Logic_Vector;
diff --git a/src/synth/synth-static_oper.adb b/src/synth/synth-static_oper.adb
index 5ad632e73..770c5d171 100644
--- a/src/synth/synth-static_oper.adb
+++ b/src/synth/synth-static_oper.adb
@@ -401,6 +401,21 @@ package body Synth.Static_Oper is
end;
end Synth_Add_Uns_Uns;
+ function Synth_Add_Sgn_Sgn (L, R : Memtyp; Loc : Syn_Src) return Memtyp
+ is
+ pragma Unreferenced (Loc);
+ L_Arr : Std_Logic_Vector (1 .. Natural (Vec_Length (L.Typ)));
+ R_Arr : Std_Logic_Vector (1 .. Natural (Vec_Length (R.Typ)));
+ begin
+ To_Std_Logic_Vector (L, L_Arr);
+ To_Std_Logic_Vector (R, R_Arr);
+ declare
+ Res_Arr : constant Std_Logic_Vector := Add_Sgn_Sgn (L_Arr, R_Arr);
+ begin
+ return To_Memtyp (Res_Arr, L.Typ.Vec_El);
+ end;
+ end Synth_Add_Sgn_Sgn;
+
function Synth_Add_Sgn_Int (L, R : Memtyp; Loc : Syn_Src) return Memtyp
is
pragma Unreferenced (Loc);
@@ -458,6 +473,21 @@ package body Synth.Static_Oper is
end;
end Synth_Sub_Uns_Nat;
+ function Synth_Sub_Sgn_Sgn (L, R : Memtyp; Loc : Syn_Src) return Memtyp
+ is
+ pragma Unreferenced (Loc);
+ L_Arr : Std_Logic_Vector (1 .. Natural (Vec_Length (L.Typ)));
+ R_Arr : Std_Logic_Vector (1 .. Natural (Vec_Length (R.Typ)));
+ begin
+ To_Std_Logic_Vector (L, L_Arr);
+ To_Std_Logic_Vector (R, R_Arr);
+ declare
+ Res_Arr : constant Std_Logic_Vector := Sub_Sgn_Sgn (L_Arr, R_Arr);
+ begin
+ return To_Memtyp (Res_Arr, L.Typ.Vec_El);
+ end;
+ end Synth_Sub_Sgn_Sgn;
+
function Synth_Sub_Sgn_Int (L, R : Memtyp; Loc : Syn_Src) return Memtyp
is
pragma Unreferenced (Loc);
@@ -997,6 +1027,8 @@ package body Synth.Static_Oper is
when Iir_Predefined_Ieee_Numeric_Std_Add_Uns_Nat
| Iir_Predefined_Ieee_Std_Logic_Unsigned_Add_Slv_Int =>
return Synth_Add_Uns_Nat (Left, Right, Expr);
+ when Iir_Predefined_Ieee_Numeric_Std_Add_Sgn_Sgn =>
+ return Synth_Add_Sgn_Sgn (Left, Right, Expr);
when Iir_Predefined_Ieee_Numeric_Std_Sub_Uns_Uns =>
return Synth_Sub_Uns_Uns (Left, Right, Expr);
@@ -1005,6 +1037,8 @@ package body Synth.Static_Oper is
when Iir_Predefined_Ieee_Numeric_Std_Sub_Sgn_Int =>
return Synth_Sub_Sgn_Int (Left, Right, Expr);
+ when Iir_Predefined_Ieee_Numeric_Std_Sub_Sgn_Sgn =>
+ return Synth_Sub_Sgn_Sgn (Left, Right, Expr);
when Iir_Predefined_Ieee_Numeric_Std_Mul_Uns_Uns =>
return Synth_Mul_Uns_Uns (Left, Right, Expr);