From eae62ec53a49edf8bbc9d840c2ee90013faca395 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 23 Jul 2019 16:41:50 +0100 Subject: [PATCH] add fsqrt test --- src/ieee754/fpcommon/test/case_gen.py | 21 ++++++++++----- src/ieee754/fpcommon/test/fpmux.py | 9 +++++-- src/ieee754/fpdiv/pipeline.py | 2 +- src/ieee754/fpdiv/test/test_fpdiv_pipe.py | 12 ++++----- src/ieee754/fpdiv/test/test_fpsqrt_pipe.py | 30 ++++++++++++++++++++++ 5 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 src/ieee754/fpdiv/test/test_fpsqrt_pipe.py diff --git a/src/ieee754/fpcommon/test/case_gen.py b/src/ieee754/fpcommon/test/case_gen.py index 2c422967..0b2a58ee 100644 --- a/src/ieee754/fpcommon/test/case_gen.py +++ b/src/ieee754/fpcommon/test/case_gen.py @@ -120,7 +120,8 @@ def get_corner_rand(mod, fixed_num, maxcount, width, single_op=False): class PipeFPCase: - def __init__(self, dut, name, mod, fmod, width, fpfn, count, single_op): + def __init__(self, dut, name, mod, fmod, width, fpfn, count, + single_op, opcode): self.dut = dut self.name = name self.mod = mod @@ -129,36 +130,42 @@ class PipeFPCase: self.fpfn = fpfn self.count = count self.single_op = single_op + self.opcode = opcode def run(self, name, fn): name = "%s_%s" % (self.name, name) pipe_cornercases_repeat(self.dut, name, self.mod, self.fmod, self.width, fn, corner_cases, self.fpfn, - self.count, self.single_op) + self.count, self.single_op, + opcode=self.opcode) def run_cornercases(self): 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) + single_op=self.single_op, + opcode=self.opcode) def run_regressions(self, regressions_fn): vals = repeat(self.dut.num_rows, regressions_fn()) #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) + single_op=self.single_op, + opcode=self.opcode) def run_random(self): tname = "test_fp%s_pipe_fp%d_rand" % (self.name, self.width) runfp(self.dut, self.width, tname, self.fmod, self.fpfn, - single_op=self.single_op) + single_op=self.single_op, + opcode=self.opcode) def run_pipe_fp(dut, width, name, mod, fmod, regressions, fpfn, count, - single_op=False): - pc = PipeFPCase(dut, name, mod, fmod, width, fpfn, count, single_op) + single_op=False, + opcode=None): + pc = PipeFPCase(dut, name, mod, fmod, width, fpfn, count, single_op, opcode) pc.run_regressions(regressions) pc.run_cornercases() pc.run("rand1", get_rand1) diff --git a/src/ieee754/fpcommon/test/fpmux.py b/src/ieee754/fpcommon/test/fpmux.py index d18438e8..f4f72536 100644 --- a/src/ieee754/fpcommon/test/fpmux.py +++ b/src/ieee754/fpcommon/test/fpmux.py @@ -171,6 +171,11 @@ def create_random(num_rows, width, single_op=False, n_vals=10): #op2 = 0x4000 #op1 = 0x3c50 #op2 = 0x3e00 + #op2 = 0xb371 + #op1 = 0x4400 + #op1 = 0x656c + op1 = 0x738c + vals.append((op1, op2,)) return vals @@ -187,14 +192,14 @@ def repeat(num_rows, vals): def pipe_cornercases_repeat(dut, name, mod, fmod, width, fn, cc, fpfn, count, - single_op=False): + single_op=False, opcode=None): for i, fixed_num in enumerate(cc(mod)): 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) + fmod, fpfn, vals=vals, single_op=single_op, opcode=opcode) def runfp(dut, width, name, fpkls, fpop, single_op=False, n_vals=10, diff --git a/src/ieee754/fpdiv/pipeline.py b/src/ieee754/fpdiv/pipeline.py index 82a33e2c..18375ef8 100644 --- a/src/ieee754/fpdiv/pipeline.py +++ b/src/ieee754/fpdiv/pipeline.py @@ -154,7 +154,7 @@ class FPDIVMuxInOut(ReservationStations): then be used to change the behaviour of the pipeline. """ - def __init__(self, width, num_rows, op_wid=1): + def __init__(self, width, num_rows, op_wid=2): self.id_wid = num_bits(width) self.pspec = PipelineSpec(width, self.id_wid, op_wid) # get the standard mantissa width, store in the pspec HOWEVER... diff --git a/src/ieee754/fpdiv/test/test_fpdiv_pipe.py b/src/ieee754/fpdiv/test/test_fpdiv_pipe.py index c1ad9732..c0b521b6 100644 --- a/src/ieee754/fpdiv/test/test_fpdiv_pipe.py +++ b/src/ieee754/fpdiv/test/test_fpdiv_pipe.py @@ -7,19 +7,19 @@ from ieee754.fpcommon.test.fpmux import runfp from sfpy import Float64, Float32, Float16 from operator import truediv as div -def test_pipe_fp16(): +def test_pipe_div_fp16(): dut = FPDIVMuxInOut(16, 4) runfp(dut, 16, "test_fpdiv_pipe_fp16", Float16, div) -def test_pipe_fp32(): +def test_pipe_div_fp32(): dut = FPDIVMuxInOut(32, 4) runfp(dut, 32, "test_fpdiv_pipe_fp32", Float32, div) -def test_pipe_fp64(): +def test_pipe_div_fp64(): dut = FPDIVMuxInOut(64, 4) runfp(dut, 64, "test_fpdiv_pipe_fp64", Float64, div) if __name__ == '__main__': - test_pipe_fp16() - test_pipe_fp32() - test_pipe_fp64() + test_pipe_div_fp16() + test_pipe_div_fp32() + test_pipe_div_fp64() diff --git a/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py b/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py new file mode 100644 index 00000000..84cd4dad --- /dev/null +++ b/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py @@ -0,0 +1,30 @@ +""" test of FPDIVMuxInOut +""" + +from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) +from ieee754.fpcommon.test.fpmux import runfp + +from sfpy import Float64, Float32, Float16 + +def sqrt(x): + return x.sqrt() + +def test_pipe_sqrt_fp16(): + dut = FPDIVMuxInOut(16, 4) + runfp(dut, 16, "test_fpsqrt_pipe_fp16", Float16, sqrt, + single_op=True, opcode=1) + +def test_pipe_sqrt_fp32(): + dut = FPDIVMuxInOut(32, 4) + runfp(dut, 32, "test_fpsqrt_pipe_fp32", Float32, sqrt, + single_op=True, opcode=1) + +def test_pipe_sqrt_fp64(): + dut = FPDIVMuxInOut(64, 4) + runfp(dut, 64, "test_fpsqrt_pipe_fp64", Float64, sqrt, + single_op=True, opcode=1) + +if __name__ == '__main__': + test_pipe_sqrt_fp16() + test_pipe_sqrt_fp32() + test_pipe_sqrt_fp64() -- 2.30.2