fix for python 2.6.6

This commit is contained in:
Clifford Wolf 2015-03-20 09:10:02 +01:00
parent aed4d763cf
commit 604c097f98
3 changed files with 172 additions and 165 deletions

View File

@ -34,76 +34,78 @@ def random_expr(variables):
raise AssertionError raise AssertionError
for idx in range(50): for idx in range(50):
with file('temp/uut_%05d.v' % idx, 'w') as f, redirect_stdout(f): with file('temp/uut_%05d.v' % idx, 'w') as f:
rst2 = random.choice([False, True]) with redirect_stdout(f):
if rst2: rst2 = random.choice([False, True])
print('module uut_%05d(clk, rst1, rst2, rst, a, b, c, x, y, z);' % (idx)) if rst2:
print(' input clk, rst1, rst2;') print('module uut_%05d(clk, rst1, rst2, rst, a, b, c, x, y, z);' % (idx))
print(' output rst;') print(' input clk, rst1, rst2;')
print(' assign rst = rst1 || rst2;') print(' output rst;')
else: print(' assign rst = rst1 || rst2;')
print('module uut_%05d(clk, rst, a, b, c, x, y, z);' % (idx)) else:
print(' input clk, rst;') print('module uut_%05d(clk, rst, a, b, c, x, y, z);' % (idx))
variables=['a', 'b', 'c', 'x', 'y', 'z'] print(' input clk, rst;')
print(' input%s [%d:0] a;' % (random.choice(['', ' signed']), random.randint(0, 31))) variables=['a', 'b', 'c', 'x', 'y', 'z']
print(' input%s [%d:0] b;' % (random.choice(['', ' signed']), random.randint(0, 31))) print(' input%s [%d:0] a;' % (random.choice(['', ' signed']), random.randint(0, 31)))
print(' input%s [%d:0] c;' % (random.choice(['', ' signed']), random.randint(0, 31))) print(' input%s [%d:0] b;' % (random.choice(['', ' signed']), random.randint(0, 31)))
print(' output reg%s [%d:0] x;' % (random.choice(['', ' signed']), random.randint(0, 31))) print(' input%s [%d:0] c;' % (random.choice(['', ' signed']), random.randint(0, 31)))
print(' output reg%s [%d:0] y;' % (random.choice(['', ' signed']), random.randint(0, 31))) print(' output reg%s [%d:0] x;' % (random.choice(['', ' signed']), random.randint(0, 31)))
print(' output reg%s [%d:0] z;' % (random.choice(['', ' signed']), random.randint(0, 31))) print(' output reg%s [%d:0] y;' % (random.choice(['', ' signed']), random.randint(0, 31)))
state_bits = random.randint(5, 16); print(' output reg%s [%d:0] z;' % (random.choice(['', ' signed']), random.randint(0, 31)))
print(' %sreg [%d:0] state;' % (random.choice(['', '(* fsm_encoding = "one-hot" *)', state_bits = random.randint(5, 16);
'(* fsm_encoding = "binary" *)']), state_bits-1)) print(' %sreg [%d:0] state;' % (random.choice(['', '(* fsm_encoding = "one-hot" *)',
states=[] '(* fsm_encoding = "binary" *)']), state_bits-1))
for i in range(random.randint(2, 10)): states=[]
n = random.randint(0, 2**state_bits-1) for i in range(random.randint(2, 10)):
if n not in states: n = random.randint(0, 2**state_bits-1)
states.append(n) if n not in states:
print(' always @(posedge clk) begin') states.append(n)
print(' if (%s) begin' % ('rst1' if rst2 else 'rst')) print(' always @(posedge clk) begin')
print(' x <= %d;' % random.randint(0, 2**31-1)) print(' if (%s) begin' % ('rst1' if rst2 else 'rst'))
print(' y <= %d;' % random.randint(0, 2**31-1)) print(' x <= %d;' % random.randint(0, 2**31-1))
print(' z <= %d;' % random.randint(0, 2**31-1)) print(' y <= %d;' % random.randint(0, 2**31-1))
print(' state <= %d;' % random.choice(states)) print(' z <= %d;' % random.randint(0, 2**31-1))
print(' end else begin') print(' state <= %d;' % random.choice(states))
print(' case (state)') print(' end else begin')
for state in states: print(' case (state)')
print(' %d: begin' % state) for state in states:
for var in ('x', 'y', 'z'): print(' %d: begin' % state)
print(' %s <= %s;' % (var, random_expr(variables))) for var in ('x', 'y', 'z'):
next_states = states[:] print(' %s <= %s;' % (var, random_expr(variables)))
for i in range(random.randint(0, len(states))): next_states = states[:]
next_state = random.choice(next_states) for i in range(random.randint(0, len(states))):
next_states.remove(next_state) next_state = random.choice(next_states)
print(' if ((%s) %s (%s)) state <= %s;' % (random_expr(variables), next_states.remove(next_state)
random.choice(['<', '<=', '>=', '>']), random_expr(variables), next_state)) print(' if ((%s) %s (%s)) state <= %s;' % (random_expr(variables),
print(' end') random.choice(['<', '<=', '>=', '>']), random_expr(variables), next_state))
print(' endcase') print(' end')
if rst2: print(' endcase')
print(' if (rst2) begin') if rst2:
print(' x <= a;') print(' if (rst2) begin')
print(' y <= b;') print(' x <= a;')
print(' z <= c;') print(' y <= b;')
print(' state <= %d;' % random.choice(states)) print(' z <= c;')
print(' end') print(' state <= %d;' % random.choice(states))
print(' end') print(' end')
print(' end') print(' end')
print('endmodule') print(' end')
with file('temp/uut_%05d.ys' % idx, 'w') as f, redirect_stdout(f): print('endmodule')
if test_verific: with file('temp/uut_%05d.ys' % idx, 'w') as f:
print('read_verilog temp/uut_%05d.v' % idx) with redirect_stdout(f):
print('proc;; rename uut_%05d gold' % idx) if test_verific:
print('verific -vlog2k temp/uut_%05d.v' % idx) print('read_verilog temp/uut_%05d.v' % idx)
print('verific -import uut_%05d' % idx) print('proc;; rename uut_%05d gold' % idx)
print('rename uut_%05d gate' % idx) print('verific -vlog2k temp/uut_%05d.v' % idx)
else: print('verific -import uut_%05d' % idx)
print('read_verilog temp/uut_%05d.v' % idx) print('rename uut_%05d gate' % idx)
print('proc;;') else:
print('copy uut_%05d gold' % idx) print('read_verilog temp/uut_%05d.v' % idx)
print('rename uut_%05d gate' % idx) print('proc;;')
print('cd gate') print('copy uut_%05d gold' % idx)
print('opt; wreduce; share%s; opt; fsm;;' % random.choice(['', ' -aggressive'])) print('rename uut_%05d gate' % idx)
print('cd ..') print('cd gate')
print('miter -equiv -flatten -ignore_gold_x -make_outputs -make_outcmp gold gate miter') print('opt; wreduce; share%s; opt; fsm;;' % random.choice(['', ' -aggressive']))
print('sat -verify-no-timeout -timeout 20 -seq 5 -set-at 1 %s_rst 1 -prove trigger 0 -prove-skip 1 -show-inputs -show-outputs miter' % ('gold' if rst2 else 'in')) print('cd ..')
print('miter -equiv -flatten -ignore_gold_x -make_outputs -make_outcmp gold gate miter')
print('sat -verify-no-timeout -timeout 20 -seq 5 -set-at 1 %s_rst 1 -prove trigger 0 -prove-skip 1 -show-inputs -show-outputs miter' % ('gold' if rst2 else 'in'))

View File

@ -40,52 +40,55 @@ def random_expression(depth = 3, maxparam = 0):
raise raise
for idx in range(100): for idx in range(100):
with file('temp/uut_%05d.v' % idx, 'w') as f, redirect_stdout(f): with file('temp/uut_%05d.v' % idx, 'w') as f:
print('module uut_%05d(output [63:0] %s);\n' % (idx, ', '.join(['y%02d' % i for i in range(100)]))) with redirect_stdout(f):
for i in range(30): print('module uut_%05d(output [63:0] %s);\n' % (idx, ', '.join(['y%02d' % i for i in range(100)])))
if idx < 10: for i in range(30):
print('localparam p%02d = %s;' % (i, random_expression())) if idx < 10:
else: print('localparam p%02d = %s;' % (i, random_expression()))
print('localparam%s p%02d = %s;' % (random.choice(['', ' real', ' integer']), i, random_expression())) else:
for i in range(30, 60): print('localparam%s p%02d = %s;' % (random.choice(['', ' real', ' integer']), i, random_expression()))
if idx < 10: for i in range(30, 60):
print('localparam p%02d = %s;' % (i, random_expression(maxparam = 30))) if idx < 10:
else: print('localparam p%02d = %s;' % (i, random_expression(maxparam = 30)))
print('localparam%s p%02d = %s;' % (random.choice(['', ' real', ' integer']), i, random_expression(maxparam = 30))) else:
for i in range(100): print('localparam%s p%02d = %s;' % (random.choice(['', ' real', ' integer']), i, random_expression(maxparam = 30)))
print('assign y%02d = 65536 * (%s);' % (i, random_expression(maxparam = 60))) for i in range(100):
print('endmodule') print('assign y%02d = 65536 * (%s);' % (i, random_expression(maxparam = 60)))
with file('temp/uut_%05d.ys' % idx, 'w') as f, redirect_stdout(f): print('endmodule')
print('read_verilog uut_%05d.v' % idx) with file('temp/uut_%05d.ys' % idx, 'w') as f:
print('rename uut_%05d uut_%05d_syn' % (idx, idx)) with redirect_stdout(f):
print('write_verilog uut_%05d_syn.v' % idx) print('read_verilog uut_%05d.v' % idx)
with file('temp/uut_%05d_tb.v' % idx, 'w') as f, redirect_stdout(f): print('rename uut_%05d uut_%05d_syn' % (idx, idx))
print('module uut_%05d_tb;\n' % idx) print('write_verilog uut_%05d_syn.v' % idx)
print('wire [63:0] %s;' % (', '.join(['r%02d' % i for i in range(100)]))) with file('temp/uut_%05d_tb.v' % idx, 'w') as f:
print('wire [63:0] %s;' % (', '.join(['s%02d' % i for i in range(100)]))) with redirect_stdout(f):
print('uut_%05d ref(%s);' % (idx, ', '.join(['r%02d' % i for i in range(100)]))) print('module uut_%05d_tb;\n' % idx)
print('uut_%05d_syn syn(%s);' % (idx, ', '.join(['s%02d' % i for i in range(100)]))) print('wire [63:0] %s;' % (', '.join(['r%02d' % i for i in range(100)])))
print('task compare_ref_syn;') print('wire [63:0] %s;' % (', '.join(['s%02d' % i for i in range(100)])))
print(' input [7:0] i;') print('uut_%05d ref(%s);' % (idx, ', '.join(['r%02d' % i for i in range(100)])))
print(' input [63:0] r, s;') print('uut_%05d_syn syn(%s);' % (idx, ', '.join(['s%02d' % i for i in range(100)])))
print(' reg [64*8-1:0] buffer;') print('task compare_ref_syn;')
print(' integer j;') print(' input [7:0] i;')
print(' begin') print(' input [63:0] r, s;')
print(' if (-1 <= $signed(r-s) && $signed(r-s) <= +1) begin') print(' reg [64*8-1:0] buffer;')
print(' // $display("%d: %b %b", i, r, s);') print(' integer j;')
print(' end else if (r === s) begin ') print(' begin')
print(' // $display("%d: %b %b", i, r, s);') print(' if (-1 <= $signed(r-s) && $signed(r-s) <= +1) begin')
print(' end else begin ') print(' // $display("%d: %b %b", i, r, s);')
print(' for (j = 0; j < 64; j = j+1)') print(' end else if (r === s) begin ')
print(' buffer[j*8 +: 8] = r[j] !== s[j] ? "^" : " ";') print(' // $display("%d: %b %b", i, r, s);')
print(' $display("\\n%3d: %b %b", i, r, s);') print(' end else begin ')
print(' $display(" %s %s", buffer, buffer);') print(' for (j = 0; j < 64; j = j+1)')
print(' end') print(' buffer[j*8 +: 8] = r[j] !== s[j] ? "^" : " ";')
print(' end') print(' $display("\\n%3d: %b %b", i, r, s);')
print('endtask') print(' $display(" %s %s", buffer, buffer);')
print('initial begin #1;') print(' end')
for i in range(100): print(' end')
print(' compare_ref_syn(%2d, r%02d, s%02d);' % (i, i, i)) print('endtask')
print('end') print('initial begin #1;')
print('endmodule') for i in range(100):
print(' compare_ref_syn(%2d, r%02d, s%02d);' % (i, i, i))
print('end')
print('endmodule')

View File

@ -25,49 +25,51 @@ def maybe_plus_x(expr):
return expr return expr
for idx in range(100): for idx in range(100):
with file('temp/uut_%05d.v' % idx, 'w') as f, redirect_stdout(f): with file('temp/uut_%05d.v' % idx, 'w') as f:
if random.choice(['bin', 'uni']) == 'bin': with redirect_stdout(f):
print('module uut_%05d(a, b, c, d, x, s, y);' % (idx)) if random.choice(['bin', 'uni']) == 'bin':
op = random.choice([ print('module uut_%05d(a, b, c, d, x, s, y);' % (idx))
random.choice(['+', '-', '*', '/', '%']), op = random.choice([
random.choice(['<', '<=', '==', '!=', '===', '!==', '>=', '>' ]), random.choice(['+', '-', '*', '/', '%']),
random.choice(['<<', '>>', '<<<', '>>>']), random.choice(['<', '<=', '==', '!=', '===', '!==', '>=', '>' ]),
random.choice(['|', '&', '^', '~^', '||', '&&']), random.choice(['<<', '>>', '<<<', '>>>']),
]) random.choice(['|', '&', '^', '~^', '||', '&&']),
print(' input%s [%d:0] a;' % (random.choice(['', ' signed']), random.randint(0, 8))) ])
print(' input%s [%d:0] b;' % (random.choice(['', ' signed']), random.randint(0, 8))) print(' input%s [%d:0] a;' % (random.choice(['', ' signed']), random.randint(0, 8)))
print(' input%s [%d:0] c;' % (random.choice(['', ' signed']), random.randint(0, 8))) print(' input%s [%d:0] b;' % (random.choice(['', ' signed']), random.randint(0, 8)))
print(' input%s [%d:0] d;' % (random.choice(['', ' signed']), random.randint(0, 8))) print(' input%s [%d:0] c;' % (random.choice(['', ' signed']), random.randint(0, 8)))
print(' input%s [%d:0] x;' % (random.choice(['', ' signed']), random.randint(0, 8))) print(' input%s [%d:0] d;' % (random.choice(['', ' signed']), random.randint(0, 8)))
print(' input s;') print(' input%s [%d:0] x;' % (random.choice(['', ' signed']), random.randint(0, 8)))
print(' output [%d:0] y;' % random.randint(0, 8)) print(' input s;')
print(' assign y = (s ? %s(%s %s %s) : %s(%s %s %s))%s;' % print(' output [%d:0] y;' % random.randint(0, 8))
(random.choice(['', '$signed', '$unsigned']), maybe_plus_x('a'), op, maybe_plus_x('b'), print(' assign y = (s ? %s(%s %s %s) : %s(%s %s %s))%s;' %
random.choice(['', '$signed', '$unsigned']), maybe_plus_x('c'), op, maybe_plus_x('d'), (random.choice(['', '$signed', '$unsigned']), maybe_plus_x('a'), op, maybe_plus_x('b'),
random_plus_x() if random.randint(0, 4) == 0 else '')) random.choice(['', '$signed', '$unsigned']), maybe_plus_x('c'), op, maybe_plus_x('d'),
print('endmodule') random_plus_x() if random.randint(0, 4) == 0 else ''))
else: print('endmodule')
print('module uut_%05d(a, b, x, s, y);' % (idx)) else:
op = random.choice(['~', '-', '!']) print('module uut_%05d(a, b, x, s, y);' % (idx))
print(' input%s [%d:0] a;' % (random.choice(['', ' signed']), random.randint(0, 8))) op = random.choice(['~', '-', '!'])
print(' input%s [%d:0] b;' % (random.choice(['', ' signed']), random.randint(0, 8))) print(' input%s [%d:0] a;' % (random.choice(['', ' signed']), random.randint(0, 8)))
print(' input%s [%d:0] x;' % (random.choice(['', ' signed']), random.randint(0, 8))) print(' input%s [%d:0] b;' % (random.choice(['', ' signed']), random.randint(0, 8)))
print(' input s;') print(' input%s [%d:0] x;' % (random.choice(['', ' signed']), random.randint(0, 8)))
print(' output [%d:0] y;' % random.randint(0, 8)) print(' input s;')
print(' assign y = (s ? %s(%s%s) : %s(%s%s))%s;' % print(' output [%d:0] y;' % random.randint(0, 8))
(random.choice(['', '$signed', '$unsigned']), op, maybe_plus_x('a'), print(' assign y = (s ? %s(%s%s) : %s(%s%s))%s;' %
random.choice(['', '$signed', '$unsigned']), op, maybe_plus_x('b'), (random.choice(['', '$signed', '$unsigned']), op, maybe_plus_x('a'),
random_plus_x() if random.randint(0, 4) == 0 else '')) random.choice(['', '$signed', '$unsigned']), op, maybe_plus_x('b'),
print('endmodule') random_plus_x() if random.randint(0, 4) == 0 else ''))
with file('temp/uut_%05d.ys' % idx, 'w') as f, redirect_stdout(f): print('endmodule')
print('read_verilog temp/uut_%05d.v' % idx) with file('temp/uut_%05d.ys' % idx, 'w') as f:
print('proc;;') with redirect_stdout(f):
print('copy uut_%05d gold' % idx) print('read_verilog temp/uut_%05d.v' % idx)
print('rename uut_%05d gate' % idx) print('proc;;')
print('tee -a temp/all_share_log.txt log') print('copy uut_%05d gold' % idx)
print('tee -a temp/all_share_log.txt log #job# uut_%05d' % idx) print('rename uut_%05d gate' % idx)
print('tee -a temp/all_share_log.txt wreduce') print('tee -a temp/all_share_log.txt log')
print('tee -a temp/all_share_log.txt share -aggressive gate') print('tee -a temp/all_share_log.txt log #job# uut_%05d' % idx)
print('miter -equiv -flatten -ignore_gold_x -make_outputs -make_outcmp gold gate miter') print('tee -a temp/all_share_log.txt wreduce')
print('sat -set-def-inputs -verify -prove trigger 0 -show-inputs -show-outputs miter') print('tee -a temp/all_share_log.txt share -aggressive gate')
print('miter -equiv -flatten -ignore_gold_x -make_outputs -make_outcmp gold gate miter')
print('sat -set-def-inputs -verify -prove trigger 0 -show-inputs -show-outputs miter')