From 76a3614439971b635828b004c6041f3ffbceb83d Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Sun, 20 Sep 2020 08:43:25 +0200 Subject: synth: handle static resize. For #1460 --- src/synth/synth-ieee-numeric_std.adb | 29 +++++++++++++++++++++++++++++ src/synth/synth-ieee-numeric_std.ads | 4 ++++ src/synth/synth-static_oper.adb | 3 +++ 3 files changed, 36 insertions(+) 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 -- cgit v1.2.3