diff --git a/lib/fixed_ja/eval_fixed_ja.vhd b/lib/fixed_ja/eval_fixed_ja.vhd new file mode 100644 index 0000000..d5a2eda --- /dev/null +++ b/lib/fixed_ja/eval_fixed_ja.vhd @@ -0,0 +1,89 @@ +---------------------------------------------------------------------------------- +-- Company: +-- Engineer: +-- +-- Create Date: 00:28:57 07/10/2006 +-- Design Name: +-- Module Name: adder_registered - Behavioral +-- Project Name: +-- Target Devices: +-- Tool versions: +-- Description: +-- +-- Dependencies: +-- +-- Revision: +-- Revision 0.01 - File Created +-- Additional Comments: +-- +---------------------------------------------------------------------------------- +library IEEE; + +USE ieee.std_logic_1164.ALL; +USE ieee.numeric_std.ALL; +use IEEE.MATH_REAL.ALL; +use std.textio.all; -- Imports the standard textio package. + +library work; +use work.fixed_ja.all; + +---- Uncomment the following library declaration if instantiating +---- any Xilinx primitives in this code. +--library UNISIM; +--use UNISIM.VComponents.all; + +entity eval_fixed_ja is + Generic ( + nbits : integer := 32; + nbits_int : integer := 2); +end eval_fixed_ja; + +architecture Behavioral of eval_fixed_ja is +--------------------------------------------------------------------- + +type my_range is range 0 downto -10; + +begin + +process +constant c1 : ufixed_t (0 downto -10) := "11111111000"; +constant c2 : ufixed_t := to_ufixed(3.141592654, nbits, 4); +constant c3 : ufixed_t := to_ufixed(1.0/3.141592654, nbits, 1); +variable t1 : ufixed_t (uproto(8,1)'range); +variable L : line; + +variable slv : string (15 downto 1) := (others => '-'); +constant jens : string (10 downto 7) := "JENS"; + + +begin + + +-- slv := (1 => '1', 2 => 'J', jens'range => jens(jens'range), others => '1'); + + slv(jens'range) := "Jens"; + slv(jens'range) := jens; + + print_info(c2, "c2"); + print_info(c3, "c3"); + + t1 := to_ufixed(c1, t1, round_to_zero, saturate); + print_info(c1, "c1"); + print_info(t1, "t1"); + + t1 := to_ufixed(c1, t1, round_half_up, saturate); + print_info(c1, "c1"); + print_info(t1, "t1"); + + print_info(to_ufixed(c2*c2, 32, 2, none, saturate), "c2*c2"); + print_info(to_ufixed(c2*c3, 32, 0, round_half_up, none), "c2*c3"); + + write (L, slv); + writeline (output, L); + + wait; +end process; + +--------------------------------------------------------------------- +end Behavioral; + diff --git a/lib/fixed_ja/eval_fixed_ja_syn.vhd b/lib/fixed_ja/eval_fixed_ja_syn.vhd new file mode 100644 index 0000000..f8b093e --- /dev/null +++ b/lib/fixed_ja/eval_fixed_ja_syn.vhd @@ -0,0 +1,80 @@ +---------------------------------------------------------------------------------- +-- Company: +-- Engineer: +-- +-- Create Date: 00:28:57 07/10/2006 +-- Design Name: +-- Module Name: adder_registered - Behavioral +-- Project Name: +-- Target Devices: +-- Tool versions: +-- Description: +-- +-- Dependencies: +-- +-- Revision: +-- Revision 0.01 - File Created +-- Additional Comments: +-- +---------------------------------------------------------------------------------- +library IEEE; + +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +library ieee_proposed; +use ieee_proposed.fixed_pkg.all; +use std.textio.all; -- Imports the standard textio package. + +library work; + +---- Uncomment the following library declaration if instantiating +---- any Xilinx primitives in this code. +--library UNISIM; +--use UNISIM.VComponents.all; + +entity eval_fixed_ja is + Generic ( + nbits : integer := 8; + nbits_int : integer := 0 + ); + Port + ( + srst : in std_logic; + clk : in std_logic; + di1 : in std_logic_vector(nbits-1 downto 0); + di2 : in std_logic_vector(nbits-1 downto 0); + in_valid : in std_logic; + do : out std_logic_vector(nbits-1 downto 0); + out_valid : out std_logic + ); + +end eval_fixed_ja; + +architecture Behavioral of eval_fixed_ja is +signal op1, op2 : sfixed(nbits_int downto -(nbits-1)); +signal result : sfixed(2*nbits_int downto -(2*nbits-1)); +begin + +op1 <= to_sfixed(di1, op1); +op2 <= to_sfixed(di2, op2); + +do <= to_slv(resize(result, op1, false, false)); + +--------------------------------------------------------------------- +process(srst, clk, in_valid, di1, di2) +begin + if rising_edge(clk) then + if srst = '1' then + result <= (others => '0'); + elsif in_valid = '1' then + result <= op1 * op2; + end if; + out_valid <= in_valid; + end if; +end process; + + +--------------------------------------------------------------------- +end Behavioral; + diff --git a/lib/fixed_ja/tb_eval_fixed_ja.vhd b/lib/fixed_ja/tb_eval_fixed_ja.vhd new file mode 100644 index 0000000..4f8f2d6 --- /dev/null +++ b/lib/fixed_ja/tb_eval_fixed_ja.vhd @@ -0,0 +1,1033 @@ +---------------------------------------------------------------------------------- +-- Company: +-- Engineer: +-- +-- Create Date: 00:28:57 07/10/2006 +-- Design Name: +-- Module Name: tb_eval_fixed_ja - Behavioral +-- Project Name: +-- Target Devices: +-- Tool versions: +-- Description: +-- +-- Dependencies: +-- +-- Revision: +-- Revision 0.01 - File Created +-- Additional Comments: +-- +---------------------------------------------------------------------------------- +library IEEE; + +USE ieee.std_logic_1164.ALL; +USE ieee.numeric_std.ALL; +use IEEE.MATH_REAL.ALL; +use std.textio.all; -- Imports the standard textio package. + +library work; +use work.fixed_ja.all; +use work.PCK_FIO.all; + +---- Uncomment the following library declaration if instantiating +---- any Xilinx primitives in this code. +--library UNISIM; +--use UNISIM.VComponents.all; + +entity tb_eval_fixed_ja is + Generic ( + nbits : integer := 32; + nbits_int : integer := 2; + halt_on_error : boolean := true); + +end tb_eval_fixed_ja; + +architecture Behavioral of tb_eval_fixed_ja is +--------------------------------------------------------------------- + +type my_range is range 0 downto -10; + +--------------------------------------------------------------------- +procedure PerformRoundTest (op1 : in ufixed_t; required : in ufixed_t; rnd : in round_mode_t; sat : in saturate_mode_t) is +variable result : ufixed_t(required'range); +variable bad_result : boolean := false; + +variable L : line; +begin + + result := to_ufixed(op1, required, rnd, sat); + bad_result := not(result = required); + + write (L, "U: " & to_string(op1) & " => " & to_string(result)); + + if bad_result then + write (L, String'(" ...failed")); + writeline (output, L); + writeline (output, L); + write (L, String'("Bad result. Should be:") & CR & LF); + write (L, to_string(op1) & " => " & to_string(required)); + writeline (output, L); + writeline (output, L); + else + write (L, String'(" ...passed")); + writeline (output, L); + end if; + + assert not (bad_result and halt_on_error) report "Test failed" severity error; + +end PerformRoundTest; + +--------------------------------------------------------------------- +procedure PerformRoundTest (op1 : in sfixed_t; required : in sfixed_t; rnd : in round_mode_t; sat : in saturate_mode_t) is +variable result : sfixed_t(required'range); +variable bad_result : boolean := false; + +variable L : line; +begin + + result := to_sfixed(op1, required, rnd, sat); + bad_result := not(result = required); + + write (L, "S: " & to_string(op1) & " => " & to_string(result)); + + if bad_result then + write (L, String'(" ...failed")); + writeline (output, L); + writeline (output, L); + write (L, String'("Bad result. Should be:") & CR & LF); + write (L, to_string(op1) & " => " & to_string(required)); + writeline (output, L); + writeline (output, L); + else + write (L, String'(" ...passed")); + writeline (output, L); + end if; + + assert not (bad_result and halt_on_error) report "Test failed" severity error; + +end PerformRoundTest; + +--------------------------------------------------------------------- +procedure PerformArithTest (op1 : in ufixed_t; op : in character; op2 : in ufixed_t; required : in ufixed_t) is +variable result : ufixed_t(required'range); +variable bad_result : boolean := false; + +variable L : line; +begin + + case op is + when '+' => + result := op1 + op2; + + when '-' => + result := op1 - op2; + + when '*' => + result := op1 * op2; + + when others => + assert false report "PerformArithTest: Bad operand" severity error; + + end case; + + bad_result := not(result = required); + + write (L, "U: " & to_string(op1) & " " & op & " " & to_string(op2) & " = " & to_string(result)); + + if bad_result then + write (L, String'(" ...failed")); + writeline (output, L); + writeline (output, L); + write (L, String'("Bad result. Should be:") & CR & LF); + write (L, to_string(op1) & " " & op & " " & to_string(op2) & " = " & to_string(required)); + writeline (output, L); + writeline (output, L); + else + write (L, String'(" ...passed")); + writeline (output, L); + end if; + + assert not (bad_result and halt_on_error) report "Test failed" severity error; + +end PerformArithTest; + +--------------------------------------------------------------------- +procedure PerformArithTest (op1 : in sfixed_t; op : in character; op2 : in sfixed_t; required : in sfixed_t) is +variable result : sfixed_t(required'range); +variable bad_result : boolean := false; + +variable L : line; +begin + + case op is + when '+' => + result := op1 + op2; + + when '-' => + result := op1 - op2; + + when '*' => + result := op1 * op2; + + when others => + assert false report "PerformArithTest: Bad operand" severity error; + + end case; + + bad_result := not(result = required); + + write (L, "S: " & to_string(op1) & " " & op & " " & to_string(op2) & " = " & to_string(result)); + + if bad_result then + write (L, String'(" ...failed")); + writeline (output, L); + writeline (output, L); + write (L, String'("Bad result. Should be:") & CR & LF); + write (L, to_string(op1) & " " & op & " " & to_string(op2) & " = " & to_string(required)); + writeline (output, L); + writeline (output, L); + else + write (L, String'(" ...passed")); + writeline (output, L); + end if; + + assert not (bad_result and halt_on_error) report "Test failed" severity error; + +end PerformArithTest; + +--------------------------------------------------------------------- +begin + +process + +variable rnd : round_mode_t := none; +variable sat : saturate_mode_t := none; +file RESULT: text open write_mode is "STD_OUTPUT"; +file file_sum_test_u: text open write_mode is "sum_test_u.txt"; +file file_sum_test_s: text open write_mode is "sum_test_s.txt"; +variable L, STR: line; +constant uconst0 : ufixed_t := to_ufixed(string'("1.000")); +constant sconst0 : sfixed_t := to_sfixed(string'("1.000")); +constant uconst1 : ufixed_t := to_ufixed(string'("1.001")); +constant sconst1 : sfixed_t := to_sfixed(string'("1.001")); +constant s1 : sfixed_t := to_sfixed(string'("0111101010101.01100010110111010011100101101101011111010101101000110100101010101010111011010000111011000110000101000001010010100111")); +constant s2 : sfixed_t := to_sfixed(string'("0010110111011.11100001100111000100101000110101111111101101000100001110010011100111000110110110010100101001010010100111100011000010")); +variable r1 : sfixed_t(sproto(s1, '*', s2)'range); +variable ures : ufixed_t(uconst0'range); +variable sres : sfixed_t(sconst0'range); +constant incu : ufixed_t := to_ufixed(string'(".0000001")); +variable yu : ufixed_t(uproto(4,0)'range); +variable xu : ufixed_t(uproto(8,1)'range); +constant incs : sfixed_t := to_sfixed(string'(".0000001")); +variable ys : sfixed_t(sproto(5,0)'range); +variable xs : sfixed_t(sproto(9,1)'range); +begin + +-- slv := (1 => '1', 2 => 'J', jens'range => jens(jens'range), others => '1'); + + rnd := round_nearest; + sat := saturate; + + -- 1.) Sum test + xu := to_ufixed(0, xu); + for i in 0 to 2**xu'length-1 loop + yu := to_ufixed(xu, yu, rnd, sat); + fprint(file_sum_test_u, L,"%s %s\n", REAL'image(to_real(xu)), REAL'image(to_real(yu))); +-- fprint(file_sum_test_u, L,"%s %s\n", to_string(xu), to_string(yu)); + xu := xu + 1; + end loop; + xs := to_sfixed(-(2**(xs'length-1)-1), xs); + for i in 0 to 2**xs'length-1 loop + ys := to_sfixed(xs, ys, rnd, sat); + fprint(file_sum_test_s, L,"%s %s\n", REAL'image(to_real(xs)), REAL'image(to_real(ys))); +-- fprint(file_sum_test_s, L,"%s %s\n", to_string(xs), to_string(ys)); + xs := xs + 1; + end loop; + + write (L, String'("Fixed Point Library Testbench 0.1")); + writeline (output, L); + + write (L, String'("----------------------" & CR & LF)); + write (L, String'(" Without saturation " & CR & LF)); + write (L, String'("----------------------" & CR & LF)); + writeline (output, L); + + --------------------------------------------------------------------- + write (L, String'("* No rounding" & CR & LF)); + writeline (output, L); + + rnd := none; + sat := none; + + PerformRoundTest (to_ufixed(string'("101.0011")), to_ufixed(string'("01.0011")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.001101")), to_ufixed(string'("001.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.01")), to_ufixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1010.1")), to_ufixed(string'("10.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.11")), to_ufixed(string'("101.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".11")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".1011")), to_ufixed(string'("0.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.0000000001")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.000000001")), to_ufixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.1010")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("101.0011")), to_sfixed(string'("01.0011")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.001101")), to_sfixed(string'("-001.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-101.01")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1010.1")), to_sfixed(string'("10.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.11")), to_sfixed(string'("101.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.11")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.1011")), to_sfixed(string'("-0.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.0000000001")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000001")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000001")), to_sfixed(string'("-1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.000000001")), to_sfixed(string'("-10.000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.101")), to_sfixed(string'("-10.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.1010")), rnd, sat); + + --------------------------------------------------------------------- + writeline (output, L); + write (L, String'("* Round to zero" & CR & LF)); + writeline (output, L); + + rnd := round_to_zero; + sat := none; + + PerformRoundTest (to_ufixed(string'("101.0011")), to_ufixed(string'("01.0011")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.001101")), to_ufixed(string'("001.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.01")), to_ufixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1010.1")), to_ufixed(string'("10.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.11")), to_ufixed(string'("101.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".11")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".1011")), to_ufixed(string'("0.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.0000000001")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.000000001")), to_ufixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.1010")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("101.0011")), to_sfixed(string'("01.0011")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.001101")), to_sfixed(string'("-001.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-101.01")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1010.1")), to_sfixed(string'("10.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.11")), to_sfixed(string'("101.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.11")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.1011")), to_sfixed(string'("-0.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.0000000001")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000001")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000001")), to_sfixed(string'("-1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.000000001")), to_sfixed(string'("-10.000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.101")), to_sfixed(string'("-10.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.1010")), rnd, sat); + + --------------------------------------------------------------------- + + writeline (output, L); + write (L, String'("* Round to infinity" & CR & LF)); + writeline (output, L); + + rnd := round_pos_infinity; + sat := none; + + PerformRoundTest (to_ufixed(string'("101.0011")), to_ufixed(string'("01.0011")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.001101")), to_ufixed(string'("010.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.01")), to_ufixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1010.1")), to_ufixed(string'("11.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.11")), to_ufixed(string'("110.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".11")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".1011")), to_ufixed(string'("0.11")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.000000001")), to_ufixed(string'("10.001")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.11")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.1010")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("101.0011")), to_sfixed(string'("01.0011")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.001101")), to_sfixed(string'("-010.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-101.01")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1010.1")), to_sfixed(string'("11.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.11")), to_sfixed(string'("110.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.11")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.1011")), to_sfixed(string'("-0.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.0000000001")), to_sfixed(string'("1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000001")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.000000001")), to_sfixed(string'("-10.000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.101")), to_sfixed(string'("-10.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.1010")), rnd, sat); + + --------------------------------------------------------------------- + writeline (output, L); + write (L, String'("* Round half up" & CR & LF)); + writeline (output, L); + + rnd := round_half_up; + sat := none; + + PerformRoundTest (to_ufixed(string'("101.0011")), to_ufixed(string'("01.0011")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.001101")), to_ufixed(string'("001.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.01")), to_ufixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1010.1")), to_ufixed(string'("11.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.11")), to_ufixed(string'("110.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".11")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".1011")), to_ufixed(string'("0.11")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.0000000001")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.000000001")), to_ufixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.11")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.1010")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("101.0011")), to_sfixed(string'("01.0011")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.001101")), to_sfixed(string'("-010.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-101.01")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1010.1")), to_sfixed(string'("11.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.11")), to_sfixed(string'("110.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.11")), to_sfixed(string'("-1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.1011")), to_sfixed(string'("-0.11")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.0000000001")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000001")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.000000001")), to_sfixed(string'("-10.000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.1011")), to_sfixed(string'("-10.11")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.101")), to_sfixed(string'("-10.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-0.1111")), to_sfixed(string'("-0.111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-0.11110")), to_sfixed(string'("-0.111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-0.11111")), to_sfixed(string'("-1.000")), rnd, sat); + + --------------------------------------------------------------------- + writeline (output, L); + write (L, String'("* Round convergent" & CR & LF)); + writeline (output, L); + + rnd := round_convergent; + sat := none; + + PerformRoundTest (to_ufixed(string'("01.001")), to_ufixed(string'("01.00")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.0010")), to_ufixed(string'("01.00")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.0011")), to_ufixed(string'("01.01")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.011")), to_ufixed(string'("01.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.0110")), to_ufixed(string'("01.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.0111")), to_ufixed(string'("01.10")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("01.001")), to_sfixed(string'("01.00")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.0010")), to_sfixed(string'("01.00")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.0011")), to_sfixed(string'("01.01")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.011")), to_sfixed(string'("01.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.0110")), to_sfixed(string'("01.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.0111")), to_sfixed(string'("01.10")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("-01.001")), to_sfixed(string'("-01.00")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0010")), to_sfixed(string'("-01.00")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0011")), to_sfixed(string'("-01.01")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.011")), to_sfixed(string'("-01.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0110")), to_sfixed(string'("-01.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0111")), to_sfixed(string'("-01.10")), rnd, sat); + + --------------------------------------------------------------------- + + writeline (output, L); + write (L, String'("----------------------" & CR & LF)); + write (L, String'(" With saturation " & CR & LF)); + write (L, String'("----------------------" & CR & LF)); + writeline (output, L); + + write (L, String'("* No rounding" & CR & LF)); + writeline (output, L); + + rnd := none; + sat := saturate; + + PerformRoundTest (to_ufixed(string'("101.0011")), to_ufixed(string'("11.1111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.001101")), to_ufixed(string'("001.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.01")), to_ufixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1010.1")), to_ufixed(string'("11.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.11")), to_ufixed(string'("101.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".11")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".1011")), to_ufixed(string'("0.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.0000000001")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.000000001")), to_ufixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'(".111111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.1010")), rnd, sat); + + PerformRoundTest (to_ufixed(string'("1.0000")), to_ufixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.000")), to_ufixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("11.000")), to_ufixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.1000")), to_ufixed(string'(".10000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("00.100")), to_ufixed(string'(".10000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0001")), to_ufixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.001")), to_ufixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.010")), to_ufixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("11.001")), to_ufixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.1001")), to_ufixed(string'(".10010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("00.101")), to_ufixed(string'(".10100")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.000000000000000001")), to_ufixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.00000000000000001")), to_ufixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.00000000000000")), to_ufixed(string'(".111111111111111")), rnd, sat); + + + PerformRoundTest (to_sfixed(string'("-101.0011")), to_sfixed(string'("-11.1111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.001101")), to_sfixed(string'("001.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.01")), to_sfixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1010.1")), to_sfixed(string'("11.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.11")), to_sfixed(string'("101.")), rnd, sat); + PerformRoundTest (to_sfixed(string'(".11")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'(".1011")), to_sfixed(string'("0.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-0.0000000001")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000001")), to_sfixed(string'("-1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.000000001")), to_sfixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.")), to_sfixed(string'("-.111111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-0.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.101")), to_sfixed(string'("-010.1010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.101")), to_sfixed(string'("-10.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-10.101")), to_sfixed(string'("-10.1010")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("-1.0000")), to_sfixed(string'("-.11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.000")), to_sfixed(string'("-.11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-11.000")), to_sfixed(string'("-.11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-0.1000")), to_sfixed(string'("-.10000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-00.100")), to_sfixed(string'("-.10000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0001")), to_sfixed(string'("-.11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.001")), to_sfixed(string'("-.11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.010")), to_sfixed(string'("-.11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-11.001")), to_sfixed(string'("-.11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-0.1001")), to_sfixed(string'("-.10010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-00.101")), to_sfixed(string'("-.10100")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("-1.000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.00000000000000")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.000000000000000001")), to_sfixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.00000000000000001")), to_sfixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.00000000000000")), to_sfixed(string'(".111111111111111")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("1.0000")), to_sfixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.000")), to_sfixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.1000")), to_sfixed(string'(".10000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("00.100")), to_sfixed(string'(".10000")), rnd, sat); + + + --------------------------------------------------------------------- + + writeline (output, L); + write (L, String'("* Round to zero" & CR & LF)); + writeline (output, L); + + rnd := round_to_zero; + sat := saturate; + + PerformRoundTest (to_ufixed(string'("101.0011")), to_ufixed(string'("11.1111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.001101")), to_ufixed(string'("001.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.01")), to_ufixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1010.1")), to_ufixed(string'("11.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.11")), to_ufixed(string'("101.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".11")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".1011")), to_ufixed(string'("0.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.0000000001")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.000000001")), to_ufixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'(".111111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.10")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.000000000000000001")), to_ufixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.00000000000000001")), to_ufixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.00000000000000")), to_ufixed(string'(".111111111111111")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("101.0011")), to_sfixed(string'("11.1111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.001101")), to_sfixed(string'("001.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.01")), to_sfixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1010.1")), to_sfixed(string'("11.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.11")), to_sfixed(string'("101.")), rnd, sat); + PerformRoundTest (to_sfixed(string'(".11")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'(".1011")), to_sfixed(string'("0.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.0000000001")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.000000001")), to_sfixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'(".111111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.10")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.1010")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("-1.000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.00000000000000")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.000000000000000001")), to_sfixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.00000000000000001")), to_sfixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.00000000000000")), to_sfixed(string'(".111111111111111")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("1.0000")), to_sfixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.000")), to_sfixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.1000")), to_sfixed(string'(".10000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("00.100")), to_sfixed(string'(".10000")), rnd, sat); + + --------------------------------------------------------------------- + + writeline (output, L); + write (L, String'("* Round to infinity" & CR & LF)); + writeline (output, L); + + rnd := round_pos_infinity; + sat := saturate; + + PerformRoundTest (to_ufixed(string'("101.0011")), to_ufixed(string'("11.1111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.001101")), to_ufixed(string'("010.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.01")), to_ufixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1010.1")), to_ufixed(string'("11.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.11")), to_ufixed(string'("110.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".11")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".1011")), to_ufixed(string'("0.11")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.000000001")), to_ufixed(string'("10.001")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'(".111111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.11")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.000000000000000001")), to_ufixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.00000000000000001")), to_ufixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.00000000000000")), to_ufixed(string'(".111111111111111")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("101.0011")), to_sfixed(string'("11.1111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.001101")), to_sfixed(string'("010.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.01")), to_sfixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1010.1")), to_sfixed(string'("11.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.11")), to_sfixed(string'("110.")), rnd, sat); + PerformRoundTest (to_sfixed(string'(".11")), to_sfixed(string'("1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'(".1011")), to_sfixed(string'("0.11")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.0000000001")), to_sfixed(string'("1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.000000001")), to_sfixed(string'("10.001")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'(".111111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.11")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.1010")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("-1.000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.00000000000000")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.000000000000000001")), to_sfixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.00000000000000001")), to_sfixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.00000000000000")), to_sfixed(string'(".111111111111111")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("1.0000")), to_sfixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.000")), to_sfixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.1000")), to_sfixed(string'(".10000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("00.100")), to_sfixed(string'(".10000")), rnd, sat); + + --------------------------------------------------------------------- + + writeline (output, L); + write (L, String'("* Round half up" & CR & LF)); + writeline (output, L); + + rnd := round_half_up; + sat := saturate; + + PerformRoundTest (to_ufixed(string'("101.0011")), to_ufixed(string'("11.1111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.001101")), to_ufixed(string'("001.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.01")), to_ufixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1010.1")), to_ufixed(string'("11.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("101.11")), to_ufixed(string'("110.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".11")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'(".1011")), to_ufixed(string'("0.11")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.0000000001")), to_ufixed(string'("0.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.0000000001")), to_ufixed(string'("1.")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.000000001")), to_ufixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.")), to_ufixed(string'(".111111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("0.")), to_ufixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.11")), rnd, sat); + PerformRoundTest (to_ufixed(string'("10.101")), to_ufixed(string'("10.1010")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.000000000000000001")), to_ufixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("01.00000000000000001")), to_ufixed(string'(".111111111111111")), rnd, sat); + PerformRoundTest (to_ufixed(string'("1.00000000000000")), to_ufixed(string'(".111111111111111")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("101.0011")), to_sfixed(string'("11.1111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.001101")), to_sfixed(string'("001.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.01")), to_sfixed(string'("1.1")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1010.1")), to_sfixed(string'("11.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("101.11")), to_sfixed(string'("110.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.11")), to_sfixed(string'("-1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-.1")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'(".1011")), to_sfixed(string'("0.11")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.0000000001")), to_sfixed(string'("0.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("1.0")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.0000000001")), to_sfixed(string'("1.")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.000000001")), to_sfixed(string'("10.000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'("1.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'("0.00000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("1.")), to_sfixed(string'(".111111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.")), to_sfixed(string'(".000000000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("010.1010")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.11")), rnd, sat); + PerformRoundTest (to_sfixed(string'("10.101")), to_sfixed(string'("10.1010")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("-1.000000000000000000")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000000")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0000000000000")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0000000000000")), to_sfixed(string'("-.11111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0000000000001")), to_sfixed(string'("-.11111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0000000000000")), to_sfixed(string'("-.1111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0000000000001")), to_sfixed(string'("-.1111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-00.1111111111111")), to_sfixed(string'("-.111111111111100")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-00.111111111111111")), to_sfixed(string'("-.11111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-00.111111111111111")), to_sfixed(string'("-1.0000000000000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.00000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.000000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.000000000000000000001")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.00000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.0000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.000000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.00000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.0000000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-01.000000000000000000011")), to_sfixed(string'("-.111111111111111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("-1.00000000000000")), to_sfixed(string'("-.111111111111111")), rnd, sat); + + PerformRoundTest (to_sfixed(string'("1.0000")), to_sfixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("01.000")), to_sfixed(string'(".11111")), rnd, sat); + PerformRoundTest (to_sfixed(string'("0.1000")), to_sfixed(string'(".10000")), rnd, sat); + PerformRoundTest (to_sfixed(string'("00.100")), to_sfixed(string'(".10000")), rnd, sat); + + --------------------------------------------------------------------- + + writeline (output, L); + write (L, String'("----------------------" & CR & LF)); + write (L, String'(" Arithmetic Test " & CR & LF)); + write (L, String'("----------------------" & CR & LF)); + +if true then + + PerformArithTest(to_ufixed(0.500, 8, 0), '+', to_ufixed(0.250, 8, 0), to_ufixed(0.500 + 0.250, 9, 1)); + PerformArithTest(to_ufixed(0.375, 8, 0), '+', to_ufixed(0.250, 8, 0), to_ufixed(0.375 + 0.250, 9, 1)); + PerformArithTest(to_ufixed(0.375, 8, 1), '-', to_ufixed(0.250, 8, 0), to_ufixed(0.375 - 0.250, 9, 1)); + PerformArithTest(to_ufixed(0.500, 8, 0), '+', to_ufixed(0.250, 8, 0), to_ufixed(0.500 + 0.250, 9, 1)); + PerformArithTest(to_ufixed(0.500, 8, 0), '-', to_ufixed(0.250, 8, 0), to_ufixed(0.500 - 0.250, 8, 0)); + PerformArithTest(to_ufixed(0.250, 8, 0), '+', to_ufixed(0.250, 8, 0), to_ufixed(0.250 + 0.250, 9, 1)); + PerformArithTest(to_ufixed(0.250, 8, 0), '-', to_ufixed(0.250, 8, 0), to_ufixed(0.250 - 0.250, 8, 0)); + PerformArithTest(to_ufixed(0.250, 4, 0), '+', to_ufixed(0.250, 8, 3), to_ufixed(0.250 + 0.250, 8, 3)); + + PerformArithTest(to_ufixed(string'("1.0000")), '+', to_ufixed(string'("1.0000")), to_ufixed(string'("10.0000"))); + PerformArithTest(to_ufixed(string'("0.1001")), '+', to_ufixed(string'("0.0110")), to_ufixed(string'("00.1111"))); + PerformArithTest(to_ufixed(string'("0.0011")), '+', to_ufixed(string'("0.0110")), to_ufixed(string'("00.1001"))); + PerformArithTest(to_ufixed(string'("0.1111")), '+', to_ufixed(string'("1.0001")), to_ufixed(string'("10.0000"))); + PerformArithTest(to_ufixed(string'("10.0000")), '-', to_ufixed(string'("1.0000")), to_ufixed(string'("01.0000"))); + PerformArithTest(to_ufixed(string'("00.1111")), '-', to_ufixed(string'("0.1001")), to_ufixed(string'("00.0110"))); + PerformArithTest(to_ufixed(string'("00.1001")), '-', to_ufixed(string'("0.0011")), to_ufixed(string'("00.0110"))); + PerformArithTest(to_ufixed(string'("10.0000")), '-', to_ufixed(string'("0.1111")), to_ufixed(string'("01.0001"))); + + PerformArithTest(to_ufixed(0.500, 8, 0), '*', to_ufixed(4.500, 8, 3), to_ufixed(0.500 * 4.500, 16, 2)); + PerformArithTest(to_ufixed(0.500, 8, 0), '*', to_ufixed(0.500, 8, 0), to_ufixed(0.500 * 0.500, 16, 0)); + PerformArithTest(to_ufixed(0.500, 8, 1), '*', to_ufixed(0.500, 8, 0), to_ufixed(0.500 * 0.500, 16, 0)); + PerformArithTest(to_ufixed(0.500, 8, 1), '*', to_ufixed(0.500, 8, 1), to_ufixed(0.500 * 0.500, 16, 2)); + + PerformArithTest(to_ufixed(0.500, 8, 1), '*', to_ufixed(0.500, 8, 0), to_ufixed(0.500 * 0.500, 16, 0)); + PerformArithTest(to_ufixed(0.500, 8, 2), '*', to_ufixed(0.500, 8, 1), to_ufixed(0.500 * 0.500, 16, 3)); + PerformArithTest(to_ufixed(1.500, 9, 2), '*', to_ufixed(0.500, 8, 0), to_ufixed(1.500 * 0.500, 17, 1)); + PerformArithTest(to_ufixed(0.500, 8, 0), '*', to_ufixed(1.500, 9, 2), to_ufixed(1.500 * 0.500, 17, 1)); + PerformArithTest(to_ufixed(1.500, 8, 2), '*', to_ufixed(0.500, 9, 0), to_ufixed(1.500 * 0.500, 17, 1)); + PerformArithTest(to_ufixed(0.500, 9, 0), '*', to_ufixed(1.500, 8, 2), to_ufixed(1.500 * 0.500, 17, 1)); + + PerformArithTest(to_sfixed(0.375, 4, 0), '+', to_sfixed(0.250, 8, 0), to_sfixed(0.375 + 0.250, 9, 1)); + PerformArithTest(to_sfixed(0.375, 8, 0), '-', to_sfixed(0.250, 8, 0), to_sfixed(0.375 - 0.250, 8, 0)); + PerformArithTest(to_sfixed(0.500, 8, 0), '+', to_sfixed(0.250, 8, 0), to_sfixed(0.500 + 0.250, 9, 1)); + PerformArithTest(to_sfixed(0.500, 8, 0), '-', to_sfixed(0.250, 8, 0), to_sfixed(0.500 - 0.250, 8, 0)); + PerformArithTest(to_sfixed(0.250, 8, 0), '+', to_sfixed(0.250, 8, 0), to_sfixed(0.250 + 0.250, 9, 1)); + PerformArithTest(to_sfixed(0.250, 8, 0), '-', to_sfixed(0.250, 8, 0), to_sfixed(0.250 - 0.250, 8, 0)); + PerformArithTest(to_sfixed(0.250, 4, 0), '+', to_sfixed(0.250, 8, 3), to_sfixed(0.250 + 0.250, 8, 3)); + PerformArithTest(to_sfixed(-0.500, 4, 0), '*', to_sfixed(4.500, 8, 3), to_sfixed(-0.500 * 4.500, 12, 2)); + PerformArithTest(to_sfixed(-0.500, 8, 0), '*', to_sfixed(0.500, 8, 0), to_sfixed(-0.500 * 0.500, 16, 0)); + PerformArithTest(to_sfixed(-0.500, 8, 1), '*', to_sfixed(0.500, 8, 0), to_sfixed(-0.500 * 0.500, 16, 0)); + PerformArithTest(to_sfixed(-0.500, 8, 1), '*', to_sfixed(0.500, 8, 1), to_sfixed(-0.500 * 0.500, 16, 2)); + PerformArithTest(to_sfixed(0.500, 4, 0), '*', to_sfixed(4.500, 8, 3), to_sfixed(0.500 * 4.500, 12, 2)); + PerformArithTest(to_sfixed(0.500, 8, 0), '*', to_sfixed(0.500, 8, 0), to_sfixed(0.500 * 0.500, 16, 0)); + PerformArithTest(to_sfixed(0.500, 8, 1), '*', to_sfixed(0.500, 8, 0), to_sfixed(0.500 * 0.500, 16, 0)); + PerformArithTest(to_sfixed(0.500, 8, 1), '*', to_sfixed(0.500, 8, 1), to_sfixed(0.500 * 0.500, 16, 2)); + + fprint(RESULT, L, "Test finished\n\n"); + +end if; +if true then + + fprint(RESULT, L, "\nPositive ufixed\n"); + for i in 0 to uconst0'length loop + ures := uconst0 sla i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(uconst0), fo(i), to_string(ures)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to uconst0'length loop + ures := uconst0 sla -i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(uconst0), fo(-i), to_string(ures)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to uconst0'length loop + ures := uconst0 sra i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(uconst0), fo(i), to_string(ures)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to uconst0'length loop + ures := uconst0 sra -i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(uconst0), fo(-i), to_string(ures)); + end loop; + + fprint(RESULT, L, "\nPositive sfixed\n"); + for i in 0 to sconst0'length loop + sres := sconst0 sla i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(sconst0), fo(i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst0'length loop + sres := sconst0 sla -i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(sconst0), fo(-i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst0'length loop + sres := sconst0 sra i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(sconst0), fo(i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst0'length loop + sres := sconst0 sra -i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(sconst0), fo(-i), to_string(sres)); + end loop; + + fprint(RESULT, L, "\nNegative sfixed\n"); + for i in 0 to sconst0'length loop + sres := -sconst0 sla i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(-sconst0), fo(i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst0'length loop + sres := -sconst0 sla -i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(-sconst0), fo(-i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst0'length loop + sres := -sconst0 sra i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(-sconst0), fo(i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst0'length loop + sres := -sconst0 sra -i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(-sconst0), fo(-i), to_string(sres)); + end loop; + + + fprint(RESULT, L, "\nPositive ufixed\n"); + for i in 0 to uconst1'length loop + ures := uconst1 sla i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(uconst1), fo(i), to_string(ures)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to uconst1'length loop + ures := uconst1 sla -i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(uconst1), fo(-i), to_string(ures)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to uconst1'length loop + ures := uconst1 sra i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(uconst1), fo(i), to_string(ures)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to uconst1'length loop + ures := uconst1 sra -i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(uconst1), fo(-i), to_string(ures)); + end loop; + + fprint(RESULT, L, "\nPositive sfixed\n"); + for i in 0 to sconst1'length loop + sres := sconst1 sla i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(sconst1), fo(i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst1'length loop + sres := sconst1 sla -i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(sconst1), fo(-i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst1'length loop + sres := sconst1 sra i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(sconst1), fo(i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst1'length loop + sres := sconst1 sra -i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(sconst1), fo(-i), to_string(sres)); + end loop; + + fprint(RESULT, L, "\nNegative sfixed\n"); + for i in 0 to sconst1'length loop + sres := -sconst1 sla i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(-sconst1), fo(i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst1'length loop + sres := -sconst1 sla -i; + fprint(RESULT, L, "%s sla %d = %s\n", to_string(-sconst1), fo(-i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst1'length loop + sres := -sconst1 sra i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(-sconst1), fo(i), to_string(sres)); + end loop; + fprint(RESULT, L, "\n"); + for i in 0 to sconst1'length loop + sres := -sconst1 sra -i; + fprint(RESULT, L, "%s sra %d = %s\n", to_string(-sconst1), fo(-i), to_string(sres)); + end loop; + +end if; + +if true then + write (L, String'("Positive ufixed"));writeline (output, L); + print_info(to_ufixed(0.5,5,0)*to_ufixed(0.5,5,0), string'("U")); + print_info(to_ufixed(0.5,5,1)*to_ufixed(0.5,5,0), string'("U")); + print_info(to_ufixed(0.5,5,0)*to_ufixed(0.5,5,1), string'("U")); + print_info(to_ufixed(0.5,5,1)*to_ufixed(0.5,5,1), string'("U")); + print_info(to_ufixed(0.5,5,0)*to_ufixed(0.5,5,2), string'("U")); + print_info(to_ufixed(0.5,5,2)*to_ufixed(0.5,5,0), string'("U")); + + write (L, String'("Positive sfixed"));writeline (output, L); + print_info(to_sfixed(0.5,5,0)*to_sfixed(0.5,5,0), string'("S")); + print_info(to_sfixed(0.5,5,1)*to_sfixed(0.5,5,0), string'("S")); + print_info(to_sfixed(0.5,5,0)*to_sfixed(0.5,5,1), string'("S")); + print_info(to_sfixed(0.5,5,1)*to_sfixed(0.5,5,1), string'("S")); + print_info(to_sfixed(0.5,5,0)*to_sfixed(0.5,5,2), string'("S")); + print_info(to_sfixed(0.5,5,2)*to_sfixed(0.5,5,0), string'("S")); + + write (L, String'("Neg/Pos sfixed"));writeline (output, L); + print_info(to_sfixed(-0.5,5,0)*to_sfixed(0.5,5,0), string'("S")); + print_info(to_sfixed(-0.5,5,1)*to_sfixed(0.5,5,0), string'("S")); + print_info(to_sfixed(-0.5,5,0)*to_sfixed(0.5,5,1), string'("S")); + print_info(to_sfixed(-0.5,5,1)*to_sfixed(0.5,5,1), string'("S")); + print_info(to_sfixed(-0.5,5,0)*to_sfixed(0.5,5,2), string'("S")); + print_info(to_sfixed(-0.5,5,2)*to_sfixed(0.5,5,0), string'("S")); + + write (L, String'("Pos/Neg sfixed"));writeline (output, L); + print_info(to_sfixed(0.5,5,0)*to_sfixed(-0.5,5,0), string'("S")); + print_info(to_sfixed(0.5,5,1)*to_sfixed(-0.5,5,0), string'("S")); + print_info(to_sfixed(0.5,5,0)*to_sfixed(-0.5,5,1), string'("S")); + print_info(to_sfixed(0.5,5,1)*to_sfixed(-0.5,5,1), string'("S")); + print_info(to_sfixed(0.5,5,0)*to_sfixed(-0.5,5,2), string'("S")); + print_info(to_sfixed(0.5,5,2)*to_sfixed(-0.5,5,0), string'("S")); + + write (L, String'("Neg/Neg sfixed"));writeline (output, L); + print_info(to_sfixed(-0.5,5,0)*to_sfixed(-0.5,5,0), string'("S")); + print_info(to_sfixed(-0.5,5,1)*to_sfixed(-0.5,5,0), string'("S")); + print_info(to_sfixed(-0.5,5,0)*to_sfixed(-0.5,5,1), string'("S")); + print_info(to_sfixed(-0.5,5,1)*to_sfixed(-0.5,5,1), string'("S")); + print_info(to_sfixed(-0.5,5,0)*to_sfixed(-0.5,5,2), string'("S")); + print_info(to_sfixed(-0.5,5,2)*to_sfixed(-0.5,5,0), string'("S")); + + fprint(RESULT, L,"Test %s:\n", to_string(to_sfixed(to_ufixed(to_ufixed(0.785398, 8, 0),8,1) sla 1))); + fprint(RESULT, L,"Test %s:\n", to_string(to_sfixed(to_sfixed(0.785398, 8, 0),8,1) sla 1)); + fprint(RESULT, L,"Test %s:\n", to_string(to_sfixed(to_sfixed(-0.785398, 8, 0),8,1) sla 1)); + fprint(RESULT, L,"Test %s:\n", to_string(to_ufixed(to_ufixed(0.785398, 8, 0),8,2) sla -1)); + fprint(RESULT, L,"Test %s:\n", to_string(to_sfixed(to_sfixed(0.785398, 8, 0),8,2) sla -1)); + fprint(RESULT, L,"Test %s:\n", to_string(to_sfixed(-to_ufixed(-0.785398, 8, 0),8,2) sla -1)); + + fprint(RESULT, L,"Integer Test %s:\n", to_string(to_sfixed(0, 8,2))); + fprint(RESULT, L,"R: Bit %s:\n", to_string(to_ufixed(3.785398, 8, 2))); + fprint(RESULT, L,"U: Bit %s.%s:\n", to_string(to_slv(ipart(to_ufixed(3.785398, 8, 2)))), to_string(to_slv(fpart(to_ufixed(3.785398, 8, 2))))); + fprint(RESULT, L,"S: Bit %s.%s:\n", to_string(to_slv(ipart(to_sfixed(3.785398, 9, 2)))), to_string(to_slv(fpart(to_sfixed(3.785398, 9, 2))))); + fprint(RESULT, L,"S: Bit %s.%s:\n", to_string(to_slv(ipart(-to_sfixed(3.785398, 9, 2)))), to_string(to_slv(fpart(-to_sfixed(3.785398, 9, 2))))); + fprint(RESULT, L,"S: Bit %d.%d:\n", fo(to_slv(ipart(to_sfixed(3.785398, 9, 2)))), fo(to_slv(fpart(to_sfixed(3.785398, 9, 2))))); + fprint(RESULT, L,"S: Bit %d:\n", fo(to_signed(to_sfixed(-3.785398, 9, 2)))); + print_info(s1, "S1"); + print_info(s2, "S2"); + print_info(s1*s2, "R1"); + print_info(to_sfixed(1.0E-6, 32, 0), "precision_test"); +end if; + + wait; +end process; + +--------------------------------------------------------------------- +end Behavioral; + diff --git a/lib/fixed_ja/tb_eval_fixed_ja_syn.vhd b/lib/fixed_ja/tb_eval_fixed_ja_syn.vhd new file mode 100644 index 0000000..c217741 --- /dev/null +++ b/lib/fixed_ja/tb_eval_fixed_ja_syn.vhd @@ -0,0 +1,104 @@ + +-------------------------------------------------------------------------------- +-- Company: +-- Engineer: +-- +-- Create Date: 20:01:25 05/22/2007 +-- Design Name: eval_fixed_ja +-- Module Name: H:/vhdl/projects/eval_fixed_ja/ise/tb_eval_fixed_ja.vhd +-- Project Name: eval_fixed +-- Target Device: +-- Tool versions: +-- Description: +-- +-- VHDL Test Bench Created by ISE for module: eval_fixed_ja +-- +-- Dependencies: +-- +-- Revision: +-- Revision 0.01 - File Created +-- Additional Comments: +-- +-- Notes: +-- This testbench has been automatically generated using types std_logic and +-- std_logic_vector for the ports of the unit under test. Xilinx recommends +-- that these types always be used for the top-level I/O of a design in order +-- to guarantee that the testbench will bind correctly to the post-implementation +-- simulation model. +-------------------------------------------------------------------------------- +LIBRARY ieee; +USE ieee.std_logic_1164.ALL; +USE ieee.std_logic_unsigned.all; +USE ieee.numeric_std.ALL; + +ENTITY tb_eval_fixed_ja_vhd IS +END tb_eval_fixed_ja_vhd; + +ARCHITECTURE behavior OF tb_eval_fixed_ja_vhd IS + + -- Component Declaration for the Unit Under Test (UUT) + COMPONENT eval_fixed_ja + PORT( + srst : IN std_logic; + clk : IN std_logic; + di1 : IN std_logic_vector(7 downto 0); + di2 : IN std_logic_vector(7 downto 0); + in_valid : IN std_logic; + do : OUT std_logic_vector(7 downto 0); + out_valid : OUT std_logic + ); + END COMPONENT; + + --Inputs + SIGNAL srst : std_logic := '1'; + SIGNAL clk : std_logic := '0'; + SIGNAL in_valid : std_logic := '0'; + SIGNAL di1 : std_logic_vector(7 downto 0) := (others=>'0'); + SIGNAL di2 : std_logic_vector(7 downto 0) := (others=>'0'); + + --Outputs + SIGNAL do : std_logic_vector(7 downto 0); + SIGNAL out_valid : std_logic; + +BEGIN + + -- Instantiate the Unit Under Test (UUT) + uut: eval_fixed_ja PORT MAP( + srst => srst, + clk => clk, + di1 => di1, + di2 => di2, + in_valid => in_valid, + do => do, + out_valid => out_valid + ); + + clk_gen : PROCESS + BEGIN + wait for 10 ns; + clk <= not clk; + END PROCESS; + + tb : PROCESS + BEGIN + + -- Wait 100 ns for global reset to finish + wait for 100 ns; + srst <= '0'; + di1 <= X"40"; + di2 <= X"20"; + + wait for 20 ns; + wait until rising_edge(clk); + in_valid <= '1'; + wait until rising_edge(clk); + in_valid <= '0'; + wait for 20 ns; + + + -- Place stimulus here + + wait; -- will wait forever + END PROCESS; + +END;