1 """ test of FPCVTMuxInOut
4 from ieee754
.fcvt
.pipeline
import FPCVTF2IntMuxInOut
5 from ieee754
.fpcommon
.test
.fpmux
import (runfp
, create_random
)
6 from ieee754
.fcvt
.test
.rangelimited
import create_int
9 from sfpy
import Float64
, Float32
, Float16
13 return sfpy
.float.f64_to_ui32(x
)
17 return sfpy
.float.f64_to_i32(x
) & 0xffffffff
21 print("fcvt i16_f32", hex(x
))
22 return sfpy
.float.i32_to_f32(x
) # XXX no i16_to_f32, it's ok though
26 print("fcvt i32_f32", hex(x
))
27 return sfpy
.float.i32_to_f32(x
)
31 print("fcvt i32_f64", hex(x
))
32 return sfpy
.float.i32_to_f64(x
)
36 return sfpy
.float.f32_to_ui32(x
)
40 return sfpy
.float.ui64_to_f32(x
)
44 return sfpy
.float.f64_to_ui64(x
)
48 x
= sfpy
.float.f64_to_ui32(x
)
55 return sfpy
.float.f16_to_ui32(x
)
59 return sfpy
.float.f16_to_ui32(x
) & 0xffff
63 x
= sfpy
.float.f16_to_i32(x
)
72 x
= sfpy
.float.f64_to_i32(x
)
81 return sfpy
.float.f32_to_i32(x
) & 0xffffffff
85 return sfpy
.float.f64_to_i64(x
) & 0xffffffffffffffff
88 ######################
90 ######################
92 def test_int_pipe_i16_f32():
93 # XXX softfloat-3 doesn't have i16_to_xxx so use ui32 instead.
95 dut
= FPCVTIntMuxInOut(16, 32, 4, op_wid
=1)
96 runfp(dut
, 16, "test_fcvt_int_pipe_i16_f32", to_int16
, fcvt_i16_f32
, True,
97 n_vals
=100, opcode
=0x1)
100 def test_int_pipe_i32_f64():
101 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
102 runfp(dut
, 32, "test_fcvt_int_pipe_i32_f64", to_int32
, fcvt_i32_f64
, True,
103 n_vals
=100, opcode
=0x1)
106 def test_int_pipe_i32_f32():
107 dut
= FPCVTIntMuxInOut(32, 32, 4, op_wid
=1)
108 runfp(dut
, 32, "test_fcvt_int_pipe_i32_f32", to_int32
, fcvt_i32_f32
, True,
109 n_vals
=100, opcode
=0x1)
112 def test_int_pipe_f64_i64():
113 dut
= FPCVTF2IntMuxInOut(64, 64, 4, op_wid
=1)
116 vals
.append(create_int(Float64
, 64))
117 vals
+= create_random(dut
.num_rows
, 64, True, 10)
118 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_i64", Float64
, fcvt_f64_i64
,
119 True, vals
=vals
, opcode
=0x1)
122 def test_int_pipe_f64_i32():
123 # XXX TODO: reduce range of FP num to actually fit (almost) into I32
124 # http://bugs.libre-riscv.org/show_bug.cgi?id=113
125 dut
= FPCVTF2IntMuxInOut(64, 32, 4, op_wid
=1)
128 vals
.append(create_int(Float64
, 32))
129 vals
+= create_random(dut
.num_rows
, 32, True, 10)
130 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_i32", Float64
, fcvt_f64_i32
,
131 True, vals
=vals
, opcode
=0x1)
134 def test_int_pipe_f64_i16():
135 # XXX TODO: reduce range of FP num to actually fit (almost) into I16
136 # http://bugs.libre-riscv.org/show_bug.cgi?id=113
137 dut
= FPCVTF2IntMuxInOut(64, 16, 4, op_wid
=1)
140 vals
.append(create_int(Float64
, 16))
141 vals
+= create_random(dut
.num_rows
, 16, True, 10)
142 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_i16", Float64
, fcvt_f64_i16
,
143 True, vals
=vals
, opcode
=0x1)
146 def test_int_pipe_f32_i32():
147 dut
= FPCVTF2IntMuxInOut(32, 32, 4, op_wid
=1)
148 runfp(dut
, 32, "test_fcvt_f2int_pipe_f32_i32", Float32
, fcvt_f32_i32
,
149 True, n_vals
=100, opcode
=0x1)
152 def test_int_pipe_f16_i16():
153 dut
= FPCVTF2IntMuxInOut(16, 16, 4, op_wid
=1)
154 runfp(dut
, 16, "test_fcvt_f2int_pipe_f16_i16", Float16
, fcvt_f16_i16
,
155 True, n_vals
=100, opcode
=0x1)
157 ######################
159 ######################
162 def test_int_pipe_f16_ui16():
163 # XXX softfloat-3 doesn't have ui16_to_xxx so use ui32 instead.
165 dut
= FPCVTF2IntMuxInOut(16, 16, 4, op_wid
=1)
166 runfp(dut
, 16, "test_fcvt_f2int_pipe_f16_ui16", Float16
, fcvt_f16_ui16
,
170 def test_int_pipe_ui16_f64():
171 dut
= FPCVTIntMuxInOut(16, 64, 4, op_wid
=1)
172 runfp(dut
, 16, "test_fcvt_int_pipe_ui16_f64", to_uint16
, fcvt_64
, True,
176 def test_int_pipe_f32_ui32():
177 dut
= FPCVTF2IntMuxInOut(32, 32, 4, op_wid
=1)
180 vals
.append(create_int(Float32
, 32))
181 vals
+= create_random(dut
.num_rows
, 32, True, 10)
182 runfp(dut
, 32, "test_fcvt_f2int_pipe_f32_ui32", Float32
, fcvt_f32_ui32
,
186 def test_int_pipe_ui32_f64():
187 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
188 runfp(dut
, 32, "test_fcvt_int_pipe_ui32_64", to_uint32
, fcvt_64
, True,
192 def test_int_pipe_ui64_f32():
193 # ok, doing 33 bits here because it's pretty pointless (not entirely)
194 # to do random numbers statistically likely 99.999% of the time to be
196 dut
= FPCVTIntMuxInOut(64, 32, 4, op_wid
=1)
197 runfp(dut
, 33, "test_fcvt_int_pipe_ui64_32", to_uint64
, fcvt_64_to_32
, True,
201 def test_int_pipe_ui64_f16():
202 # ok, doing 17 bits here because it's pretty pointless (not entirely)
203 # to do random numbers statistically likely 99.999% of the time to be
205 dut
= FPCVTIntMuxInOut(64, 16, 4, op_wid
=1)
206 runfp(dut
, 17, "test_fcvt_int_pipe_ui64_16", to_uint64
, fcvt_16
, True,
210 def test_int_pipe_ui32_f16():
211 # ok, doing 17 bits here because it's pretty pointless (not entirely)
212 # to do random numbers statistically likely 99.999% of the time to be
214 dut
= FPCVTIntMuxInOut(32, 16, 4, op_wid
=1)
215 runfp(dut
, 17, "test_fcvt_int_pipe_ui32_16", to_uint32
, fcvt_16
, True,
219 def test_int_pipe_f64_ui64():
220 dut
= FPCVTF2IntMuxInOut(64, 64, 4, op_wid
=1)
223 vals
.append(create_int(Float64
, 64))
224 vals
+= create_random(dut
.num_rows
, 64, True, 10)
225 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui64", Float64
, fcvt_f64_ui64
,
229 def test_int_pipe_f64_ui32():
230 dut
= FPCVTF2IntMuxInOut(64, 32, 4, op_wid
=1)
233 vals
.append(create_int(Float64
, 32))
234 vals
+= create_random(dut
.num_rows
, 32, True, 10)
235 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui32", Float64
, fcvt_f64_ui32
,
239 def test_int_pipe_f64_ui16():
240 dut
= FPCVTF2IntMuxInOut(64, 16, 4, op_wid
=1)
243 vals
.append(create_int(Float64
, 16))
244 vals
+= create_random(dut
.num_rows
, 16, True, 10)
245 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui16", Float64
, fcvt_f64_ui16
,
249 if __name__
== '__main__':
251 test_int_pipe_f64_i16()
252 test_int_pipe_f64_i32()
253 test_int_pipe_f64_ui16()
254 test_int_pipe_f64_ui32()
255 test_int_pipe_f16_i16()
256 test_int_pipe_f32_i32()
257 test_int_pipe_f64_i64()
258 test_int_pipe_f64_ui64()
259 test_int_pipe_f32_ui32()
260 test_int_pipe_f16_ui16()