data/full_repos/permissive/123218339/betterNeighborsInMyCluster.v
1: b'%Warning-REALCVT: data/full_repos/permissive/123218339/betterNeighborsInMyCluster.v:81: Implicit conversion of real to integer\n                            k = $ceil((11-1) * batteryStat);  \n                                ^~~~~\n                  ... Use "/* verilator lint_off REALCVT */" and lint_on around source to disable this message.\n%Error: Exiting due to 1 warning(s)\n'
module betterNeighborsInMyCluster(clock, nrst, start, address, data_in, MY_CLUSTER_ID, mybest, betterneighbors, besthop, bestvalue, bestneighborID, nextsinks, done);
    input clock, nrst, start;
    input [`WORD_WIDTH-1:0] data_in, MY_CLUSTER_ID;
    input [`WORD_WIDTH-1:0] mybest;
    output done;
    output [`WORD_WIDTH-1:0] address;
    output [`WORD_WIDTH-1:0] betterneighbors, besthop, bestneighborID, nextsinks;
    output [`WORD_WIDTH-1:0] bestvalue;


    reg done_buf;
    reg [`WORD_WIDTH-1:0] address_count, i, j, k;
    reg [`WORD_WIDTH-1:0] neighborID, knownSinks, betterneighbors_buf, besthop_buf, bestneighborID_buf, nextsinks_buf;
    reg [`WORD_WIDTH-1:0] BATTERY_THRESHOLD, batteryStat, qValue, bestvalue_buf;
    reg [2:0] state;

    always @ (posedge clock) begin
        if (!nrst) begin
            done_buf <= 0;
            address_count <= 16'hC8;
            betterneighbors_buf <= 0;
            besthop_buf <= 16'd65;
            bestvalue_buf  <= 16'hFFFE;
            BATTERY_THRESHOLD <= 0;
            nextsinks_buf <= 16'd65;
            state <= 0;
            i <= 0;
            j <= 0;
            k <= 0;
        end
        else begin
            if (start && !done_buf) begin
                case (state)
                    3'd0: begin
                        if (MY_CLUSTER_ID != data_in) begin
                            i = i + 1;
                        end
                        else begin
                            state = 3'd1;
                            address_count = 16'h148 + 2*i;
                        end
                    end

                    3'd1: begin
                        batteryStat = data_in; 
                        if (BATTERY_THRESHOLD > batteryStat) begin
                            i = i + 1;
                            state = 3'd0;
                            address_count = 16'hC8 + 2*i;
                        end
                        else begin
                            state = 3'd2;
                            address_count = 16'h1C8 + 2*i;
                        end
                    end

                    3'd2: begin

                        qValue = data_in;
                        if (qValue <= mybest) begin
                            betterneighbors_buf = betterneighbors_buf + 1;
                            state = 3'd3;
                            k = $ceil((`HCM_LENGTH-1) * batteryStat);
                            if (k >= `HCM_LENGTH)
                                k = `HCM_LENGTH - 1;
                            address_count = 16'h648 + 2*k;
                        end
                        else begin
                            state = 3'd4;
                            address_count = 16'h48 + 2*i;
                        end

                    end

                    3'd3: begin

                        qValue = qValue * data_in;
                        if (qValue < bestvalue_buf) begin
                            besthop_buf = i;
                            bestvalue_buf = qValue;
                        end
                        state = 3'd4;
                        address_count = 16'h48 + 2*i;
                    end

                    3'd4: begin

                        neighborID = data_in;
                        state = 3'd5;
                        address_count = 16'h8 + 2*j;
                        
                    end

                    3'd5: begin

                        knownSinks = data_in;
                        $display("%d,%d,%d,%d,%d,%d,%d", batteryStat, qValue, k, neighborID, knownSinks, i, j);

                        if (neighborID == knownSinks) begin
                            nextsinks_buf = i;
                        end

                        j = j + 1;
                        address_count = 16'h8 + 2*j;

                        if (j == 16) begin
                            j = 0;
                            i = i + 1;
                            state = 3'd0;
                            address_count = 16'hC8 + 2*i;
                        end

                        if (i == 64) begin
                            state = 3'd6;
                            address_count = 16'h48 + 2*besthop_buf;
                            
                        end
                    end

                    3'd6: begin
                        bestneighborID_buf = data_in;
                        done_buf = 1;

                    end
                endcase
            end
        end     
    end

    assign done = done_buf;
    assign address = address_count;
    assign betterneighbors = betterneighbors_buf;
    assign besthop = besthop_buf;
    assign bestvalue = bestvalue_buf;
    assign bestneighborID = bestneighborID_buf;
    assign nextsinks = nextsinks_buf;
endmodule
module betterNeighborsInMyCluster(clock, nrst, start, address, data_in, MY_CLUSTER_ID, mybest, betterneighbors, besthop, bestvalue, bestneighborID, nextsinks, done);

    input clock, nrst, start;
    input [`WORD_WIDTH-1:0] data_in, MY_CLUSTER_ID;
    input [`WORD_WIDTH-1:0] mybest;
    output done;
    output [`WORD_WIDTH-1:0] address;
    output [`WORD_WIDTH-1:0] betterneighbors, besthop, bestneighborID, nextsinks;
    output [`WORD_WIDTH-1:0] bestvalue;


    reg done_buf;
    reg [`WORD_WIDTH-1:0] address_count, i, j, k;
    reg [`WORD_WIDTH-1:0] neighborID, knownSinks, betterneighbors_buf, besthop_buf, bestneighborID_buf, nextsinks_buf;
    reg [`WORD_WIDTH-1:0] BATTERY_THRESHOLD, batteryStat, qValue, bestvalue_buf;
    reg [2:0] state;

    always @ (posedge clock) begin
        if (!nrst) begin
            done_buf <= 0;
            address_count <= 16'hC8;
            betterneighbors_buf <= 0;
            besthop_buf <= 16'd65;
            bestvalue_buf  <= 16'hFFFE;
            BATTERY_THRESHOLD <= 0;
            nextsinks_buf <= 16'd65;
            state <= 0;
            i <= 0;
            j <= 0;
            k <= 0;
        end
        else begin
            if (start && !done_buf) begin
                case (state)
                    3'd0: begin
                        if (MY_CLUSTER_ID != data_in) begin
                            i = i + 1;
                        end
                        else begin
                            state = 3'd1;
                            address_count = 16'h148 + 2*i;
                        end
                    end

                    3'd1: begin
                        batteryStat = data_in; 
                        if (BATTERY_THRESHOLD > batteryStat) begin
                            i = i + 1;
                            state = 3'd0;
                            address_count = 16'hC8 + 2*i;
                        end
                        else begin
                            state = 3'd2;
                            address_count = 16'h1C8 + 2*i;
                        end
                    end

                    3'd2: begin

                        qValue = data_in;
                        if (qValue <= mybest) begin
                            betterneighbors_buf = betterneighbors_buf + 1;
                            state = 3'd3;
                            k = $ceil((`HCM_LENGTH-1) * batteryStat);
                            if (k >= `HCM_LENGTH)
                                k = `HCM_LENGTH - 1;
                            address_count = 16'h648 + 2*k;
                        end
                        else begin
                            state = 3'd4;
                            address_count = 16'h48 + 2*i;
                        end

                    end

                    3'd3: begin

                        qValue = qValue * data_in;
                        if (qValue < bestvalue_buf) begin
                            besthop_buf = i;
                            bestvalue_buf = qValue;
                        end
                        state = 3'd4;
                        address_count = 16'h48 + 2*i;
                    end

                    3'd4: begin

                        neighborID = data_in;
                        state = 3'd5;
                        address_count = 16'h8 + 2*j;
                        
                    end

                    3'd5: begin

                        knownSinks = data_in;
                        $display("%d,%d,%d,%d,%d,%d,%d", batteryStat, qValue, k, neighborID, knownSinks, i, j);

                        if (neighborID == knownSinks) begin
                            nextsinks_buf = i;
                        end

                        j = j + 1;
                        address_count = 16'h8 + 2*j;

                        if (j == 16) begin
                            j = 0;
                            i = i + 1;
                            state = 3'd0;
                            address_count = 16'hC8 + 2*i;
                        end

                        if (i == 64) begin
                            state = 3'd6;
                            address_count = 16'h48 + 2*besthop_buf;
                            
                        end
                    end

                    3'd6: begin
                        bestneighborID_buf = data_in;
                        done_buf = 1;

                    end
                endcase
            end
        end     
    end

    assign done = done_buf;
    assign address = address_count;
    assign betterneighbors = betterneighbors_buf;
    assign besthop = besthop_buf;
    assign bestvalue = bestvalue_buf;
    assign bestneighborID = bestneighborID_buf;
    assign nextsinks = nextsinks_buf;
endmodule