8c4726b82378756ef5f488c0e7759a75d9a8690c
[ieee754fpu.git] / src / ieee754 / fclass / test / test_fclass_pipe.py
1 """ test of FPClassMuxInOut
2 """
3
4 from ieee754.fclass.pipeline import (FPClassMuxInOut,)
5 from ieee754.fpcommon.test.fpmux import runfp
6 from ieee754.fpcommon.fpbase import FPFormat
7
8 import sfpy
9 from sfpy import Float64, Float32, Float16
10
11 def fclass(wid, x):
12 x = x.bits
13 fmt = FPFormat.standard(wid)
14 print (hex(x), "exp", fmt.get_exponent(x), fmt.emax,
15 "m", hex(fmt.get_mantissa(x)),
16 fmt.get_mantissa(x) & (1<<fmt.m_width-1))
17 if fmt.is_inf(x):
18 if fmt.get_sign(x):
19 return 1<<0
20 else:
21 return 1<<7
22 if fmt.is_zero(x):
23 if fmt.get_sign(x):
24 return 1<<3
25 else:
26 return 1<<4
27 if fmt.get_exponent(x) == fmt.emax and fmt.get_mantissa(x) != 0:
28 if fmt.is_nan_signalling(x):
29 return 1<<8
30 else:
31 return 1<<9
32 if fmt.is_subnormal(x) and fmt.get_mantissa(x) != 0:
33 if fmt.get_sign(x):
34 return 1<<2
35 else:
36 return 1<<5
37 if fmt.get_sign(x):
38 return 1<<1
39 else:
40 return 1<<6
41
42
43 def fclass_16(x):
44 return fclass(16, x)
45
46
47 def test_class_pipe_f16():
48 dut = FPClassMuxInOut(16, 16, 4, op_wid=1)
49 runfp(dut, 16, "test_fcvt_class_pipe_f16", Float16, fclass_16,
50 True, n_vals=100)
51
52
53 if __name__ == '__main__':
54 for i in range(200):
55 test_class_pipe_f16()