fc44458e95b1a10d62e0e69893fd3cefa2919a30
[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_16(x):
26 return sfpy.float.ui32_to_f16(x)
27
28 def test_int_pipe_ui16_f32():
29 # XXX softfloat-3 doesn't have ui16_to_xxx so use ui32 instead.
30 # should be fine.
31 dut = FPCVTIntMuxInOut(16, 32, 4)
32 runfp(dut, 16, "test_fcvt_int_pipe_ui16_f32", to_uint16, fcvt_32, True,
33 n_vals=100)
34
35 def test_int_pipe_ui16_f64():
36 dut = FPCVTIntMuxInOut(16, 64, 4)
37 runfp(dut, 16, "test_fcvt_int_pipe_ui16_f64", to_uint16, fcvt_64, True,
38 n_vals=100)
39
40 def test_int_pipe_ui32_f64():
41 dut = FPCVTIntMuxInOut(32, 64, 4)
42 runfp(dut, 32, "test_fcvt_int_pipe_ui32_64", to_uint32, fcvt_64, True,
43 n_vals=100)
44
45 def test_int_pipe_ui64_f16():
46 # ok, doing 17 bits here because it's pretty pointless (not entirely)
47 # to do random numbers statistically likely 99.999% of the time to be
48 # converted to Inf
49 dut = FPCVTIntMuxInOut(64, 16, 4)
50 runfp(dut, 17, "test_fcvt_int_pipe_ui64_16", to_uint64, fcvt_16, True,
51 n_vals=100)
52
53 def test_int_pipe_ui32_f16():
54 # ok, doing 17 bits here because it's pretty pointless (not entirely)
55 # to do random numbers statistically likely 99.999% of the time to be
56 # converted to Inf
57 dut = FPCVTIntMuxInOut(32, 16, 4)
58 runfp(dut, 17, "test_fcvt_int_pipe_ui32_16", to_uint32, fcvt_16, True,
59 n_vals=100)
60
61 if __name__ == '__main__':
62 for i in range(200):
63 test_int_pipe_ui32_f16()
64 test_int_pipe_ui64_f16()
65 test_int_pipe_ui16_f32()
66 test_int_pipe_ui16_f64()
67 test_int_pipe_ui32_f64()
68