Advertisement
AlexanderAntonov

Untitled

Nov 2nd, 2022
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module FindMaxVal_multicycle (
  2.     input clk_i
  3.     , input rst_i
  4.    
  5.     , input [31:0] elem_bi [15:0]
  6.    
  7.     , output logic [31:0] max_elem_bo
  8.     , output logic [3:0] max_index_bo
  9. );
  10.  
  11. localparam CSTEP_NUM = 16;  // number of computational stages
  12. logic [31:0] max_elem_next;
  13. logic [3:0] max_index_next;
  14. logic [3:0] cstep_counter, cstep_counter_next;
  15. logic [31:0] current_max_elem, current_max_elem_next;
  16. logic [3:0] current_max_index, current_max_index_next;
  17.  
  18. // subcomputation combinational processing
  19. always @*
  20.     begin
  21.  
  22.     // default values assignments
  23.     cstep_counter_next = cstep_counter;
  24.     current_max_elem_next = current_max_elem;
  25.     current_max_index_next = current_max_index;
  26.     max_elem_next = max_elem_bo;
  27.     max_index_next = max_index_bo;
  28.  
  29.     // subcomputation on current cstep
  30.     if (elem_bi[cstep_counter_next] > current_max_elem_next)
  31.         begin
  32.         current_max_elem_next = elem_bi[cstep_counter_next];
  33.         current_max_index_next = cstep_counter_next;
  34.         end
  35.  
  36.     // cstep processing
  37.     if (cstep_counter_next == (CSTEP_NUM-1))
  38.         begin
  39.         max_elem_next = current_max_elem_next;
  40.         max_index_next = current_max_index_next;
  41.         current_max_elem_next = 0;
  42.         current_max_index_next = 0;
  43.         cstep_counter_next = 0;
  44.         end
  45.     else
  46.         begin
  47.         cstep_counter_next = cstep_counter_next + 1;
  48.         end
  49.     end
  50.  
  51. // sequential processing (register assignments)
  52. always @(posedge clk_i)
  53.     begin
  54.     if (rst_i)
  55.         begin
  56.         cstep_counter <= 0;
  57.         current_max_elem <= 0;
  58.         current_max_index <= 0;
  59.         max_elem_bo <= 0;
  60.         max_index_bo <= 0;
  61.         end
  62.     else
  63.         begin
  64.         cstep_counter <= cstep_counter_next;
  65.         current_max_elem <= current_max_elem_next;
  66.         current_max_index <= current_max_index_next;
  67.         max_elem_bo <= max_elem_next;
  68.         max_index_bo <= max_index_next;
  69.         end
  70.     end
  71.  
  72. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement