From 99ed7303ff519e4f5a8cc4410eef3159500291b7 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 1 Aug 2019 00:57:19 +0100 Subject: [PATCH] add to float2int unit tests --- src/ieee754/fcvt/test/test_fcvt_f2int_pipe.py | 44 +++++++++++++++++++ src/ieee754/fpcommon/test/fpmux.py | 11 +++++ 2 files changed, 55 insertions(+) diff --git a/src/ieee754/fcvt/test/test_fcvt_f2int_pipe.py b/src/ieee754/fcvt/test/test_fcvt_f2int_pipe.py index 727c1ae3..82789136 100644 --- a/src/ieee754/fcvt/test/test_fcvt_f2int_pipe.py +++ b/src/ieee754/fcvt/test/test_fcvt_f2int_pipe.py @@ -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() diff --git a/src/ieee754/fpcommon/test/fpmux.py b/src/ieee754/fpcommon/test/fpmux.py index a5195c67..72e22c26 100644 --- a/src/ieee754/fpcommon/test/fpmux.py +++ b/src/ieee754/fpcommon/test/fpmux.py @@ -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) -- 2.30.2