1 """ test of FPCVTMuxInOut
4 from ieee754
.fcvt
.pipeline
import FPCVTIntMuxInOut
5 from ieee754
.fpcommon
.test
.fpmux
import runfp
8 from sfpy
import Float64
, Float32
, Float16
12 """ input: an unsigned int in the range 0..65535
13 output: a signed int in the range -32768..32767
21 """ input: an unsigned int in the range 0..2^32-1
22 output: a signed int in the range -2^31..2^31-1
42 return sfpy
.float.ui32_to_f64(x
)
46 print("fcvt i16_f32", hex(x
))
47 return sfpy
.float.i32_to_f32(x
) # XXX no i16_to_f32, it's ok though
51 print("fcvt i32_f32", hex(x
))
52 return sfpy
.float.i32_to_f32(x
)
56 print("fcvt i32_f64", hex(x
))
57 return sfpy
.float.i32_to_f64(x
)
61 return sfpy
.float.ui32_to_f32(x
)
65 return sfpy
.float.ui64_to_f32(x
)
69 return sfpy
.float.ui32_to_f16(x
)
71 ######################
73 ######################
76 def test_int_pipe_i16_f32():
77 # XXX softfloat-3 doesn't have i16_to_xxx so use ui32 instead.
79 dut
= FPCVTIntMuxInOut(16, 32, 4, op_wid
=1)
80 runfp(dut
, 16, "test_fcvt_int_pipe_i16_f32", to_int16
, fcvt_i16_f32
, True,
81 n_vals
=20, opcode
=0x1)
84 def test_int_pipe_i32_f64():
85 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
86 runfp(dut
, 32, "test_fcvt_int_pipe_i32_f64", to_int32
, fcvt_i32_f64
, True,
87 n_vals
=20, opcode
=0x1)
90 def test_int_pipe_i32_f32():
91 dut
= FPCVTIntMuxInOut(32, 32, 4, op_wid
=1)
92 runfp(dut
, 32, "test_fcvt_int_pipe_i32_f32", to_int32
, fcvt_i32_f32
, True,
93 n_vals
=20, opcode
=0x1)
95 ######################
97 ######################
100 def test_int_pipe_ui16_f32():
101 # XXX softfloat-3 doesn't have ui16_to_xxx so use ui32 instead.
103 dut
= FPCVTIntMuxInOut(16, 32, 4, op_wid
=1)
104 runfp(dut
, 16, "test_fcvt_int_pipe_ui16_f32", to_uint16
, fcvt_32
, True,
108 def test_int_pipe_ui16_f64():
109 dut
= FPCVTIntMuxInOut(16, 64, 4, op_wid
=1)
110 runfp(dut
, 16, "test_fcvt_int_pipe_ui16_f64", to_uint16
, fcvt_64
, True,
114 def test_int_pipe_ui32_f32():
115 dut
= FPCVTIntMuxInOut(32, 32, 4, op_wid
=1)
116 runfp(dut
, 32, "test_fcvt_int_pipe_ui32_32", to_uint32
, fcvt_32
, True,
120 def test_int_pipe_ui32_f64():
121 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
122 runfp(dut
, 32, "test_fcvt_int_pipe_ui32_64", to_uint32
, fcvt_64
, True,
126 def test_int_pipe_ui64_f32():
127 # ok, doing 33 bits here because it's pretty pointless (not entirely)
128 # to do random numbers statistically likely 99.999% of the time to be
130 dut
= FPCVTIntMuxInOut(64, 32, 4, op_wid
=1)
131 runfp(dut
, 33, "test_fcvt_int_pipe_ui64_32", to_uint64
, fcvt_64_to_32
, True,
135 def test_int_pipe_ui64_f16():
136 # ok, doing 17 bits here because it's pretty pointless (not entirely)
137 # to do random numbers statistically likely 99.999% of the time to be
139 dut
= FPCVTIntMuxInOut(64, 16, 4, op_wid
=1)
140 runfp(dut
, 17, "test_fcvt_int_pipe_ui64_16", to_uint64
, fcvt_16
, True,
144 def test_int_pipe_ui32_f16():
145 # ok, doing 17 bits here because it's pretty pointless (not entirely)
146 # to do random numbers statistically likely 99.999% of the time to be
148 dut
= FPCVTIntMuxInOut(32, 16, 4, op_wid
=1)
149 runfp(dut
, 17, "test_fcvt_int_pipe_ui32_16", to_uint32
, fcvt_16
, True,
153 if __name__
== '__main__':
155 test_int_pipe_i16_f32()
156 test_int_pipe_i32_f64()
157 test_int_pipe_ui32_f32()
158 test_int_pipe_i32_f32()
159 test_int_pipe_ui16_f32()
160 test_int_pipe_ui64_f32()
161 test_int_pipe_ui32_f16()
162 test_int_pipe_ui64_f16()
163 test_int_pipe_ui16_f64()
164 test_int_pipe_ui32_f64()