30fcf4e817791f3902a0dd91caf708ebb2d8936f
1 """ test of FPClassMuxInOut
4 from ieee754
.fclass
.pipeline
import (FPClassMuxInOut
,)
5 from ieee754
.fpcommon
.test
.fpmux
import runfp
6 from ieee754
.fpcommon
.fpbase
import FPFormat
9 from sfpy
import Float64
, Float32
, Float16
12 """ analyses the FP number and returns a RISC-V "FCLASS" unary bitfield
14 this is easy to understand however it has redundant checks (which
15 don't matter because performance of *testing* is not hardware-critical)
16 see FPClassMod for a hardware-optimal (hard-to-read) version
19 fmt
= FPFormat
.standard(wid
)
20 print (hex(x
), "exp", fmt
.get_exponent(x
), fmt
.e_max
,
21 "m", hex(fmt
.get_mantissa_field(x
)),
22 fmt
.get_mantissa_field(x
) & (1<<fmt
.m_width
-1))
24 if fmt
.get_sign_field(x
):
29 if fmt
.get_sign_field(x
):
33 if fmt
.get_exponent(x
) == fmt
.e_max
and fmt
.get_mantissa_field(x
) != 0:
34 if fmt
.is_nan_signaling(x
):
38 if fmt
.is_subnormal(x
) and fmt
.get_mantissa_field(x
) != 0:
39 if fmt
.get_sign_field(x
):
43 if fmt
.get_sign_field(x
):
61 def test_class_pipe_f16():
62 dut
= FPClassMuxInOut(16, 16, 4, op_wid
=1)
63 runfp(dut
, 16, "test_fclass_pipe_f16", Float16
, fclass_16
,
67 def test_class_pipe_f32():
68 dut
= FPClassMuxInOut(32, 32, 4, op_wid
=1)
69 runfp(dut
, 32, "test_fclass_pipe_f32", Float32
, fclass_32
,
73 def test_class_pipe_f64():
74 dut
= FPClassMuxInOut(64, 64, 4, op_wid
=1)
75 runfp(dut
, 64, "test_fclass_pipe_f64", Float64
, fclass_64
,
79 if __name__
== '__main__':