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 # http://bugs.libre-riscv.org/show_bug.cgi?id=113
101 dut
= FPCVTF2IntMuxInOut(64, 32, 4, op_wid
=1)
102 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_i32", Float64
, fcvt_f64_i32
,
103 True, n_vals
=100, opcode
=0x1)
105 def test_int_pipe_f64_i16():
106 # XXX TODO: reduce range of FP num to actually fit (almost) into I16
107 # http://bugs.libre-riscv.org/show_bug.cgi?id=113
108 dut
= FPCVTF2IntMuxInOut(64, 16, 4, op_wid
=1)
109 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_i16", Float64
, fcvt_f64_i16
,
110 True, n_vals
=100, opcode
=0x1)
112 def test_int_pipe_f32_i32():
113 dut
= FPCVTF2IntMuxInOut(32, 32, 4, op_wid
=1)
114 runfp(dut
, 32, "test_fcvt_f2int_pipe_f32_i32", Float32
, fcvt_f32_i32
,
115 True, n_vals
=100, opcode
=0x1)
117 def test_int_pipe_f16_i16():
118 dut
= FPCVTF2IntMuxInOut(16, 16, 4, op_wid
=1)
119 runfp(dut
, 16, "test_fcvt_f2int_pipe_f16_i16", Float16
, fcvt_f16_i16
,
120 True, n_vals
=100, opcode
=0x1)
122 ######################
124 ######################
126 def test_int_pipe_f16_ui16():
127 # XXX softfloat-3 doesn't have ui16_to_xxx so use ui32 instead.
129 dut
= FPCVTF2IntMuxInOut(16, 16, 4, op_wid
=1)
130 runfp(dut
, 16, "test_fcvt_f2int_pipe_f16_ui16", Float16
, fcvt_f16_ui16
,
133 def test_int_pipe_ui16_f64():
134 dut
= FPCVTIntMuxInOut(16, 64, 4, op_wid
=1)
135 runfp(dut
, 16, "test_fcvt_int_pipe_ui16_f64", to_uint16
, fcvt_64
, True,
138 def test_int_pipe_f32_ui32():
139 dut
= FPCVTF2IntMuxInOut(32, 32, 4, op_wid
=1)
140 runfp(dut
, 32, "test_fcvt_f2int_pipe_f32_ui32", Float32
, fcvt_f32_ui32
,
143 def test_int_pipe_ui32_f64():
144 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
145 runfp(dut
, 32, "test_fcvt_int_pipe_ui32_64", to_uint32
, fcvt_64
, True,
148 def test_int_pipe_ui64_f32():
149 # ok, doing 33 bits here because it's pretty pointless (not entirely)
150 # to do random numbers statistically likely 99.999% of the time to be
152 dut
= FPCVTIntMuxInOut(64, 32, 4, op_wid
=1)
153 runfp(dut
, 33, "test_fcvt_int_pipe_ui64_32", to_uint64
, fcvt_64_to_32
, True,
156 def test_int_pipe_ui64_f16():
157 # ok, doing 17 bits here because it's pretty pointless (not entirely)
158 # to do random numbers statistically likely 99.999% of the time to be
160 dut
= FPCVTIntMuxInOut(64, 16, 4, op_wid
=1)
161 runfp(dut
, 17, "test_fcvt_int_pipe_ui64_16", to_uint64
, fcvt_16
, True,
164 def test_int_pipe_ui32_f16():
165 # ok, doing 17 bits here because it's pretty pointless (not entirely)
166 # to do random numbers statistically likely 99.999% of the time to be
168 dut
= FPCVTIntMuxInOut(32, 16, 4, op_wid
=1)
169 runfp(dut
, 17, "test_fcvt_int_pipe_ui32_16", to_uint32
, fcvt_16
, True,
172 def test_int_pipe_f64_ui64():
173 dut
= FPCVTF2IntMuxInOut(64, 64, 4, op_wid
=1)
174 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui64", Float64
, fcvt_f64_ui64
,
177 def test_int_pipe_f64_ui32():
178 dut
= FPCVTF2IntMuxInOut(64, 32, 4, op_wid
=1)
179 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui32", Float64
, fcvt_f64_ui32
,
182 def test_int_pipe_f64_ui16():
183 dut
= FPCVTF2IntMuxInOut(64, 16, 4, op_wid
=1)
184 runfp(dut
, 64, "test_fcvt_f2int_pipe_f64_ui16", Float64
, fcvt_f64_ui16
,
187 if __name__
== '__main__':
189 test_int_pipe_f64_i16()
190 test_int_pipe_f64_i32()
191 test_int_pipe_f64_ui16()
192 test_int_pipe_f64_ui32()
193 test_int_pipe_f16_i16()
194 test_int_pipe_f32_i32()
195 test_int_pipe_f64_i64()
196 test_int_pipe_f64_ui64()
197 test_int_pipe_f32_ui32()
198 test_int_pipe_f16_ui16()