From a2b2a64f5d9b24a6864f424a4d3fa2a83613e3b0 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 29 Jul 2019 14:50:39 +0100 Subject: [PATCH] add fprsqrt coverage tests for fp16 and fp32 --- .../fpdiv/test/test_fprsqrt_pipe_16.py | 29 +++++++++++++++++++ .../fpdiv/test/test_fprsqrt_pipe_32.py | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/ieee754/fpdiv/test/test_fprsqrt_pipe_16.py create mode 100644 src/ieee754/fpdiv/test/test_fprsqrt_pipe_32.py diff --git a/src/ieee754/fpdiv/test/test_fprsqrt_pipe_16.py b/src/ieee754/fpdiv/test/test_fprsqrt_pipe_16.py new file mode 100644 index 00000000..d8e4b2d1 --- /dev/null +++ b/src/ieee754/fpdiv/test/test_fprsqrt_pipe_16.py @@ -0,0 +1,29 @@ +""" test of FPDIVMuxInOut +""" + +from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) +from ieee754.fpcommon.test.case_gen import run_pipe_fp +from ieee754.fpcommon.test import unit_test_half +#from ieee754.fpdiv.test.rsqrt_data16 import regressions +from ieee754.div_rem_sqrt_rsqrt.core import DivPipeCoreOperation + +import unittest +from sfpy import Float16, Float64 + + +def rsqrt(x): + # FIXME: switch to correct implementation + # needs to use exact arithmetic and rounding only once at the end + return x.__class__(float(Float64(1.0) / x.to_f64().sqrt())) + + +class TestDivPipe(unittest.TestCase): + def test_pipe_rsqrt_fp16(self): + dut = FPDIVMuxInOut(16, 4) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.RSqrtRem) + run_pipe_fp(dut, 16, "rsqrt16", unit_test_half, Float16, None, + rsqrt, 100, single_op=True, opcode=opcode) + +if __name__ == '__main__': + unittest.main() diff --git a/src/ieee754/fpdiv/test/test_fprsqrt_pipe_32.py b/src/ieee754/fpdiv/test/test_fprsqrt_pipe_32.py new file mode 100644 index 00000000..24465ee9 --- /dev/null +++ b/src/ieee754/fpdiv/test/test_fprsqrt_pipe_32.py @@ -0,0 +1,29 @@ +""" test of FPDIVMuxInOut +""" + +from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) +from ieee754.fpcommon.test.case_gen import run_pipe_fp +from ieee754.fpcommon.test import unit_test_single +#from ieee754.fpdiv.test.rsqrt_data32 import regressions +from ieee754.div_rem_sqrt_rsqrt.core import DivPipeCoreOperation + +import unittest +from sfpy import Float32, Float64 + + +def rsqrt(x): + # FIXME: switch to correct implementation + # needs to use exact arithmetic and rounding only once at the end + return x.__class__(float(Float64(1.0) / x.to_f64().sqrt())) + + +class TestDivPipe(unittest.TestCase): + def test_pipe_rsqrt_fp32(self): + dut = FPDIVMuxInOut(32, 4) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.RSqrtRem) + run_pipe_fp(dut, 32, "rsqrt32", unit_test_single, Float32, None, + rsqrt, 100, single_op=True, opcode=opcode) + +if __name__ == '__main__': + unittest.main() -- 2.30.2