data/full_repos/permissive/153690221/Source/instructioncacheL1.v
 line:110: before: ","
1: b'%Error: data/full_repos/permissive/153690221/Source/instructioncacheL1.v:110: Unsupported: for loop initialization after the first comma\n            for(k = 0, j = 4; j > 0 && k < 4; j = j - 1, k = k + 1) begin\n                     ^\n%Error: data/full_repos/permissive/153690221/Source/instructioncacheL1.v:110: Unsupported: for loop step after the first comma\n            for(k = 0, j = 4; j > 0 && k < 4; j = j - 1, k = k + 1) begin\n                                              ^\n%Error: data/full_repos/permissive/153690221/Source/instructioncacheL1.v:158: Unsupported: for loop initialization after the first comma\n                for(curLine = 0, curLRU = 4; curLine < 4 && curLRU > 0; curLine = curLine + 1, curLRU = curLRU - 1) begin\n                               ^\n%Error: data/full_repos/permissive/153690221/Source/instructioncacheL1.v:158: Unsupported: for loop step after the first comma\n                for(curLine = 0, curLRU = 4; curLine < 4 && curLRU > 0; curLine = curLine + 1, curLRU = curLRU - 1) begin\n                                                                        ^~~~~~~\n%Error: data/full_repos/permissive/153690221/Source/instructioncacheL1.v:270: Unsupported: for loop initialization after the first comma\n                                for(curLine = 0, curLRU = 4; curLine < 4 && curLRU > 0; curLine = curLine + 1, curLRU = curLRU - 1) begin\n                                               ^\n%Error: data/full_repos/permissive/153690221/Source/instructioncacheL1.v:270: Unsupported: for loop step after the first comma\n                                for(curLine = 0, curLRU = 4; curLine < 4 && curLRU > 0; curLine = curLine + 1, curLRU = curLRU - 1) begin\n                                                                                        ^~~~~~~\n%Error: Exiting due to 6 error(s)\n        ... See the manual and https://verilator.org for more assistance.\n'
module instructioncacheL1(
    input clk,rst,write,

    input [59:0] address,
    input [2:0] command,
    input [13:0] setRead,

    output reg [61:0] L2message,
    output reg processing,
    
    output reg [44:0] way1, way2, way3, way4,
    output reg [63:0] hits, misses, total, reads, writes
    );
    
    parameter

      READ = 3'd0,
      WRITE = 3'd1,
      INVALIDATE = 3'd2,
      CLEAR = 3'd3,
      L2DATAREQUEST = 3'd4,
      

      RETURNDATA = 2'd0,
      LWWRITE = 2'd1,
      L2READ = 2'd2,
      L2READFOWN = 2'd3,
      

      INVALID = 2'd0,
      MODIFIED = 2'd1,
      SHARED = 2'd2,
      EXCLUSIVE = 2'd3;
      








    

    


    reg [44:0] cacheArray [15999:0][3:0];
    
    reg [2:0] command1;
    reg [13:0] index1, index;
    reg [5:0] byte_sel1;
    reg [39:0] tag1, tag;
    reg [59:0] address1;

    assign index1 = address1[19:6];
    assign index = address[19:6];
    assign byte_sel1 = address1[5:0];
    assign tag1 = address1[59:20];
    assign tag = address[59:20];
        
    reg match1, match;
    reg [1:0] matchingLine1, matchingLine, matchingLineLRU, matchingLineLRU1;
    reg [2:0] line;
    reg [39:0] currentTag;
    
    reg [2:0] LRUupdatecount;
    reg LRUupdate;
    
    reg [1:0] LRUcompValue;
    reg [1:0] LRULineSet;
    
    integer i, j, k;
    initial begin
        reads = 0;
        writes = 0;
        hits = 0;
        misses = 0;
        total = 0;
        
        processing = 0;
        LRUupdate = 0;
        L2message = 0;
        
        for(i = 0; i < 16000; i = i + 1) begin
            for(k = 0, j = 4; j > 0 && k < 4; j = j - 1, k = k + 1) begin
                cacheArray[i][k][44:5] = 0;
                cacheArray[i][k][4:3] = INVALID;
                cacheArray[i][k][2:1] = j-1;
                cacheArray[i][k][0] = 1;
            end
        end
    end
    
    reg [44:0] currentLineForMatching;
    reg [1:0] lineArrayLRU [7:0];
    reg [1:0] lineArrayMESI [7:0];





    reg [14:0] curSet;
    reg [2:0] curLine, curLRU;


    reg invalidExists;
    reg [1:0] LRUinvalidLine, LRUinvalidValue;



    reg [1:0] LRUline, LRULineValue;



    reg [1:0] victimLine, victimLRUvalue, victimLine1, victimLRUvalue1;

    

    always@(posedge clk) begin
        if(rst) begin
            reads <= 0;
            writes <= 0;
            hits <= 0;
            misses <= 0;
            total <= 0;
        
            processing <= 0;
            LRUupdate <= 0;
            L2message <= 0;


            for(curSet = 0; curSet < 16000; curSet = curSet + 1) begin
                for(curLine = 0, curLRU = 4; curLine < 4 && curLRU > 0; curLine = curLine + 1, curLRU = curLRU - 1) begin
                    cacheArray[curSet][curLine][44:5] <= 0;
                    cacheArray[curSet][curLine][4:3] <= INVALID;
                    cacheArray[curSet][curLine][2:1] <= curLRU-1;
                    cacheArray[curSet][curLine][0] <= 1;
                end
             end
        end
        else begin
            if(!processing && write) begin





               command1 <= command;

               match1 <= match;
               matchingLine1 <= matchingLine;
               matchingLineLRU1 <= matchingLineLRU;
               
               victimLine1 <= victimLine;
               victimLRUvalue1 <= victimLRUvalue;
               
               address1 <= address;
               L2message <= 0;
               
               processing <= 1;

            end
            else if(processing) begin
                if(LRUupdate) begin 
                    for(LRUupdatecount = 0; LRUupdatecount < 4; LRUupdatecount = LRUupdatecount + 1) begin

                        if(cacheArray[index1][LRUupdatecount][2:1] < LRUcompValue && LRUupdatecount != LRULineSet) begin 
                            cacheArray[index1][LRUupdatecount][2:1] <= cacheArray[index1][LRUupdatecount][2:1] + 1;
                        end
                        else if(LRUupdatecount == LRULineSet) begin
                            cacheArray[index1][LRUupdatecount][2:1] <= 0;
                        end
                    end
                    LRUupdate <= 0; 
                    processing <= 0;
                end
                else begin




                    




                    case(command1)


                        READ: begin
                            reads <= reads + 1;
                            total <= total + 1;

                            
                            if(!match1) begin

                                L2message[61:2] <= address1;
                                L2message[2:0] <= L2READ;
                                
                                misses <= misses + 1;
                                if(cacheArray[index1][victimLine1][4:3] == INVALID) begin

                                    cacheArray[index1][victimLine1][44:5] <= tag1;

                                    cacheArray[index1][victimLine1][4:3] <= EXCLUSIVE;
                                end
                                else begin
                                    cacheArray[index1][victimLine1][44:5] <= tag1;

                                    cacheArray[index1][victimLine1][4:3] <= cacheArray[index1][victimLine1][5:4];
                                end


                                LRUupdate <= 1;

                                LRULineSet <= victimLine1;
                                LRUcompValue <= victimLRUvalue1;

                            end
                            else begin

                                hits <= hits + 1;

                                if(cacheArray[index1][matchingLine1][4:3] == MODIFIED || cacheArray[index1][matchingLine1][4:3] == EXCLUSIVE) begin

                                    cacheArray[index1][matchingLine1][4:3] <= SHARED;
                                end
                                
                                LRUupdate <= 1;

                                LRUcompValue <= matchingLineLRU1;
                                LRULineSet <= matchingLine1;
                            end
                        end
                        WRITE: begin

                        end
                        INVALIDATE:
                        begin
                                               
                        end
                        CLEAR: begin

                            for(curSet = 0; curSet < 16000; curSet = curSet + 1) begin
                                for(curLine = 0, curLRU = 4; curLine < 4 && curLRU > 0; curLine = curLine + 1, curLRU = curLRU - 1) begin
                                    cacheArray[curSet][curLine][44:5] <= 0;
                                    cacheArray[curSet][curLine][4:3] <= INVALID;
                                    cacheArray[curSet][curLine][2:1] <= curLRU-1;
                                    cacheArray[curSet][curLine][0] <= 1;
                                end
                            end
                            processing <= 0;

                        end
                        L2DATAREQUEST: begin
                        
                        end
                        default: begin
                        
                        end
                    endcase
                end
            end
        end
    end
    
    

    always@(*) begin

        way1 = cacheArray[setRead][0];
        way2 = cacheArray[setRead][1];
        way3 = cacheArray[setRead][2];
        way4 = cacheArray[setRead][3];

        for(line = 0; line < 4; line=line+1) begin
            lineArrayLRU[line] = cacheArray[index][line][2:1];
            lineArrayMESI[line] = cacheArray[index][line][4:3];
        end

        match = 0;
        matchingLine = 0;
        matchingLineLRU = lineArrayLRU[0];




        for(line = 0; line < 4; line=line+1) begin
            currentLineForMatching = cacheArray[index][line];
            currentTag = currentLineForMatching[44:5];
            if(currentTag == tag) begin
                match = 1;
                matchingLine = line;
                matchingLineLRU = lineArrayLRU[line];
                break;
            end
        end





        LRUinvalidLine = 0;
        invalidExists = 0;
        LRUinvalidValue = 0;


        for(line = 0; line < 4; line=line+1) begin
            if(lineArrayMESI[line] == INVALID) begin
                invalidExists = 1;
                LRUinvalidLine = line;
                LRUinvalidValue = lineArrayLRU[line];
                break;
            end
        end


        if(invalidExists) begin
            for(line = 0; line < 4; line=line+1) begin
                if(lineArrayMESI[line] == INVALID && lineArrayLRU[line] > LRUinvalidValue) begin
                    LRUinvalidValue = lineArrayLRU[line];
                    LRUinvalidLine = line;
                end
            end
        end 
        





        LRUline = 0;
        LRULineValue = lineArrayLRU[0];

        for(line = 0; line < 4; line=line+1) begin
            if(lineArrayLRU[line] > LRULineValue) begin
                LRUline = line;
                LRULineValue = lineArrayLRU[line];
            end
        end




        if(invalidExists) begin
            victimLine = LRUinvalidLine;
            victimLRUvalue = LRUinvalidValue;
        end
        else begin
            victimLine = LRUline;
            victimLRUvalue = LRULineValue;
        end
    end
    
    
endmodule
module instructioncacheL1(
    input clk,rst,write,

    input [59:0] address,
    input [2:0] command,
    input [13:0] setRead,

    output reg [61:0] L2message,
    output reg processing,
    
    output reg [44:0] way1, way2, way3, way4,
    output reg [63:0] hits, misses, total, reads, writes
    );

    
    parameter

      READ = 3'd0,
      WRITE = 3'd1,
      INVALIDATE = 3'd2,
      CLEAR = 3'd3,
      L2DATAREQUEST = 3'd4,
      

      RETURNDATA = 2'd0,
      LWWRITE = 2'd1,
      L2READ = 2'd2,
      L2READFOWN = 2'd3,
      

      INVALID = 2'd0,
      MODIFIED = 2'd1,
      SHARED = 2'd2,
      EXCLUSIVE = 2'd3;
      








    

    


    reg [44:0] cacheArray [15999:0][3:0];
    
    reg [2:0] command1;
    reg [13:0] index1, index;
    reg [5:0] byte_sel1;
    reg [39:0] tag1, tag;
    reg [59:0] address1;

    assign index1 = address1[19:6];
    assign index = address[19:6];
    assign byte_sel1 = address1[5:0];
    assign tag1 = address1[59:20];
    assign tag = address[59:20];
        
    reg match1, match;
    reg [1:0] matchingLine1, matchingLine, matchingLineLRU, matchingLineLRU1;
    reg [2:0] line;
    reg [39:0] currentTag;
    
    reg [2:0] LRUupdatecount;
    reg LRUupdate;
    
    reg [1:0] LRUcompValue;
    reg [1:0] LRULineSet;
    
    integer i, j, k;
    initial begin
        reads = 0;
        writes = 0;
        hits = 0;
        misses = 0;
        total = 0;
        
        processing = 0;
        LRUupdate = 0;
        L2message = 0;
        
        for(i = 0; i < 16000; i = i + 1) begin
            for(k = 0, j = 4; j > 0 && k < 4; j = j - 1, k = k + 1) begin
                cacheArray[i][k][44:5] = 0;
                cacheArray[i][k][4:3] = INVALID;
                cacheArray[i][k][2:1] = j-1;
                cacheArray[i][k][0] = 1;
            end
        end
    end
    
    reg [44:0] currentLineForMatching;
    reg [1:0] lineArrayLRU [7:0];
    reg [1:0] lineArrayMESI [7:0];





    reg [14:0] curSet;
    reg [2:0] curLine, curLRU;


    reg invalidExists;
    reg [1:0] LRUinvalidLine, LRUinvalidValue;



    reg [1:0] LRUline, LRULineValue;



    reg [1:0] victimLine, victimLRUvalue, victimLine1, victimLRUvalue1;

    

    always@(posedge clk) begin
        if(rst) begin
            reads <= 0;
            writes <= 0;
            hits <= 0;
            misses <= 0;
            total <= 0;
        
            processing <= 0;
            LRUupdate <= 0;
            L2message <= 0;


            for(curSet = 0; curSet < 16000; curSet = curSet + 1) begin
                for(curLine = 0, curLRU = 4; curLine < 4 && curLRU > 0; curLine = curLine + 1, curLRU = curLRU - 1) begin
                    cacheArray[curSet][curLine][44:5] <= 0;
                    cacheArray[curSet][curLine][4:3] <= INVALID;
                    cacheArray[curSet][curLine][2:1] <= curLRU-1;
                    cacheArray[curSet][curLine][0] <= 1;
                end
             end
        end
        else begin
            if(!processing && write) begin





               command1 <= command;

               match1 <= match;
               matchingLine1 <= matchingLine;
               matchingLineLRU1 <= matchingLineLRU;
               
               victimLine1 <= victimLine;
               victimLRUvalue1 <= victimLRUvalue;
               
               address1 <= address;
               L2message <= 0;
               
               processing <= 1;

            end
            else if(processing) begin
                if(LRUupdate) begin 
                    for(LRUupdatecount = 0; LRUupdatecount < 4; LRUupdatecount = LRUupdatecount + 1) begin

                        if(cacheArray[index1][LRUupdatecount][2:1] < LRUcompValue && LRUupdatecount != LRULineSet) begin 
                            cacheArray[index1][LRUupdatecount][2:1] <= cacheArray[index1][LRUupdatecount][2:1] + 1;
                        end
                        else if(LRUupdatecount == LRULineSet) begin
                            cacheArray[index1][LRUupdatecount][2:1] <= 0;
                        end
                    end
                    LRUupdate <= 0; 
                    processing <= 0;
                end
                else begin




                    




                    case(command1)


                        READ: begin
                            reads <= reads + 1;
                            total <= total + 1;

                            
                            if(!match1) begin

                                L2message[61:2] <= address1;
                                L2message[2:0] <= L2READ;
                                
                                misses <= misses + 1;
                                if(cacheArray[index1][victimLine1][4:3] == INVALID) begin

                                    cacheArray[index1][victimLine1][44:5] <= tag1;

                                    cacheArray[index1][victimLine1][4:3] <= EXCLUSIVE;
                                end
                                else begin
                                    cacheArray[index1][victimLine1][44:5] <= tag1;

                                    cacheArray[index1][victimLine1][4:3] <= cacheArray[index1][victimLine1][5:4];
                                end


                                LRUupdate <= 1;

                                LRULineSet <= victimLine1;
                                LRUcompValue <= victimLRUvalue1;

                            end
                            else begin

                                hits <= hits + 1;

                                if(cacheArray[index1][matchingLine1][4:3] == MODIFIED || cacheArray[index1][matchingLine1][4:3] == EXCLUSIVE) begin

                                    cacheArray[index1][matchingLine1][4:3] <= SHARED;
                                end
                                
                                LRUupdate <= 1;

                                LRUcompValue <= matchingLineLRU1;
                                LRULineSet <= matchingLine1;
                            end
                        end
                        WRITE: begin

                        end
                        INVALIDATE:
                        begin
                                               
                        end
                        CLEAR: begin

                            for(curSet = 0; curSet < 16000; curSet = curSet + 1) begin
                                for(curLine = 0, curLRU = 4; curLine < 4 && curLRU > 0; curLine = curLine + 1, curLRU = curLRU - 1) begin
                                    cacheArray[curSet][curLine][44:5] <= 0;
                                    cacheArray[curSet][curLine][4:3] <= INVALID;
                                    cacheArray[curSet][curLine][2:1] <= curLRU-1;
                                    cacheArray[curSet][curLine][0] <= 1;
                                end
                            end
                            processing <= 0;

                        end
                        L2DATAREQUEST: begin
                        
                        end
                        default: begin
                        
                        end
                    endcase
                end
            end
        end
    end
    
    

    always@(*) begin

        way1 = cacheArray[setRead][0];
        way2 = cacheArray[setRead][1];
        way3 = cacheArray[setRead][2];
        way4 = cacheArray[setRead][3];

        for(line = 0; line < 4; line=line+1) begin
            lineArrayLRU[line] = cacheArray[index][line][2:1];
            lineArrayMESI[line] = cacheArray[index][line][4:3];
        end

        match = 0;
        matchingLine = 0;
        matchingLineLRU = lineArrayLRU[0];




        for(line = 0; line < 4; line=line+1) begin
            currentLineForMatching = cacheArray[index][line];
            currentTag = currentLineForMatching[44:5];
            if(currentTag == tag) begin
                match = 1;
                matchingLine = line;
                matchingLineLRU = lineArrayLRU[line];
                break;
            end
        end





        LRUinvalidLine = 0;
        invalidExists = 0;
        LRUinvalidValue = 0;


        for(line = 0; line < 4; line=line+1) begin
            if(lineArrayMESI[line] == INVALID) begin
                invalidExists = 1;
                LRUinvalidLine = line;
                LRUinvalidValue = lineArrayLRU[line];
                break;
            end
        end


        if(invalidExists) begin
            for(line = 0; line < 4; line=line+1) begin
                if(lineArrayMESI[line] == INVALID && lineArrayLRU[line] > LRUinvalidValue) begin
                    LRUinvalidValue = lineArrayLRU[line];
                    LRUinvalidLine = line;
                end
            end
        end 
        





        LRUline = 0;
        LRULineValue = lineArrayLRU[0];

        for(line = 0; line < 4; line=line+1) begin
            if(lineArrayLRU[line] > LRULineValue) begin
                LRUline = line;
                LRULineValue = lineArrayLRU[line];
            end
        end




        if(invalidExists) begin
            victimLine = LRUinvalidLine;
            victimLRUvalue = LRUinvalidValue;
        end
        else begin
            victimLine = LRUline;
            victimLRUvalue = LRULineValue;
        end
    end
    
    
endmodule