aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-04-22 06:29:09 +0200
committerTristan Gingold <tgingold@free.fr>2020-04-22 06:29:09 +0200
commit5841b245ee5f3d31b1c1856a443d6aed26fcf582 (patch)
tree87c52f61ccee86476f7f87b7d1d33431f9ecf735 /src/synth
parent5b9fb81982ef2405772013509016ecede70fd238 (diff)
downloadghdl-5841b245ee5f3d31b1c1856a443d6aed26fcf582.tar.gz
ghdl-5841b245ee5f3d31b1c1856a443d6aed26fcf582.tar.bz2
ghdl-5841b245ee5f3d31b1c1856a443d6aed26fcf582.zip
synth: minor refactoring.
Diffstat (limited to 'src/synth')
-rw-r--r--src/synth/netlists-folds.adb3
-rw-r--r--src/synth/types_utils.adb33
-rw-r--r--src/synth/types_utils.ads4
3 files changed, 38 insertions, 2 deletions
diff --git a/src/synth/netlists-folds.adb b/src/synth/netlists-folds.adb
index 01c210656..e591c35cf 100644
--- a/src/synth/netlists-folds.adb
+++ b/src/synth/netlists-folds.adb
@@ -231,8 +231,7 @@ package body Netlists.Folds is
Sh : constant Natural := Natural (Width'Min (Wn, W));
begin
V := Get_Net_Uns64 (I);
- V := Shift_Left (V, 64 - Sh);
- V := Shift_Right_Arithmetic (V, 64 - Sh);
+ V := Sext (V, Sh);
Res := Build2_Const_Int (Ctxt, To_Int64 (V), W);
end;
else
diff --git a/src/synth/types_utils.adb b/src/synth/types_utils.adb
new file mode 100644
index 000000000..861827520
--- /dev/null
+++ b/src/synth/types_utils.adb
@@ -0,0 +1,33 @@
+-- Utils for common types.
+-- Copyright (C) 2019 Tristan Gingold
+--
+-- GHDL is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by the Free
+-- Software Foundation; either version 2, or (at your option) any later
+-- version.
+--
+-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or
+-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+-- for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with GHDL; see the file COPYING. If not, write to the Free
+-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+-- 02111-1307, USA.
+
+package body Types_Utils is
+ function Sext (V : Uns64; Sz : Natural) return Uns64
+ is
+ Sh : constant Natural range 0 .. 64 := 64 - Sz;
+ begin
+ return Shift_Right_Arithmetic (Shift_Left (V, Sh), Sh);
+ end Sext;
+
+ function Sext (V : Uns32; Sz : Natural) return Uns32
+ is
+ Sh : constant Natural range 0 .. 32 := 32 - Sz;
+ begin
+ return Shift_Right_Arithmetic (Shift_Left (V, Sh), Sh);
+ end Sext;
+end Types_Utils;
diff --git a/src/synth/types_utils.ads b/src/synth/types_utils.ads
index 71bdf5399..04196e11c 100644
--- a/src/synth/types_utils.ads
+++ b/src/synth/types_utils.ads
@@ -35,4 +35,8 @@ package Types_Utils is
function To_Uns64 is new Ada.Unchecked_Conversion
(Fp64, Uns64);
+
+ -- Sign extend V: bit SZ is copied to bits SZ + 1 .. 63/31.
+ function Sext (V : Uns64; Sz : Natural) return Uns64;
+ function Sext (V : Uns32; Sz : Natural) return Uns32;
end Types_Utils;