From: Luke Kenneth Casson Leighton Date: Sun, 28 Jul 2019 12:15:34 +0000 (+0100) Subject: use opcode rather than magic constants (will need a class, later) X-Git-Tag: ls180-24jan2020~705 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c9d0ae4942505ada12efdecbe4dd1bda5bb139a1;p=ieee754fpu.git use opcode rather than magic constants (will need a class, later) --- diff --git a/src/ieee754/fpdiv/test/test_fpdiv_pipe.py b/src/ieee754/fpdiv/test/test_fpdiv_pipe.py index 451d979d..a1ed5787 100644 --- a/src/ieee754/fpdiv/test/test_fpdiv_pipe.py +++ b/src/ieee754/fpdiv/test/test_fpdiv_pipe.py @@ -3,6 +3,7 @@ from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) from ieee754.fpcommon.test.fpmux import runfp +from ieee754.div_rem_sqrt_rsqrt.core import DivPipeCoreOperation import unittest from sfpy import Float64, Float32, Float16 @@ -12,15 +13,24 @@ from operator import truediv as div class TestDivPipe(unittest.TestCase): def test_pipe_div_fp16(self): dut = FPDIVMuxInOut(16, 4) - runfp(dut, 16, "test_fpdiv_pipe_fp16", Float16, div) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.UDivRem) + runfp(dut, 16, "test_fpdiv_pipe_fp16", Float16, div, + opcode=opcode) def test_pipe_div_fp32(self): dut = FPDIVMuxInOut(32, 4) - runfp(dut, 32, "test_fpdiv_pipe_fp32", Float32, div) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.UDivRem) + runfp(dut, 32, "test_fpdiv_pipe_fp32", Float32, div, + opcode=opcode) def test_pipe_div_fp64(self): dut = FPDIVMuxInOut(64, 4) - runfp(dut, 64, "test_fpdiv_pipe_fp64", Float64, div) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.UDivRem) + runfp(dut, 64, "test_fpdiv_pipe_fp64", Float64, div, + opcode=opcode) if __name__ == '__main__': diff --git a/src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py b/src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py index da617e9e..c520e095 100644 --- a/src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py +++ b/src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py @@ -5,6 +5,7 @@ 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.div_data16 import regressions +from ieee754.div_rem_sqrt_rsqrt.core import DivPipeCoreOperation import unittest from sfpy import Float16 @@ -14,8 +15,10 @@ from operator import truediv as div class TestDivPipe(unittest.TestCase): def test_pipe_fp16(self): dut = FPDIVMuxInOut(16, 4) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.UDivRem) run_pipe_fp(dut, 16, "div16", unit_test_half, Float16, - regressions, div, 10) + regressions, div, 10, opcode=opcode) if __name__ == '__main__': diff --git a/src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py b/src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py index d79eddce..91f3677f 100644 --- a/src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py +++ b/src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py @@ -5,6 +5,7 @@ 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.div_data32 import regressions +from ieee754.div_rem_sqrt_rsqrt.core import DivPipeCoreOperation import unittest from sfpy import Float32 @@ -14,8 +15,10 @@ from operator import truediv as div class TestDivPipe(unittest.TestCase): def test_pipe_fp32(self): dut = FPDIVMuxInOut(32, 4) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.UDivRem) run_pipe_fp(dut, 32, "div32", unit_test_single, Float32, - regressions, div, 10) + regressions, div, 10, opcode=opcode) if __name__ == '__main__': diff --git a/src/ieee754/fpdiv/test/test_fprsqrt_pipe.py b/src/ieee754/fpdiv/test/test_fprsqrt_pipe.py index d8e47235..0457c524 100644 --- a/src/ieee754/fpdiv/test/test_fprsqrt_pipe.py +++ b/src/ieee754/fpdiv/test/test_fprsqrt_pipe.py @@ -3,31 +3,40 @@ from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) from ieee754.fpcommon.test.fpmux import runfp +from ieee754.div_rem_sqrt_rsqrt.core import DivPipeCoreOperation import unittest from sfpy import Float64, Float32, Float16 def rsqrt(x): - # FIXME: switch to correct implementation (rounding once) - return x.__class__(1.0) / x.sqrt() + # 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) runfp(dut, 16, "test_fprsqrt_pipe_fp16", Float16, rsqrt, - single_op=True, opcode=2, n_vals=100) + single_op=True, opcode=opcode, n_vals=100) 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) runfp(dut, 32, "test_fprsqrt_pipe_fp32", Float32, rsqrt, - single_op=True, opcode=2, n_vals=100) + single_op=True, opcode=opcode, n_vals=100) + @unittest.skip("rsqrt not implemented for fp64") def test_pipe_rsqrt_fp64(self): dut = FPDIVMuxInOut(64, 4) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.RSqrtRem) runfp(dut, 64, "test_fprsqrt_pipe_fp64", Float64, rsqrt, - single_op=True, opcode=2, n_vals=100) + single_op=True, opcode=opcode, n_vals=100) if __name__ == '__main__': diff --git a/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py b/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py index e474ba86..7f46d8f4 100644 --- a/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py +++ b/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py @@ -3,6 +3,7 @@ from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) from ieee754.fpcommon.test.fpmux import runfp +from ieee754.div_rem_sqrt_rsqrt.core import DivPipeCoreOperation import unittest from sfpy import Float64, Float32, Float16 @@ -15,18 +16,24 @@ def sqrt(x): class TestDivPipe(unittest.TestCase): def test_pipe_sqrt_fp16(self): dut = FPDIVMuxInOut(16, 4) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.SqrtRem) runfp(dut, 16, "test_fpsqrt_pipe_fp16", Float16, sqrt, - single_op=True, opcode=1, n_vals=100) + single_op=True, opcode=opcode, n_vals=100) def test_pipe_sqrt_fp32(self): dut = FPDIVMuxInOut(32, 4) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.SqrtRem) runfp(dut, 32, "test_fpsqrt_pipe_fp32", Float32, sqrt, - single_op=True, opcode=1, n_vals=100) + single_op=True, opcode=opcode, n_vals=100) def test_pipe_sqrt_fp64(self): dut = FPDIVMuxInOut(64, 4) + # don't forget to initialize opcode; don't use magic numbers + opcode = int(DivPipeCoreOperation.SqrtRem) runfp(dut, 64, "test_fpsqrt_pipe_fp64", Float64, sqrt, - single_op=True, opcode=1, n_vals=100) + single_op=True, opcode=opcode, n_vals=100) if __name__ == '__main__':