data/full_repos/permissive/175100691/gpu/shadercore/GPU32BitInterface.v
data/verilator_xmls/8e2b7eee-8e00-4519-a406-6edc4c0d2e7f.xml
module GPU32BitInterface
    #(parameter WORD_WIDTH=32, ADDRESS_WIDTH=16)
(
    input wire clock,

    input wire [31:0] h2f_value,
    output wire [31:0] f2h_value,

    output wire reset_n,
    output wire run,

    input wire halted,
    input wire exception,
    input wire [23:0] exception_data,

    output reg enable_write_inst_ram,
    output reg enable_write_data_ram,
    output reg enable_read_inst_ram,
    output reg enable_read_data_ram,
    output reg enable_read_register,
    output reg enable_read_floatreg,
    output reg enable_read_special,

    output reg [ADDRESS_WIDTH-1:0] rw_address,
    output wire [WORD_WIDTH-1:0] write_data,
    input wire [WORD_WIDTH-1:0] read_data
);

    localparam H2F_RESET_N_BIT = 31;
    localparam H2F_RUN_BIT = 30;
    localparam H2F_REQUEST_BIT = 29;

    localparam H2F_CMD_PUT_LOW_16 = 8'd0;
    localparam H2F_CMD_PUT_HIGH_16 = 8'd1;
    localparam H2F_CMD_WRITE_INST_RAM = 8'd2;
    localparam H2F_CMD_WRITE_DATA_RAM = 8'd3;
    localparam H2F_CMD_READ_INST_RAM = 8'd4;
    localparam H2F_CMD_READ_DATA_RAM = 8'd5;

    localparam H2F_CMD_READ_X_REG = 8'd6;
    localparam H2F_CMD_READ_F_REG = 8'd7;
    localparam H2F_CMD_READ_SPECIAL = 8'd8;
    localparam H2F_CMD_GET_LOW_16 = 8'd9;
    localparam H2F_CMD_GET_HIGH_16 = 8'd10;

    localparam F2H_ERR_UNKNOWN_CMD = 24'hdead00;

    assign reset_n = h2f_value[H2F_RESET_N_BIT];
    assign run = h2f_value[H2F_RUN_BIT];
    wire h2f_request= h2f_value[H2F_REQUEST_BIT];
    wire [7:0] h2f_command= h2f_value[23:16];
    wire [15:0] h2f_parameter= h2f_value[15:0];



    reg f2h_exited_reset;
    reg f2h_busy;
    reg f2h_cmd_error;
    reg [23:0] f2h_data_field;

    assign f2h_value = {
        f2h_exited_reset,
        f2h_busy,
        f2h_cmd_error,
        halted,
        exception,
        3'b0,
        exception ? exception_data : f2h_data_field
    };


    reg [31:0] read_register;
    reg [15:0] write_register_low16;
    reg [15:0] write_register_high16;



    localparam STATE_INIT = 0;
    localparam STATE_IDLE = 1;
    localparam STATE_ERROR = 2;
    localparam STATE_WAIT_WRITE_INST_RAM = 3;
    localparam STATE_WAIT_WRITE_DATA_RAM = 4;
    localparam STATE_WAIT_READ_INST_RAM = 5;
    localparam STATE_WAIT_READ_DATA_RAM = 6;
    localparam STATE_WAIT_READ_X_REG = 7;
    localparam STATE_WAIT_READ_F_REG = 8;
    localparam STATE_WAIT_READ_SPECIAL = 9;
    reg [3:0] state;

    assign write_data = {write_register_high16, write_register_low16};

    always @(posedge clock) begin
        if(!reset_n) begin

            f2h_exited_reset <= 0;
            state <= STATE_INIT;
            f2h_busy <= 1;

        end else begin

            if (run) begin




            end else begin

                if (h2f_request) begin



                    f2h_busy <= 1;
                    f2h_cmd_error <= 0;

                    case (h2f_command)
                        H2F_CMD_PUT_LOW_16: begin
                            write_register_low16 <= h2f_parameter;
                            state <= STATE_IDLE;
                        end
                        H2F_CMD_PUT_HIGH_16: begin
                            write_register_high16 <= h2f_parameter;
                            state <= STATE_IDLE;
                        end
                        H2F_CMD_WRITE_INST_RAM: begin
                            enable_write_inst_ram <= 1;
                            rw_address <= h2f_parameter;
                            state <= STATE_WAIT_WRITE_INST_RAM;
                        end
                        H2F_CMD_WRITE_DATA_RAM: begin
                            enable_write_data_ram <= 1;
                            rw_address <= h2f_parameter;
                            state <= STATE_WAIT_WRITE_DATA_RAM;
                        end
                        H2F_CMD_READ_INST_RAM: begin
                            enable_read_inst_ram <= 1;
                            rw_address <= h2f_parameter;
                            state <= STATE_WAIT_READ_INST_RAM;
                        end
                        H2F_CMD_READ_DATA_RAM: begin
                            enable_read_data_ram <= 1;
                            rw_address <= h2f_parameter;
                            state <= STATE_WAIT_READ_DATA_RAM;
                        end
                        H2F_CMD_READ_X_REG: begin
                            enable_read_register <= 1;
                            rw_address <= h2f_parameter[ADDRESS_WIDTH-1:0];
                            state <= STATE_WAIT_READ_X_REG;
                        end
                        H2F_CMD_READ_F_REG: begin
                            enable_read_floatreg <= 1;
                            rw_address <= h2f_parameter[ADDRESS_WIDTH-1:0];
                            state <= STATE_WAIT_READ_F_REG;
                        end
                        H2F_CMD_READ_SPECIAL: begin
                            enable_read_special <= 1;
                            rw_address <= h2f_parameter[ADDRESS_WIDTH-1:0];
                            state <= STATE_WAIT_READ_SPECIAL;
                        end
                        H2F_CMD_GET_LOW_16: begin
                            f2h_data_field <= {8'b0, read_register[15:0]};
                            state <= STATE_IDLE;
                        end
                        H2F_CMD_GET_HIGH_16: begin
                            f2h_data_field <= {8'b0, read_register[31:16]};
                            state <= STATE_IDLE;
                        end
                        default: begin
                            f2h_data_field <= F2H_ERR_UNKNOWN_CMD;
                            state <= STATE_IDLE;
                        end
                    endcase

                end else begin







                    case (state)
                        STATE_INIT: begin
                            f2h_exited_reset <= 1;
                            f2h_cmd_error <= 0;
                            f2h_busy <= 1;
                            state <= STATE_IDLE;
                        end
                        STATE_ERROR: begin
                            f2h_busy <= 0;
                            f2h_cmd_error <= 1;
                            state <= STATE_ERROR;
                        end
                        STATE_IDLE: begin
                            f2h_busy <= 0;
                            state <= STATE_IDLE;
                        end
                        STATE_WAIT_WRITE_INST_RAM: begin

                            enable_write_inst_ram <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_WRITE_DATA_RAM: begin

                            enable_write_data_ram <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_INST_RAM: begin

                            read_register <= read_data;
                            enable_read_inst_ram <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_DATA_RAM: begin

                            read_register <= read_data;
                            enable_read_data_ram <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_X_REG: begin
                            read_register <= read_data; 
                            enable_read_register <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_F_REG: begin
                            read_register <= read_data;
                            enable_read_floatreg <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_SPECIAL: begin
                            read_register <= read_data;
                            enable_read_special <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                    endcase

                end

            end

        end

    end

endmodule
module GPU32BitInterface
    #(parameter WORD_WIDTH=32, ADDRESS_WIDTH=16)
(
    input wire clock,

    input wire [31:0] h2f_value,
    output wire [31:0] f2h_value,

    output wire reset_n,
    output wire run,

    input wire halted,
    input wire exception,
    input wire [23:0] exception_data,

    output reg enable_write_inst_ram,
    output reg enable_write_data_ram,
    output reg enable_read_inst_ram,
    output reg enable_read_data_ram,
    output reg enable_read_register,
    output reg enable_read_floatreg,
    output reg enable_read_special,

    output reg [ADDRESS_WIDTH-1:0] rw_address,
    output wire [WORD_WIDTH-1:0] write_data,
    input wire [WORD_WIDTH-1:0] read_data
);


    localparam H2F_RESET_N_BIT = 31;
    localparam H2F_RUN_BIT = 30;
    localparam H2F_REQUEST_BIT = 29;

    localparam H2F_CMD_PUT_LOW_16 = 8'd0;
    localparam H2F_CMD_PUT_HIGH_16 = 8'd1;
    localparam H2F_CMD_WRITE_INST_RAM = 8'd2;
    localparam H2F_CMD_WRITE_DATA_RAM = 8'd3;
    localparam H2F_CMD_READ_INST_RAM = 8'd4;
    localparam H2F_CMD_READ_DATA_RAM = 8'd5;

    localparam H2F_CMD_READ_X_REG = 8'd6;
    localparam H2F_CMD_READ_F_REG = 8'd7;
    localparam H2F_CMD_READ_SPECIAL = 8'd8;
    localparam H2F_CMD_GET_LOW_16 = 8'd9;
    localparam H2F_CMD_GET_HIGH_16 = 8'd10;

    localparam F2H_ERR_UNKNOWN_CMD = 24'hdead00;

    assign reset_n = h2f_value[H2F_RESET_N_BIT];
    assign run = h2f_value[H2F_RUN_BIT];
    wire h2f_request= h2f_value[H2F_REQUEST_BIT];
    wire [7:0] h2f_command= h2f_value[23:16];
    wire [15:0] h2f_parameter= h2f_value[15:0];



    reg f2h_exited_reset;
    reg f2h_busy;
    reg f2h_cmd_error;
    reg [23:0] f2h_data_field;

    assign f2h_value = {
        f2h_exited_reset,
        f2h_busy,
        f2h_cmd_error,
        halted,
        exception,
        3'b0,
        exception ? exception_data : f2h_data_field
    };


    reg [31:0] read_register;
    reg [15:0] write_register_low16;
    reg [15:0] write_register_high16;



    localparam STATE_INIT = 0;
    localparam STATE_IDLE = 1;
    localparam STATE_ERROR = 2;
    localparam STATE_WAIT_WRITE_INST_RAM = 3;
    localparam STATE_WAIT_WRITE_DATA_RAM = 4;
    localparam STATE_WAIT_READ_INST_RAM = 5;
    localparam STATE_WAIT_READ_DATA_RAM = 6;
    localparam STATE_WAIT_READ_X_REG = 7;
    localparam STATE_WAIT_READ_F_REG = 8;
    localparam STATE_WAIT_READ_SPECIAL = 9;
    reg [3:0] state;

    assign write_data = {write_register_high16, write_register_low16};

    always @(posedge clock) begin
        if(!reset_n) begin

            f2h_exited_reset <= 0;
            state <= STATE_INIT;
            f2h_busy <= 1;

        end else begin

            if (run) begin




            end else begin

                if (h2f_request) begin



                    f2h_busy <= 1;
                    f2h_cmd_error <= 0;

                    case (h2f_command)
                        H2F_CMD_PUT_LOW_16: begin
                            write_register_low16 <= h2f_parameter;
                            state <= STATE_IDLE;
                        end
                        H2F_CMD_PUT_HIGH_16: begin
                            write_register_high16 <= h2f_parameter;
                            state <= STATE_IDLE;
                        end
                        H2F_CMD_WRITE_INST_RAM: begin
                            enable_write_inst_ram <= 1;
                            rw_address <= h2f_parameter;
                            state <= STATE_WAIT_WRITE_INST_RAM;
                        end
                        H2F_CMD_WRITE_DATA_RAM: begin
                            enable_write_data_ram <= 1;
                            rw_address <= h2f_parameter;
                            state <= STATE_WAIT_WRITE_DATA_RAM;
                        end
                        H2F_CMD_READ_INST_RAM: begin
                            enable_read_inst_ram <= 1;
                            rw_address <= h2f_parameter;
                            state <= STATE_WAIT_READ_INST_RAM;
                        end
                        H2F_CMD_READ_DATA_RAM: begin
                            enable_read_data_ram <= 1;
                            rw_address <= h2f_parameter;
                            state <= STATE_WAIT_READ_DATA_RAM;
                        end
                        H2F_CMD_READ_X_REG: begin
                            enable_read_register <= 1;
                            rw_address <= h2f_parameter[ADDRESS_WIDTH-1:0];
                            state <= STATE_WAIT_READ_X_REG;
                        end
                        H2F_CMD_READ_F_REG: begin
                            enable_read_floatreg <= 1;
                            rw_address <= h2f_parameter[ADDRESS_WIDTH-1:0];
                            state <= STATE_WAIT_READ_F_REG;
                        end
                        H2F_CMD_READ_SPECIAL: begin
                            enable_read_special <= 1;
                            rw_address <= h2f_parameter[ADDRESS_WIDTH-1:0];
                            state <= STATE_WAIT_READ_SPECIAL;
                        end
                        H2F_CMD_GET_LOW_16: begin
                            f2h_data_field <= {8'b0, read_register[15:0]};
                            state <= STATE_IDLE;
                        end
                        H2F_CMD_GET_HIGH_16: begin
                            f2h_data_field <= {8'b0, read_register[31:16]};
                            state <= STATE_IDLE;
                        end
                        default: begin
                            f2h_data_field <= F2H_ERR_UNKNOWN_CMD;
                            state <= STATE_IDLE;
                        end
                    endcase

                end else begin







                    case (state)
                        STATE_INIT: begin
                            f2h_exited_reset <= 1;
                            f2h_cmd_error <= 0;
                            f2h_busy <= 1;
                            state <= STATE_IDLE;
                        end
                        STATE_ERROR: begin
                            f2h_busy <= 0;
                            f2h_cmd_error <= 1;
                            state <= STATE_ERROR;
                        end
                        STATE_IDLE: begin
                            f2h_busy <= 0;
                            state <= STATE_IDLE;
                        end
                        STATE_WAIT_WRITE_INST_RAM: begin

                            enable_write_inst_ram <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_WRITE_DATA_RAM: begin

                            enable_write_data_ram <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_INST_RAM: begin

                            read_register <= read_data;
                            enable_read_inst_ram <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_DATA_RAM: begin

                            read_register <= read_data;
                            enable_read_data_ram <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_X_REG: begin
                            read_register <= read_data; 
                            enable_read_register <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_F_REG: begin
                            read_register <= read_data;
                            enable_read_floatreg <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                        STATE_WAIT_READ_SPECIAL: begin
                            read_register <= read_data;
                            enable_read_special <= 0;
                            state <= STATE_IDLE;
                            f2h_busy <= 0;
                        end
                    endcase

                end

            end

        end

    end

endmodule