add single op fcvt test case
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 8 Jul 2019 13:26:15 +0000 (14:26 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 8 Jul 2019 13:26:15 +0000 (14:26 +0100)
src/ieee754/fcvt/test/fcvt_data_32_16.py
src/ieee754/fcvt/test/test_fcvt_pipe_32_16.py [new file with mode: 0644]
src/ieee754/fpcommon/test/case_gen.py
src/ieee754/fpcommon/test/fpmux.py

index e5a0b79bf6bd8f535b727bd98d9ba0d4c7aae5fa..7be0829aaf9e2195e918f8810f24dff9162125b6 100644 (file)
@@ -1,17 +1,17 @@
 def regressions():
-    yield 0x40900000
-    yield 0x94607b66
-    yield 0x889cd8c
-    yield 0xe98646d7
-    yield 0x3340f2a7
-    yield 0xfff13f05
-    yield 0x453eb000
-    yield 0x3a05de50
-    yield 0xc27ff989
-    yield 0x41689000
-    yield 0xbbc0edec
-    yield 0x2EDBE6FF
-    yield 0x358637BD
-    yield 0x3340f2a7
-    yield 0x33D6BF95
+    yield 0x40900000,
+    yield 0x94607b66,
+    yield 0x889cd8c,
+    yield 0xe98646d7,
+    yield 0x3340f2a7,
+    yield 0xfff13f05,
+    yield 0x453eb000,
+    yield 0x3a05de50,
+    yield 0xc27ff989,
+    yield 0x41689000,
+    yield 0xbbc0edec,
+    yield 0x2EDBE6FF,
+    yield 0x358637BD,
+    yield 0x3340f2a7,
+    yield 0x33D6BF95,
 
diff --git a/src/ieee754/fcvt/test/test_fcvt_pipe_32_16.py b/src/ieee754/fcvt/test/test_fcvt_pipe_32_16.py
new file mode 100644 (file)
index 0000000..7183a8c
--- /dev/null
@@ -0,0 +1,21 @@
+""" test of FPCVTMuxInOut
+"""
+
+from ieee754.fcvt.pipeline import (FPCVTMuxInOut,)
+from ieee754.fpcommon.test.case_gen import run_pipe_fp
+from ieee754.fpcommon.test import unit_test_single
+from ieee754.fcvt.test.fcvt_data_32_16 import regressions
+
+from sfpy import Float32, Float16
+
+def fcvt_16(x):
+    return Float16(x)
+
+def test_pipe_fp32_16():
+    dut = FPCVTMuxInOut(32, 16, 4)
+    run_pipe_fp(dut, 32, "add", unit_test_single, Float32,
+                regressions, fcvt_16, 10, True)
+
+if __name__ == '__main__':
+    test_pipe_fp32_16()
+
index f7a6e12518cbbcc006509493719bd2270c320c1c..1e81f341eb6d45312e2de5da19b727842d70fc12 100644 (file)
@@ -34,7 +34,8 @@ def get_rval(width):
 def get_rand1(mod, fixed_num, maxcount, width, single_op=False):
     stimulus_b = [get_rval(width) for i in range(maxcount)]
     if single_op:
-        return stimulus_b
+        yield from stimulus_b
+        return
     stimulus_a = replicate(fixed_num, maxcount)
     yield from zip(stimulus_a, stimulus_b)
     yield from zip(stimulus_b, stimulus_a)
@@ -45,7 +46,8 @@ def get_nan_noncan(mod, fixed_num, maxcount, width, single_op=False):
     stimulus_b = [mod.set_exponent(get_rval(width), mod.max_e) \
                         for i in range(maxcount)]
     if single_op:
-        return stimulus_b
+        yield from stimulus_b
+        return
     stimulus_a = replicate(fixed_num, maxcount)
     yield from zip(stimulus_a, stimulus_b)
     yield from zip(stimulus_b, stimulus_a)
@@ -56,7 +58,8 @@ def get_n127(mod, fixed_num, maxcount, width, single_op=False):
     stimulus_b = [mod.set_exponent(get_rval(width), -mod.max_e+1) \
                         for i in range(maxcount)]
     if single_op:
-        return stimulus_b
+        yield from stimulus_b
+        return
     stimulus_a = replicate(fixed_num, maxcount)
     yield from zip(stimulus_a, stimulus_b)
     yield from zip(stimulus_b, stimulus_a)
@@ -67,7 +70,8 @@ def get_nearly_zero(mod, fixed_num, maxcount, width, single_op=False):
     stimulus_b = [mod.set_exponent(get_rval(width), -mod.max_e+2) \
                         for i in range(maxcount)]
     if single_op:
-        return stimulus_b
+        yield from stimulus_b
+        return
     stimulus_a = replicate(fixed_num, maxcount)
     yield from zip(stimulus_a, stimulus_b)
     yield from zip(stimulus_b, stimulus_a)
@@ -78,7 +82,8 @@ def get_nearly_inf(mod, fixed_num, maxcount, width, single_op=False):
     stimulus_b = [mod.set_exponent(get_rval(width), mod.max_e-1) \
                         for i in range(maxcount)]
     if single_op:
-        return stimulus_b
+        yield from stimulus_b
+        return
     stimulus_a = replicate(fixed_num, maxcount)
     yield from zip(stimulus_a, stimulus_b)
     yield from zip(stimulus_b, stimulus_a)
@@ -88,7 +93,8 @@ def get_corner_rand(mod, fixed_num, maxcount, width, single_op=False):
     # random
     stimulus_b = [get_rval(width) for i in range(maxcount)]
     if single_op:
-        return stimulus_b
+        yield from stimulus_b
+        return
     stimulus_a = replicate(fixed_num, maxcount)
     yield from zip(stimulus_a, stimulus_b)
     yield from zip(stimulus_b, stimulus_a)
@@ -112,14 +118,15 @@ class PipeFPCase:
                                 self.count, self.single_op)
 
     def run_cornercases(self):
-        vals = repeat(self.dut.num_rows, get_corner_cases(self.mod))
+        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)
 
     def run_regressions(self, regressions_fn):
         vals = repeat(self.dut.num_rows, regressions_fn())
-        print ("regressions", vals)
+        #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)
index 74612802f4c146f44557f5085171642a207015ad..f520a6393ffb9827fc1b74453b7f80dafcdbd7ad 100644 (file)
@@ -25,7 +25,11 @@ class MuxInOut:
             self.do[muxid] = []
             for i in range(self.tlen):
                 if self.single_op:
-                    (op1, ) = vals.pop(0)
+                    #print ("vals", vals)
+                    op1 = vals.pop(0)
+                    if isinstance(op1, tuple):
+                        assert len(op1) == 1
+                        op1 = op1[0]
                     res = self.fpop(self.fpkls(op1))
                     self.di[muxid][i] = (op1, )
                 else:
@@ -157,14 +161,16 @@ def repeat(num_rows, vals):
     """
     vals = list(vals)
     n_to_repeat = len(vals) % num_rows
+    #print ("repeat", vals)
     return vals + [vals[-1]] * n_to_repeat
 
 
 def pipe_cornercases_repeat(dut, name, mod, fmod, width, fn, cc, fpfn, count,
                             single_op=False):
     for i, fixed_num in enumerate(cc(mod)):
-        vals = fn(mod, fixed_num, count, width)
+        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)