857432b09cae9d77eaec09720dfbdacac877c878
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
11 """ input: an unsigned int in the range 0..65535
12 output: a signed int in the range -32768..32767
19 """ input: an unsigned int in the range 0..2^32-1
20 output: a signed int in the range -2^31..2^31-1
36 return sfpy
.float.ui32_to_f64(x
)
39 print ("fcvt i16_f32", hex(x
))
40 return sfpy
.float.i32_to_f32(x
) # XXX no i16_to_f32, it's ok though
43 print ("fcvt i32_f32", hex(x
))
44 return sfpy
.float.i32_to_f32(x
)
47 print ("fcvt i32_f64", hex(x
))
48 return sfpy
.float.i32_to_f64(x
)
51 return sfpy
.float.ui32_to_f32(x
)
54 return sfpy
.float.ui64_to_f32(x
)
57 return sfpy
.float.ui32_to_f16(x
)
59 ######################
61 ######################
63 def test_int_pipe_i16_f32():
64 # XXX softfloat-3 doesn't have i16_to_xxx so use ui32 instead.
66 dut
= FPCVTIntMuxInOut(16, 32, 4, op_wid
=1)
67 runfp(dut
, 16, "test_fcvt_int_pipe_i16_f32", to_int16
, fcvt_i16_f32
, True,
68 n_vals
=100, opcode
=0x1)
70 def test_int_pipe_i32_f64():
71 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
72 runfp(dut
, 32, "test_fcvt_int_pipe_i32_f64", to_int32
, fcvt_i32_f64
, True,
73 n_vals
=100, opcode
=0x1)
75 def test_int_pipe_i32_f32():
76 dut
= FPCVTIntMuxInOut(32, 32, 4, op_wid
=1)
77 runfp(dut
, 32, "test_fcvt_int_pipe_i32_f32", to_int32
, fcvt_i32_f32
, True,
78 n_vals
=100, opcode
=0x1)
80 ######################
82 ######################
84 def test_int_pipe_ui16_f32():
85 # XXX softfloat-3 doesn't have ui16_to_xxx so use ui32 instead.
87 dut
= FPCVTIntMuxInOut(16, 32, 4, op_wid
=1)
88 runfp(dut
, 16, "test_fcvt_int_pipe_ui16_f32", to_uint16
, fcvt_32
, True,
91 def test_int_pipe_ui16_f64():
92 dut
= FPCVTIntMuxInOut(16, 64, 4, op_wid
=1)
93 runfp(dut
, 16, "test_fcvt_int_pipe_ui16_f64", to_uint16
, fcvt_64
, True,
96 def test_int_pipe_ui32_f32():
97 dut
= FPCVTIntMuxInOut(32, 32, 4, op_wid
=1)
98 runfp(dut
, 32, "test_fcvt_int_pipe_ui32_32", to_uint32
, fcvt_32
, True,
101 def test_int_pipe_ui32_f64():
102 dut
= FPCVTIntMuxInOut(32, 64, 4, op_wid
=1)
103 runfp(dut
, 32, "test_fcvt_int_pipe_ui32_64", to_uint32
, fcvt_64
, True,
106 def test_int_pipe_ui64_f32():
107 # ok, doing 33 bits here because it's pretty pointless (not entirely)
108 # to do random numbers statistically likely 99.999% of the time to be
110 dut
= FPCVTIntMuxInOut(64, 32, 4, op_wid
=1)
111 runfp(dut
, 33, "test_fcvt_int_pipe_ui64_32", to_uint64
, fcvt_64_to_32
, True,
114 def test_int_pipe_ui64_f16():
115 # ok, doing 17 bits here because it's pretty pointless (not entirely)
116 # to do random numbers statistically likely 99.999% of the time to be
118 dut
= FPCVTIntMuxInOut(64, 16, 4, op_wid
=1)
119 runfp(dut
, 17, "test_fcvt_int_pipe_ui64_16", to_uint64
, fcvt_16
, True,
122 def test_int_pipe_ui32_f16():
123 # ok, doing 17 bits here because it's pretty pointless (not entirely)
124 # to do random numbers statistically likely 99.999% of the time to be
126 dut
= FPCVTIntMuxInOut(32, 16, 4, op_wid
=1)
127 runfp(dut
, 17, "test_fcvt_int_pipe_ui32_16", to_uint32
, fcvt_16
, True,
130 if __name__
== '__main__':
132 test_int_pipe_ui32_f32()
133 test_int_pipe_i32_f32()
135 test_int_pipe_i16_f32()
136 test_int_pipe_i32_f64()
138 test_int_pipe_ui16_f32()
139 test_int_pipe_ui64_f32()
140 test_int_pipe_ui32_f16()
141 test_int_pipe_ui64_f16()
142 test_int_pipe_ui16_f64()
143 test_int_pipe_ui32_f64()