aboutsummaryrefslogtreecommitdiffstats
path: root/techlibs/xilinx/tests/bram2_tb.v
blob: 0fe4137c677954a65759bf64cd607b82ecea69d4 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
`timescale 1 ns / 1 ps

module testbench;
	reg         rd_clk;
	reg  [ 7:0] rd_addr;
	wire [17:0] rd_data;

	wire        wr_clk    = 0;
	wire        wr_enable = 0;
	wire [ 7:0] wr_addr   = 0;
	wire [17:0] wr_data   = 0;

	function [17:0] hash(input [7:0] k);
		reg [31:0] x;
		begin
			x = {k, ~k, k, ~k};
			x = x ^ (x << 13);
			x = x ^ (x >> 17);
			x = x ^ (x << 5);
			hash = x;
		end
	endfunction

	myram uut (
		.rd_clk   (rd_clk   ),
		.rd_addr  (rd_addr  ),
		.rd_data  (rd_data  ),
		.wr_clk   (wr_clk   ),
		.wr_enable(wr_enable),
		.wr_addr  (wr_addr  ),
		.wr_data  (wr_data  )
	);

	initial begin
		rd_clk = 0;
		#1000;
		forever #10 rd_clk <= ~rd_clk;
	end

	integer i;
	initial begin
		rd_addr <= 0;
		@(posedge rd_clk);
		for (i = 0; i < 256; i=i+1) begin
			rd_addr <= rd_addr + 1;
			@(posedge rd_clk);
			// $display("%3d %3d", i, rd_data);
			if (hash(i) !== rd_data) begin
				$display("[%1t] ERROR: addr=%3d, data_mem=%18b, data_ref=%18b", $time, i, rd_data, hash(i));
				$stop;
			end
		end
		$display("[%1t] Passed bram2 test.", $time);
		$finish;
	end
endmodule
class="p">()); void *symbol = dlsym(loaded_plugins.at(plugin_name), real_symbol_name.c_str()); if (symbol == nullptr) log_error("unable to resolve '%s': can't find symbol `%s' in plugin `%s'\n", symbol_name.c_str(), real_symbol_name.c_str(), plugin_name.c_str()); return (ffi_fptr) symbol; } for (auto &it : loaded_plugins) { void *symbol = dlsym(it.second, symbol_name.c_str()); if (symbol != nullptr) return (ffi_fptr) symbol; } void *symbol = dlsym(RTLD_DEFAULT, symbol_name.c_str()); if (symbol != nullptr) return (ffi_fptr) symbol; log_error("unable to resolve '%s'.\n", symbol_name.c_str()); } AST::AstNode *AST::dpi_call(const std::string &rtype, const std::string &fname, const std::vector<std::string> &argtypes, const std::vector<AstNode*> &args) { AST::AstNode *newNode = nullptr; union { double f64; float f32; int32_t i32; } value_store [args.size() + 1]; ffi_type *types [args.size() + 1]; void *values [args.size() + 1]; ffi_cif cif; int status; log("Calling DPI function `%s' and returning `%s':\n", fname.c_str(), rtype.c_str()); log_assert(GetSize(args) == GetSize(argtypes)); for (int i = 0; i < GetSize(args); i++) { if (argtypes[i] == "real") { log(" arg %d (%s): %f\n", i, argtypes[i].c_str(), args[i]->asReal(args[i]->is_signed)); value_store[i].f64 = args[i]->asReal(args[i]->is_signed); values[i] = &value_store[i].f64; types[i] = &ffi_type_double; } else if (argtypes[i] == "shortreal") { log(" arg %d (%s): %f\n", i, argtypes[i].c_str(), args[i]->asReal(args[i]->is_signed)); value_store[i].f32 = args[i]->asReal(args[i]->is_signed); values[i] = &value_store[i].f32; types[i] = &ffi_type_double; } else if (argtypes[i] == "integer") { log(" arg %d (%s): %lld\n", i, argtypes[i].c_str(), (long long)args[i]->asInt(args[i]->is_signed)); value_store[i].i32 = args[i]->asInt(args[i]->is_signed); values[i] = &value_store[i].i32; types[i] = &ffi_type_sint32; } else { log_error("invalid argtype '%s' for argument %d.\n", argtypes[i].c_str(), i); } } if (rtype == "integer") { types[args.size()] = &ffi_type_slong; values[args.size()] = &value_store[args.size()].i32; } else if (rtype == "shortreal") { types[args.size()] = &ffi_type_float; values[args.size()] = &value_store[args.size()].f32; } else if (rtype == "real") { types[args.size()] = &ffi_type_double; values[args.size()] = &value_store[args.size()].f64; } else { log_error("invalid rtype '%s'.\n", rtype.c_str()); } if ((status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, args.size(), types[args.size()], types)) != FFI_OK) log_error("ffi_prep_cif failed: status %d.\n", status); ffi_call(&cif, resolve_fn(fname.c_str()), values[args.size()], values); if (rtype == "real") { newNode = new AstNode(AST_REALVALUE); newNode->realvalue = value_store[args.size()].f64; log(" return realvalue: %g\n", newNode->asReal(true)); } else if (rtype == "shortreal") { newNode = new AstNode(AST_REALVALUE); newNode->realvalue = value_store[args.size()].f32; log(" return realvalue: %g\n", newNode->asReal(true)); } else { newNode = AstNode::mkconst_int(value_store[args.size()].i32, false); log(" return integer: %lld\n", (long long)newNode->asInt(true)); } return newNode; } YOSYS_NAMESPACE_END #else /* YOSYS_ENABLE_PLUGINS */ YOSYS_NAMESPACE_BEGIN AST::AstNode *AST::dpi_call(const std::string&, const std::string &fname, const std::vector<std::string>&, const std::vector<AstNode*>&) { log_error("Can't call DPI function `%s': this version of yosys is built without plugin support\n", fname.c_str()); } YOSYS_NAMESPACE_END #endif /* YOSYS_ENABLE_PLUGINS */