Advertisement
AlexanderAntonov

Untitled

Nov 2nd, 2022
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module FindMaxVal_pipelined (
  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. // stage 0
  12. logic [31:0] max_elem_stage0  [7:0];
  13. logic [31:0] max_index_stage0 [7:0];
  14. always @(posedge clk_i)
  15.     begin
  16.     for(integer i=0; i<8; i++)
  17.         begin
  18.         if (elem_bi[(i<<1)] > elem_bi[(i<<1)+1])
  19.             begin
  20.             max_elem_stage0[i] <= elem_bi[(i<<1)];
  21.             max_index_stage0[i] <= i<<1;
  22.             end
  23.         else
  24.             begin
  25.             max_elem_stage0[i] <= elem_bi[(i<<1)+1];
  26.             max_index_stage0[i] <= (i<<1)+1;
  27.             end
  28.         end
  29.     end
  30.  
  31. // stage 1
  32.  
  33. // stage 2
  34.  
  35. // stage 3
  36. always @(posedge clk_i)
  37.     begin
  38.     if (max_elem_stage2[0] > max_elem_stage2[1])
  39.         begin
  40.         max_elem_bo <= max_elem_stage2[0];
  41.         max_index_bo <= max_index_stage2[0];
  42.         end
  43.     else
  44.         begin
  45.         max_elem_bo <= max_elem_stage2[1];
  46.         max_index_bo <= max_index_stage2[1];
  47.         end
  48.     end
  49.  
  50. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement