Advertisement
mayankherode_04

Untitled

Sep 14th, 2023
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module matrix_multiplier_8x8 (
  2.   input wire clk,
  3.   input wire rst,
  4.   input wire [63:0] matrix_A,
  5.   input wire [63:0] matrix_B,
  6.   output wire [63:0] matrix_C
  7. );
  8.  
  9. reg [31:0] temp_result [0:7][0:7];
  10. reg [31:0] matrix_C_ [0:7][0:7];
  11.  
  12. reg [2:0] i, j, k;
  13. reg multiply_done;
  14.  
  15. always @(posedge clk) begin
  16.   if (rst) begin
  17.     i <= 0;
  18.     j <= 0;
  19.     k <= 0;
  20.     multiply_done <= 0;
  21.   end
  22.   else begin
  23.     if (!multiply_done) begin
  24.       if (k < 8) begin
  25.         temp_result[i][j] <= temp_result[i][j] + matrix_A[i * 8 + k] * matrix_B[k * 8 + j];
  26.         k <= k + 1;
  27.       end
  28.       else if (j < 7) begin
  29.         k <= 0;
  30.         j <= j + 1;
  31.       end
  32.       else if (i < 7) begin
  33.         k <= 0;
  34.         j <= 0;
  35.         i <= i + 1;
  36.       end
  37.       else begin
  38.         multiply_done <= 1;
  39.       end
  40.     end
  41.     else begin
  42.       if (i < 7) begin
  43.         j <= 0;
  44.         i <= i + 1;
  45.       end
  46.       else begin
  47.         i <= 0;
  48.         multiply_done <= 0;
  49.       end
  50.     end
  51.   end
  52. end
  53.  
  54. always @(posedge clk or posedge rst) begin
  55.   if (rst) begin
  56.     i = 0;
  57.     j = 0;
  58.     begin: reset_loop
  59.       if (i < 8) begin
  60.         if (j < 8) begin
  61.           temp_result[i][j] <= 32'h0;
  62.           matrix_C_[i][j] <= 32'h0;
  63.           j = j + 1;
  64.         end
  65.         else begin
  66.           j = 0;
  67.           i = i + 1;
  68.         end
  69.       end
  70.       else begin
  71.         i = 0;
  72.       end
  73.     end
  74.   end
  75.   else if (multiply_done) begin
  76.     i = 0;
  77.     j = 0;
  78.     begin: transfer_output_loop
  79.       if (i < 8) begin
  80.         if (j < 8) begin
  81.           matrix_C_[i][j] <= temp_result[i][j];
  82.           j = j + 1;
  83.         end
  84.         else begin
  85.           j = 0;
  86.           i = i + 1;
  87.         end
  88.       end
  89.       else begin
  90.         i = 0;
  91.       end
  92.     end
  93.   end
  94. end
  95.  
  96.  
  97. endmodule
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement