From 7f67c091fe045b9e6f304a718486b8c936235aaf Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 18 Feb 2019 18:05:38 +0000 Subject: [PATCH] quite a lot of corrections to div special cases --- src/add/nmigen_div_experiment.py | 16 ++++++---------- src/add/test_div.py | 4 +++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/add/nmigen_div_experiment.py b/src/add/nmigen_div_experiment.py index 3ae7a51f..f5adb9db 100644 --- a/src/add/nmigen_div_experiment.py +++ b/src/add/nmigen_div_experiment.py @@ -77,37 +77,33 @@ class FPDIV(FPBase): m.d.sync += z.nan(1) # if a is Inf and b is Inf return NaN - with m.Elif(a.is_inf() | b.is_inf()): + with m.Elif(a.is_inf() & b.is_inf()): m.next = "put_z" m.d.sync += z.nan(1) # if a is inf return inf (or NaN if b is zero) with m.Elif(a.is_inf()): m.next = "put_z" - # if b is zero return NaN - with m.If(b.is_zero()): - m.d.sync += z.nan(1) - with m.Else(): - m.d.sync += z.inf(a.s ^ b.s) + m.d.sync += z.inf(a.s ^ b.s) # if b is inf return zero with m.Elif(b.is_inf()): m.next = "put_z" m.d.sync += z.zero(a.s ^ b.s) - # if a is inf return zero (or NaN if b is zero) - with m.Elif(a.is_inf()): + # if a is zero return zero (or NaN if b is zero) + with m.Elif(a.is_zero()): m.next = "put_z" # if b is zero return NaN with m.If(b.is_zero()): m.d.sync += z.nan(1) with m.Else(): - m.d.sync += z.inf(a.s ^ b.s) + m.d.sync += z.zero(a.s ^ b.s) # if b is zero return Inf with m.Elif(b.is_zero()): m.next = "put_z" - m.d.sync += z.zero(a.s ^ b.s) + m.d.sync += z.inf(a.s ^ b.s) # Denormalised Number checks with m.Else(): diff --git a/src/add/test_div.py b/src/add/test_div.py index 61882e58..58bc714c 100644 --- a/src/add/test_div.py +++ b/src/add/test_div.py @@ -15,7 +15,9 @@ from unit_test_single import (get_mantissa, get_exponent, get_sign, is_nan, def testbench(dut): - yield from check_case(dut, 0x2b017, 0xff3807ab, 0x80000000) + yield from check_case(dut, 0x80000000, 0x00000000, 0xffc00000) + yield from check_case(dut, 0x00000000, 0x80000000, 0xffc00000) + yield from check_case(dut, 0x0002b017, 0xff3807ab, 0x80000000) yield from check_case(dut, 0x40000000, 0x3F800000, 0x40000000) yield from check_case(dut, 0x3F800000, 0x40000000, 0x3F000000) yield from check_case(dut, 0x3F800000, 0x40400000, 0x3EAAAAAB) -- 2.30.2