| # 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 | |
| bufgces = [] | |
| 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 ("BUFGCE" in site) and "HDIO" not in site and "DIV" not in site: | |
| bufgces.append((site.split(":")[0], sl[2])) | |
| np.random.shuffle(bufgces) | |
| print("module top(input i, output o);") | |
| N = int(len(bufgces) * 0.08) | |
| print(" wire [%d:0] r;" % N) | |
| print(" assign r[0] = i;") | |
| print(" assign o = r[%d];" % N) | |
| for i in range(N): | |
| bg, tile = bufgces[i] | |
| print("(* LOC=\"%s\" *)" % bg) | |
| if "BUFGCTRL" in bg: | |
| print( | |
| " BUFGCTRL bufg_%d (.I0(r[%d]), .I1(r[%d]), .S0(1'b1), .S1(1'b0), .CE0(1'b1), .O(r[%d]));" | |
| % (i, i, i, i + 1)) | |
| elif "DIV" in bg: | |
| print( | |
| " BUFGCE_DIV #(.BUFGCE_DIVIDE(3)) bufg_%d (.I(r[%d]), .CLR(0), .CE(1'b1), .O(r[%d]));" | |
| % (i, i, i + 1)) | |
| else: | |
| print(" BUFGCE bufg_%d (.I(r[%d]), .CE(1'b1), .O(r[%d]));" % | |
| (i, i, i + 1)) | |
| print("endmodule") |