From ac6ce0e78b3a89e7fa83d0b0c80bfcd7ec0ef49b Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 5 Nov 2019 19:09:16 +0100 Subject: synth: do more constant propagation (on build2 --- src/synth/synth-expr.adb | 50 +++++++++--------------------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) (limited to 'src/synth/synth-expr.adb') diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb index f1bdeeead..fddc32954 100644 --- a/src/synth/synth-expr.adb +++ b/src/synth/synth-expr.adb @@ -51,7 +51,6 @@ package body Synth.Expr is function Get_Const_Discrete (V : Value_Acc) return Int64 is N : Net; - Inst : Instance; begin case V.Kind is when Value_Discrete => @@ -65,20 +64,7 @@ package body Synth.Expr is when others => raise Internal_Error; end case; - Inst := Get_Net_Parent (N); - case Get_Id (Inst) is - when Id_Const_UB32 => - declare - Va : constant Uns32 := Get_Param_Uns32 (Inst, 0); - Wd : constant Natural := Natural (Get_Width (N)); - T : Uns64; - begin - T := Shift_Left (Uns64 (Va), 64 - Wd); - return To_Int64 (Shift_Right_Arithmetic (T, 64 - Wd)); - end; - when others => - raise Internal_Error; - end case; + return Get_Net_Int64 (N); end Get_Const_Discrete; procedure From_Std_Logic (Enum : Int64; Val : out Uns32; Zx : out Uns32) is @@ -806,16 +792,20 @@ package body Synth.Expr is declare N : Net; begin - if Vtype.W > Dtype.W then + if Vtype.W /= Dtype.W then -- Truncate. -- TODO: check overflow. case Val.Kind is when Value_Net | Value_Wire => N := Get_Net (Val); - N := Build_Trunc - (Build_Context, Id_Utrunc, N, Dtype.W); - Set_Location (N, Loc); + if Vtype.Drange.Is_Signed then + N := Build2_Sresize + (Build_Context, N, Dtype.W, Get_Location (Loc)); + else + N := Build2_Uresize + (Build_Context, N, Dtype.W, Get_Location (Loc)); + end if; return Create_Value_Net (N, Dtype); when Value_Discrete => return Create_Value_Discrete (Val.Scal, Dtype); @@ -824,28 +814,6 @@ package body Synth.Expr is when others => raise Internal_Error; end case; - elsif Vtype.W < Dtype.W then - -- Extend. - case Val.Kind is - when Value_Discrete => - return Create_Value_Discrete (Val.Scal, Dtype); - when Value_Const => - return Create_Value_Discrete (Val.C_Val.Scal, Dtype); - when Value_Net - | Value_Wire => - N := Get_Net (Val); - if Vtype.Drange.Is_Signed then - N := Build_Extend - (Build_Context, Id_Sextend, N, Dtype.W); - else - N := Build_Extend - (Build_Context, Id_Uextend, N, Dtype.W); - end if; - Set_Location (N, Loc); - return Create_Value_Net (N, Dtype); - when others => - raise Internal_Error; - end case; else -- TODO: check overflow if sign differ. return Val; -- cgit v1.2.3