-
Notifications
You must be signed in to change notification settings - Fork 0
/
rv32_ImmGen.v
25 lines (22 loc) · 950 Bytes
/
rv32_ImmGen.v
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
`include "defines.v"
module rv32_ImmGen (
input wire [31:0] IR,
output reg [31:0] Imm
);
always @(*) begin
case (`OPCODE)
`OPCODE_Arith_I :
if(IR[`IR_funct3] == 3'b101) Imm = { 7'b0, IR[24:21], IR[20] };
else Imm = { {21{IR[31]}}, IR[30:25], IR[24:21], IR[20] };
`OPCODE_Store : Imm = { {21{IR[31]}}, IR[30:25], IR[11:8], IR[7] };
`OPCODE_LUI : Imm = { IR[31], IR[30:20], IR[19:12], 12'b0 };
`OPCODE_AUIPC : Imm = { IR[31], IR[30:20], IR[19:12], 12'b0 };
`OPCODE_JAL : Imm = { {12{IR[31]}}, IR[19:12], IR[20], IR[30:25], IR[24:21], 1'b0 };
`OPCODE_JALR : Imm = { {21{IR[31]}}, IR[30:25], IR[24:21], IR[20] };
`OPCODE_Branch : Imm = { {20{IR[31]}}, IR[7], IR[30:25], IR[11:8], 1'b0};
`OPCODE_SYSTEM : Imm = 0;
`OPCODE_FENCE : Imm = 0;
default : Imm = { {21{IR[31]}}, IR[30:25], IR[24:21], IR[20] }; // IMM_I
endcase
end
endmodule