-import sys
-import subprocess
from random import randint
from random import seed
+from operator import add
from nmigen import Module, Signal
from nmigen.compat.sim import run_simulation
#regression tests
stimulus_a = [0x22cb525a, 0x40000000, 0x83e73d5c, 0xbf9b1e94, 0x34082401, 0x5e8ef81, 0x5c75da81, 0x2b017]
stimulus_b = [0xadd79efa, 0xC0000000, 0x1c800000, 0xc038ed3a, 0xb328cd45, 0x114f3db, 0x2f642a39, 0xff3807ab]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
from itertools import permutations
stimulus_a = [i[0] for i in permutations([0x80000000, 0x00000000, 0x7f800000, 0xff800000, 0x7fc00000, 0xffc00000], 2)]
stimulus_b = [i[1] for i in permutations([0x80000000, 0x00000000, 0x7f800000, 0xff800000, 0x7fc00000, 0xffc00000], 2)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
#edge cases
stimulus_a = [0x80000000 for i in range(1000)]
stimulus_b = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0x00000000 for i in range(1000)]
stimulus_b = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0x80000000 for i in range(1000)]
stimulus_a = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0x00000000 for i in range(1000)]
stimulus_a = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0x7F800000 for i in range(1000)]
stimulus_b = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0xFF800000 for i in range(1000)]
stimulus_b = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0x7F800000 for i in range(1000)]
stimulus_a = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0xFF800000 for i in range(1000)]
stimulus_a = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0x7FC00000 for i in range(1000)]
stimulus_b = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0xFFC00000 for i in range(1000)]
stimulus_b = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0x7FC00000 for i in range(1000)]
stimulus_a = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0xFFC00000 for i in range(1000)]
stimulus_a = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
for i in range(100000):
stimulus_a = [randint(0, 1<<32) for i in range(1000)]
stimulus_b = [randint(0, 1<<32) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += 1000
print (count, "random vectors passed")
from nmigen import Module, Signal
from nmigen.compat.sim import run_simulation
+from operator import add
from nmigen_add_experiment import FPADD
#regression tests
stimulus_a = [0x3ff00000000000c5, 0xff80000000000000]
stimulus_b = [0xbd28a404211fb72b, 0x7f80000000000000]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
0x7ff0000000000000,
0xfff0000000000000
], 2)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
#edge cases
stimulus_a = [0x8000000000000000 for i in range(1000)]
stimulus_b = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0x0000000000000000 for i in range(1000)]
stimulus_b = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0x8000000000000000 for i in range(1000)]
stimulus_a = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0x0000000000000000 for i in range(1000)]
stimulus_a = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0x7FF8000000000000 for i in range(1000)]
stimulus_b = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0xFFF8000000000000 for i in range(1000)]
stimulus_b = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0x7FF8000000000000 for i in range(1000)]
stimulus_a = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0xFFF8000000000000 for i in range(1000)]
stimulus_a = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0x7FF0000000000000 for i in range(1000)]
stimulus_b = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_a = [0xFFF0000000000000 for i in range(1000)]
stimulus_b = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0x7FF0000000000000 for i in range(1000)]
stimulus_a = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
stimulus_b = [0xFFF0000000000000 for i in range(1000)]
stimulus_a = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += len(stimulus_a)
print (count, "vectors passed")
for i in range(100000):
stimulus_a = [randint(0, 1<<64) for i in range(1000)]
stimulus_b = [randint(0, 1<<64) for i in range(1000)]
- yield from run_test(dut, stimulus_a, stimulus_b)
+ yield from run_test(dut, stimulus_a, stimulus_b, add)
count += 1000
print (count, "random vectors passed")
def testbench(dut):
+ yield from check_case(dut, 0xbf9b1e94, 0xc038ed3a, 0xc0833e42)
yield from check_case(dut, 0x40000000, 0x3F800000, 0x40000000)
yield from check_case(dut, 0x3F800000, 0x40000000, 0x3F000000)
yield from check_case(dut, 0x3F800000, 0x40400000, 0x3EAAAAAB)
assert out_z == z, "Output z 0x%x not equal to expected 0x%x" % (out_z, z)
-def run_test(dut, stimulus_a, stimulus_b):
+def run_test(dut, stimulus_a, stimulus_b, op):
expected_responses = []
actual_responses = []
for a, b in zip(stimulus_a, stimulus_b):
af = Float64.from_bits(a)
bf = Float64.from_bits(b)
- z = af + bf
+ z = op(af, bf)
expected_responses.append(z.get_bits())
#print (af, bf, z)
actual = yield from get_case(dut, a, b)
assert out_z == z, "Output z 0x%x not equal to expected 0x%x" % (out_z, z)
-def run_test(dut, stimulus_a, stimulus_b):
+def run_test(dut, stimulus_a, stimulus_b, op):
expected_responses = []
actual_responses = []
for a, b in zip(stimulus_a, stimulus_b):
af = Float32.from_bits(a)
bf = Float32.from_bits(b)
- z = af + bf
+ z = op(af, bf)
expected_responses.append(z.get_bits())
#print (af, bf, z)
actual = yield from get_case(dut, a, b)