icicle/rv32_branch.sv

55 lines
1.1 KiB
Systemverilog
Raw Normal View History

2017-12-02 15:23:12 +00:00
`ifndef RV32_BRANCH
`define RV32_BRANCH
2017-12-09 10:46:08 +00:00
`define RV32_BRANCH_OP_NEVER 2'b00
`define RV32_BRANCH_OP_ZERO 2'b01
`define RV32_BRANCH_OP_NON_ZERO 2'b10
`define RV32_BRANCH_OP_ALWAYS 2'b11
2017-12-05 19:54:01 +00:00
`define RV32_BRANCH_PC_SRC_IMM 1'b0
`define RV32_BRANCH_PC_SRC_REG 1'b1
2017-12-02 15:23:12 +00:00
module rv32_branch_pc_mux (
/* control in */
input pc_src_in,
/* data in */
input [31:0] pc_in,
input [31:0] rs1_value_in,
input [31:0] imm_in,
/* data out */
output logic [31:0] pc_out
2017-12-02 15:23:12 +00:00
);
logic [31:0] pc;
2017-12-03 14:00:50 +00:00
assign pc = (pc_src_in ? rs1_value_in : pc_in) + imm_in;
assign pc_out = {pc[31:1], 1'b0};
2017-12-02 15:23:12 +00:00
endmodule
2017-12-12 21:05:02 +00:00
module rv32_branch_unit (
2017-12-02 15:23:12 +00:00
/* control in */
input [1:0] op_in,
/* data in */
input [31:0] result_in,
/* control out */
output logic taken_out
2017-12-02 15:23:12 +00:00
);
logic non_zero;
2017-12-12 21:05:02 +00:00
assign non_zero = |result_in;
2017-12-02 15:23:12 +00:00
always_comb begin
2017-12-02 15:23:12 +00:00
case (op_in)
`RV32_BRANCH_OP_NEVER: taken_out = 0;
`RV32_BRANCH_OP_ZERO: taken_out = ~non_zero;
`RV32_BRANCH_OP_NON_ZERO: taken_out = non_zero;
`RV32_BRANCH_OP_ALWAYS: taken_out = 1;
2017-12-02 15:23:12 +00:00
endcase
end
endmodule
`endif