2015-10-21 10:27:25 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2016-01-06 16:50:49 +01:00
|
|
|
import sys, os, re, shutil
|
2015-10-21 10:27:25 +02:00
|
|
|
import numpy as np
|
|
|
|
|
|
2016-01-06 16:50:49 +01:00
|
|
|
max_span_hack = True
|
|
|
|
|
|
2015-10-21 10:27:25 +02:00
|
|
|
pins = np.random.permutation("""
|
|
|
|
|
1 2 3 4 7 8 9 10 11 12 19 22 23 24 25 26 28 29 31 32 33 34
|
|
|
|
|
37 38 41 42 43 44 45 47 48 52 56 58 60 61 62 63 64
|
|
|
|
|
73 74 75 76 78 79 80 81 87 88 90 91 95 96 97 98 101 102 104 105 106 107
|
|
|
|
|
112 113 114 115 116 117 118 119 120 121 122 134 135 136 137 138 139 141 142 143 144
|
|
|
|
|
""".split())
|
|
|
|
|
|
2015-10-25 02:18:04 +02:00
|
|
|
io_names = None
|
2016-01-06 16:50:49 +01:00
|
|
|
mode = sys.argv[1]
|
2015-10-25 02:18:04 +02:00
|
|
|
|
2015-10-21 10:27:25 +02:00
|
|
|
with open("%s.v" % sys.argv[1], "w") as f:
|
2015-10-25 02:18:04 +02:00
|
|
|
if mode == "test0":
|
|
|
|
|
io_names = [ "clk", "i0", "o0", "o1", "o2" ]
|
|
|
|
|
print("module top(input clk, i0, output o0, o1, o2);", file=f)
|
2015-10-25 15:28:58 +01:00
|
|
|
print(" reg [31:0] state;", file=f)
|
|
|
|
|
print(" always @(posedge clk) state <= ((state << 5) + state) ^ i0;", file=f)
|
|
|
|
|
print(" assign o0 = ^state, o1 = |state, o2 = state[31:16] + state[15:0];", file=f)
|
2015-10-25 02:18:04 +02:00
|
|
|
print("endmodule", file=f)
|
|
|
|
|
if mode == "test1":
|
|
|
|
|
io_names = [ "clk", "i0", "i1", "i2", "i3", "o0", "o1", "o2", "o3" ]
|
|
|
|
|
print("module top(input clk, i0, i1, i2, i3, output o0, o1, o2, o3);", file=f)
|
|
|
|
|
print(" reg [15:0] din, dout;", file=f)
|
|
|
|
|
print(" always @(posedge clk) din <= {din, i3, i2, i1, i0};", file=f)
|
|
|
|
|
print(" always @(posedge clk) dout <= din + {din[7:0], din[15:8]};", file=f)
|
|
|
|
|
print(" assign {o3, o2, o1, o0} = dout >> din;", file=f)
|
|
|
|
|
print("endmodule", file=f)
|
2016-01-01 00:32:28 +01:00
|
|
|
if mode == "test2":
|
2016-01-06 16:50:49 +01:00
|
|
|
io_names = [ "clk", "i0", "i1", "i2", "i3", "o0", "o1", "o2", "o3" ]
|
|
|
|
|
print("""
|
|
|
|
|
module top(input clk, i0, i1, i2, i3, output reg o0, o1, o2, o3);
|
|
|
|
|
reg [7:0] raddr, waddr, rdata, wdata;
|
|
|
|
|
reg [7:0] memory [0:255];
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
|
case ({i0, i1, i2})
|
|
|
|
|
0: raddr <= {raddr, i3};
|
|
|
|
|
1: waddr <= {waddr, i3};
|
|
|
|
|
2: wdata <= {wdata, i3};
|
|
|
|
|
3: rdata <= memory[raddr];
|
|
|
|
|
4: memory[waddr] <= wdata;
|
|
|
|
|
5: {o0, o1, o2, o3} <= rdata[3:0];
|
|
|
|
|
6: {o0, o1, o2, o3} <= rdata[7:4];
|
|
|
|
|
endcase
|
|
|
|
|
end
|
|
|
|
|
endmodule
|
|
|
|
|
""", file=f)
|
|
|
|
|
if mode == "test3":
|
2016-01-01 00:32:28 +01:00
|
|
|
io_names = [ "clk", "i0", "i1", "i2", "i3", "o0", "o1", "o2", "o3", "o4" ]
|
|
|
|
|
print("""
|
|
|
|
|
module top(input clk, i0, i1, i2, i3, output reg o0, o1, o2, o3, o4);
|
|
|
|
|
reg [9:0] raddr, waddr, rdata, wdata;
|
|
|
|
|
reg [9:0] memory [0:1023];
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
|
case ({i0, i1, i2})
|
|
|
|
|
0: raddr <= {raddr, i3};
|
|
|
|
|
1: waddr <= {waddr, i3};
|
|
|
|
|
2: wdata <= {wdata, i3};
|
|
|
|
|
3: rdata <= memory[raddr];
|
|
|
|
|
4: memory[waddr] <= wdata;
|
|
|
|
|
5: rdata <= memory[waddr];
|
|
|
|
|
6: {o0, o1, o2, o3, o4} <= rdata[4:0];
|
|
|
|
|
7: {o0, o1, o2, o3, o4} <= rdata[9:5];
|
|
|
|
|
endcase
|
|
|
|
|
end
|
|
|
|
|
endmodule
|
|
|
|
|
""", file=f)
|
2015-10-21 10:27:25 +02:00
|
|
|
|
|
|
|
|
with open("%s.pcf" % sys.argv[1], "w") as f:
|
2015-10-25 02:18:04 +02:00
|
|
|
for i, name in enumerate(io_names):
|
|
|
|
|
print("set_io %s %s" % (name, pins[i]), file=f)
|
2015-10-21 10:27:25 +02:00
|
|
|
|
2015-10-22 15:50:25 +02:00
|
|
|
with open("%s.ys" % sys.argv[1], "w") as f:
|
|
|
|
|
print("echo on", file=f)
|
|
|
|
|
print("read_verilog -lib cells.v", file=f)
|
|
|
|
|
print("read_verilog %s_ref.v" % sys.argv[1], file=f)
|
|
|
|
|
print("read_verilog %s_out.v" % sys.argv[1], file=f)
|
|
|
|
|
print("prep", file=f)
|
|
|
|
|
print("equiv_make top chip equiv", file=f)
|
2016-01-06 16:50:49 +01:00
|
|
|
print("# check -assert", file=f)
|
2015-10-25 15:28:58 +01:00
|
|
|
print("cd equiv", file=f)
|
|
|
|
|
print("script %s.lc" % sys.argv[1], file=f)
|
2015-10-23 17:16:37 +02:00
|
|
|
print("rename -hide w:N_*", file=f)
|
2016-01-06 16:50:49 +01:00
|
|
|
print("equiv_struct -maxiter 100", file=f)
|
2015-10-25 15:28:58 +01:00
|
|
|
print("opt_clean -purge", file=f)
|
2015-10-23 21:08:36 +02:00
|
|
|
print("write_ilang %s.il" % sys.argv[1], file=f)
|
|
|
|
|
print("equiv_status -assert", file=f)
|
2015-10-22 15:50:25 +02:00
|
|
|
|
2015-10-24 15:01:32 +02:00
|
|
|
assert os.system("bash ../icefuzz/icecube.sh %s.v" % sys.argv[1]) == 0
|
2015-10-21 10:27:25 +02:00
|
|
|
os.rename("%s.v" % sys.argv[1], "%s_in.v" % sys.argv[1])
|
2015-10-23 17:16:37 +02:00
|
|
|
|
|
|
|
|
with open("%s_ref.v" % sys.argv[1], "w") as f:
|
|
|
|
|
for line in open("%s.vsb" % sys.argv[1], "r"):
|
2016-01-06 16:50:49 +01:00
|
|
|
if re.match(r" *defparam .*\.(IO_STANDARD|PULLUP)=", line):
|
|
|
|
|
continue
|
2016-01-01 00:32:28 +01:00
|
|
|
|
|
|
|
|
line = line.replace(" Span4Mux_s0_h ", " Span4Mux_h4 " if max_span_hack else " Span4Mux_h0 ")
|
|
|
|
|
line = line.replace(" Span4Mux_s1_h ", " Span4Mux_h4 " if max_span_hack else " Span4Mux_h1 ")
|
|
|
|
|
line = line.replace(" Span4Mux_s2_h ", " Span4Mux_h4 " if max_span_hack else " Span4Mux_h2 ")
|
|
|
|
|
line = line.replace(" Span4Mux_s3_h ", " Span4Mux_h4 " if max_span_hack else " Span4Mux_h3 ")
|
|
|
|
|
line = line.replace(" Span4Mux_h ", " Span4Mux_h4 " if max_span_hack else " Span4Mux_h4 ")
|
|
|
|
|
|
|
|
|
|
line = line.replace(" Span4Mux_s0_v ", " Span4Mux_v4 " if max_span_hack else " Span4Mux_v0 ")
|
|
|
|
|
line = line.replace(" Span4Mux_s1_v ", " Span4Mux_v4 " if max_span_hack else " Span4Mux_v1 ")
|
|
|
|
|
line = line.replace(" Span4Mux_s2_v ", " Span4Mux_v4 " if max_span_hack else " Span4Mux_v2 ")
|
|
|
|
|
line = line.replace(" Span4Mux_s3_v ", " Span4Mux_v4 " if max_span_hack else " Span4Mux_v3 ")
|
|
|
|
|
line = line.replace(" Span4Mux_v ", " Span4Mux_v4 " if max_span_hack else " Span4Mux_v4 ")
|
|
|
|
|
line = line.replace(" Span4Mux ", " Span4Mux_v4 " if max_span_hack else " Span4Mux_v4 ")
|
|
|
|
|
|
|
|
|
|
line = line.replace(" Span12Mux_s0_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h0 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s1_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h1 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s2_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h2 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s3_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h3 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s4_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h4 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s5_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h5 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s6_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h6 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s7_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h7 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s8_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h8 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s9_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h9 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s10_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h10 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s11_h ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h11 ")
|
|
|
|
|
line = line.replace(" Span12Mux ", " Span12Mux_h12 " if max_span_hack else " Span12Mux_h12 ")
|
|
|
|
|
|
|
|
|
|
line = line.replace(" Span12Mux_s0_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v0 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s1_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v1 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s2_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v2 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s3_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v3 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s4_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v4 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s5_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v5 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s6_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v6 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s7_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v7 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s8_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v8 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s9_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v9 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s10_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v10 ")
|
|
|
|
|
line = line.replace(" Span12Mux_s11_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v11 ")
|
|
|
|
|
line = line.replace(" Span12Mux_v ", " Span12Mux_v12 " if max_span_hack else " Span12Mux_v12 ")
|
2015-10-23 17:16:37 +02:00
|
|
|
|
|
|
|
|
f.write(line)
|
2015-10-21 10:27:25 +02:00
|
|
|
|
2015-10-25 15:28:58 +01:00
|
|
|
assert os.system("yosys -qp 'select -write %s.lc t:LogicCell40' %s_ref.v" % (sys.argv[1], sys.argv[1])) == 0
|
2016-01-06 16:50:49 +01:00
|
|
|
assert os.system(r"sed -i -r 's,.*/(.*)LC_(.*),equiv_add -try -cell \1LC_\2_gold lc40_\2_gate,' %s.lc" % sys.argv[1]) == 0
|
2015-10-25 15:28:58 +01:00
|
|
|
|
2015-10-21 10:27:25 +02:00
|
|
|
os.remove("%s.bin" % sys.argv[1])
|
2015-10-22 15:50:25 +02:00
|
|
|
os.remove("%s.vsb" % sys.argv[1])
|
2015-10-21 10:27:25 +02:00
|
|
|
os.remove("%s.glb" % sys.argv[1])
|
|
|
|
|
os.remove("%s.psb" % sys.argv[1])
|
|
|
|
|
os.remove("%s.sdf" % sys.argv[1])
|
|
|
|
|
shutil.rmtree("%s.tmp" % sys.argv[1])
|
|
|
|
|
|