From ee00fd20e0d3717ac32227c6ecad308ede7d99e5 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 19 Feb 2019 11:23:22 +0000 Subject: [PATCH] take out FP16 non-canonical NaN weirdness for now --- src/add/nmigen_add_experiment.py | 44 +++++++++++++++++++------------- src/add/test_add.py | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/add/nmigen_add_experiment.py b/src/add/nmigen_add_experiment.py index 6baaad66..ec4ebb84 100644 --- a/src/add/nmigen_add_experiment.py +++ b/src/add/nmigen_add_experiment.py @@ -55,25 +55,33 @@ class FPADD(FPBase): with m.State("special_cases"): - # if a is zero and b is NaN return -b - with m.If(a.is_zero() & (a.s==0) & b.is_nan()): + # if a is NaN or b is NaN return NaN + with m.If(a.is_nan() | b.is_nan()): m.next = "put_z" - m.d.sync += z.create(b.s, b.e, Cat(b.m[3:-2], ~b.m[0])) - - # if b is zero and a is NaN return -a - with m.Elif(b.is_zero() & (b.s==0) & a.is_nan()): - m.next = "put_z" - m.d.sync += z.create(a.s, a.e, Cat(a.m[3:-2], ~a.m[0])) - - # if a is -zero and b is NaN return -b - with m.Elif(a.is_zero() & (a.s==1) & b.is_nan()): - m.next = "put_z" - m.d.sync += z.create(a.s & b.s, b.e, Cat(b.m[3:-2], 1)) - - # if b is -zero and a is NaN return -a - with m.Elif(b.is_zero() & (b.s==1) & a.is_nan()): - m.next = "put_z" - m.d.sync += z.create(a.s & b.s, a.e, Cat(a.m[3:-2], 1)) + m.d.sync += z.nan(1) + + # XXX WEIRDNESS for FP16 non-canonical NaN handling + # under review + + ## if a is zero and b is NaN return -b + #with m.If(a.is_zero() & (a.s==0) & b.is_nan()): + # m.next = "put_z" + # m.d.sync += z.create(b.s, b.e, Cat(b.m[3:-2], ~b.m[0])) + + ## if b is zero and a is NaN return -a + #with m.Elif(b.is_zero() & (b.s==0) & a.is_nan()): + # m.next = "put_z" + # m.d.sync += z.create(a.s, a.e, Cat(a.m[3:-2], ~a.m[0])) + + ## if a is -zero and b is NaN return -b + #with m.Elif(a.is_zero() & (a.s==1) & b.is_nan()): + # m.next = "put_z" + # m.d.sync += z.create(a.s & b.s, b.e, Cat(b.m[3:-2], 1)) + + ## if b is -zero and a is NaN return -a + #with m.Elif(b.is_zero() & (b.s==1) & a.is_nan()): + # m.next = "put_z" + # m.d.sync += z.create(a.s & b.s, a.e, Cat(a.m[3:-2], 1)) # if a is inf return inf (or NaN) with m.Elif(a.is_inf()): diff --git a/src/add/test_add.py b/src/add/test_add.py index bb419049..cc0ff98a 100644 --- a/src/add/test_add.py +++ b/src/add/test_add.py @@ -13,6 +13,7 @@ from unit_test_single import (get_mantissa, get_exponent, get_sign, is_nan, run_edge_cases, run_corner_cases) def testbench(dut): + yield from check_case(dut, 0xFFFFFFFF, 0xC63B800A, 0xFFC00000) yield from check_case(dut, 0xFF800000, 0x7F800000, 0xFFC00000) #yield from check_case(dut, 0xFF800000, 0x7F800000, 0x7FC00000) yield from check_case(dut, 0x7F800000, 0xFF800000, 0xFFC00000) @@ -31,7 +32,6 @@ def testbench(dut): yield from check_case(dut, 0xC2BA8A3D, 0x463B800A, 0x463A0AF6) yield from check_case(dut, 0xC63B800A, 0x42BA8A3D, 0xC63A0AF6) yield from check_case(dut, 0x42BA8A3D, 0xC63B800A, 0xC63A0AF6) - yield from check_case(dut, 0xFFFFFFFF, 0xC63B800A, 0xFFC00000) yield from check_case(dut, 0x7F800000, 0x00000000, 0x7F800000) yield from check_case(dut, 0x00000000, 0x7F800000, 0x7F800000) yield from check_case(dut, 0xFF800000, 0x00000000, 0xFF800000) -- 2.30.2