From 22cae9b4d337a725612aa5176bd86aa6cc90f3f8 Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Sun, 2 Feb 2020 11:29:48 -0500 Subject: [PATCH] Add feq functionality to fpcmp --- src/ieee754/fpcmp/fpcmp.py | 6 +++++- src/ieee754/fpcmp/pipeline.py | 2 +- src/ieee754/fpmax/test/test_fpmax_pipe.py | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ieee754/fpcmp/fpcmp.py b/src/ieee754/fpcmp/fpcmp.py index 1b0629f5..8b22a862 100644 --- a/src/ieee754/fpcmp/fpcmp.py +++ b/src/ieee754/fpcmp/fpcmp.py @@ -46,8 +46,12 @@ class FPCMPPipeMod(PipeModBase): m.d.comb += [a1.v.eq(self.i.a), b1.v.eq(self.i.b)] + ab_equal = Signal() + m.d.comb += ab_equal.eq(a1.v == b1.v) - comb += z1.eq(0) + with m.Switch(opcode): + with m.Case(0b10): + comb += z1.eq(ab_equal) # copy the context (muxid, operator) comb += self.o.ctx.eq(self.i.ctx) diff --git a/src/ieee754/fpcmp/pipeline.py b/src/ieee754/fpcmp/pipeline.py index 57fa9105..ab2f9a34 100644 --- a/src/ieee754/fpcmp/pipeline.py +++ b/src/ieee754/fpcmp/pipeline.py @@ -46,7 +46,7 @@ class FPCMPMuxInOut(ReservationStations): Fan-in and Fan-out are combinatorial. """ - def __init__(self, in_width, num_rows, op_wid=1): + def __init__(self, in_width, num_rows, op_wid=2): self.op_wid = op_wid self.id_wid = num_bits(num_rows) diff --git a/src/ieee754/fpmax/test/test_fpmax_pipe.py b/src/ieee754/fpmax/test/test_fpmax_pipe.py index e95d3430..b8168af7 100644 --- a/src/ieee754/fpmax/test/test_fpmax_pipe.py +++ b/src/ieee754/fpmax/test/test_fpmax_pipe.py @@ -9,6 +9,11 @@ import math def fpmax_f32_max(a, b): + # Apparently, sfpy doesn't include a min or max function. Python's + # min/max work, however python min/max are not IEEE754 Compliant + # (namely, they don't behave correctly with NaNs + # IEEE754 defines max(num, NaN) and max(NaN, num) as both + # returning num (and the same for min) if math.isnan(a) or math.isnan(b): if math.isnan(a) and math.isnan(b): return Float32(float('nan')) @@ -46,5 +51,5 @@ def test_fpmax_f32_min(): if __name__ == '__main__': for i in range(50): - test_fpmax_f32_min() test_fpmax_f32_max() + test_fpmax_f32_min() -- 2.30.2