5 return ((x
& 0x7f800000) >> 23) - 127
8 return ((x
& 0x80000000) >> 31)
11 return get_exponent(x
) == 128 and get_mantissa(x
) != 0
14 return get_exponent(x
) == 128 and get_mantissa(x
) == 0
17 return is_inf(x
) and not get_sign(x
)
20 return is_inf(x
) and get_sign(x
)
24 (is_pos_inf(x
) and is_pos_inf(y
)) or
25 (is_neg_inf(x
) and is_neg_inf(y
)) or
26 (is_nan(x
) and is_nan(y
)) or
30 def get_case(dut
, a
, b
):
31 yield dut
.in_a
.v
.eq(a
)
32 yield dut
.in_a
.stb
.eq(1)
35 a_ack
= (yield dut
.in_a
.ack
)
37 yield dut
.in_b
.v
.eq(b
)
38 yield dut
.in_b
.stb
.eq(1)
39 b_ack
= (yield dut
.in_b
.ack
)
44 out_z_stb
= (yield dut
.out_z
.stb
)
47 yield dut
.in_a
.stb
.eq(0)
48 yield dut
.in_b
.stb
.eq(0)
49 yield dut
.out_z
.ack
.eq(1)
51 yield dut
.out_z
.ack
.eq(0)
56 out_z
= yield dut
.out_z
.v
59 def check_case(dut
, a
, b
, z
):
60 out_z
= yield from get_case(dut
, a
, b
)
61 assert out_z
== z
, "Output z 0x%x not equal to expected 0x%x" % (out_z
, z
)
64 def run_test(dut
, stimulus_a
, stimulus_b
):
66 expected_responses
= []
68 for a
, b
in zip(stimulus_a
, stimulus_b
):
69 af
= Float32
.from_bits(a
)
70 bf
= Float32
.from_bits(b
)
72 expected_responses
.append(z
.get_bits())
74 actual
= yield from get_case(dut
, a
, b
)
75 actual_responses
.append(actual
)
77 if len(actual_responses
) < len(expected_responses
):
78 print ("Fail ... not enough results")
81 for expected
, actual
, a
, b
in zip(expected_responses
, actual_responses
,
82 stimulus_a
, stimulus_b
):
83 passed
= match(expected
, actual
)
87 print ("Fail ... expected:", hex(expected
), "actual:", hex(actual
))
90 print ("a mantissa:", a
& 0x7fffff)
91 print ("a exponent:", ((a
& 0x7f800000) >> 23) - 127)
92 print ("a sign:", ((a
& 0x80000000) >> 31))
95 print ("b mantissa:", b
& 0x7fffff)
96 print ("b exponent:", ((b
& 0x7f800000) >> 23) - 127)
97 print ("b sign:", ((b
& 0x80000000) >> 31))
100 print ("expected mantissa:", expected
& 0x7fffff)
101 print ("expected exponent:", ((expected
& 0x7f800000) >> 23) - 127)
102 print ("expected sign:", ((expected
& 0x80000000) >> 31))
105 print ("actual mantissa:", actual
& 0x7fffff)
106 print ("actual exponent:", ((actual
& 0x7f800000) >> 23) - 127)
107 print ("actual sign:", ((actual
& 0x80000000) >> 31))