// Copyright (C) 2023 Victor Suarez Rovere <suarezvictor@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
//
// ** Autogenerated file **


module M_accel_line32 (
        in_bus_ack,
        in_bus_dat_r,
        in_x0,
        in_x1,
        in_y0,
        in_y1,
        in_rgba,
        in_base,
        in_xstride,
        in_ystride,
        out_bus_cyc,
        out_bus_stb,
        out_bus_adr,
        out_bus_we,
        out_bus_dat_w,
        out_bus_sel,
        in_run,
        out_done,
        reset,
        out_clock,
        clock
    );
    input  [0:0] in_bus_ack;
    input  [31:0] in_bus_dat_r;
    input  [15:0] in_x0;
    input  [15:0] in_x1;
    input  [15:0] in_y0;
    input  [15:0] in_y1;
    input  [31:0] in_rgba;
    input  [31:0] in_base;
    input signed [15:0] in_xstride;
    input signed [15:0] in_ystride;
    output  [0:0] out_bus_cyc;
    output  [0:0] out_bus_stb;
    output  [31:0] out_bus_adr;
    output  [0:0] out_bus_we;
    output  [31:0] out_bus_dat_w;
    output  [15:0] out_bus_sel;
    input in_run;
    output out_done;
    input reset;
    output out_clock;
    input clock;
    assign out_clock = clock;
    reg signed [15:0] _t___block_2_x0i;
    reg signed [15:0] _t___block_2_x1i;
    reg signed [15:0] _t___block_2_y0i;
    reg signed [15:0] _t___block_2_y1i;
    reg signed [15:0] _t___block_2_e2;

    reg signed [15:0] _d___block_2_dx;
    reg signed [15:0] _q___block_2_dx;
    reg signed [15:0] _d___block_2_dy;
    reg signed [15:0] _q___block_2_dy;
    reg signed [1:0] _d___block_2_sx;
    reg signed [1:0] _q___block_2_sx;
    reg signed [1:0] _d___block_2_sy;
    reg signed [1:0] _q___block_2_sy;
    reg signed [15:0] _d___block_2_err;
    reg signed [15:0] _q___block_2_err;
    reg signed [15:0] _d___block_2_x;
    reg signed [15:0] _q___block_2_x;
    reg signed [15:0] _d___block_2_y;
    reg signed [15:0] _q___block_2_y;
    reg signed [31:0] _d___block_11_xincaddr;
    reg signed [31:0] _q___block_11_xincaddr;
    reg signed [31:0] _d___block_11_yincaddr;
    reg signed [31:0] _q___block_11_yincaddr;
    reg signed [15:0] _d___block_11_dxe;
    reg signed [15:0] _q___block_11_dxe;
    reg signed [15:0] _d___block_16_dye;
    reg signed [15:0] _q___block_16_dye;
    reg  [0:0] _d_bus_cyc;
    reg  [0:0] _q_bus_cyc;
    reg  [0:0] _d_bus_stb;
    reg  [0:0] _q_bus_stb;
    reg  [31:0] _d_bus_adr;
    reg  [31:0] _q_bus_adr;
    reg  [0:0] _d_bus_we;
    reg  [0:0] _q_bus_we;
    reg  [31:0] _d_bus_dat_w;
    reg  [31:0] _q_bus_dat_w;
    reg  [15:0] _d_bus_sel;
    reg  [15:0] _q_bus_sel;
    reg  [2:0] _d__idx_fsm0,_q__idx_fsm0;
    assign out_bus_cyc = _q_bus_cyc;
    assign out_bus_stb = _q_bus_stb;
    assign out_bus_adr = _q_bus_adr;
    assign out_bus_we = _q_bus_we;
    assign out_bus_dat_w = _q_bus_dat_w;
    assign out_bus_sel = _q_bus_sel;
    assign out_done = (_q__idx_fsm0 == 0)
           ;



`ifdef FORMAL
    initial begin
        assume(reset);
    end
    assume property($initstate || (in_run || out_done));
`endif
    always @* begin
        _d___block_2_dx = _q___block_2_dx;
        _d___block_2_dy = _q___block_2_dy;
        _d___block_2_sx = _q___block_2_sx;
        _d___block_2_sy = _q___block_2_sy;
        _d___block_2_err = _q___block_2_err;
        _d___block_2_x = _q___block_2_x;
        _d___block_2_y = _q___block_2_y;
        _d___block_11_xincaddr = _q___block_11_xincaddr;
        _d___block_11_yincaddr = _q___block_11_yincaddr;
        _d___block_11_dxe = _q___block_11_dxe;
        _d___block_16_dye = _q___block_16_dye;
        _d_bus_cyc = _q_bus_cyc;
        _d_bus_stb = _q_bus_stb;
        _d_bus_adr = _q_bus_adr;
        _d_bus_we = _q_bus_we;
        _d_bus_dat_w = _q_bus_dat_w;
        _d_bus_sel = _q_bus_sel;
        _d__idx_fsm0 = _q__idx_fsm0;
        _t___block_2_x0i = 0;
        _t___block_2_x1i = 0;
        _t___block_2_y0i = 0;
        _t___block_2_y1i = 0;
        _t___block_2_e2 = 0;
        // _always_pre
        (* full_case *)
        case (_q__idx_fsm0)
            1: begin
                // _top
                // __block_1
                _d_bus_cyc = 0;

                _d_bus_stb = 0;

                _d_bus_sel = 65535;

                // __block_2
                _t___block_2_x0i = in_x0;

                _t___block_2_x1i = in_x1;

                _t___block_2_y0i = in_y0;

                _t___block_2_y1i = in_y1;

                _d___block_2_dx = ((_t___block_2_x1i-_t___block_2_x0i)<0 ? -(_t___block_2_x1i-_t___block_2_x0i):(_t___block_2_x1i-_t___block_2_x0i));

                _d___block_2_dy = -((_t___block_2_y1i-_t___block_2_y0i)<0 ? -(_t___block_2_y1i-_t___block_2_y0i):(_t___block_2_y1i-_t___block_2_y0i));

                _d___block_2_sx = in_x0<in_x1 ? 1:-1;

                _d___block_2_sy = in_y0<in_y1 ? 1:-1;

                _d___block_2_err = _d___block_2_dx+_d___block_2_dy;

                _d___block_2_x = in_x0;

                _d___block_2_y = in_y0;

                _d_bus_adr = (in_base);

                _d__idx_fsm0 = 2;
            end
            2: begin
                // __while__block_3
                if (_q___block_2_x!=in_x1||_q___block_2_y!=in_y1) begin
                    // __block_4
                    // __block_6
                    // __block_7
                    _d_bus_dat_w = in_rgba;

                    _d_bus_we = 1;

                    _d_bus_stb = 1;

                    _d_bus_cyc = 1;

                    // __block_8
                    if (!((_d_bus_stb&&_d_bus_we)&&!(_d_bus_stb&&in_bus_ack&&_d_bus_we))) begin
                        // __block_9
                        // __block_11
                        // var inits
                        _d___block_11_xincaddr = 0;
                        _d___block_11_yincaddr = 0;
                        _d___block_11_dxe = 0;
                        // --
                        _d_bus_stb = 0;

                        _t___block_2_e2 = _q___block_2_err<<1;

                        if (_t___block_2_e2<=_q___block_2_dx) begin
                            // __block_12
                            // __block_14
                            _d___block_11_dxe = _q___block_2_dx;

                            _d___block_2_y = _q___block_2_y+_q___block_2_sy;

                            _d___block_11_yincaddr = in_ystride;

                            // __block_15
                        end else begin
                            // __block_13
                        end
                        // __block_16
                        // var inits
                        _d___block_16_dye = 0;
                        // --
                        if (_t___block_2_e2>=_q___block_2_dy) begin
                            // __block_17
                            // __block_19
                            _d___block_16_dye = _q___block_2_dy;

                            _d___block_2_x = _q___block_2_x+_q___block_2_sx;

                            _d___block_11_xincaddr = in_xstride;

                            // __block_20
                        end else begin
                            // __block_18
                        end
                        // __block_21
                        _d_bus_adr = (_q_bus_adr+(_d___block_11_xincaddr+_d___block_11_yincaddr));

                        _d___block_2_err = _q___block_2_err+_d___block_11_dxe+_d___block_16_dye;

                        // __block_22
                    end else begin
                        // __block_10
                    end
                    // __block_23
                    // __block_24
                    _d__idx_fsm0 = 2;
                end else begin
                    _d__idx_fsm0 = 3;
                end
            end
            3: begin
                // __while__block_25
                if (((_q_bus_stb&&_q_bus_we)&&!(_q_bus_stb&&in_bus_ack&&_q_bus_we))) begin
                    // __block_26
                    // __block_28
                    // __block_29
                    _d__idx_fsm0 = 3;
                end else begin
                    _d__idx_fsm0 = 4;
                end
            end
            4: begin
                // __block_27
                // __block_30
                _d_bus_cyc = 0;

                _d_bus_stb = 0;

                // __block_31
                _d__idx_fsm0 = 0;
            end
            0: begin
            end
            default: begin
                _d__idx_fsm0 = {3{1'bx}};
`ifdef FORMAL
                assume(0);
`endif
            end
        endcase
        // _always_post
        // pipeline stage triggers
    end

    always @(posedge clock) begin
        _q___block_2_dx <= _d___block_2_dx;
        _q___block_2_dy <= _d___block_2_dy;
        _q___block_2_sx <= _d___block_2_sx;
        _q___block_2_sy <= _d___block_2_sy;
        _q___block_2_err <= _d___block_2_err;
        _q___block_2_x <= _d___block_2_x;
        _q___block_2_y <= _d___block_2_y;
        _q___block_11_xincaddr <= (reset | ~in_run) ? 0 : _d___block_11_xincaddr;
        _q___block_11_yincaddr <= (reset | ~in_run) ? 0 : _d___block_11_yincaddr;
        _q___block_11_dxe <= (reset | ~in_run) ? 0 : _d___block_11_dxe;
        _q___block_16_dye <= (reset | ~in_run) ? 0 : _d___block_16_dye;
        _q_bus_cyc <= _d_bus_cyc;
        _q_bus_stb <= _d_bus_stb;
        _q_bus_adr <= _d_bus_adr;
        _q_bus_we <= _d_bus_we;
        _q_bus_dat_w <= _d_bus_dat_w;
        _q_bus_sel <= _d_bus_sel;
        _q__idx_fsm0 <= reset ? 0 : ( ~in_run ? 1 : _d__idx_fsm0);
    end

endmodule

