2015-04-06 06:03:37 -05:00
|
|
|
module myram(
|
|
|
|
input rd_clk,
|
|
|
|
input [ 7:0] rd_addr,
|
2015-04-06 10:07:10 -05:00
|
|
|
output reg [17:0] rd_data,
|
2015-04-06 06:03:37 -05:00
|
|
|
input wr_clk,
|
|
|
|
input wr_enable,
|
|
|
|
input [ 7:0] wr_addr,
|
2015-04-06 10:07:10 -05:00
|
|
|
input [17:0] wr_data
|
2015-04-06 06:03:37 -05:00
|
|
|
);
|
2015-04-06 10:07:10 -05:00
|
|
|
reg [17:0] memory [0:255];
|
2015-04-06 06:03:37 -05:00
|
|
|
integer i;
|
|
|
|
|
2015-04-06 10:07:10 -05:00
|
|
|
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
|
|
|
|
|
2015-04-06 06:03:37 -05:00
|
|
|
initial begin
|
|
|
|
for (i = 0; i < 256; i = i+1)
|
2015-04-06 10:07:10 -05:00
|
|
|
memory[i] = hash(i);
|
2015-04-06 06:03:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge rd_clk)
|
|
|
|
rd_data <= memory[rd_addr];
|
|
|
|
|
|
|
|
always @(posedge wr_clk)
|
|
|
|
if (wr_enable)
|
|
|
|
memory[wr_addr] <= wr_data;
|
|
|
|
endmodule
|