mirror of
https://github.com/lowRISC/ibex.git
synced 2025-04-24 22:07:43 -04:00
completely generic The only dependency that limits the number of hwloops now is the encoding, the rest adapts automatically
84 lines
3.3 KiB
Systemverilog
84 lines
3.3 KiB
Systemverilog
////////////////////////////////////////////////////////////////////////////////
|
|
// Company: IIS @ ETHZ - Federal Institute of Technology //
|
|
// DEI @ UNIBO - University of Bologna //
|
|
// //
|
|
// Engineer: Michael Gautschi - gautschi@iis.ee.ethz.ch //
|
|
// //
|
|
// Additional contributions by: //
|
|
// //
|
|
// //
|
|
// Create Date: 08/08/2014 //
|
|
// Design Name: hwloop controller //
|
|
// Module Name: hwloop_controller.sv //
|
|
// Project Name: RI5CY //
|
|
// Language: SystemVerilog //
|
|
// //
|
|
// Description: Hardware loop controller unit. This unit is responsible to //
|
|
// handle hardware loops. Tasks are: //
|
|
// a) compare PC to all stored end addresses //
|
|
// b) jump to the right start address if counter =/ 0 //
|
|
// //
|
|
// Revision: //
|
|
// Revision v0.1 - File Created //
|
|
// //
|
|
// //
|
|
// //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
`include "defines.sv"
|
|
|
|
module riscv_hwloop_controller
|
|
#(
|
|
parameter N_REGS = 2
|
|
)
|
|
(
|
|
// from id stage
|
|
input logic [31:0] current_pc_i,
|
|
|
|
// from hwloop_regs
|
|
input logic [N_REGS-1:0] [31:0] hwlp_start_addr_i,
|
|
input logic [N_REGS-1:0] [31:0] hwlp_end_addr_i,
|
|
input logic [N_REGS-1:0] [31:0] hwlp_counter_i,
|
|
|
|
// to hwloop_regs
|
|
output logic [N_REGS-1:0] hwlp_dec_cnt_o,
|
|
|
|
// to id stage
|
|
output logic hwlp_jump_o,
|
|
output logic [31:0] hwlp_targ_addr_o
|
|
);
|
|
|
|
|
|
logic [N_REGS-1:0] pc_is_end_addr;
|
|
|
|
// end address detection
|
|
integer j;
|
|
|
|
|
|
// generate comparators. check for end address and the loop counter
|
|
genvar i;
|
|
for (i = 0; i < N_REGS; i++) begin
|
|
assign pc_is_end_addr[i] = (current_pc_i == hwlp_end_addr_i[i]) &&
|
|
(hwlp_counter_i[i] > 32'h1);
|
|
end
|
|
|
|
// output signal for ID stage
|
|
assign hwlp_jump_o = (|pc_is_end_addr);
|
|
|
|
|
|
// select corresponding start address and decrement counter
|
|
always_comb
|
|
begin
|
|
hwlp_targ_addr_o = 'x;
|
|
hwlp_dec_cnt_o = '0;
|
|
|
|
for (j = N_REGS-1; j >= 0; j--) begin
|
|
if (pc_is_end_addr[j]) begin
|
|
hwlp_targ_addr_o = hwlp_start_addr_i[j];
|
|
hwlp_dec_cnt_o[j] = 1'b1;
|
|
end
|
|
end
|
|
end
|
|
|
|
endmodule
|