aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2021-11-27 07:33:34 +0100
committerTristan Gingold <tgingold@free.fr>2021-11-27 07:33:34 +0100
commit40fc2c2020ea9ed7e4315d0a5c6fe52e5deaf5ef (patch)
tree05f714896f649d256d88e7a7bb3917f77e806574 /testsuite
parent15b84d1fbcfb26b2fb4a4467727eec691c5b73a4 (diff)
downloadghdl-40fc2c2020ea9ed7e4315d0a5c6fe52e5deaf5ef.tar.gz
ghdl-40fc2c2020ea9ed7e4315d0a5c6fe52e5deaf5ef.tar.bz2
ghdl-40fc2c2020ea9ed7e4315d0a5c6fe52e5deaf5ef.zip
testsuite/gna: add test from #1924
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/gna/issue1924/fixed_pkg.vhdl9
-rw-r--r--testsuite/gna/issue1924/float32_pkg.vhdl13
-rw-r--r--testsuite/gna/issue1924/test_float_to_sfixed.vhdl67
-rwxr-xr-xtestsuite/gna/issue1924/testsuite.sh11
4 files changed, 100 insertions, 0 deletions
diff --git a/testsuite/gna/issue1924/fixed_pkg.vhdl b/testsuite/gna/issue1924/fixed_pkg.vhdl
new file mode 100644
index 000000000..9b5a73a7a
--- /dev/null
+++ b/testsuite/gna/issue1924/fixed_pkg.vhdl
@@ -0,0 +1,9 @@
+library ieee;
+
+package Package_Fixed is new ieee.fixed_generic_pkg
+ generic map (
+ FIXED_ROUND_STYLE => ieee.fixed_float_types.FIXED_TRUNCATE,
+ FIXED_OVERFLOW_STYLE => ieee.fixed_float_types.FIXED_SATURATE,
+ FIXED_GUARD_BITS => 0,
+ NO_WARNING => false
+ );
diff --git a/testsuite/gna/issue1924/float32_pkg.vhdl b/testsuite/gna/issue1924/float32_pkg.vhdl
new file mode 100644
index 000000000..ce50fcd9a
--- /dev/null
+++ b/testsuite/gna/issue1924/float32_pkg.vhdl
@@ -0,0 +1,13 @@
+library ieee;
+
+package Package_Float32 is new ieee.float_generic_pkg
+ generic map (
+ FLOAT_EXPONENT_WIDTH => 8, -- float32'high
+ FLOAT_FRACTION_WIDTH => 23, -- -float32'low
+ FLOAT_ROUND_STYLE => ieee.fixed_float_types.ROUND_ZERO, -- Truncate
+ FLOAT_DENORMALIZE => false, -- Use IEEE extended floating
+ FLOAT_CHECK_ERROR => false, -- Turn on NAN and overflow processing
+ FLOAT_GUARD_BITS => 0, -- number of guard bits
+ NO_WARNING => false, -- show warnings
+ FIXED_PKG => work.Package_Fixed
+ );
diff --git a/testsuite/gna/issue1924/test_float_to_sfixed.vhdl b/testsuite/gna/issue1924/test_float_to_sfixed.vhdl
new file mode 100644
index 000000000..ce68af85d
--- /dev/null
+++ b/testsuite/gna/issue1924/test_float_to_sfixed.vhdl
@@ -0,0 +1,67 @@
+library ieee;
+use ieee.std_logic_1164.all;
+use ieee.numeric_std.all;
+use ieee.fixed_float_types.all;
+
+use work.Package_Float32.all;
+use work.Package_Fixed.all;
+
+entity test_Float_To_sFixed is
+end entity test_Float_To_sFixed;
+
+architecture RTL of test_Float_To_sFixed is
+
+procedure compute_and_show(sign : in std_logic; exponent : in Integer; fraction : in std_logic_vector(23-1 downto 0)) is
+ variable s : std_logic_vector(32-1 downto 0);
+ variable f : float32;
+ variable sf : sFixed(4-1 downto -2);
+ variable r : Real;
+begin
+ s := sign & std_logic_vector(to_unsigned(exponent, 8)) & fraction;
+ f := to_float(s, f);
+ sf := to_sFixed(f, sf, round_style => fixed_truncate);
+ r := to_real(f);
+
+ report "s : " & to_string(sign) & "."
+ & to_string(to_unsigned(exponent, 8)) & "."
+ & to_string(fraction)
+ & " -> " & to_string(r);
+ report "sf : " & to_string(sf);
+ report "";
+end compute_and_show;
+
+
+begin
+
+ process
+ begin
+ compute_and_show('0', 0, "00000000000000000000000"); -- 0
+ compute_and_show('0', 123, "00000000000000000000000"); -- 0.0625
+ compute_and_show('0', 124, "00000000000000000000000"); -- 0.125
+ compute_and_show('0', 125, "00000000000000000000000"); -- 0.25
+ compute_and_show('0', 126, "00000000000000000000000"); -- 0.5
+ compute_and_show('0', 127, "00000000000000000000000"); -- 1
+ compute_and_show('0', 127, "10000000000000000000000"); -- 1.5
+ compute_and_show('0', 127, "11000000000000000000000"); -- 1.75
+ compute_and_show('0', 127, "11100000000000000000000"); -- 1.875
+ compute_and_show('0', 127, "11110000000000000000000"); -- 1.875
+ report "------";
+ report "";
+ compute_and_show('1', 0, "00000000000000000000000"); -- -0
+ compute_and_show('1', 123, "00000000000000000000000"); -- -0.0625
+ compute_and_show('1', 124, "00000000000000000000000"); -- -0.125
+ compute_and_show('1', 125, "00000000000000000000000"); -- -0.25
+ compute_and_show('1', 126, "00000000000000000000000"); -- -0.5
+ compute_and_show('1', 127, "00000000000000000000000"); -- -1
+ compute_and_show('1', 127, "10000000000000000000000"); -- -1.5
+ compute_and_show('1', 127, "11000000000000000000000"); -- -1.75
+ compute_and_show('1', 127, "11100000000000000000000"); -- -1.875
+ compute_and_show('1', 127, "11110000000000000000000"); -- -1.9375
+ compute_and_show('1', 127, "11111000000000000000000"); -- -1.9375
+ compute_and_show('1', 127, "11111100000000000000000"); -- -1.9375
+ compute_and_show('1', 127, "11111110000000000000000"); -- -1.9375
+ compute_and_show('1', 127, "11111111000000000000000"); -- -1.9375
+ wait;
+ end process;
+
+end architecture RTL;
diff --git a/testsuite/gna/issue1924/testsuite.sh b/testsuite/gna/issue1924/testsuite.sh
new file mode 100755
index 000000000..28ae5727b
--- /dev/null
+++ b/testsuite/gna/issue1924/testsuite.sh
@@ -0,0 +1,11 @@
+#! /bin/sh
+
+. ../../testenv.sh
+
+export GHDL_STD_FLAGS=--std=08
+analyze fixed_pkg.vhdl float32_pkg.vhdl test_float_to_sfixed.vhdl
+elab_simulate test_float_to_sfixed
+
+clean
+
+echo "Test successful"