data/full_repos/permissive/430026064/forwarding_unit.v
data/verilator_xmls/b580ff79-0b5b-4465-91d8-770d43c529a4.xml
module forwarding_unit(
	input ex_mem_regwrite,
    input mem_wb_regwrite,
  	input [4:0] ex_mem_reg_rd,
  	input [4:0] id_ex_reg_rd,
  	input [4:0] id_ex_reg_rs1,
  	input [4:0] id_ex_reg_rs2,
  	input [4:0] mem_wb_reg_rd,
  	output reg [1:0] forward_A,
  	output reg [1:0] forward_B
);
  
  always@(*) begin
      if ((ex_mem_regwrite == 1) && (ex_mem_reg_rd != 0) && (ex_mem_reg_rd == id_ex_reg_rs1)) begin  
        $display("EX hazard rs1"); 
        forward_A = 2'b10; 
      end
	  else if (mem_wb_regwrite && (mem_wb_reg_rd != 0) && !(ex_mem_regwrite && (ex_mem_reg_rd != 0) && (ex_mem_reg_rd == id_ex_reg_rs1)) && (mem_wb_reg_rd == 
        id_ex_reg_rs1)) begin $display("MEM hazard rs1"); forward_A = 2'b01; end
	  else begin forward_A = 2'b00; end

      if ((ex_mem_regwrite == 1) && (ex_mem_reg_rd != 0) && (ex_mem_reg_rd == id_ex_reg_rs2)) begin
		$display("EX hazard rs2");
        forward_B = 2'b10;
      end
	  else if (mem_wb_regwrite && (mem_wb_reg_rd != 0) && !(ex_mem_regwrite && (ex_mem_reg_rd != 0) && (ex_mem_reg_rd == id_ex_reg_rs2)) && (mem_wb_reg_rd == 
        id_ex_reg_rs2)) begin $display("MEM hazard rs2"); forward_B = 2'b01; end
	  else begin  forward_B = 2'b00; end
    end
endmodule
module forwarding_unit(
	input ex_mem_regwrite,
    input mem_wb_regwrite,
  	input [4:0] ex_mem_reg_rd,
  	input [4:0] id_ex_reg_rd,
  	input [4:0] id_ex_reg_rs1,
  	input [4:0] id_ex_reg_rs2,
  	input [4:0] mem_wb_reg_rd,
  	output reg [1:0] forward_A,
  	output reg [1:0] forward_B
);

  
  always@(*) begin
      if ((ex_mem_regwrite == 1) && (ex_mem_reg_rd != 0) && (ex_mem_reg_rd == id_ex_reg_rs1)) begin  
        $display("EX hazard rs1"); 
        forward_A = 2'b10; 
      end
	  else if (mem_wb_regwrite && (mem_wb_reg_rd != 0) && !(ex_mem_regwrite && (ex_mem_reg_rd != 0) && (ex_mem_reg_rd == id_ex_reg_rs1)) && (mem_wb_reg_rd == 
        id_ex_reg_rs1)) begin $display("MEM hazard rs1"); forward_A = 2'b01; end
	  else begin forward_A = 2'b00; end

      if ((ex_mem_regwrite == 1) && (ex_mem_reg_rd != 0) && (ex_mem_reg_rd == id_ex_reg_rs2)) begin
		$display("EX hazard rs2");
        forward_B = 2'b10;
      end
	  else if (mem_wb_regwrite && (mem_wb_reg_rd != 0) && !(ex_mem_regwrite && (ex_mem_reg_rd != 0) && (ex_mem_reg_rd == id_ex_reg_rs2)) && (mem_wb_reg_rd == 
        id_ex_reg_rs2)) begin $display("MEM hazard rs2"); forward_B = 2'b01; end
	  else begin  forward_B = 2'b00; end
    end
endmodule