3 from __future__
import division
4 from __future__
import print_function
8 from contextlib
import contextmanager
12 old_target, sys.stdout = sys.stdout, new_target
16 sys.stdout = old_target
22 if maxparam != 0
and random.randint(0, 1) != 0:
23 return 'p%02d' % random.randint(0, maxparam-1)
24 return random.choice([
'%e',
'%f',
'%g' ]) % random.uniform(-2, +2)
25 if random.randint(0, 4) == 0:
26 return recursion() + random.choice([
' < ',
' <= ',
' == ',
' != ',
' >= ',
' > ' ]) + recursion() +
' ? ' + recursion() +
' : ' + recursion()
27 op_prefix = [
'+(',
'-(' ]
28 op_infix = [
' + ',
' - ',
' * ',
' / ' ]
29 op_func1 = [
'$ln',
'$log10',
'$exp',
'$sqrt',
'$floor',
'$ceil',
'$sin',
'$cos',
'$tan',
'$asin',
'$acos',
'$atan',
'$sinh',
'$cosh',
'$tanh',
'$asinh',
'$acosh',
'$atanh' ]
30 op_func2 = [
'$pow',
'$atan2',
'$hypot' ]
31 op = random.choice(op_prefix + op_infix + op_func1 + op_func2)
33 return op + recursion() +
')'
35 return '(' + recursion() + op + recursion() +
')'
37 return op +
'(' + recursion() +
')'
39 return op +
'(' + recursion() +
', ' + recursion() +
')'
42 for idx
in range(100):
44 print(
'module uut_%05d(output [63:0] %s);\n' % (idx,
', '.join([
'y%02d' % i
for i
in range(100)])))
49 print(
'localparam%s p%02d = %s;' % (random.choice([
'',
' real',
' integer']), i,
random_expression()))
50 for i
in range(30, 60):
54 print(
'localparam%s p%02d = %s;' % (random.choice([
'',
' real',
' integer']), i,
random_expression(maxparam = 30)))
59 print(
'read_verilog uut_%05d.v' % idx)
60 print(
'rename uut_%05d uut_%05d_syn' % (idx, idx))
61 print(
'write_verilog uut_%05d_syn.v' % idx)
63 print(
'module uut_%05d_tb;\n' % idx)
64 print(
'wire [63:0] %s;' % (
', '.join([
'r%02d' % i
for i
in range(100)])))
65 print(
'wire [63:0] %s;' % (
', '.join([
's%02d' % i
for i
in range(100)])))
66 print(
'uut_%05d ref(%s);' % (idx,
', '.join([
'r%02d' % i
for i
in range(100)])))
67 print(
'uut_%05d_syn syn(%s);' % (idx,
', '.join([
's%02d' % i
for i
in range(100)])))
68 print(
'task compare_ref_syn;')
69 print(
' input [7:0] i;')
70 print(
' input [63:0] r, s;')
71 print(
' reg [64*8-1:0] buffer;')
74 print(
' if (-1 <= $signed(r-s) && $signed(r-s) <= +1) begin')
75 print(
' // $display("%d: %b %b", i, r, s);')
76 print(
' end else if (r === s) begin ')
77 print(
' // $display("%d: %b %b", i, r, s);')
78 print(
' end else begin ')
79 print(
' for (j = 0; j < 64; j = j+1)')
80 print(
' buffer[j*8 +: 8] = r[j] !== s[j] ? "^" : " ";')
81 print(
' $display("\\n%3d: %b %b", i, r, s);')
82 print(
' $display(" %s %s", buffer, buffer);')
86 print(
'initial begin #1;')
88 print(
' compare_ref_syn(%2d, r%02d, s%02d);' % (i, i, i))