add to float2int unit tests
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 31 Jul 2019 23:57:19 +0000 (00:57 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 31 Jul 2019 23:57:19 +0000 (00:57 +0100)
src/ieee754/fcvt/test/test_fcvt_f2int_pipe.py
src/ieee754/fpcommon/test/fpmux.py

index 727c1ae339adc380540ad5264882a2f4eaba264f..82789136ff2626e8b0ebf19be393bd5a6de2b26f 100644 (file)
@@ -10,6 +10,9 @@ from sfpy import Float64, Float32, Float16
 def fcvt_f64_ui32(x):
     return sfpy.float.f64_to_ui32(x)
 
+def fcvt_f64_i32(x):
+    return sfpy.float.f64_to_i32(x) & 0xffffffff
+
 def fcvt_i16_f32(x):
     print ("fcvt i16_f32", hex(x))
     return sfpy.float.i32_to_f32(x) # XXX no i16_to_f32, it's ok though
@@ -31,6 +34,12 @@ def fcvt_64_to_32(x):
 def fcvt_f64_ui64(x):
     return sfpy.float.f64_to_ui64(x)
 
+def fcvt_f64_ui16(x):
+    x = sfpy.float.f64_to_ui32(x)
+    if x >= 0xffff:
+        return 0xffff
+    return x
+
 def fcvt_f16_ui32(x):
     return sfpy.float.f16_to_ui32(x)
 
@@ -45,6 +54,14 @@ def fcvt_f16_i16(x):
         return 0x8000
     return x & 0xffff
 
+def fcvt_f64_i16(x):
+    x = sfpy.float.f64_to_i32(x)
+    if x >= 0x7fff:
+        return 0x7fff
+    if x <= -0x8000:
+        return 0x8000
+    return x & 0xffff
+
 def fcvt_f32_i32(x):
     return sfpy.float.f32_to_i32(x) & 0xffffffff
 
@@ -78,6 +95,18 @@ def test_int_pipe_f64_i64():
     runfp(dut, 64, "test_fcvt_f2int_pipe_f64_i64", Float64, fcvt_f64_i64,
                 True, n_vals=100, opcode=0x1)
 
+def test_int_pipe_f64_i32():
+    # XXX TODO: reduce range of FP num to actually fit (almost) into I32
+    dut = FPCVTF2IntMuxInOut(64, 32, 4, op_wid=1)
+    runfp(dut, 64, "test_fcvt_f2int_pipe_f64_i32", Float64, fcvt_f64_i32,
+                    True, n_vals=100, opcode=0x1)
+
+def test_int_pipe_f64_i16():
+    # XXX TODO: reduce range of FP num to actually fit (almost) into I16
+    dut = FPCVTF2IntMuxInOut(64, 16, 4, op_wid=1)
+    runfp(dut, 64, "test_fcvt_f2int_pipe_f64_i16", Float64, fcvt_f64_i16,
+                    True, n_vals=100, opcode=0x1)
+
 def test_int_pipe_f32_i32():
     dut = FPCVTF2IntMuxInOut(32, 32, 4, op_wid=1)
     runfp(dut, 32, "test_fcvt_f2int_pipe_f32_i32", Float32, fcvt_f32_i32,
@@ -143,8 +172,23 @@ def test_int_pipe_f64_ui64():
     runfp(dut, 64, "test_fcvt_f2int_pipe_f64_ui64", Float64, fcvt_f64_ui64,
                     True, n_vals=100)
 
+def test_int_pipe_f64_ui32():
+    dut = FPCVTF2IntMuxInOut(64, 32, 4, op_wid=1)
+    runfp(dut, 64, "test_fcvt_f2int_pipe_f64_ui32", Float64, fcvt_f64_ui32,
+                    True, n_vals=100)
+
+def test_int_pipe_f64_ui16():
+    dut = FPCVTF2IntMuxInOut(64, 16, 4, op_wid=1)
+    runfp(dut, 64, "test_fcvt_f2int_pipe_f64_ui16", Float64, fcvt_f64_ui16,
+                    True, n_vals=100)
+
 if __name__ == '__main__':
     for i in range(200):
+        test_int_pipe_f64_i16()
+        test_int_pipe_f64_i32()
+        test_int_pipe_f64_ui16()
+        test_int_pipe_f64_ui32()
+        continue
         test_int_pipe_f16_i16()
         test_int_pipe_f32_i32()
         test_int_pipe_f64_i64()
index a5195c677fe238fbefc2fa588d41d309c6e3125c..72e22c26062a611adc5650949328fa2fca8397df 100644 (file)
@@ -207,6 +207,17 @@ def create_random(num_rows, width, single_op=False, n_vals=10):
                 #op1 = 0xfea8
                 #op1 = 0xfd57
 
+                # f2int unsigned (fp64 to ui16)
+                #op1 = 0x40e6f5bc4d88b0cc
+
+                # f2int signed (fp64 to i16)
+                #op1 = 0xff292cf09f159ddb
+                #op1 = 0x5880e09f7cb716a1
+
+                # f2int signed (fp64 to i32)
+                #op1 = 0x5beb66ffc69a9a64
+                #op1 = 0xd4cdd178a1f2cdec
+
                 vals.append((op1,))
             else:
                 op1 = randint(0, (1 << width)-1)