1
0
mirror of https://github.com/olofk/serv.git synced 2026-01-15 07:52:52 +00:00
olofk.serv/rtl/serv_bufreg.v
Olof Kindgren 75decc8251 Bring back old immediate decoder
This was originally thrown out since it was slow and cost too much
resources. Due to other changes in the core, it is now cheaper
than the other one
2019-10-29 21:54:22 +01:00

46 lines
1.1 KiB
Verilog

module serv_bufreg
(
input wire i_clk,
input wire i_rst,
input wire [4:2] i_cnt,
input wire [1:0] i_cnt_r,
input wire i_en,
input wire i_init,
input wire i_loop,
input wire i_rs1,
input wire i_rs1_en,
input wire i_imm,
input wire i_imm_en,
input wire i_clr_lsb,
output reg [1:0] o_lsb,
output wire [31:0] o_reg,
output wire o_q);
wire c, q;
reg c_r;
reg [31:0] data;
wire clr_lsb = (i_cnt[4:2] == 3'd0) & i_cnt_r[0] & i_clr_lsb;
assign {c,q} = {1'b0,(i_rs1 & i_rs1_en)} + {1'b0,(i_imm & i_imm_en & !clr_lsb)} + c_r;
always @(posedge i_clk) begin
//Clear carry when not in INIT state
c_r <= c & i_init;
if (i_rst)
data <= 32'd0;
else if (i_en)
data <= {(i_loop & !i_init) ? o_q : q, data[31:1]};
if ((i_cnt[4:2] == 3'd0) & i_cnt_r[0] & i_init)
o_lsb[0] <= q;
if ((i_cnt[4:2] == 3'd0) & i_cnt_r[1] & i_init)
o_lsb[1] <= q;
end
assign o_q = data[0];
assign o_reg = data;
endmodule