OpenCores
URL https://opencores.org/ocsvn/integer_square_root/integer_square_root/trunk

Subversion Repositories integer_square_root

[/] [integer_square_root/] [trunk/] [src/] [ISR.sv] - Diff between revs 4 and 6

Show entire file | Details | Blame | View Log

Rev 4 Rev 6
Line 18... Line 18...
// Additional Comments:
// Additional Comments:
//
//
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
 
 
 
 
module ISR(
typedef enum logic [3:0] {
 
    INIT,
 
    GUESS,
 
    MULT_LOAD,
 
    MULT_WAIT,
 
    COMPARE,
 
    CHANGE,
 
    CHECK,
 
    INCRE,
 
    ENDLOOP,
 
    DONE
 
} state;
 
 
 
module ISR_FSM(
    input               reset,
    input               reset,
    input        [63:0] value,
    input        [63:0] value,
    input               clock,
    input               clock,
 
    input               mult_done,
 
    input        [63:0] mult_result,
 
    output logic        mult_start,
 
    output logic        mult_reset,
 
    output logic [63:0] mult_input,
    output logic [31:0] result,
    output logic [31:0] result,
    output logic        done
    output logic        done
);
);
    logic [63:0] new_value, proposed_solution_square;
 
    logic [31:0] proposed_solution;
 
    logic [4:0] i;
 
    logic start, it_done, flush;
 
    logic reset_sync;
 
 
 
    mult Multiplier (
    logic [63:0] value_reg;
        .clock(clock),
    logic [31:0] result_next, guess, guess_next;
        .reset(reset),
    integer i, i_next;
        .mcand({32'h00000000, proposed_solution}),
 
        .mplier({32'h00000000, proposed_solution}),
    state current_state, next_state;
        .start(start),
 
        .product(proposed_solution_square),
    assign mult_input = {32'b0, guess};
        .done(it_done)
    assign mult_start = current_state == MULT_LOAD | current_state == MULT_WAIT;
    );
    assign done = current_state == DONE;
 
    assign mult_reset = current_state == INIT | current_state == COMPARE;
 
 
 
 
    always_comb begin
    always_comb begin
//        if (reset_async) begin
        guess_next = guess;
//            done = 0;
        i_next = i;
//            result = 0;
        result_next = result;
//        end
        case (current_state)
//        else begin
            INIT: begin
            // Reduction operator
                guess_next = 32'h0000_0000;
            // see http://www.asic-world.com/verilog/operators2.html
                i_next = 31;
            // done = ~|i & it_done & ~flush;
                result_next = 0;
            // result[i] = (proposed_solution_square <= new_value) & it_done;
                next_state = GUESS;
        done = ~|i & it_done & ~flush & ~reset_sync;
            end
        result[i] = (proposed_solution_square <= new_value) & it_done & ~reset_sync;
            GUESS: begin
//        end
                guess_next = guess + (32'h0000_0001 << i);
 
                next_state = MULT_LOAD;
 
            end
 
            MULT_LOAD: next_state = MULT_WAIT;
 
            MULT_WAIT: next_state = (mult_done) ? COMPARE : MULT_WAIT;
 
            COMPARE: next_state = (mult_result > value_reg) ? CHANGE : CHECK;
 
            CHANGE: begin
 
                guess_next = guess - (32'h0000_0001 << i);
 
                next_state = CHECK;
 
            end
 
            CHECK: next_state = i ? INCRE : ENDLOOP;
 
            INCRE: begin
 
                i_next = i - 1;
 
                next_state = GUESS;
 
            end
 
            ENDLOOP: begin
 
                result_next = guess;
 
                next_state = DONE;
 
            end
 
            DONE: next_state = DONE;
 
            default: next_state = INIT;
 
        endcase
    end
    end
 
 
    always_ff @(posedge clock or posedge reset) begin
    always_ff @(posedge clock) begin
        if (reset) begin
        if (reset) begin
            // done <= 0;
            current_state <= INIT;
            // result <= 0;
            value_reg <= value;
            reset_sync <= 1;
            result <= 32'b0;
            start <= 0;
            i <= 31;
            flush <= 0;
            guess <= 32'h0000_0000;
            i <= 5'b11111;
 
            proposed_solution <= 32'h80000000;
 
            new_value <= value;
 
        end
        end
        else begin
        else begin
            reset_sync <= 0;
            current_state <= next_state;
            start <= !it_done || !flush;
            value_reg <= value_reg;
            flush <= it_done;
            result <= result_next;
            // if (!it_done && flush) begin
            i <= i_next;
            //     flush <= 0;
            guess <= guess_next;
            // end
 
            if (i && it_done && !flush) begin
 
                // flush <= 1;
 
                i <= i - 1;
 
                proposed_solution[i-1] <= 1;
 
                proposed_solution[i] <= result[i];
 
            end
 
        end
        end
    end
    end
 
 
 
endmodule
 
 
 
 
 
 
 
module ISR(
 
    input               reset,
 
    input        [63:0] value,
 
    input               clock,
 
    output logic [31:0] result,
 
    output logic        done
 
);
 
    logic mult_start;
 
    logic mult_done;
 
    logic [63:0] mult_result;
 
    logic [63:0] mult_input;
 
    logic mult_reset;
 
 
 
 
 
    mult multiplier(
 
        .clock(clock),
 
        .reset(mult_reset),
 
        .mcand(mult_input),
 
        .mplier(mult_input),
 
        .start(mult_start),
 
        .product(mult_result),
 
        .done(mult_done)
 
    );
 
 
 
    ISR_FSM FSM(
 
        .reset(reset),
 
        .value(value),
 
        .clock(clock),
 
        .mult_done(mult_done),
 
        .mult_result(mult_result),
 
        .mult_start(mult_start),
 
        .mult_reset(mult_reset),
 
        .mult_input(mult_input),
 
        .result(result),
 
        .done(done)
 
    );
 
 
 
 
endmodule
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.