aboutsummaryrefslogtreecommitdiffstats
path: root/ice40/regressions/issue0148/hdl/cpu/regfile.v
blob: c5345f31d3771036fb7229c47937407b197479d3 (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
// Copyright 2015, Brian Swetland <swetland@frotz.net>
// Licensed under the Apache License, Version 2.0.

`timescale 1ns / 1ps

module regfile #(
	parameter AWIDTH = 4,
	parameter DWIDTH = 16
	)(
	input clk,
	input [AWIDTH-1:0]asel,
	input [AWIDTH-1:0]bsel,
	input [AWIDTH-1:0]wsel,
	input wreg,
	output [DWIDTH-1:0]adata,
	output [DWIDTH-1:0]bdata,
	input [DWIDTH-1:0]wdata
	);

reg [DWIDTH-1:0] R[0:((1<<AWIDTH)-1)];

always @(posedge clk) begin
	if (wreg)
		R[wsel] <= wdata;
end
assign adata = R[asel];
assign bdata = R[bsel];

endmodule