diff options
Diffstat (limited to 'testsuite/gna/issue2097/tb_fixed1.vhdl')
-rw-r--r-- | testsuite/gna/issue2097/tb_fixed1.vhdl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/testsuite/gna/issue2097/tb_fixed1.vhdl b/testsuite/gna/issue2097/tb_fixed1.vhdl new file mode 100644 index 000000000..1a2d02c6f --- /dev/null +++ b/testsuite/gna/issue2097/tb_fixed1.vhdl @@ -0,0 +1,43 @@ +library IEEE; +context IEEE.IEEE_std_context; + +library work; +use work.my_fixed_pkg.all; + +entity tb_fixed1 is +end; + +architecture arch of tb_fixed1 is + +begin + + process + constant ref : real := -9.96484375; + + subtype stype is sfixed(7 downto -8); + + -- Subtype not allowed as size_res argument of to_sfixed: + -- constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, stype)); + -- Therefore, a variable needs to be created: + variable fmt : stype; + constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, fmt)); + + variable sfmt : fmt'subtype; + + procedure report_sfixed(arg: sfixed) is begin report to_string(to_real(arg)); end procedure; + + begin + report_sfixed(stype(input)); + report_sfixed(stype(signed(input))); + + -- CRASH + report_sfixed(fmt'subtype(input)); + + -- However, sfmt, which is declared using fmt'subtype, does work + sfmt := stype(input); + report_sfixed(sfmt); + + wait; + end process; + +end; |