aboutsummaryrefslogtreecommitdiffstats
path: root/techlibs/xilinx/tests/bram1.v
blob: ac7140a04438cf16580ec8656fc029ad4adf76b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module bram1 #(
	parameter ABITS = 8, DBITS = 8, TRANSP = 0
) (
	input clk,

	input [ABITS-1:0] WR_ADDR,
	input [DBITS-1:0] WR_DATA,
	input WR_EN,

	input [ABITS-1:0] RD_ADDR,
	output [DBITS-1:0] RD_DATA
);
	localparam [ABITS-1:0] INIT_ADDR_0 = 1234;
	localparam [ABITS-1:0] INIT_ADDR_1 = 4321;
	localparam [ABITS-1:0] INIT_ADDR_2 = 2**ABITS-1;
	localparam [ABITS-1:0] INIT_ADDR_3 = (2**ABITS-1) / 2;

	localparam [DBITS-1:0] INIT_DATA_0 = 128'h 51e152a7300e309ccb8cd06d34558f49;
	localparam [DBITS-1:0] INIT_DATA_1 = 128'h 07b1fe94a530ddf3027520f9d23ab43e;
	localparam [DBITS-1:0] INIT_DATA_2 = 128'h 3cedc6de43ef3f607af3193658d0eb0b;
	localparam [DBITS-1:0] INIT_DATA_3 = 128'h f6bc5514a8abf1e2810df966bcc13b46;

	reg [DBITS-1:0] memory [0:2**ABITS-1];
	reg [ABITS-1:0] RD_ADDR_BUF;
	reg [DBITS-1:0] RD_DATA_BUF;

	initial begin
		memory[INIT_ADDR_0] <= INIT_DATA_0;
		memory[INIT_ADDR_1] <= INIT_DATA_1;
		memory[INIT_ADDR_2] <= INIT_DATA_2;
		memory[INIT_ADDR_3] <= INIT_DATA_3;
	end

	always @(posedge clk) begin
		if (WR_EN) memory[WR_ADDR] <= WR_DATA;
		RD_ADDR_BUF <= RD_ADDR;
		RD_DATA_BUF <= memory[RD_ADDR];
	end

	assign RD_DATA = TRANSP ? memory[RD_ADDR_BUF] : RD_DATA_BUF;
endmodule
">, "Y", "add_1", "B"); #ifdef VERBOSE printf("\n"); needle.print(); #endif // create haystack graph #if 0 for (int i = 0; i < 4; i++) { char id[100]; snprintf(id, 100, "mul_%d", i); haystack.createNode(id, "mul"); haystack.createPort(id, "A", 4); haystack.createPort(id, "B", 4); haystack.createPort(id, "Y", 4); haystack.markExtern(id, "A"); haystack.markExtern(id, "B"); } for (int i = 0; i < 3; i++) { char id[100]; snprintf(id, 100, "add_%d", i); haystack.createNode(id, "add"); haystack.createPort(id, "A", 4); haystack.createPort(id, "B", 4); haystack.createPort(id, "Y", 4); } haystack.createConnection("mul_0", "Y", "add_0", "A"); haystack.createConnection("mul_1", "Y", "add_0", "B"); haystack.createConnection("mul_2", "Y", "add_1", "A"); haystack.createConnection("mul_3", "Y", "add_1", "B"); haystack.createConnection("add_0", "Y", "add_2", "A"); haystack.createConnection("add_1", "Y", "add_2", "B"); haystack.markExtern("add_2", "Y"); #else std::vector<std::string> cellIds; srand48(12345); for (int i = 0; i < 45; i++) { char id[100]; snprintf(id, 100, "cell_%02d", i); haystack.createNode(id, i < 30 ? "mul" : "add"); haystack.createPort(id, "A", 4); haystack.createPort(id, "B", 4); haystack.createPort(id, "Y", 4); cellIds.push_back(id); } for (int i = 0; i < int(cellIds.size()); i++) { if (lrand48() % (i < 20 ? 3 : 2) != 0) continue; const std::string &id = cellIds[i]; const std::string &id_left = cellIds[lrand48() % cellIds.size()]; const std::string &id_right = cellIds[lrand48() % cellIds.size()]; haystack.createConnection(id_left, "Y", id, "A"); haystack.createConnection(id_right, "Y", id, "B"); } #endif #ifdef VERBOSE printf("\n"); haystack.print(); #endif // search needle in haystack SubCircuit::Solver solver; std::vector<SubCircuit::Solver::Result> results; #ifdef VERBOSE solver.setVerbose(); #endif solver.addCompatibleTypes("product", "mul"); solver.addCompatibleTypes("sum", "add"); solver.addSwappablePorts("product", "A", "B"); solver.addSwappablePorts("sum", "A", "B"); solver.addGraph("needle", needle); solver.addGraph("haystack", haystack); solver.solve(results, "needle", "haystack"); for (int i = 0; i < int(results.size()); i++) { printf("\nMatch #%d: (%s in %s)\n", i, results[i].needleGraphId.c_str(), results[i].haystackGraphId.c_str()); for (const auto &it : results[i].mappings) { printf(" %s -> %s", it.first.c_str(), it.second.haystackNodeId.c_str()); for (const auto &it2 : it.second.portMapping) printf(" %s:%s", it2.first.c_str(), it2.second.c_str()); printf("\n"); } } printf("\n"); return 0; }