1 """ test of FPCVTMuxInOut
4 from ieee754
.fcvt
.pipeline
import (FPCVTF2IntMuxInOut
,)
5 from ieee754
.fpcommon
.test
.fpmux
import runfp
8 from sfpy
import Float64
, Float32
, Float16
11 return sfpy
.float.f64_to_ui32(x
)
14 return sfpy
.float.f64_to_i32(x
) & 0xffffffff
17 print ("fcvt i16_f32", hex(x
))
18 return sfpy
.float.i32_to_f32(x
) # XXX no i16_to_f32, it's ok though
21 print ("fcvt i32_f32", hex(x
))
22 return sfpy
.float.i32_to_f32(x
)
25 print ("fcvt i32_f64", hex(x
))
26 return sfpy
.float.i32_to_f64(x
)
29 return sfpy
.float.f32_to_ui32(x
)
32 return sfpy
.float.ui64_to_f32(x
)
35 return sfpy
.float.f64_to_ui64(x
)
38 x
= sfpy
.float.f64_to_ui32(x
)
44 return sfpy
.float.f16_to_ui32(x
)
47 return sfpy
.float.f16_to_ui32(x
) & 0xffff
50 x
= sfpy
.float.f16_to_i32(x
)
58 x
= sfpy
.float.f64_to_i32(x
)
66 return sfpy
.float.f32_to_i32(x
) & 0xffffffff
69 return sfpy
.float.f64_to_i64(x
) & 0xffffffffffffffff
72 ######################
74 ######################
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
=100, opcode
=0x1)
83 def test_int_pipe_i32_f64():
84 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
85 runfp(dut
, 32, "test_fcvt_int_pipe_i32_f64", to_int32
, fcvt_i32_f64
, True,
86 n_vals
=100, opcode
=0x1)
88 def test_int_pipe_i32_f32():
89 dut
= FPCVTIntMuxInOut(32, 32, 4, op_wid
=1)
90 runfp(dut
, 32, "test_fcvt_int_pipe_i32_f32", to_int32
, fcvt_i32_f32
, True,
91 n_vals
=100, opcode
=0x1)
93 def test_int_pipe_f64_i64():
94 dut
= FPCVTF2IntMuxInOut(64, 64, 4, op_wid
=1)
95 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_i64", Float64
, fcvt_f64_i64
,
96 True, n_vals
=100, opcode
=0x1)
98 def test_int_pipe_f64_i32():
99 # XXX TODO: reduce range of FP num to actually fit (almost) into I32
100 dut
= FPCVTF2IntMuxInOut(64, 32, 4, op_wid
=1)
101 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_i32", Float64
, fcvt_f64_i32
,
102 True, n_vals
=100, opcode
=0x1)
104 def test_int_pipe_f64_i16():
105 # XXX TODO: reduce range of FP num to actually fit (almost) into I16
106 dut
= FPCVTF2IntMuxInOut(64, 16, 4, op_wid
=1)
107 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_i16", Float64
, fcvt_f64_i16
,
108 True, n_vals
=100, opcode
=0x1)
110 def test_int_pipe_f32_i32():
111 dut
= FPCVTF2IntMuxInOut(32, 32, 4, op_wid
=1)
112 runfp(dut
, 32, "test_fcvt_f2int_pipe_f32_i32", Float32
, fcvt_f32_i32
,
113 True, n_vals
=100, opcode
=0x1)
115 def test_int_pipe_f16_i16():
116 dut
= FPCVTF2IntMuxInOut(16, 16, 4, op_wid
=1)
117 runfp(dut
, 16, "test_fcvt_f2int_pipe_f16_i16", Float16
, fcvt_f16_i16
,
118 True, n_vals
=100, opcode
=0x1)
120 ######################
122 ######################
124 def test_int_pipe_f16_ui16():
125 # XXX softfloat-3 doesn't have ui16_to_xxx so use ui32 instead.
127 dut
= FPCVTF2IntMuxInOut(16, 16, 4, op_wid
=1)
128 runfp(dut
, 16, "test_fcvt_f2int_pipe_f16_ui16", Float16
, fcvt_f16_ui16
,
131 def test_int_pipe_ui16_f64():
132 dut
= FPCVTIntMuxInOut(16, 64, 4, op_wid
=1)
133 runfp(dut
, 16, "test_fcvt_int_pipe_ui16_f64", to_uint16
, fcvt_64
, True,
136 def test_int_pipe_f32_ui32():
137 dut
= FPCVTF2IntMuxInOut(32, 32, 4, op_wid
=1)
138 runfp(dut
, 32, "test_fcvt_f2int_pipe_f32_ui32", Float32
, fcvt_f32_ui32
,
141 def test_int_pipe_ui32_f64():
142 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
143 runfp(dut
, 32, "test_fcvt_int_pipe_ui32_64", to_uint32
, fcvt_64
, True,
146 def test_int_pipe_ui64_f32():
147 # ok, doing 33 bits here because it's pretty pointless (not entirely)
148 # to do random numbers statistically likely 99.999% of the time to be
150 dut
= FPCVTIntMuxInOut(64, 32, 4, op_wid
=1)
151 runfp(dut
, 33, "test_fcvt_int_pipe_ui64_32", to_uint64
, fcvt_64_to_32
, True,
154 def test_int_pipe_ui64_f16():
155 # ok, doing 17 bits here because it's pretty pointless (not entirely)
156 # to do random numbers statistically likely 99.999% of the time to be
158 dut
= FPCVTIntMuxInOut(64, 16, 4, op_wid
=1)
159 runfp(dut
, 17, "test_fcvt_int_pipe_ui64_16", to_uint64
, fcvt_16
, True,
162 def test_int_pipe_ui32_f16():
163 # ok, doing 17 bits here because it's pretty pointless (not entirely)
164 # to do random numbers statistically likely 99.999% of the time to be
166 dut
= FPCVTIntMuxInOut(32, 16, 4, op_wid
=1)
167 runfp(dut
, 17, "test_fcvt_int_pipe_ui32_16", to_uint32
, fcvt_16
, True,
170 def test_int_pipe_f64_ui64():
171 dut
= FPCVTF2IntMuxInOut(64, 64, 4, op_wid
=1)
172 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui64", Float64
, fcvt_f64_ui64
,
175 def test_int_pipe_f64_ui32():
176 dut
= FPCVTF2IntMuxInOut(64, 32, 4, op_wid
=1)
177 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui32", Float64
, fcvt_f64_ui32
,
180 def test_int_pipe_f64_ui16():
181 dut
= FPCVTF2IntMuxInOut(64, 16, 4, op_wid
=1)
182 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui16", Float64
, fcvt_f64_ui16
,
185 if __name__
== '__main__':
187 test_int_pipe_f64_i16()
188 test_int_pipe_f64_i32()
189 test_int_pipe_f64_ui16()
190 test_int_pipe_f64_ui32()
192 test_int_pipe_f16_i16()
193 test_int_pipe_f32_i32()
194 test_int_pipe_f64_i64()
195 test_int_pipe_f64_ui64()
196 test_int_pipe_f32_ui32()
197 test_int_pipe_f16_ui16()
199 test_int_pipe_i32_f32()
200 test_int_pipe_i16_f32()
201 test_int_pipe_i32_f64()
203 test_int_pipe_ui16_f32()
204 test_int_pipe_ui64_f32()
205 test_int_pipe_ui32_f16()
206 test_int_pipe_ui64_f16()
207 test_int_pipe_ui16_f64()
208 test_int_pipe_ui32_f64()