add ui64 to f32 conversion test
[ieee754fpu.git] / src / ieee754 / fcvt / test / test_fcvt_int_pipe.py
1 """ test of FPCVTMuxInOut
2 """
3
4 from ieee754.fcvt.pipeline import (FPCVTIntMuxInOut,)
5 from ieee754.fpcommon.test.fpmux import runfp
6
7 import sfpy
8 from sfpy import Float64, Float32, Float16
9
10 def to_uint16(x):
11 return x
12
13 def to_uint32(x):
14 return x
15
16 def to_uint64(x):
17 return x
18
19 def fcvt_64(x):
20 return sfpy.float.ui32_to_f64(x)
21
22 def fcvt_32(x):
23 return sfpy.float.ui32_to_f32(x)
24
25 def fcvt_64_to_32(x):
26 return sfpy.float.ui64_to_f32(x)
27
28 def fcvt_16(x):
29 return sfpy.float.ui32_to_f16(x)
30
31 def test_int_pipe_ui16_f32():
32 # XXX softfloat-3 doesn't have ui16_to_xxx so use ui32 instead.
33 # should be fine.
34 dut = FPCVTIntMuxInOut(16, 32, 4)
35 runfp(dut, 16, "test_fcvt_int_pipe_ui16_f32", to_uint16, fcvt_32, True,
36 n_vals=100)
37
38 def test_int_pipe_ui16_f64():
39 dut = FPCVTIntMuxInOut(16, 64, 4)
40 runfp(dut, 16, "test_fcvt_int_pipe_ui16_f64", to_uint16, fcvt_64, True,
41 n_vals=100)
42
43 def test_int_pipe_ui32_f64():
44 dut = FPCVTIntMuxInOut(32, 64, 4)
45 runfp(dut, 32, "test_fcvt_int_pipe_ui32_64", to_uint32, fcvt_64, True,
46 n_vals=100)
47
48 def test_int_pipe_ui64_f32():
49 # ok, doing 33 bits here because it's pretty pointless (not entirely)
50 # to do random numbers statistically likely 99.999% of the time to be
51 # converted to Inf
52 dut = FPCVTIntMuxInOut(64, 32, 4)
53 runfp(dut, 33, "test_fcvt_int_pipe_ui64_32", to_uint64, fcvt_64_to_32, True,
54 n_vals=100)
55
56 def test_int_pipe_ui64_f16():
57 # ok, doing 17 bits here because it's pretty pointless (not entirely)
58 # to do random numbers statistically likely 99.999% of the time to be
59 # converted to Inf
60 dut = FPCVTIntMuxInOut(64, 16, 4)
61 runfp(dut, 17, "test_fcvt_int_pipe_ui64_16", to_uint64, fcvt_16, True,
62 n_vals=100)
63
64 def test_int_pipe_ui32_f16():
65 # ok, doing 17 bits here because it's pretty pointless (not entirely)
66 # to do random numbers statistically likely 99.999% of the time to be
67 # converted to Inf
68 dut = FPCVTIntMuxInOut(32, 16, 4)
69 runfp(dut, 17, "test_fcvt_int_pipe_ui32_16", to_uint32, fcvt_16, True,
70 n_vals=100)
71
72 if __name__ == '__main__':
73 for i in range(200):
74 test_int_pipe_ui64_f32()
75 test_int_pipe_ui32_f16()
76 test_int_pipe_ui64_f16()
77 test_int_pipe_ui16_f32()
78 test_int_pipe_ui16_f64()
79 test_int_pipe_ui32_f64()
80