icicle/rv32_hazard.sv

69 lines
2.1 KiB
Systemverilog
Raw Normal View History

2017-12-04 21:26:26 +00:00
`ifndef RV32_HAZARD
`define RV32_HAZARD
2017-12-12 21:04:33 +00:00
module rv32_hazard_unit (
2017-12-04 21:47:09 +00:00
/* control in */
2017-12-27 15:23:59 +00:00
input [4:0] decode_rs1_unreg_in,
input decode_rs1_read_unreg_in,
2017-12-27 15:23:59 +00:00
input [4:0] decode_rs2_unreg_in,
input decode_rs2_read_unreg_in,
2017-12-27 15:23:59 +00:00
input decode_mem_fence_unreg_in,
input decode_mem_read_in,
2017-12-27 15:23:59 +00:00
input decode_mem_fence_in,
2017-12-05 18:33:25 +00:00
input [4:0] decode_rd_in,
input decode_rd_write_in,
2017-12-05 18:33:25 +00:00
2017-12-27 15:23:59 +00:00
input execute_mem_fence_in,
2017-12-30 13:48:14 +00:00
input mem_branch_mispredicted_in,
2017-12-25 23:12:55 +00:00
input instr_read_in,
input instr_ready_in,
input data_read_in,
input data_write_in,
input data_ready_in,
2017-12-04 21:47:09 +00:00
/* control out */
output logic fetch_stall_out,
output logic fetch_flush_out,
2017-12-04 21:26:26 +00:00
output logic decode_stall_out,
output logic decode_flush_out,
2017-12-04 21:26:26 +00:00
output logic execute_stall_out,
output logic execute_flush_out,
2017-12-04 21:26:26 +00:00
output logic mem_stall_out,
output logic mem_flush_out
2017-12-04 21:26:26 +00:00
);
logic rs1_matches;
logic rs2_matches;
2017-12-25 23:12:55 +00:00
logic fetch_wait_for_bus;
logic fetch_wait_for_mem_read;
2017-12-27 15:23:59 +00:00
logic fetch_wait_for_mem_fence;
2017-12-25 23:12:55 +00:00
logic mem_wait_for_bus;
assign rs1_matches = decode_rs1_unreg_in == decode_rd_in && decode_rs1_read_unreg_in;
assign rs2_matches = decode_rs2_unreg_in == decode_rd_in && decode_rs2_read_unreg_in;
2017-12-25 23:12:55 +00:00
assign fetch_wait_for_bus = instr_read_in && !instr_ready_in;
assign fetch_wait_for_mem_read = (rs1_matches || rs2_matches) && |decode_rd_in && decode_mem_read_in && decode_rd_write_in;
2017-12-27 15:23:59 +00:00
assign fetch_wait_for_mem_fence = decode_mem_fence_unreg_in || decode_mem_fence_in || execute_mem_fence_in;
2017-12-25 23:12:55 +00:00
assign mem_wait_for_bus = (data_read_in || data_write_in) && !data_ready_in;
2017-12-25 23:12:55 +00:00
assign fetch_stall_out = decode_stall_out || fetch_wait_for_mem_read || fetch_wait_for_bus;
2017-12-04 21:26:26 +00:00
assign fetch_flush_out = 0;
2017-12-05 18:33:25 +00:00
assign decode_stall_out = execute_stall_out;
2017-12-30 13:48:14 +00:00
assign decode_flush_out = fetch_stall_out || mem_branch_mispredicted_in;
2017-12-04 21:26:26 +00:00
assign execute_stall_out = mem_stall_out;
2017-12-30 13:48:14 +00:00
assign execute_flush_out = decode_stall_out || mem_branch_mispredicted_in;
2017-12-04 21:26:26 +00:00
2017-12-25 23:12:55 +00:00
assign mem_stall_out = mem_wait_for_bus;
2017-12-04 21:26:26 +00:00
assign mem_flush_out = execute_stall_out;
endmodule
`endif