data/full_repos/permissive/122497324/final_project/cache.v
 line:210: before: "("
1: b'%Warning-WIDTH: data/full_repos/permissive/122497324/final_project/cache.v:139: Operator ASSIGN expects 22 bits on the Assign RHS, but Assign RHS\'s CONST \'21\'bzzzzzzzzzzzzzzzzzzzzz\' generates 21 bits.\n                                                                              : ... In instance cache\n    temp_address_line = 21\'bz;\n                      ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-UNSIGNED: data/full_repos/permissive/122497324/final_project/cache.v:150: Comparison is constant due to unsigned arithmetic\n                                                                                 : ... In instance cache\n    if(p0_request >= 0)begin\n                  ^~\n%Warning-UNSIGNED: data/full_repos/permissive/122497324/final_project/cache.v:161: Comparison is constant due to unsigned arithmetic\n                                                                                 : ... In instance cache\n    if(p1_request >= 0)begin\n                  ^~\n%Error: Exiting due to 3 warning(s)\n'
module cache(clk,p0_request,p1_request,data_out, is_busy);


  input clk;
  






  input [21:0] p0_request, p1_request;
  







  output reg [29:0] data_out;
  

  output reg is_busy;
  







  reg [15:0] cache_line [15:0];
  


  reg [21:0] address_line [15:0];
  



  reg [1:0] valid_line [15:0];
  


  


  reg [3:0] counter;

  reg [1:0] requests;

  reg arbiter;

  reg [21:0] previous_p0_request, previous_p1_request;

  reg [21:0] request_to_process;

  reg [21:0] temp_address_line;

  reg [10:0] address_tag0, address_tag1, selected_tag;


  

  reg block_offset;
  


  



  

  initial begin
    is_busy = 0;
    arbiter = 0;
    counter = 0;
    requests = 0;
    temp_address_line = 22'bz;
    previous_p0_request = 22'bz;
    previous_p1_request = 22'bz;
    request_to_process = 22'bz;
    address_tag0 = 11'bz;
    address_tag1 = 11'bz;
    selected_tag = 11'bz;
    block_offset = 1'bz;
    data_out = 30'bz;



    cache_line[0] [15:0] = 16'b0110_0100__0000_0000;
    cache_line[1] [15:0] = 16'b0110_0101__1111_1111;
    cache_line[2] [15:0] = 16'b0110_0110__1111_1110;
    cache_line[3] [15:0] = 16'b0110_0111__1111_1101;
    cache_line[4] [15:0] = 16'b0110_1000__1111_1100;
    cache_line[5] [15:0] = 16'b0110_1001__1111_1011;
    cache_line[6] [15:0] = 16'b0110_1010__1111_1010;
    cache_line[7] [15:0] = 16'b0110_1011__1111_1001;
    cache_line[8] [15:0] = 16'b0110_1100__1111_1000;
    cache_line[9] [15:0] = 16'b0110_1101__1111_0111;
    cache_line[10] [15:0] = 16'b0110_1110__1111_0110;
    cache_line[11] [15:0] = 16'b0110_1111__1111_0101;
    cache_line[12] [15:0] = 16'b0111_0000__1111_0100;
    cache_line[13] [15:0] = 16'b0111_0001__1111_0011;
    cache_line[14] [15:0] = 16'b0111_0010__1111_0010;
    cache_line[15] [15:0] = 16'b0111_0011__1111_0001;
    
    address_line[0] [21:0] = 22'b0101_0000_000__0101_0000_000;
    address_line[1] [21:0] = 22'b0101_0001_000__0101_0001_000;
    address_line[2] [21:0] = 22'b0101_0010_000__0101_0010_000;
    address_line[3] [21:0] = 22'b0101_0011_000__0101_0011_000;
    address_line[4] [21:0] = 22'b0101_0100_000__0101_0100_000;
    address_line[5] [21:0] = 22'b0101_0101_000__0101_0101_000;
    address_line[6] [21:0] = 22'b0101_0110_000__0101_0110_000;
    address_line[7] [21:0] = 22'b0101_0111_000__0101_0111_000;
    address_line[8] [21:0] = 22'b0101_1000_000__0101_1000_000;
    address_line[9] [21:0] = 22'b0101_1001_000__0101_1001_000;
    address_line[10] [21:0] = 22'b0101_1010_000__0101_1010_000;
    address_line[11] [21:0] = 22'b0101_1011_000__0101_1011_000;
    address_line[12] [21:0] = 22'b0101_1100_000__0101_1100_000;
    address_line[13] [21:0] = 22'b0101_1101_000__0101_1101_000;
    address_line[14] [21:0] = 22'b0101_1110_000__0101_1110_000;
    address_line[15] [21:0] = 22'b0101_1111_000__0101_1111_000;
  end

  always@(posedge clk)begin
    counter = 0;
    requests = 0;
    temp_address_line = 21'bz;
    data_out = 30'bz;









    if(p0_request >= 0)begin
      $display("CACHE: p0_request is valid (%b)",p0_request);

        $display("CACHE: request from p0 is valid and new");
        requests[0] = 1;
        previous_p0_request = p0_request;

    end
    else begin
      $display("CACHE: p0_request is invalid (%b)",p0_request);
    end
    if(p1_request >= 0)begin
      $display("CACHE: p1_request is valid (%b)",p1_request);

        $display("CACHE: request from p1 is valid and new");
        requests[1] = 1;
        previous_p1_request = p1_request;

    end
    else begin
      $display("CACHE: p1_request is invalid (%b)",p1_request);
    end


    if(requests == 2'b11)begin
      $display("CACHE: new requests from p0 and p1, arbiting (arbiter = %b)",arbiter);
      is_busy = 1;
      request_to_process = arbiter? p1_request:p0_request;
      arbiter = ~arbiter;
    end

    else if (requests == 2'b01)begin
      $display("CACHE: new request from p0");
      is_busy = 0;
      request_to_process = p0_request;
    end
    else if (requests == 2'b10)begin
      $display("CACHE: new request from p1");
      is_busy = 0;
      request_to_process = p1_request;
    end
    else if ((requests == 2'b00) && is_busy)begin
      $display("CACHE: processing second request due to busy signal");
      request_to_process = arbiter? previous_p1_request:previous_p0_request;
    end

    if(requests > 0 || is_busy)begin






      $display("CACHE: processing request (p_id=%b, load/store=%b, tag=%b, offset=%b, data=%b)",
      request_to_process[21],request_to_process[20],request_to_process[19:9],request_to_process[8],request_to_process[7:0]);




      begin:tag_search_break;
        repeat(16)begin:tag_search_continue



          temp_address_line = address_line[counter];

          address_tag0 = temp_address_line[21:11];
          address_tag1 = temp_address_line[10:0];

          selected_tag = (block_offset)? address_tag1:address_tag0;
          block_offset = request_to_process[8];
          $display("CACHE: searching line %d, tag=%b, block_offset=%b,",counter,selected_tag,block_offset);
          if(request_to_process[19:9] == selected_tag)begin
            $display("CACHE: match found at line %d, saving counter location",counter);
            disable tag_search_break;
          end
          counter = counter+1;
        end
      end






      case(request_to_process[20])
        1'b1: begin

          $display("CACHE: mode is store, writing data=%b and new address=%b (even tho address is same)",request_to_process[7:0],selected_tag);
          if(block_offset)begin
            cache_line[counter] [7:0] = request_to_process[7:0];


          end
          else begin
            cache_line[counter] [15:8] = request_to_process[7:0];


          end
          data_out = {request_to_process[21],request_to_process[20],selected_tag,block_offset,cache_line[counter] [15:0]};
        end
        1'b0: begin




            $display("CACHE: mode is load, loading data=%b to dataline from address %b",cache_line[counter] [15:0],selected_tag);
            data_out = {request_to_process[21],request_to_process[20],selected_tag,block_offset,cache_line[counter] [15:0]};


        end
      endcase

      if((requests == 2'b00) && is_busy)begin
        $display("CACHE: finished with second request from is_busy state, setting it back to false");
        is_busy =0;
      end
    end
    else begin
      $display("CACHE: 0 requesets, nothing to do, closing output");
      data_out = 30'bz;
    end
  end
endmodule
module cache(clk,p0_request,p1_request,data_out, is_busy);



  input clk;
  






  input [21:0] p0_request, p1_request;
  







  output reg [29:0] data_out;
  

  output reg is_busy;
  







  reg [15:0] cache_line [15:0];
  


  reg [21:0] address_line [15:0];
  



  reg [1:0] valid_line [15:0];
  


  


  reg [3:0] counter;

  reg [1:0] requests;

  reg arbiter;

  reg [21:0] previous_p0_request, previous_p1_request;

  reg [21:0] request_to_process;

  reg [21:0] temp_address_line;

  reg [10:0] address_tag0, address_tag1, selected_tag;


  

  reg block_offset;
  


  



  

  initial begin
    is_busy = 0;
    arbiter = 0;
    counter = 0;
    requests = 0;
    temp_address_line = 22'bz;
    previous_p0_request = 22'bz;
    previous_p1_request = 22'bz;
    request_to_process = 22'bz;
    address_tag0 = 11'bz;
    address_tag1 = 11'bz;
    selected_tag = 11'bz;
    block_offset = 1'bz;
    data_out = 30'bz;



    cache_line[0] [15:0] = 16'b0110_0100__0000_0000;
    cache_line[1] [15:0] = 16'b0110_0101__1111_1111;
    cache_line[2] [15:0] = 16'b0110_0110__1111_1110;
    cache_line[3] [15:0] = 16'b0110_0111__1111_1101;
    cache_line[4] [15:0] = 16'b0110_1000__1111_1100;
    cache_line[5] [15:0] = 16'b0110_1001__1111_1011;
    cache_line[6] [15:0] = 16'b0110_1010__1111_1010;
    cache_line[7] [15:0] = 16'b0110_1011__1111_1001;
    cache_line[8] [15:0] = 16'b0110_1100__1111_1000;
    cache_line[9] [15:0] = 16'b0110_1101__1111_0111;
    cache_line[10] [15:0] = 16'b0110_1110__1111_0110;
    cache_line[11] [15:0] = 16'b0110_1111__1111_0101;
    cache_line[12] [15:0] = 16'b0111_0000__1111_0100;
    cache_line[13] [15:0] = 16'b0111_0001__1111_0011;
    cache_line[14] [15:0] = 16'b0111_0010__1111_0010;
    cache_line[15] [15:0] = 16'b0111_0011__1111_0001;
    
    address_line[0] [21:0] = 22'b0101_0000_000__0101_0000_000;
    address_line[1] [21:0] = 22'b0101_0001_000__0101_0001_000;
    address_line[2] [21:0] = 22'b0101_0010_000__0101_0010_000;
    address_line[3] [21:0] = 22'b0101_0011_000__0101_0011_000;
    address_line[4] [21:0] = 22'b0101_0100_000__0101_0100_000;
    address_line[5] [21:0] = 22'b0101_0101_000__0101_0101_000;
    address_line[6] [21:0] = 22'b0101_0110_000__0101_0110_000;
    address_line[7] [21:0] = 22'b0101_0111_000__0101_0111_000;
    address_line[8] [21:0] = 22'b0101_1000_000__0101_1000_000;
    address_line[9] [21:0] = 22'b0101_1001_000__0101_1001_000;
    address_line[10] [21:0] = 22'b0101_1010_000__0101_1010_000;
    address_line[11] [21:0] = 22'b0101_1011_000__0101_1011_000;
    address_line[12] [21:0] = 22'b0101_1100_000__0101_1100_000;
    address_line[13] [21:0] = 22'b0101_1101_000__0101_1101_000;
    address_line[14] [21:0] = 22'b0101_1110_000__0101_1110_000;
    address_line[15] [21:0] = 22'b0101_1111_000__0101_1111_000;
  end

  always@(posedge clk)begin
    counter = 0;
    requests = 0;
    temp_address_line = 21'bz;
    data_out = 30'bz;









    if(p0_request >= 0)begin
      $display("CACHE: p0_request is valid (%b)",p0_request);

        $display("CACHE: request from p0 is valid and new");
        requests[0] = 1;
        previous_p0_request = p0_request;

    end
    else begin
      $display("CACHE: p0_request is invalid (%b)",p0_request);
    end
    if(p1_request >= 0)begin
      $display("CACHE: p1_request is valid (%b)",p1_request);

        $display("CACHE: request from p1 is valid and new");
        requests[1] = 1;
        previous_p1_request = p1_request;

    end
    else begin
      $display("CACHE: p1_request is invalid (%b)",p1_request);
    end


    if(requests == 2'b11)begin
      $display("CACHE: new requests from p0 and p1, arbiting (arbiter = %b)",arbiter);
      is_busy = 1;
      request_to_process = arbiter? p1_request:p0_request;
      arbiter = ~arbiter;
    end

    else if (requests == 2'b01)begin
      $display("CACHE: new request from p0");
      is_busy = 0;
      request_to_process = p0_request;
    end
    else if (requests == 2'b10)begin
      $display("CACHE: new request from p1");
      is_busy = 0;
      request_to_process = p1_request;
    end
    else if ((requests == 2'b00) && is_busy)begin
      $display("CACHE: processing second request due to busy signal");
      request_to_process = arbiter? previous_p1_request:previous_p0_request;
    end

    if(requests > 0 || is_busy)begin






      $display("CACHE: processing request (p_id=%b, load/store=%b, tag=%b, offset=%b, data=%b)",
      request_to_process[21],request_to_process[20],request_to_process[19:9],request_to_process[8],request_to_process[7:0]);




      begin:tag_search_break;
        repeat(16)begin:tag_search_continue



          temp_address_line = address_line[counter];

          address_tag0 = temp_address_line[21:11];
          address_tag1 = temp_address_line[10:0];

          selected_tag = (block_offset)? address_tag1:address_tag0;
          block_offset = request_to_process[8];
          $display("CACHE: searching line %d, tag=%b, block_offset=%b,",counter,selected_tag,block_offset);
          if(request_to_process[19:9] == selected_tag)begin
            $display("CACHE: match found at line %d, saving counter location",counter);
            disable tag_search_break;
          end
          counter = counter+1;
        end
      end






      case(request_to_process[20])
        1'b1: begin

          $display("CACHE: mode is store, writing data=%b and new address=%b (even tho address is same)",request_to_process[7:0],selected_tag);
          if(block_offset)begin
            cache_line[counter] [7:0] = request_to_process[7:0];


          end
          else begin
            cache_line[counter] [15:8] = request_to_process[7:0];


          end
          data_out = {request_to_process[21],request_to_process[20],selected_tag,block_offset,cache_line[counter] [15:0]};
        end
        1'b0: begin




            $display("CACHE: mode is load, loading data=%b to dataline from address %b",cache_line[counter] [15:0],selected_tag);
            data_out = {request_to_process[21],request_to_process[20],selected_tag,block_offset,cache_line[counter] [15:0]};


        end
      endcase

      if((requests == 2'b00) && is_busy)begin
        $display("CACHE: finished with second request from is_busy state, setting it back to false");
        is_busy =0;
      end
    end
    else begin
      $display("CACHE: 0 requesets, nothing to do, closing output");
      data_out = 30'bz;
    end
  end
endmodule