add fsqrt test
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 23 Jul 2019 15:41:50 +0000 (16:41 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 23 Jul 2019 15:41:50 +0000 (16:41 +0100)
src/ieee754/fpcommon/test/case_gen.py
src/ieee754/fpcommon/test/fpmux.py
src/ieee754/fpdiv/pipeline.py
src/ieee754/fpdiv/test/test_fpdiv_pipe.py
src/ieee754/fpdiv/test/test_fpsqrt_pipe.py [new file with mode: 0644]

index 2c422967c912569ad9fad6df4cf63d361c049154..0b2a58eed3ca74a20bd57888ad685d31ed340168 100644 (file)
@@ -120,7 +120,8 @@ def get_corner_rand(mod, fixed_num, maxcount, width, single_op=False):
 
 
 class PipeFPCase:
-    def __init__(self, dut, name, mod, fmod, width, fpfn, count, single_op):
+    def __init__(self, dut, name, mod, fmod, width, fpfn, count,
+                 single_op, opcode):
         self.dut = dut
         self.name = name
         self.mod = mod
@@ -129,36 +130,42 @@ class PipeFPCase:
         self.fpfn = fpfn
         self.count = count
         self.single_op = single_op
+        self.opcode = opcode
 
     def run(self, name, fn):
         name = "%s_%s" % (self.name, name)
         pipe_cornercases_repeat(self.dut, name, self.mod, self.fmod,
                                 self.width, fn, corner_cases, self.fpfn,
-                                self.count, self.single_op)
+                                self.count, self.single_op,
+                                opcode=self.opcode)
 
     def run_cornercases(self):
         ccs = get_corner_cases(self.mod, self.single_op)
         vals = repeat(self.dut.num_rows, ccs)
         tname = "test_fp%s_pipe_fp%d_cornercases" % (self.name, self.width)
         runfp(self.dut, self.width, tname, self.fmod, self.fpfn, vals=vals,
-              single_op=self.single_op)
+              single_op=self.single_op,
+                                opcode=self.opcode)
 
     def run_regressions(self, regressions_fn):
         vals = repeat(self.dut.num_rows, regressions_fn())
         #print ("regressions", self.single_op, vals)
         tname = "test_fp%s_pipe_fp%d_regressions" % (self.name, self.width)
         runfp(self.dut, self.width, tname, self.fmod, self.fpfn, vals=vals,
-              single_op=self.single_op)
+              single_op=self.single_op,
+                                opcode=self.opcode)
 
     def run_random(self):
         tname = "test_fp%s_pipe_fp%d_rand" % (self.name, self.width)
         runfp(self.dut, self.width, tname, self.fmod, self.fpfn,
-              single_op=self.single_op)
+              single_op=self.single_op,
+                                opcode=self.opcode)
 
 
 def run_pipe_fp(dut, width, name, mod, fmod, regressions, fpfn, count,
-                single_op=False):
-    pc = PipeFPCase(dut, name, mod, fmod, width, fpfn, count, single_op)
+                single_op=False,
+                opcode=None):
+    pc = PipeFPCase(dut, name, mod, fmod, width, fpfn, count, single_op, opcode)
     pc.run_regressions(regressions)
     pc.run_cornercases()
     pc.run("rand1", get_rand1)
index d18438e8c43e163289b0b2eb759ee84101938541..f4f7253614bc4a07eabbee52f902f215fe7a4db4 100644 (file)
@@ -171,6 +171,11 @@ def create_random(num_rows, width, single_op=False, n_vals=10):
                 #op2 = 0x4000
                 #op1 = 0x3c50
                 #op2 = 0x3e00
+                #op2 = 0xb371
+                #op1 = 0x4400
+                #op1 = 0x656c
+                op1 = 0x738c
+
                 vals.append((op1, op2,))
     return vals
 
@@ -187,14 +192,14 @@ def repeat(num_rows, vals):
 
 
 def pipe_cornercases_repeat(dut, name, mod, fmod, width, fn, cc, fpfn, count,
-                            single_op=False):
+                            single_op=False, opcode=None):
     for i, fixed_num in enumerate(cc(mod)):
         vals = fn(mod, fixed_num, count, width, single_op)
         vals = repeat(dut.num_rows, vals)
         #print ("repeat", i, fn, single_op, list(vals))
         fmt = "test_pipe_fp%d_%s_cornercases_%d"
         runfp(dut, width, fmt % (width, name, i),
-                   fmod, fpfn, vals=vals, single_op=single_op)
+                   fmod, fpfn, vals=vals, single_op=single_op, opcode=opcode)
 
 
 def runfp(dut, width, name, fpkls, fpop, single_op=False, n_vals=10,
index 82a33e2cf8561d50978e38e82681f2f22d63a1bf..18375ef89ac8dae553d015c99b8cbc5f1a2a6b3e 100644 (file)
@@ -154,7 +154,7 @@ class FPDIVMuxInOut(ReservationStations):
                    then be used to change the behaviour of the pipeline.
     """
 
-    def __init__(self, width, num_rows, op_wid=1):
+    def __init__(self, width, num_rows, op_wid=2):
         self.id_wid = num_bits(width)
         self.pspec = PipelineSpec(width, self.id_wid, op_wid)
         # get the standard mantissa width, store in the pspec HOWEVER...
index c1ad9732a6a451499c01db3db2885b81f55d538c..c0b521b66a5ac3904cc6a3ab7c6b66888af67939 100644 (file)
@@ -7,19 +7,19 @@ from ieee754.fpcommon.test.fpmux import runfp
 from sfpy import Float64, Float32, Float16
 from operator import truediv as div
 
-def test_pipe_fp16():
+def test_pipe_div_fp16():
     dut = FPDIVMuxInOut(16, 4)
     runfp(dut, 16, "test_fpdiv_pipe_fp16", Float16, div)
 
-def test_pipe_fp32():
+def test_pipe_div_fp32():
     dut = FPDIVMuxInOut(32, 4)
     runfp(dut, 32, "test_fpdiv_pipe_fp32", Float32, div)
 
-def test_pipe_fp64():
+def test_pipe_div_fp64():
     dut = FPDIVMuxInOut(64, 4)
     runfp(dut, 64, "test_fpdiv_pipe_fp64", Float64, div)
 
 if __name__ == '__main__':
-    test_pipe_fp16()
-    test_pipe_fp32()
-    test_pipe_fp64()
+    test_pipe_div_fp16()
+    test_pipe_div_fp32()
+    test_pipe_div_fp64()
diff --git a/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py b/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py
new file mode 100644 (file)
index 0000000..84cd4da
--- /dev/null
@@ -0,0 +1,30 @@
+""" test of FPDIVMuxInOut
+"""
+
+from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,)
+from ieee754.fpcommon.test.fpmux import runfp
+
+from sfpy import Float64, Float32, Float16
+
+def sqrt(x):
+    return x.sqrt()
+
+def test_pipe_sqrt_fp16():
+    dut = FPDIVMuxInOut(16, 4)
+    runfp(dut, 16, "test_fpsqrt_pipe_fp16", Float16, sqrt,
+          single_op=True, opcode=1)
+
+def test_pipe_sqrt_fp32():
+    dut = FPDIVMuxInOut(32, 4)
+    runfp(dut, 32, "test_fpsqrt_pipe_fp32", Float32, sqrt,
+          single_op=True, opcode=1)
+
+def test_pipe_sqrt_fp64():
+    dut = FPDIVMuxInOut(64, 4)
+    runfp(dut, 64, "test_fpsqrt_pipe_fp64", Float64, sqrt,
+          single_op=True, opcode=1)
+
+if __name__ == '__main__':
+    test_pipe_sqrt_fp16()
+    test_pipe_sqrt_fp32()
+    test_pipe_sqrt_fp64()