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
, single_op
=False):
15 from itertools
import permutations
16 cc
= corner_cases(mod
)
17 stimulus_a
= [i
[0] for i
in permutations(cc
, 2)]
20 stimulus_b
= [i
[1] for i
in permutations(cc
, 2)]
21 return zip(stimulus_a
, stimulus_b
)
24 def replicate(fixed_num
, maxcount
):
25 if isinstance(fixed_num
, int):
26 return [fixed_num
for i
in range(maxcount
)]
32 return randint(0, mval
)
34 def get_rand1(mod
, fixed_num
, maxcount
, width
, single_op
=False):
35 stimulus_b
= [get_rval(width
) for i
in range(maxcount
)]
39 stimulus_a
= replicate(fixed_num
, maxcount
)
40 yield from zip(stimulus_a
, stimulus_b
)
41 yield from zip(stimulus_b
, stimulus_a
)
44 def get_nan_noncan(mod
, fixed_num
, maxcount
, width
, single_op
=False):
46 stimulus_b
= [mod
.set_exponent(get_rval(width
), mod
.max_e
) \
47 for i
in range(maxcount
)]
51 stimulus_a
= replicate(fixed_num
, maxcount
)
52 yield from zip(stimulus_a
, stimulus_b
)
53 yield from zip(stimulus_b
, stimulus_a
)
56 def get_n127(mod
, fixed_num
, maxcount
, width
, single_op
=False):
58 stimulus_b
= [mod
.set_exponent(get_rval(width
), -mod
.max_e
+1
) \
59 for i
in range(maxcount
)]
63 stimulus_a
= replicate(fixed_num
, maxcount
)
64 yield from zip(stimulus_a
, stimulus_b
)
65 yield from zip(stimulus_b
, stimulus_a
)
68 def get_nearly_zero(mod
, fixed_num
, maxcount
, width
, single_op
=False):
70 stimulus_b
= [mod
.set_exponent(get_rval(width
), -mod
.max_e
+2
) \
71 for i
in range(maxcount
)]
75 stimulus_a
= replicate(fixed_num
, maxcount
)
76 yield from zip(stimulus_a
, stimulus_b
)
77 yield from zip(stimulus_b
, stimulus_a
)
80 def get_nearly_inf(mod
, fixed_num
, maxcount
, width
, single_op
=False):
82 stimulus_b
= [mod
.set_exponent(get_rval(width
), mod
.max_e
-1
) \
83 for i
in range(maxcount
)]
87 stimulus_a
= replicate(fixed_num
, maxcount
)
88 yield from zip(stimulus_a
, stimulus_b
)
89 yield from zip(stimulus_b
, stimulus_a
)
92 def get_corner_rand(mod
, fixed_num
, maxcount
, width
, single_op
=False):
94 stimulus_b
= [get_rval(width
) for i
in range(maxcount
)]
98 stimulus_a
= replicate(fixed_num
, maxcount
)
99 yield from zip(stimulus_a
, stimulus_b
)
100 yield from zip(stimulus_b
, stimulus_a
)
104 def __init__(self
, dut
, name
, mod
, fmod
, width
, fpfn
, count
, single_op
):
112 self
.single_op
= single_op
114 def run(self
, name
, fn
):
115 name
= "%s_%s" % (self
.name
, name
)
116 pipe_cornercases_repeat(self
.dut
, name
, self
.mod
, self
.fmod
,
117 self
.width
, fn
, corner_cases
, self
.fpfn
,
118 self
.count
, self
.single_op
)
120 def run_cornercases(self
):
121 ccs
= get_corner_cases(self
.mod
, self
.single_op
)
122 vals
= repeat(self
.dut
.num_rows
, ccs
)
123 tname
= "test_fp%s_pipe_fp%d_cornercases" % (self
.name
, self
.width
)
124 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
, vals
=vals
,
125 single_op
=self
.single_op
)
127 def run_regressions(self
, regressions_fn
):
128 vals
= repeat(self
.dut
.num_rows
, regressions_fn())
129 #print ("regressions", self.single_op, vals)
130 tname
= "test_fp%s_pipe_fp%d_regressions" % (self
.name
, self
.width
)
131 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
, vals
=vals
,
132 single_op
=self
.single_op
)
134 def run_random(self
):
135 tname
= "test_fp%s_pipe_fp%d_rand" % (self
.name
, self
.width
)
136 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
,
137 single_op
=self
.single_op
)
140 def run_pipe_fp(dut
, width
, name
, mod
, fmod
, regressions
, fpfn
, count
,
142 pc
= PipeFPCase(dut
, name
, mod
, fmod
, width
, fpfn
, count
, single_op
)
143 pc
.run_regressions(regressions
)
145 pc
.run("rand1", get_rand1
)
146 pc
.run("n127", get_n127
)
147 pc
.run("noncan", get_nan_noncan
)
148 pc
.run("nearlyzero", get_nearly_zero
)
149 pc
.run("nearlyinf", get_nearly_inf
)
150 pc
.run("corner_rand", get_corner_rand
)