5a1661a159c6c1167cd6580e23ad60aa6bfc7457
1 from ieee754
.fpcommon
.test
.fpmux
import runfp
, repeat
, pipe_cornercases_repeat
3 from random
import randint
4 from random
import seed
9 return [mod
.zero(1), mod
.zero(0),
10 mod
.inf(1), mod
.inf(0),
11 mod
.nan(1), mod
.nan(0)]
13 def get_corner_cases(mod
):
15 from itertools
import permutations
16 cc
= corner_cases(mod
)
17 stimulus_a
= [i
[0] for i
in permutations(cc
, 2)]
18 stimulus_b
= [i
[1] for i
in permutations(cc
, 2)]
19 return zip(stimulus_a
, stimulus_b
)
22 def replicate(fixed_num
, maxcount
):
23 if isinstance(fixed_num
, int):
24 return [fixed_num
for i
in range(maxcount
)]
30 return randint(0, mval
)
32 def get_rand1(mod
, fixed_num
, maxcount
, width
):
33 stimulus_a
= replicate(fixed_num
, maxcount
)
34 stimulus_b
= [get_rval(width
) for i
in range(maxcount
)]
35 return zip(stimulus_a
, stimulus_b
)
38 def get_nan_noncan(mod
, fixed_num
, maxcount
, width
):
39 stimulus_a
= replicate(fixed_num
, maxcount
)
41 stimulus_b
= [mod
.set_exponent(get_rval(width
), mod
.max_e
) \
42 for i
in range(maxcount
)]
43 return zip(stimulus_a
, stimulus_b
)
46 def get_n127(mod
, fixed_num
, maxcount
, width
):
47 stimulus_a
= replicate(fixed_num
, maxcount
)
49 stimulus_b
= [mod
.set_exponent(get_rval(width
), -mod
.max_e
+1
) \
50 for i
in range(maxcount
)]
51 return zip(stimulus_a
, stimulus_b
)
54 def get_nearly_zero(mod
, fixed_num
, maxcount
, width
):
55 stimulus_a
= replicate(fixed_num
, maxcount
)
57 stimulus_b
= [mod
.set_exponent(get_rval(width
), -mod
.max_e
+2
) \
58 for i
in range(maxcount
)]
59 return zip(stimulus_a
, stimulus_b
)
62 def get_nearly_inf(mod
, fixed_num
, maxcount
, width
):
63 stimulus_a
= replicate(fixed_num
, maxcount
)
65 stimulus_b
= [mod
.set_exponent(get_rval(width
), mod
.max_e
-1
) \
66 for i
in range(maxcount
)]
67 return zip(stimulus_a
, stimulus_b
)
70 def get_corner_rand(mod
, fixed_num
, maxcount
, width
):
71 stimulus_a
= replicate(fixed_num
, maxcount
)
73 stimulus_b
= [get_rval(width
) for i
in range(maxcount
)]
74 return zip(stimulus_a
, stimulus_b
)
78 def __init__(self
, dut
, name
, mod
, fmod
, width
, fpfn
, count
):
87 def run(self
, name
, fn
):
88 name
= "%s_%s" % (self
.name
, name
)
89 pipe_cornercases_repeat(self
.dut
, name
, self
.mod
, self
.fmod
,
90 self
.width
, fn
, corner_cases
, self
.fpfn
,
93 def run_cornercases(self
):
94 vals
= repeat(self
.dut
.num_rows
, get_corner_cases(self
.mod
))
95 tname
= "test_fp%s_pipe_fp%d_cornercases" % (self
.name
, self
.width
)
96 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
, vals
=vals
)
98 def run_regressions(self
, regressions_fn
):
99 vals
= repeat(self
.dut
.num_rows
, regressions_fn())
100 tname
= "test_fp%s_pipe_fp%d_regressions" % (self
.name
, self
.width
)
101 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
, vals
=vals
)
103 def run_random(self
):
104 tname
= "test_fp%s_pipe_fp%d_rand" % (self
.name
, self
.width
)
105 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
)
108 def run_pipe_fp(dut
, width
, name
, mod
, fmod
, regressions
, fpfn
, count
):
109 pc
= PipeFPCase(dut
, name
, mod
, fmod
, width
, fpfn
, count
)
110 pc
.run("rand1", get_rand1
)
111 pc
.run("n127", get_n127
)
112 pc
.run("noncan", get_nan_noncan
)
113 pc
.run("nearlyzero", get_nearly_zero
)
114 pc
.run("nearlyinf", get_nearly_inf
)
115 pc
.run("corner_rand", get_corner_rand
)
117 pc
.run_regressions(regressions
)