data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv
1: b'%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:1: Cannot find include file: VX_define.vh\n`include "VX_define.vh" \n         ^~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/473423187/hw/rtl,data/full_repos/permissive/473423187/VX_define.vh\n             data/full_repos/permissive/473423187/hw/rtl,data/full_repos/permissive/473423187/VX_define.vh.v\n             data/full_repos/permissive/473423187/hw/rtl,data/full_repos/permissive/473423187/VX_define.vh.sv\n             VX_define.vh\n             VX_define.vh.v\n             VX_define.vh.sv\n             obj_dir/VX_define.vh\n             obj_dir/VX_define.vh.v\n             obj_dir/VX_define.vh.sv\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:6: Define or directive not defined: \'`SCOPE_IO_VX_gpu_unit\'\n    `SCOPE_IO_VX_gpu_unit\n    ^~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:24: syntax error, unexpected IDENTIFIER, expecting PACKAGE-IDENTIFIER or STRING\n    import gpu_types::*;\n           ^~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:26: Define or directive not defined: \'`UNUSED_PARAM\'\n    `UNUSED_PARAM (CORE_ID)\n    ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:28: Define or directive not defined: \'`GPU_TMC_BITS\'\n    localparam WCTL_DATAW = `GPU_TMC_BITS + `GPU_WSPAWN_BITS + `GPU_SPLIT_BITS + `GPU_BARRIER_BITS;\n                            ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:28: Define or directive not defined: \'`GPU_WSPAWN_BITS\'\n    localparam WCTL_DATAW = `GPU_TMC_BITS + `GPU_WSPAWN_BITS + `GPU_SPLIT_BITS + `GPU_BARRIER_BITS;\n                                            ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:28: Define or directive not defined: \'`GPU_SPLIT_BITS\'\n    localparam WCTL_DATAW = `GPU_TMC_BITS + `GPU_WSPAWN_BITS + `GPU_SPLIT_BITS + `GPU_BARRIER_BITS;\n                                                               ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:28: Define or directive not defined: \'`GPU_BARRIER_BITS\'\n    localparam WCTL_DATAW = `GPU_TMC_BITS + `GPU_WSPAWN_BITS + `GPU_SPLIT_BITS + `GPU_BARRIER_BITS;\n                                                                                 ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:29: Define or directive not defined: \'`MAX\'\n    localparam RSP_DATAW  = `MAX(`NUM_THREADS * 32, WCTL_DATAW);\n                            ^~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:29: Define or directive not defined: \'`NUM_THREADS\'\n    localparam RSP_DATAW  = `MAX(`NUM_THREADS * 32, WCTL_DATAW);\n                                 ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:29: syntax error, unexpected \'*\', expecting TYPE-IDENTIFIER\n    localparam RSP_DATAW  = `MAX(`NUM_THREADS * 32, WCTL_DATAW);\n                                              ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:32: Define or directive not defined: \'`NW_BITS\'\n    wire [`NW_BITS-1:0]           rsp_wid;\n          ^~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:33: Define or directive not defined: \'`NUM_THREADS\'\n    wire [`NUM_THREADS-1:0]       rsp_tmask;\n          ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:35: Define or directive not defined: \'`NR_BITS\'\n    wire [`NR_BITS-1:0]           rsp_rd;   \n          ^~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:50: Define or directive not defined: \'`INST_GPU_WSPAWN\'\n    wire is_wspawn = (gpu_req_if.op_type == `INST_GPU_WSPAWN);\n                                            ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:50: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n    wire is_wspawn = (gpu_req_if.op_type == `INST_GPU_WSPAWN);\n                                                            ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:51: Define or directive not defined: \'`INST_GPU_TMC\'\n    wire is_tmc    = (gpu_req_if.op_type == `INST_GPU_TMC);\n                                            ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:51: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n    wire is_tmc    = (gpu_req_if.op_type == `INST_GPU_TMC);\n                                                         ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:52: Define or directive not defined: \'`INST_GPU_SPLIT\'\n    wire is_split  = (gpu_req_if.op_type == `INST_GPU_SPLIT);\n                                            ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:52: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n    wire is_split  = (gpu_req_if.op_type == `INST_GPU_SPLIT);\n                                                           ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:53: Define or directive not defined: \'`INST_GPU_BAR\'\n    wire is_bar    = (gpu_req_if.op_type == `INST_GPU_BAR);\n                                            ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:53: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n    wire is_bar    = (gpu_req_if.op_type == `INST_GPU_BAR);\n                                                         ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:54: Define or directive not defined: \'`INST_GPU_PRED\'\n    wire is_pred   = (gpu_req_if.op_type == `INST_GPU_PRED);\n                                            ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:54: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n    wire is_pred   = (gpu_req_if.op_type == `INST_GPU_PRED);\n                                                          ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:59: Define or directive not defined: \'`NUM_THREADS\'\n    wire [`NUM_THREADS-1:0] taken_tmask;\n          ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:60: Define or directive not defined: \'`NUM_THREADS\'\n    wire [`NUM_THREADS-1:0] not_taken_tmask;\n          ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:62: Define or directive not defined: \'`NUM_THREADS\'\n    for (genvar i = 0; i < `NUM_THREADS; i++) begin\n                           ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:62: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    for (genvar i = 0; i < `NUM_THREADS; i++) begin\n                                       ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:66: syntax error, unexpected end\n    end\n    ^~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:70: Define or directive not defined: \'`NUM_THREADS\'\n    wire [`NUM_THREADS-1:0] pred_mask = (taken_tmask != 0) ? taken_tmask : gpu_req_if.tmask;\n          ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:73: Define or directive not defined: \'`NUM_THREADS\'\n    assign tmc.tmask = is_pred ? pred_mask : rs1_data[`NUM_THREADS-1:0];\n                                                      ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:78: Define or directive not defined: \'`NUM_WARPS\'\n    wire [`NUM_WARPS-1:0] wspawn_wmask;\n          ^~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:79: Define or directive not defined: \'`NUM_WARPS\'\n    for (genvar i = 0; i < `NUM_WARPS; i++) begin\n                           ^~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:79: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n    for (genvar i = 0; i < `NUM_WARPS; i++) begin\n                                     ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:97: Define or directive not defined: \'`NB_BITS\'\n    assign barrier.id      = rs1_data[`NB_BITS-1:0];\n                                      ^~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:98: Define or directive not defined: \'`NW_BITS\'\n    assign barrier.size_m1 = (`NW_BITS)\'(rs2_data - 1);       \n                              ^~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:98: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n    assign barrier.size_m1 = (`NW_BITS)\'(rs2_data - 1);       \n                                      ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:155: Define or directive not defined: \'`UNUSED_VAR\'\n    `UNUSED_VAR (gpu_req_if.op_mod)\n    ^~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:155: syntax error, unexpected \'(\'\n    `UNUSED_VAR (gpu_req_if.op_mod)\n                 ^~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:156: Define or directive not defined: \'`UNUSED_VAR\'\n    `UNUSED_VAR (gpu_req_if.rs3_data)\n    ^~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:157: Define or directive not defined: \'`UNUSED_VAR\'\n    `UNUSED_VAR (gpu_req_if.wb)\n    ^~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:158: Define or directive not defined: \'`UNUSED_VAR\'\n    `UNUSED_VAR (gpu_req_if.rd)\n    ^~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:179: Define or directive not defined: \'`NW_BITS\'\n        .DATAW  (1 + `NW_BITS + `NUM_THREADS + 32 + `NR_BITS + 1 + RSP_DATAW + 1),\n                     ^~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:179: Define or directive not defined: \'`NUM_THREADS\'\n        .DATAW  (1 + `NW_BITS + `NUM_THREADS + 32 + `NR_BITS + 1 + RSP_DATAW + 1),\n                                ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:179: Define or directive not defined: \'`NR_BITS\'\n        .DATAW  (1 + `NW_BITS + `NUM_THREADS + 32 + `NR_BITS + 1 + RSP_DATAW + 1),\n                                                    ^~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:189: Define or directive not defined: \'`NUM_THREADS\'\n    assign gpu_commit_if.data = rsp_data_r[(`NUM_THREADS * 32)-1:0];\n                                            ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:189: syntax error, unexpected \'*\', expecting TYPE-IDENTIFIER\n    assign gpu_commit_if.data = rsp_data_r[(`NUM_THREADS * 32)-1:0];\n                                                         ^\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:202: Define or directive not defined: \'`SCOPE_ASSIGN\'\n    `SCOPE_ASSIGN (gpu_rsp_valid, warp_ctl_if.valid);\n    ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:202: syntax error, unexpected \'(\'\n    `SCOPE_ASSIGN (gpu_rsp_valid, warp_ctl_if.valid);\n                   ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/473423187/hw/rtl/VX_gpu_unit.sv:203: Define or directive not defined: \'`SCOPE_ASSIGN\'\n    `SCOPE_ASSIGN (gpu_rsp_wid, warp_ctl_if.wid);\n    ^~~~~~~~~~~~~\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module VX_gpu_unit #(
    parameter CORE_ID = 0
) (
    `SCOPE_IO_VX_gpu_unit
    
    input wire          clk,
    input wire          reset,


    VX_gpu_req_if.slave gpu_req_if,

`ifdef EXT_TEX_ENABLE
    VX_dcache_req_if.master dcache_req_if,
    VX_dcache_rsp_if.slave  dcache_rsp_if,
    VX_tex_csr_if.slave tex_csr_if,
`endif


    VX_warp_ctl_if.master warp_ctl_if,
    VX_commit_if.master gpu_commit_if
);
    import gpu_types::*;

    `UNUSED_PARAM (CORE_ID)

    localparam WCTL_DATAW = `GPU_TMC_BITS + `GPU_WSPAWN_BITS + `GPU_SPLIT_BITS + `GPU_BARRIER_BITS;
    localparam RSP_DATAW  = `MAX(`NUM_THREADS * 32, WCTL_DATAW);

    wire                          rsp_valid;
    wire [`NW_BITS-1:0]           rsp_wid;
    wire [`NUM_THREADS-1:0]       rsp_tmask;
    wire [31:0]                   rsp_PC;
    wire [`NR_BITS-1:0]           rsp_rd;   
    wire                          rsp_wb;

    wire [RSP_DATAW-1:0] rsp_data, rsp_data_r;

    gpu_tmc_t       tmc;
    gpu_wspawn_t    wspawn;
    gpu_barrier_t   barrier;
    gpu_split_t     split;
    
    wire [WCTL_DATAW-1:0] warp_ctl_data;
    wire is_warp_ctl;
    
    wire stall_in, stall_out;
    
    wire is_wspawn = (gpu_req_if.op_type == `INST_GPU_WSPAWN);
    wire is_tmc    = (gpu_req_if.op_type == `INST_GPU_TMC);
    wire is_split  = (gpu_req_if.op_type == `INST_GPU_SPLIT);
    wire is_bar    = (gpu_req_if.op_type == `INST_GPU_BAR);
    wire is_pred   = (gpu_req_if.op_type == `INST_GPU_PRED);

    wire [31:0] rs1_data = gpu_req_if.rs1_data[gpu_req_if.tid];
    wire [31:0] rs2_data = gpu_req_if.rs2_data[gpu_req_if.tid];
    
    wire [`NUM_THREADS-1:0] taken_tmask;
    wire [`NUM_THREADS-1:0] not_taken_tmask;

    for (genvar i = 0; i < `NUM_THREADS; i++) begin
        wire taken = (gpu_req_if.rs1_data[i] != 0);
        assign taken_tmask[i]     = gpu_req_if.tmask[i] & taken;
        assign not_taken_tmask[i] = gpu_req_if.tmask[i] & ~taken;
    end



    wire [`NUM_THREADS-1:0] pred_mask = (taken_tmask != 0) ? taken_tmask : gpu_req_if.tmask;

    assign tmc.valid = is_tmc || is_pred;
    assign tmc.tmask = is_pred ? pred_mask : rs1_data[`NUM_THREADS-1:0];



    wire [31:0] wspawn_pc = rs2_data;
    wire [`NUM_WARPS-1:0] wspawn_wmask;
    for (genvar i = 0; i < `NUM_WARPS; i++) begin
        assign wspawn_wmask[i] = (i < rs1_data);
    end
    assign wspawn.valid = is_wspawn;
    assign wspawn.wmask = wspawn_wmask;
    assign wspawn.pc    = wspawn_pc;



    assign split.valid      = is_split;
    assign split.diverged   = (| taken_tmask) && (| not_taken_tmask);
    assign split.then_tmask = taken_tmask;
    assign split.else_tmask = not_taken_tmask;
    assign split.pc         = gpu_req_if.next_PC;


    
    assign barrier.valid   = is_bar;
    assign barrier.id      = rs1_data[`NB_BITS-1:0];
    assign barrier.size_m1 = (`NW_BITS)'(rs2_data - 1);       


    assign warp_ctl_data = {tmc, wspawn, split, barrier};



`ifdef EXT_TEX_ENABLE

    `UNUSED_VAR (gpu_req_if.op_mod)
    
    VX_tex_req_if   tex_req_if();
    VX_tex_rsp_if   tex_rsp_if();    

    wire is_tex = (gpu_req_if.op_type == `INST_GPU_TEX);

    assign tex_req_if.valid = gpu_req_if.valid && is_tex;
    assign tex_req_if.wid   = gpu_req_if.wid;
    assign tex_req_if.tmask = gpu_req_if.tmask;
    assign tex_req_if.PC    = gpu_req_if.PC;
    assign tex_req_if.rd    = gpu_req_if.rd;
    assign tex_req_if.wb    = gpu_req_if.wb;
    
    assign tex_req_if.unit      = gpu_req_if.op_mod[`NTEX_BITS-1:0];
    assign tex_req_if.coords[0] = gpu_req_if.rs1_data;
    assign tex_req_if.coords[1] = gpu_req_if.rs2_data;
    assign tex_req_if.lod       = gpu_req_if.rs3_data;        

    VX_tex_unit #(
        .CORE_ID(CORE_ID)
    ) tex_unit (
        .clk           (clk),
        .reset         (reset),
        .tex_req_if    (tex_req_if),
        .tex_csr_if    (tex_csr_if),
        .tex_rsp_if    (tex_rsp_if),
        .dcache_req_if (dcache_req_if),
        .dcache_rsp_if (dcache_rsp_if)
    );

    assign tex_rsp_if.ready = !stall_out;

    assign stall_in = (is_tex && ~tex_req_if.ready)
                   || (~is_tex && (tex_rsp_if.valid || stall_out));

    assign is_warp_ctl = !(is_tex || tex_rsp_if.valid);

    assign rsp_valid = tex_rsp_if.valid || (gpu_req_if.valid && ~is_tex);
    assign rsp_wid   = tex_rsp_if.valid ? tex_rsp_if.wid : gpu_req_if.wid;
    assign rsp_tmask = tex_rsp_if.valid ? tex_rsp_if.tmask : gpu_req_if.tmask;
    assign rsp_PC    = tex_rsp_if.valid ? tex_rsp_if.PC : gpu_req_if.PC;
    assign rsp_rd    = tex_rsp_if.rd;
    assign rsp_wb    = tex_rsp_if.valid && tex_rsp_if.wb;
    assign rsp_data  = tex_rsp_if.valid ? RSP_DATAW'(tex_rsp_if.data) : RSP_DATAW'(warp_ctl_data);
    
`else   

    `UNUSED_VAR (gpu_req_if.op_mod)
    `UNUSED_VAR (gpu_req_if.rs3_data)
    `UNUSED_VAR (gpu_req_if.wb)
    `UNUSED_VAR (gpu_req_if.rd)

    assign stall_in = stall_out;
    assign is_warp_ctl = 1;

    assign rsp_valid = gpu_req_if.valid;
    assign rsp_wid   = gpu_req_if.wid;
    assign rsp_tmask = gpu_req_if.tmask;
    assign rsp_PC    = gpu_req_if.PC;
    assign rsp_rd    = 0;
    assign rsp_wb    = 0;
    assign rsp_data  = RSP_DATAW'(warp_ctl_data);

`endif

    wire is_warp_ctl_r;


    assign stall_out = ~gpu_commit_if.ready && gpu_commit_if.valid;

    VX_pipe_register #(
        .DATAW  (1 + `NW_BITS + `NUM_THREADS + 32 + `NR_BITS + 1 + RSP_DATAW + 1),
        .RESETW (1)
    ) pipe_reg (
        .clk      (clk),
        .reset    (reset),
        .enable   (!stall_out),
        .data_in  ({rsp_valid,           rsp_wid,           rsp_tmask,           rsp_PC,           rsp_rd,           rsp_wb,           rsp_data,   is_warp_ctl}),
        .data_out ({gpu_commit_if.valid, gpu_commit_if.wid, gpu_commit_if.tmask, gpu_commit_if.PC, gpu_commit_if.rd, gpu_commit_if.wb, rsp_data_r, is_warp_ctl_r})
    );  

    assign gpu_commit_if.data = rsp_data_r[(`NUM_THREADS * 32)-1:0];
    assign gpu_commit_if.eop  = 1'b1;


     
    assign {warp_ctl_if.tmc, warp_ctl_if.wspawn, warp_ctl_if.split, warp_ctl_if.barrier} = rsp_data_r[WCTL_DATAW-1:0];
    
    assign warp_ctl_if.valid = gpu_commit_if.valid && gpu_commit_if.ready && is_warp_ctl_r;
    assign warp_ctl_if.wid   = gpu_commit_if.wid;    


    assign gpu_req_if.ready = ~stall_in;

    `SCOPE_ASSIGN (gpu_rsp_valid, warp_ctl_if.valid);
    `SCOPE_ASSIGN (gpu_rsp_wid, warp_ctl_if.wid);
    `SCOPE_ASSIGN (gpu_rsp_tmc, warp_ctl_if.tmc.valid);
    `SCOPE_ASSIGN (gpu_rsp_wspawn, warp_ctl_if.wspawn.valid);          
    `SCOPE_ASSIGN (gpu_rsp_split, warp_ctl_if.split.valid);
    `SCOPE_ASSIGN (gpu_rsp_barrier, warp_ctl_if.barrier.valid);

endmodule
module VX_gpu_unit #(
    parameter CORE_ID = 0
) (
    `SCOPE_IO_VX_gpu_unit
    
    input wire          clk,
    input wire          reset,


    VX_gpu_req_if.slave gpu_req_if,

`ifdef EXT_TEX_ENABLE
    VX_dcache_req_if.master dcache_req_if,
    VX_dcache_rsp_if.slave  dcache_rsp_if,
    VX_tex_csr_if.slave tex_csr_if,
`endif


    VX_warp_ctl_if.master warp_ctl_if,
    VX_commit_if.master gpu_commit_if
);

    import gpu_types::*;

    `UNUSED_PARAM (CORE_ID)

    localparam WCTL_DATAW = `GPU_TMC_BITS + `GPU_WSPAWN_BITS + `GPU_SPLIT_BITS + `GPU_BARRIER_BITS;
    localparam RSP_DATAW  = `MAX(`NUM_THREADS * 32, WCTL_DATAW);

    wire                          rsp_valid;
    wire [`NW_BITS-1:0]           rsp_wid;
    wire [`NUM_THREADS-1:0]       rsp_tmask;
    wire [31:0]                   rsp_PC;
    wire [`NR_BITS-1:0]           rsp_rd;   
    wire                          rsp_wb;

    wire [RSP_DATAW-1:0] rsp_data, rsp_data_r;

    gpu_tmc_t       tmc;
    gpu_wspawn_t    wspawn;
    gpu_barrier_t   barrier;
    gpu_split_t     split;
    
    wire [WCTL_DATAW-1:0] warp_ctl_data;
    wire is_warp_ctl;
    
    wire stall_in, stall_out;
    
    wire is_wspawn = (gpu_req_if.op_type == `INST_GPU_WSPAWN);
    wire is_tmc    = (gpu_req_if.op_type == `INST_GPU_TMC);
    wire is_split  = (gpu_req_if.op_type == `INST_GPU_SPLIT);
    wire is_bar    = (gpu_req_if.op_type == `INST_GPU_BAR);
    wire is_pred   = (gpu_req_if.op_type == `INST_GPU_PRED);

    wire [31:0] rs1_data = gpu_req_if.rs1_data[gpu_req_if.tid];
    wire [31:0] rs2_data = gpu_req_if.rs2_data[gpu_req_if.tid];
    
    wire [`NUM_THREADS-1:0] taken_tmask;
    wire [`NUM_THREADS-1:0] not_taken_tmask;

    for (genvar i = 0; i < `NUM_THREADS; i++) begin
        wire taken = (gpu_req_if.rs1_data[i] != 0);
        assign taken_tmask[i]     = gpu_req_if.tmask[i] & taken;
        assign not_taken_tmask[i] = gpu_req_if.tmask[i] & ~taken;
    end



    wire [`NUM_THREADS-1:0] pred_mask = (taken_tmask != 0) ? taken_tmask : gpu_req_if.tmask;

    assign tmc.valid = is_tmc || is_pred;
    assign tmc.tmask = is_pred ? pred_mask : rs1_data[`NUM_THREADS-1:0];



    wire [31:0] wspawn_pc = rs2_data;
    wire [`NUM_WARPS-1:0] wspawn_wmask;
    for (genvar i = 0; i < `NUM_WARPS; i++) begin
        assign wspawn_wmask[i] = (i < rs1_data);
    end
    assign wspawn.valid = is_wspawn;
    assign wspawn.wmask = wspawn_wmask;
    assign wspawn.pc    = wspawn_pc;



    assign split.valid      = is_split;
    assign split.diverged   = (| taken_tmask) && (| not_taken_tmask);
    assign split.then_tmask = taken_tmask;
    assign split.else_tmask = not_taken_tmask;
    assign split.pc         = gpu_req_if.next_PC;


    
    assign barrier.valid   = is_bar;
    assign barrier.id      = rs1_data[`NB_BITS-1:0];
    assign barrier.size_m1 = (`NW_BITS)'(rs2_data - 1);       


    assign warp_ctl_data = {tmc, wspawn, split, barrier};



`ifdef EXT_TEX_ENABLE

    `UNUSED_VAR (gpu_req_if.op_mod)
    
    VX_tex_req_if   tex_req_if();
    VX_tex_rsp_if   tex_rsp_if();    

    wire is_tex = (gpu_req_if.op_type == `INST_GPU_TEX);

    assign tex_req_if.valid = gpu_req_if.valid && is_tex;
    assign tex_req_if.wid   = gpu_req_if.wid;
    assign tex_req_if.tmask = gpu_req_if.tmask;
    assign tex_req_if.PC    = gpu_req_if.PC;
    assign tex_req_if.rd    = gpu_req_if.rd;
    assign tex_req_if.wb    = gpu_req_if.wb;
    
    assign tex_req_if.unit      = gpu_req_if.op_mod[`NTEX_BITS-1:0];
    assign tex_req_if.coords[0] = gpu_req_if.rs1_data;
    assign tex_req_if.coords[1] = gpu_req_if.rs2_data;
    assign tex_req_if.lod       = gpu_req_if.rs3_data;        

    VX_tex_unit #(
        .CORE_ID(CORE_ID)
    ) tex_unit (
        .clk           (clk),
        .reset         (reset),
        .tex_req_if    (tex_req_if),
        .tex_csr_if    (tex_csr_if),
        .tex_rsp_if    (tex_rsp_if),
        .dcache_req_if (dcache_req_if),
        .dcache_rsp_if (dcache_rsp_if)
    );

    assign tex_rsp_if.ready = !stall_out;

    assign stall_in = (is_tex && ~tex_req_if.ready)
                   || (~is_tex && (tex_rsp_if.valid || stall_out));

    assign is_warp_ctl = !(is_tex || tex_rsp_if.valid);

    assign rsp_valid = tex_rsp_if.valid || (gpu_req_if.valid && ~is_tex);
    assign rsp_wid   = tex_rsp_if.valid ? tex_rsp_if.wid : gpu_req_if.wid;
    assign rsp_tmask = tex_rsp_if.valid ? tex_rsp_if.tmask : gpu_req_if.tmask;
    assign rsp_PC    = tex_rsp_if.valid ? tex_rsp_if.PC : gpu_req_if.PC;
    assign rsp_rd    = tex_rsp_if.rd;
    assign rsp_wb    = tex_rsp_if.valid && tex_rsp_if.wb;
    assign rsp_data  = tex_rsp_if.valid ? RSP_DATAW'(tex_rsp_if.data) : RSP_DATAW'(warp_ctl_data);
    
`else   

    `UNUSED_VAR (gpu_req_if.op_mod)
    `UNUSED_VAR (gpu_req_if.rs3_data)
    `UNUSED_VAR (gpu_req_if.wb)
    `UNUSED_VAR (gpu_req_if.rd)

    assign stall_in = stall_out;
    assign is_warp_ctl = 1;

    assign rsp_valid = gpu_req_if.valid;
    assign rsp_wid   = gpu_req_if.wid;
    assign rsp_tmask = gpu_req_if.tmask;
    assign rsp_PC    = gpu_req_if.PC;
    assign rsp_rd    = 0;
    assign rsp_wb    = 0;
    assign rsp_data  = RSP_DATAW'(warp_ctl_data);

`endif

    wire is_warp_ctl_r;


    assign stall_out = ~gpu_commit_if.ready && gpu_commit_if.valid;

    VX_pipe_register #(
        .DATAW  (1 + `NW_BITS + `NUM_THREADS + 32 + `NR_BITS + 1 + RSP_DATAW + 1),
        .RESETW (1)
    ) pipe_reg (
        .clk      (clk),
        .reset    (reset),
        .enable   (!stall_out),
        .data_in  ({rsp_valid,           rsp_wid,           rsp_tmask,           rsp_PC,           rsp_rd,           rsp_wb,           rsp_data,   is_warp_ctl}),
        .data_out ({gpu_commit_if.valid, gpu_commit_if.wid, gpu_commit_if.tmask, gpu_commit_if.PC, gpu_commit_if.rd, gpu_commit_if.wb, rsp_data_r, is_warp_ctl_r})
    );  

    assign gpu_commit_if.data = rsp_data_r[(`NUM_THREADS * 32)-1:0];
    assign gpu_commit_if.eop  = 1'b1;


     
    assign {warp_ctl_if.tmc, warp_ctl_if.wspawn, warp_ctl_if.split, warp_ctl_if.barrier} = rsp_data_r[WCTL_DATAW-1:0];
    
    assign warp_ctl_if.valid = gpu_commit_if.valid && gpu_commit_if.ready && is_warp_ctl_r;
    assign warp_ctl_if.wid   = gpu_commit_if.wid;    


    assign gpu_req_if.ready = ~stall_in;

    `SCOPE_ASSIGN (gpu_rsp_valid, warp_ctl_if.valid);
    `SCOPE_ASSIGN (gpu_rsp_wid, warp_ctl_if.wid);
    `SCOPE_ASSIGN (gpu_rsp_tmc, warp_ctl_if.tmc.valid);
    `SCOPE_ASSIGN (gpu_rsp_wspawn, warp_ctl_if.wspawn.valid);          
    `SCOPE_ASSIGN (gpu_rsp_split, warp_ctl_if.split.valid);
    `SCOPE_ASSIGN (gpu_rsp_barrier, warp_ctl_if.barrier.valid);

endmodule