"""
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))
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()
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<<width) for i in range(maxcount)]
+ return zip(stimulus_a, stimulus_b)
- stimulus_b = [randint(0, 1<<32) for i in range(maxcount)]
- yield from run_fpunit_2(dut, stimulus_a, stimulus_b, op, get_case_fn)
- count += len(stimulus_a)
- print (count, "vectors passed 2^32", report)
+def get_nan_noncan(mod, fixed_num, maxcount, width):
+ stimulus_a = replicate(fixed_num, maxcount)
# non-canonical NaNs.
- stimulus_b = [set_exponent(randint(0, 1<<32), 128) \
+ stimulus_b = [mod.set_exponent(randint(0, 1<<width), mod.max_e) \
for i in range(maxcount)]
- yield from run_fpunit_2(dut, stimulus_a, stimulus_b, op, get_case_fn)
- count += len(stimulus_a)
- print (count, "vectors passed Non-Canonical NaN", report)
+ return zip(stimulus_a, stimulus_b)
+
+def get_n127(mod, fixed_num, maxcount, width):
+ stimulus_a = replicate(fixed_num, maxcount)
# -127
- stimulus_b = [set_exponent(randint(0, 1<<32), -127) \
+ stimulus_b = [mod.set_exponent(randint(0, 1<<width), -mod.max_e+1) \
for i in range(maxcount)]
- yield from run_fpunit_2(dut, stimulus_a, stimulus_b, op, get_case_fn)
- count += len(stimulus_a)
- print (count, "vectors passed exp=-127", report)
+ return zip(stimulus_a, stimulus_b)
+
+def get_nearly_zero(mod, fixed_num, maxcount, width):
+ stimulus_a = replicate(fixed_num, maxcount)
# nearly zero
- stimulus_b = [set_exponent(randint(0, 1<<32), -126) \
+ stimulus_b = [mod.set_exponent(randint(0, 1<<width), -mod.max_e+2) \
for i in range(maxcount)]
- yield from run_fpunit_2(dut, stimulus_a, stimulus_b, op, get_case_fn)
- count += len(stimulus_a)
- print (count, "vectors passed exp=-126", report)
+ return zip(stimulus_a, stimulus_b)
+
+def get_nearly_inf(mod, fixed_num, maxcount, width):
+ stimulus_a = replicate(fixed_num, maxcount)
# nearly inf
- stimulus_b = [set_exponent(randint(0, 1<<32), 127) \
+ stimulus_b = [mod.set_exponent(randint(0, 1<<width), mod.max_e-1) \
for i in range(maxcount)]
- yield from run_fpunit_2(dut, stimulus_a, stimulus_b, op, get_case_fn)
- count += len(stimulus_a)
- print (count, "vectors passed exp=127", report)
-
- return count
-
-def run_edge_cases(dut, count, op, get_case_fn, maxcount=10, num_loops=1000):
- #edge cases
- for testme in corner_cases:
- count = yield from run_cases(dut, count, op, testme,
- maxcount, get_case_fn)
-
- for i in range(num_loops):
- stimulus_a = [randint(0, 1<<32) for i in range(maxcount)]
- count = yield from run_cases(dut, count, op, stimulus_a, 10,
- get_case_fn)
- return count
+ return zip(stimulus_a, stimulus_b)
+
+
+def get_corner_rand(mod, fixed_num, maxcount, width):
+ stimulus_a = replicate(fixed_num, maxcount)
+ # random
+ stimulus_b = [randint(0, 1<<width) for i in range(maxcount)]
+ return zip(stimulus_a, stimulus_b)
self.di[muxid][i] = (op1, )
else:
(op1, op2, ) = vals.pop(0)
- print ("test", hex(op1), hex(op2))
+ #print ("test", hex(op1), hex(op2))
res = self.fpop(self.fpkls(op1), self.fpkls(op2))
self.di[muxid][i] = (op1, op2)
self.do[muxid].append(res.bits)
return vals + [vals[-1]] * n_to_repeat
+def pipe_cornercases_repeat(dut, name, mod, fmod, width, fn, cc, fpfn, count):
+ for i, fixed_num in enumerate(cc(mod)):
+ vals = fn(mod, fixed_num, count, width)
+ vals = repeat(dut.num_rows, vals)
+ fmt = "test_pipe_fp%d_%s_cornercases_%d"
+ runfp(dut, width, fmt % (width, name, i),
+ fmod, fpfn, vals=vals)
+
+
def runfp(dut, width, name, fpkls, fpop, single_op=False, n_vals=10, vals=None):
vl = rtlil.convert(dut, ports=dut.ports())
with open("%s.il" % name, "w") as f: