From: Luke Kenneth Casson Leighton Date: Mon, 8 Jul 2019 07:49:25 +0000 (+0100) Subject: add corner-cases X-Git-Tag: ls180-24jan2020~880 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4862236bd28d68bad6be5a65297d58ffcb0b8051;p=ieee754fpu.git add corner-cases --- diff --git a/src/ieee754/fpadd/test/test_fpadd_pipe_32.py b/src/ieee754/fpadd/test/test_fpadd_pipe_32.py index d6cbd599..c1d852fc 100644 --- a/src/ieee754/fpadd/test/test_fpadd_pipe_32.py +++ b/src/ieee754/fpadd/test/test_fpadd_pipe_32.py @@ -2,14 +2,48 @@ """ from ieee754.fpadd.pipeline import (FPADDMuxInOut,) -from ieee754.fpcommon.test.fpmux import runfp, repeat -from ieee754.fpcommon.test.case_gen import get_corner_cases +from ieee754.fpcommon.test.fpmux import runfp, repeat, pipe_cornercases_repeat +from ieee754.fpcommon.test.case_gen import get_corner_cases, corner_cases +from ieee754.fpcommon.test.case_gen import (get_rand1, get_nan_noncan, + get_n127, get_nearly_zero, + get_nearly_inf, get_corner_rand) from ieee754.fpcommon.test import unit_test_single from ieee754.fpadd.test.add_data32 import regressions from sfpy import Float32 from operator import add + +def test_pipe_fp32_rand1(): + dut = FPADDMuxInOut(32, 4) + pipe_cornercases_repeat(dut, "add_rand1", unit_test_single, Float32, + 32, get_rand1, corner_cases, add, 10) + +def test_pipe_fp32_n127(): + dut = FPADDMuxInOut(32, 4) + pipe_cornercases_repeat(dut, "add_n127", unit_test_single, Float32, + 32, get_n127, corner_cases, add, 10) + +def test_pipe_fp32_nan_noncan(): + dut = FPADDMuxInOut(32, 4) + pipe_cornercases_repeat(dut, "add_noncan", unit_test_single, Float32, + 32, get_nan_noncan, corner_cases, add, 10) + +def test_pipe_fp32_nearly_zero(): + dut = FPADDMuxInOut(32, 4) + pipe_cornercases_repeat(dut, "add_nearlyzero", unit_test_single, Float32, + 32, get_nearly_zero, corner_cases, add, 10) + +def test_pipe_fp32_nearly_inf(): + dut = FPADDMuxInOut(32, 4) + pipe_cornercases_repeat(dut, "add_nearlyinf", unit_test_single, Float32, + 32, get_nearly_inf, corner_cases, add, 10) + +def test_pipe_fp32_corner_rand(): + dut = FPADDMuxInOut(32, 4) + pipe_cornercases_repeat(dut, "add_corner_rand", unit_test_single, Float32, + 32, get_corner_rand, corner_cases, add, 10) + def test_pipe_fp32_cornercases(): dut = FPADDMuxInOut(32, 4) vals = repeat(dut.num_rows, get_corner_cases(unit_test_single)) @@ -24,8 +58,15 @@ def test_pipe_fp32_rand(): dut = FPADDMuxInOut(32, 4) runfp(dut, 32, "test_fpadd_pipe_fp32_rand", Float32, add) + if __name__ == '__main__': - test_pipe_fp32_rand() test_pipe_fp32_regressions() test_pipe_fp32_cornercases() + test_pipe_fp32_rand() + test_pipe_fp32_rand1() + test_pipe_fp32_nan_noncan() + test_pipe_fp32_n127() + test_pipe_fp32_nearly_zero() + test_pipe_fp32_nearly_inf() + test_pipe_fp32_corner_rand() diff --git a/src/ieee754/fpcommon/test/case_gen.py b/src/ieee754/fpcommon/test/case_gen.py index 0d7aa9bd..2aad4387 100644 --- a/src/ieee754/fpcommon/test/case_gen.py +++ b/src/ieee754/fpcommon/test/case_gen.py @@ -4,76 +4,68 @@ from random import seed import sys from sfpy import Float32 -corner_cases = [0x80000000, 0x00000000, 0x7f800000, 0xff800000, - 0x7fc00000, 0xffc00000] +def corner_cases(mod): + return [mod.zero(1), mod.zero(0), + mod.inf(1), mod.inf(0), + mod.nan(1), mod.nan(0)] def get_corner_cases(mod): #corner cases from itertools import permutations - corner_cases = [mod.zero(1), mod.zero(0), - mod.inf(1), mod.inf(0), - mod.nan(1), mod.nan(0)] - stimulus_a = [i[0] for i in permutations(corner_cases, 2)] - stimulus_b = [i[1] for i in permutations(corner_cases, 2)] + cc = corner_cases(mod) + stimulus_a = [i[0] for i in permutations(cc, 2)] + stimulus_b = [i[1] for i in permutations(cc, 2)] return zip(stimulus_a, stimulus_b) -def run_fpunit_2(dut, stimulus_a, stimulus_b, op, get_case_fn): - yield from run_fpunit(dut, stimulus_a, stimulus_b, op, get_case_fn) - yield from run_fpunit(dut, stimulus_b, stimulus_a, op, get_case_fn) - -def run_cases(dut, count, op, fixed_num, maxcount, get_case_fn): +def replicate(fixed_num, maxcount): if isinstance(fixed_num, int): - stimulus_a = [fixed_num for i in range(maxcount)] - report = hex(fixed_num) + return [fixed_num for i in range(maxcount)] else: - stimulus_a = fixed_num - report = "random" + return fixed_num + + +def get_rand1(mod, fixed_num, maxcount, width): + stimulus_a = replicate(fixed_num, maxcount) + stimulus_b = [randint(0, 1<