From 614ecd23c4f446e87865869d7888b05a1966b8a8 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 8 Jul 2019 14:26:15 +0100 Subject: [PATCH] add single op fcvt test case --- src/ieee754/fcvt/test/fcvt_data_32_16.py | 30 +++++++++---------- src/ieee754/fcvt/test/test_fcvt_pipe_32_16.py | 21 +++++++++++++ src/ieee754/fpcommon/test/case_gen.py | 23 +++++++++----- src/ieee754/fpcommon/test/fpmux.py | 10 +++++-- 4 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 src/ieee754/fcvt/test/test_fcvt_pipe_32_16.py diff --git a/src/ieee754/fcvt/test/fcvt_data_32_16.py b/src/ieee754/fcvt/test/fcvt_data_32_16.py index e5a0b79b..7be0829a 100644 --- a/src/ieee754/fcvt/test/fcvt_data_32_16.py +++ b/src/ieee754/fcvt/test/fcvt_data_32_16.py @@ -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 index 00000000..7183a8c9 --- /dev/null +++ b/src/ieee754/fcvt/test/test_fcvt_pipe_32_16.py @@ -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() + diff --git a/src/ieee754/fpcommon/test/case_gen.py b/src/ieee754/fpcommon/test/case_gen.py index f7a6e125..1e81f341 100644 --- a/src/ieee754/fpcommon/test/case_gen.py +++ b/src/ieee754/fpcommon/test/case_gen.py @@ -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) diff --git a/src/ieee754/fpcommon/test/fpmux.py b/src/ieee754/fpcommon/test/fpmux.py index 74612802..f520a639 100644 --- a/src/ieee754/fpcommon/test/fpmux.py +++ b/src/ieee754/fpcommon/test/fpmux.py @@ -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) -- 2.30.2