| # Copyright 2020 Project U-Ray Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import numpy as np |
| import sys |
| |
| print("module top(input [15:0] clk, rst, cen, input [6:0] d, output q);") |
| N = 10000 |
| print(" wire [%d:0] int_d;" % N) |
| print(" assign int_d[6:0] = d;") |
| print(" assign q = int_d[%d];" % N) |
| |
| slices = [] |
| with open(sys.argv[1], "r") as tf: |
| for line in tf: |
| sl = line.strip().split(",") |
| if len(sl) < 4: |
| continue |
| for site in sl[4:]: |
| if "SLICEM" in site or "SLICEL" in site: |
| slices.append(site.split(":")[0]) |
| for i in range(6, N): |
| fftype, srsig = np.random.choice(["FDPE,PRE", "FDCE,CLR", "FDSE,S", "FDRE,R"]).split(",") |
| sl = slices.pop() |
| if np.random.ranf() < 0.5: |
| data = "int_d[%d]" % i |
| else: |
| lutsize = np.random.randint(2, 10) |
| if lutsize > 6: |
| lutsize = 6 |
| print (" wire lut_q_%d;" % i) |
| |
| print(" (* BEL=\"%s%dLUT\" *) (* LOC=\"%s\" *) LUT%d #(" % (np.random.choice(list("ABCDEFGH")), np.random.randint(6 if lutsize == 6 else 5, 7), sl, lutsize)) |
| print(" .INIT(%d'h%016x)" % (2 ** lutsize, np.random.randint(1, (2 ** ((2 ** lutsize) - 1) - 1)))) |
| print(" ) lut_%d (" % i) |
| for j in range(lutsize): |
| print(" .I%d(int_d[%d])," % (j, i - j)) |
| print(" .O(lut_q_%d)" % i) |
| print(" );") |
| data = "lut_q_%d" % i |
| |
| print(" (* BEL=\"%sFF%s\" *) (* LOC=\"%s\" *) %s #(" % (np.random.choice(list("ABCDEFGH")), np.random.choice(["", "2"]), sl, fftype)) |
| print(" .IS_C_INVERTED(%s)," % np.random.choice(["0", "1"])) |
| print(" .IS_%s_INVERTED(%s)," % (srsig, np.random.choice(["0", "1"]))) |
| print(" .INIT(%s)" % np.random.choice(["1'b0", "1'b1"])) |
| print(" ) ff_%d (" % i) |
| print(" .C(clk[%d])," % np.random.randint(0, 16)) |
| print(" .CE(cen[%d])," % np.random.randint(0, 16)) |
| print(" .%s(rst[%d])," % (srsig, np.random.randint(0, 16))) |
| print(" .D(%s)," % (data)) |
| print(" .Q(int_d[%d])" % (i + 1)) |
| print(" );") |
| print("endmodule") |