Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module FindMaxVal_multicycle (
- input clk_i
- , input rst_i
- , input [31:0] elem_bi [15:0]
- , output logic [31:0] max_elem_bo
- , output logic [3:0] max_index_bo
- );
- localparam CSTEP_NUM = 16; // number of computational stages
- logic [31:0] max_elem_next;
- logic [3:0] max_index_next;
- logic [3:0] cstep_counter, cstep_counter_next;
- logic [31:0] current_max_elem, current_max_elem_next;
- logic [3:0] current_max_index, current_max_index_next;
- // subcomputation combinational processing
- always @*
- begin
- // default values assignments
- cstep_counter_next = cstep_counter;
- current_max_elem_next = current_max_elem;
- current_max_index_next = current_max_index;
- max_elem_next = max_elem_bo;
- max_index_next = max_index_bo;
- // subcomputation on current cstep
- if (elem_bi[cstep_counter_next] > current_max_elem_next)
- begin
- current_max_elem_next = elem_bi[cstep_counter_next];
- current_max_index_next = cstep_counter_next;
- end
- // cstep processing
- if (cstep_counter_next == (CSTEP_NUM-1))
- begin
- max_elem_next = current_max_elem_next;
- max_index_next = current_max_index_next;
- current_max_elem_next = 0;
- current_max_index_next = 0;
- cstep_counter_next = 0;
- end
- else
- begin
- cstep_counter_next = cstep_counter_next + 1;
- end
- end
- // sequential processing (register assignments)
- always @(posedge clk_i)
- begin
- if (rst_i)
- begin
- cstep_counter <= 0;
- current_max_elem <= 0;
- current_max_index <= 0;
- max_elem_bo <= 0;
- max_index_bo <= 0;
- end
- else
- begin
- cstep_counter <= cstep_counter_next;
- current_max_elem <= current_max_elem_next;
- current_max_index <= current_max_index_next;
- max_elem_bo <= max_elem_next;
- max_index_bo <= max_index_next;
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement