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 yield from zip(stimulus_a
, stimulus_b
)
36 yield from zip(stimulus_b
, stimulus_a
)
39 def get_nan_noncan(mod
, fixed_num
, maxcount
, width
):
40 stimulus_a
= replicate(fixed_num
, maxcount
)
42 stimulus_b
= [mod
.set_exponent(get_rval(width
), mod
.max_e
) \
43 for i
in range(maxcount
)]
44 yield from zip(stimulus_a
, stimulus_b
)
45 yield from zip(stimulus_b
, stimulus_a
)
48 def get_n127(mod
, fixed_num
, maxcount
, width
):
49 stimulus_a
= replicate(fixed_num
, maxcount
)
51 stimulus_b
= [mod
.set_exponent(get_rval(width
), -mod
.max_e
+1
) \
52 for i
in range(maxcount
)]
53 yield from zip(stimulus_a
, stimulus_b
)
54 yield from zip(stimulus_b
, stimulus_a
)
57 def get_nearly_zero(mod
, fixed_num
, maxcount
, width
):
58 stimulus_a
= replicate(fixed_num
, maxcount
)
60 stimulus_b
= [mod
.set_exponent(get_rval(width
), -mod
.max_e
+2
) \
61 for i
in range(maxcount
)]
62 yield from zip(stimulus_a
, stimulus_b
)
63 yield from zip(stimulus_b
, stimulus_a
)
66 def get_nearly_inf(mod
, fixed_num
, maxcount
, width
):
67 stimulus_a
= replicate(fixed_num
, maxcount
)
69 stimulus_b
= [mod
.set_exponent(get_rval(width
), mod
.max_e
-1
) \
70 for i
in range(maxcount
)]
71 yield from zip(stimulus_a
, stimulus_b
)
72 yield from zip(stimulus_b
, stimulus_a
)
75 def get_corner_rand(mod
, fixed_num
, maxcount
, width
):
76 stimulus_a
= replicate(fixed_num
, maxcount
)
78 stimulus_b
= [get_rval(width
) for i
in range(maxcount
)]
79 yield from zip(stimulus_a
, stimulus_b
)
80 yield from zip(stimulus_b
, stimulus_a
)
84 def __init__(self
, dut
, name
, mod
, fmod
, width
, fpfn
, count
):
93 def run(self
, name
, fn
):
94 name
= "%s_%s" % (self
.name
, name
)
95 pipe_cornercases_repeat(self
.dut
, name
, self
.mod
, self
.fmod
,
96 self
.width
, fn
, corner_cases
, self
.fpfn
,
99 def run_cornercases(self
):
100 vals
= repeat(self
.dut
.num_rows
, get_corner_cases(self
.mod
))
101 tname
= "test_fp%s_pipe_fp%d_cornercases" % (self
.name
, self
.width
)
102 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
, vals
=vals
)
104 def run_regressions(self
, regressions_fn
):
105 vals
= repeat(self
.dut
.num_rows
, regressions_fn())
106 print ("regressions", vals
)
107 tname
= "test_fp%s_pipe_fp%d_regressions" % (self
.name
, self
.width
)
108 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
, vals
=vals
)
110 def run_random(self
):
111 tname
= "test_fp%s_pipe_fp%d_rand" % (self
.name
, self
.width
)
112 runfp(self
.dut
, self
.width
, tname
, self
.fmod
, self
.fpfn
)
115 def run_pipe_fp(dut
, width
, name
, mod
, fmod
, regressions
, fpfn
, count
):
116 pc
= PipeFPCase(dut
, name
, mod
, fmod
, width
, fpfn
, count
)
117 pc
.run_regressions(regressions
)
119 pc
.run("rand1", get_rand1
)
120 pc
.run("n127", get_n127
)
121 pc
.run("noncan", get_nan_noncan
)
122 pc
.run("nearlyzero", get_nearly_zero
)
123 pc
.run("nearlyinf", get_nearly_inf
)
124 pc
.run("corner_rand", get_corner_rand
)