diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-09-20 08:43:25 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-09-20 08:43:25 +0200 |
commit | 76a3614439971b635828b004c6041f3ffbceb83d (patch) | |
tree | 6c91b39b04cf046b0c9ef91e6a5f58b3b32e359a | |
parent | 1337962c251723acaf021a8df2efbc261804f88a (diff) | |
download | ghdl-76a3614439971b635828b004c6041f3ffbceb83d.tar.gz ghdl-76a3614439971b635828b004c6041f3ffbceb83d.tar.bz2 ghdl-76a3614439971b635828b004c6041f3ffbceb83d.zip |
synth: handle static resize. For #1460
-rw-r--r-- | src/synth/synth-ieee-numeric_std.adb | 29 | ||||
-rw-r--r-- | src/synth/synth-ieee-numeric_std.ads | 4 | ||||
-rw-r--r-- | src/synth/synth-static_oper.adb | 3 |
3 files changed, 36 insertions, 0 deletions
diff --git a/src/synth/synth-ieee-numeric_std.adb b/src/synth/synth-ieee-numeric_std.adb index 47e2e2a54..2c0951f3b 100644 --- a/src/synth/synth-ieee-numeric_std.adb +++ b/src/synth/synth-ieee-numeric_std.adb @@ -854,6 +854,35 @@ package body Synth.Ieee.Numeric_Std is return Res; end Shift_Vec; + function Resize_Vec (Val : Memtyp; + Size : Uns32; + Signed : Boolean) return Memtyp + is + Old_Size : constant Uns32 := Uns32 (Vec_Length (Val.Typ)); + Res : Memtyp; + Pad, B : Std_Ulogic; + begin + Res.Typ := Create_Res_Type (Val.Typ, Size); + Res := Create_Memory (Res.Typ); + + if Signed and then Old_Size > 0 then + Pad := Read_Std_Logic (Val.Mem, 0); + else + Pad := '0'; + end if; + + for I in 1 .. Size loop + if I <= Old_Size then + B := Read_Std_Logic (Val.Mem, I - 1); + else + B := Pad; + end if; + Write_Std_Logic (Res.Mem, I - 1, B); + end loop; + + return Res; + end Resize_Vec; + type Std_Logic_Vector_Type is array (Uns32 range <>) of Std_Ulogic; procedure Divmod (Num, Dem : Memtyp; Quot, Remain : Memtyp) diff --git a/src/synth/synth-ieee-numeric_std.ads b/src/synth/synth-ieee-numeric_std.ads index 2a75fe8b6..cd7a80cec 100644 --- a/src/synth/synth-ieee-numeric_std.ads +++ b/src/synth/synth-ieee-numeric_std.ads @@ -70,4 +70,8 @@ package Synth.Ieee.Numeric_Std is Amt : Uns32; Right : Boolean; Arith : Boolean) return Memtyp; + + function Resize_Vec (Val : Memtyp; + Size : Uns32; + Signed : Boolean) return Memtyp; end Synth.Ieee.Numeric_Std; diff --git a/src/synth/synth-static_oper.adb b/src/synth/synth-static_oper.adb index 7fa3a86fc..2da770ba1 100644 --- a/src/synth/synth-static_oper.adb +++ b/src/synth/synth-static_oper.adb @@ -858,6 +858,9 @@ package body Synth.Static_Oper is return Shift_Vec (Get_Memtyp (Param1), Uns32 (Read_Discrete (Param2)), True, True); + when Iir_Predefined_Ieee_Numeric_Std_Resize_Sgn_Nat => + return Resize_Vec + (Get_Memtyp (Param1), Uns32 (Read_Discrete (Param2)), True); when Iir_Predefined_Ieee_1164_To_Stdlogicvector_Bv => declare |