/*
 * Copyright (c) 2015-2017 Advanced Micro Devices, Inc.
 * All rights reserved.
 *
 * For use for simulation and test purposes only
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Anthony Gutierrez
 */

#ifndef __ARCH_GCN3_INSTS_INSTRUCTIONS_HH__
#define __ARCH_GCN3_INSTS_INSTRUCTIONS_HH__

#include "arch/gcn3/gpu_decoder.hh"
#include "arch/gcn3/insts/gpu_static_inst.hh"
#include "arch/gcn3/insts/op_encodings.hh"
#include "debug/GCN3.hh"

namespace Gcn3ISA
{
    class Inst_SOP2__S_ADD_U32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ADD_U32(InFmt_SOP2*);
        ~Inst_SOP2__S_ADD_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ADD_U32

    class Inst_SOP2__S_SUB_U32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_SUB_U32(InFmt_SOP2*);
        ~Inst_SOP2__S_SUB_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_SUB_U32

    class Inst_SOP2__S_ADD_I32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ADD_I32(InFmt_SOP2*);
        ~Inst_SOP2__S_ADD_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ADD_I32

    class Inst_SOP2__S_SUB_I32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_SUB_I32(InFmt_SOP2*);
        ~Inst_SOP2__S_SUB_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_SUB_I32

    class Inst_SOP2__S_ADDC_U32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ADDC_U32(InFmt_SOP2*);
        ~Inst_SOP2__S_ADDC_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ADDC_U32

    class Inst_SOP2__S_SUBB_U32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_SUBB_U32(InFmt_SOP2*);
        ~Inst_SOP2__S_SUBB_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_SUBB_U32

    class Inst_SOP2__S_MIN_I32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_MIN_I32(InFmt_SOP2*);
        ~Inst_SOP2__S_MIN_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_MIN_I32

    class Inst_SOP2__S_MIN_U32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_MIN_U32(InFmt_SOP2*);
        ~Inst_SOP2__S_MIN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_MIN_U32

    class Inst_SOP2__S_MAX_I32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_MAX_I32(InFmt_SOP2*);
        ~Inst_SOP2__S_MAX_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_MAX_I32

    class Inst_SOP2__S_MAX_U32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_MAX_U32(InFmt_SOP2*);
        ~Inst_SOP2__S_MAX_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_MAX_U32

    class Inst_SOP2__S_CSELECT_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_CSELECT_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_CSELECT_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_CSELECT_B32

    class Inst_SOP2__S_CSELECT_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_CSELECT_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_CSELECT_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_CSELECT_B64

    class Inst_SOP2__S_AND_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_AND_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_AND_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_AND_B32

    class Inst_SOP2__S_AND_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_AND_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_AND_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_AND_B64

    class Inst_SOP2__S_OR_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_OR_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_OR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_OR_B32

    class Inst_SOP2__S_OR_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_OR_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_OR_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_OR_B64

    class Inst_SOP2__S_XOR_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_XOR_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_XOR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_XOR_B32

    class Inst_SOP2__S_XOR_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_XOR_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_XOR_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_XOR_B64

    class Inst_SOP2__S_ANDN2_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ANDN2_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_ANDN2_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ANDN2_B32

    class Inst_SOP2__S_ANDN2_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ANDN2_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_ANDN2_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ANDN2_B64

    class Inst_SOP2__S_ORN2_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ORN2_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_ORN2_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ORN2_B32

    class Inst_SOP2__S_ORN2_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ORN2_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_ORN2_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ORN2_B64

    class Inst_SOP2__S_NAND_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_NAND_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_NAND_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_NAND_B32

    class Inst_SOP2__S_NAND_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_NAND_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_NAND_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_NAND_B64

    class Inst_SOP2__S_NOR_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_NOR_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_NOR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_NOR_B32

    class Inst_SOP2__S_NOR_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_NOR_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_NOR_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_NOR_B64

    class Inst_SOP2__S_XNOR_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_XNOR_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_XNOR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_XNOR_B32

    class Inst_SOP2__S_XNOR_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_XNOR_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_XNOR_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_XNOR_B64

    class Inst_SOP2__S_LSHL_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_LSHL_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_LSHL_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_LSHL_B32

    class Inst_SOP2__S_LSHL_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_LSHL_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_LSHL_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_LSHL_B64

    class Inst_SOP2__S_LSHR_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_LSHR_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_LSHR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_LSHR_B32

    class Inst_SOP2__S_LSHR_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_LSHR_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_LSHR_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_LSHR_B64

    class Inst_SOP2__S_ASHR_I32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ASHR_I32(InFmt_SOP2*);
        ~Inst_SOP2__S_ASHR_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ASHR_I32

    class Inst_SOP2__S_ASHR_I64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ASHR_I64(InFmt_SOP2*);
        ~Inst_SOP2__S_ASHR_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ASHR_I64

    class Inst_SOP2__S_BFM_B32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_BFM_B32(InFmt_SOP2*);
        ~Inst_SOP2__S_BFM_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_BFM_B32

    class Inst_SOP2__S_BFM_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_BFM_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_BFM_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_BFM_B64

    class Inst_SOP2__S_MUL_I32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_MUL_I32(InFmt_SOP2*);
        ~Inst_SOP2__S_MUL_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_MUL_I32

    class Inst_SOP2__S_BFE_U32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_BFE_U32(InFmt_SOP2*);
        ~Inst_SOP2__S_BFE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_BFE_U32

    class Inst_SOP2__S_BFE_I32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_BFE_I32(InFmt_SOP2*);
        ~Inst_SOP2__S_BFE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_BFE_I32

    class Inst_SOP2__S_BFE_U64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_BFE_U64(InFmt_SOP2*);
        ~Inst_SOP2__S_BFE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_BFE_U64

    class Inst_SOP2__S_BFE_I64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_BFE_I64(InFmt_SOP2*);
        ~Inst_SOP2__S_BFE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_BFE_I64

    class Inst_SOP2__S_CBRANCH_G_FORK : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_CBRANCH_G_FORK(InFmt_SOP2*);
        ~Inst_SOP2__S_CBRANCH_G_FORK();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_CBRANCH_G_FORK

    class Inst_SOP2__S_ABSDIFF_I32 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_ABSDIFF_I32(InFmt_SOP2*);
        ~Inst_SOP2__S_ABSDIFF_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_ABSDIFF_I32

    class Inst_SOP2__S_RFE_RESTORE_B64 : public Inst_SOP2
    {
      public:
        Inst_SOP2__S_RFE_RESTORE_B64(InFmt_SOP2*);
        ~Inst_SOP2__S_RFE_RESTORE_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP2__S_RFE_RESTORE_B64

    class Inst_SOPK__S_MOVK_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_MOVK_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_MOVK_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_MOVK_I32

    class Inst_SOPK__S_CMOVK_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMOVK_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMOVK_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMOVK_I32

    class Inst_SOPK__S_CMPK_EQ_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_EQ_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_EQ_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_EQ_I32

    class Inst_SOPK__S_CMPK_LG_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_LG_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_LG_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_LG_I32

    class Inst_SOPK__S_CMPK_GT_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_GT_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_GT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_GT_I32

    class Inst_SOPK__S_CMPK_GE_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_GE_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_GE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_GE_I32

    class Inst_SOPK__S_CMPK_LT_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_LT_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_LT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_LT_I32

    class Inst_SOPK__S_CMPK_LE_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_LE_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_LE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_LE_I32

    class Inst_SOPK__S_CMPK_EQ_U32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_EQ_U32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_EQ_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_EQ_U32

    class Inst_SOPK__S_CMPK_LG_U32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_LG_U32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_LG_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_LG_U32

    class Inst_SOPK__S_CMPK_GT_U32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_GT_U32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_GT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_GT_U32

    class Inst_SOPK__S_CMPK_GE_U32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_GE_U32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_GE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_GE_U32

    class Inst_SOPK__S_CMPK_LT_U32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_LT_U32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_LT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_LT_U32

    class Inst_SOPK__S_CMPK_LE_U32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CMPK_LE_U32(InFmt_SOPK*);
        ~Inst_SOPK__S_CMPK_LE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CMPK_LE_U32

    class Inst_SOPK__S_ADDK_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_ADDK_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_ADDK_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_ADDK_I32

    class Inst_SOPK__S_MULK_I32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_MULK_I32(InFmt_SOPK*);
        ~Inst_SOPK__S_MULK_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_MULK_I32

    class Inst_SOPK__S_CBRANCH_I_FORK : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_CBRANCH_I_FORK(InFmt_SOPK*);
        ~Inst_SOPK__S_CBRANCH_I_FORK();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return 8;
              case 1: //
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return true;
              case 1: //
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return false;
              case 1: //
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_CBRANCH_I_FORK

    class Inst_SOPK__S_GETREG_B32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_GETREG_B32(InFmt_SOPK*);
        ~Inst_SOPK__S_GETREG_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_GETREG_B32

    class Inst_SOPK__S_SETREG_B32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_SETREG_B32(InFmt_SOPK*);
        ~Inst_SOPK__S_SETREG_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_SETREG_B32

    class Inst_SOPK__S_SETREG_IMM32_B32 : public Inst_SOPK
    {
      public:
        Inst_SOPK__S_SETREG_IMM32_B32(InFmt_SOPK*);
        ~Inst_SOPK__S_SETREG_IMM32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm32
                return 4;
              case 1: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm32
                return true;
              case 1: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm32
                return false;
              case 1: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPK__S_SETREG_IMM32_B32

    class Inst_SOP1__S_MOV_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_MOV_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_MOV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_MOV_B32

    class Inst_SOP1__S_MOV_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_MOV_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_MOV_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_MOV_B64

    class Inst_SOP1__S_CMOV_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_CMOV_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_CMOV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_CMOV_B32

    class Inst_SOP1__S_CMOV_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_CMOV_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_CMOV_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_CMOV_B64

    class Inst_SOP1__S_NOT_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_NOT_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_NOT_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_NOT_B32

    class Inst_SOP1__S_NOT_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_NOT_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_NOT_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_NOT_B64

    class Inst_SOP1__S_WQM_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_WQM_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_WQM_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_WQM_B32

    class Inst_SOP1__S_WQM_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_WQM_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_WQM_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_WQM_B64

    class Inst_SOP1__S_BREV_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BREV_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_BREV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BREV_B32

    class Inst_SOP1__S_BREV_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BREV_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_BREV_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BREV_B64

    class Inst_SOP1__S_BCNT0_I32_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BCNT0_I32_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_BCNT0_I32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BCNT0_I32_B32

    class Inst_SOP1__S_BCNT0_I32_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BCNT0_I32_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_BCNT0_I32_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BCNT0_I32_B64

    class Inst_SOP1__S_BCNT1_I32_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BCNT1_I32_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_BCNT1_I32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BCNT1_I32_B32

    class Inst_SOP1__S_BCNT1_I32_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BCNT1_I32_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_BCNT1_I32_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BCNT1_I32_B64

    class Inst_SOP1__S_FF0_I32_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_FF0_I32_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_FF0_I32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_FF0_I32_B32

    class Inst_SOP1__S_FF0_I32_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_FF0_I32_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_FF0_I32_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_FF0_I32_B64

    class Inst_SOP1__S_FF1_I32_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_FF1_I32_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_FF1_I32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_FF1_I32_B32

    class Inst_SOP1__S_FF1_I32_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_FF1_I32_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_FF1_I32_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_FF1_I32_B64

    class Inst_SOP1__S_FLBIT_I32_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_FLBIT_I32_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_FLBIT_I32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_FLBIT_I32_B32

    class Inst_SOP1__S_FLBIT_I32_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_FLBIT_I32_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_FLBIT_I32_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_FLBIT_I32_B64

    class Inst_SOP1__S_FLBIT_I32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_FLBIT_I32(InFmt_SOP1*);
        ~Inst_SOP1__S_FLBIT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_FLBIT_I32

    class Inst_SOP1__S_FLBIT_I32_I64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_FLBIT_I32_I64(InFmt_SOP1*);
        ~Inst_SOP1__S_FLBIT_I32_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_FLBIT_I32_I64

    class Inst_SOP1__S_SEXT_I32_I8 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_SEXT_I32_I8(InFmt_SOP1*);
        ~Inst_SOP1__S_SEXT_I32_I8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_SEXT_I32_I8

    class Inst_SOP1__S_SEXT_I32_I16 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_SEXT_I32_I16(InFmt_SOP1*);
        ~Inst_SOP1__S_SEXT_I32_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_SEXT_I32_I16

    class Inst_SOP1__S_BITSET0_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BITSET0_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_BITSET0_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BITSET0_B32

    class Inst_SOP1__S_BITSET0_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BITSET0_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_BITSET0_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BITSET0_B64

    class Inst_SOP1__S_BITSET1_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BITSET1_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_BITSET1_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BITSET1_B32

    class Inst_SOP1__S_BITSET1_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_BITSET1_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_BITSET1_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_BITSET1_B64

    class Inst_SOP1__S_GETPC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_GETPC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_GETPC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_GETPC_B64

    class Inst_SOP1__S_SETPC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_SETPC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_SETPC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_SETPC_B64

    class Inst_SOP1__S_SWAPPC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_SWAPPC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_SWAPPC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_SWAPPC_B64

    class Inst_SOP1__S_RFE_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_RFE_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_RFE_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_RFE_B64

    class Inst_SOP1__S_AND_SAVEEXEC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_AND_SAVEEXEC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_AND_SAVEEXEC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_AND_SAVEEXEC_B64

    class Inst_SOP1__S_OR_SAVEEXEC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_OR_SAVEEXEC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_OR_SAVEEXEC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_OR_SAVEEXEC_B64

    class Inst_SOP1__S_XOR_SAVEEXEC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_XOR_SAVEEXEC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_XOR_SAVEEXEC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_XOR_SAVEEXEC_B64

    class Inst_SOP1__S_ANDN2_SAVEEXEC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_ANDN2_SAVEEXEC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_ANDN2_SAVEEXEC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_ANDN2_SAVEEXEC_B64

    class Inst_SOP1__S_ORN2_SAVEEXEC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_ORN2_SAVEEXEC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_ORN2_SAVEEXEC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_ORN2_SAVEEXEC_B64

    class Inst_SOP1__S_NAND_SAVEEXEC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_NAND_SAVEEXEC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_NAND_SAVEEXEC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_NAND_SAVEEXEC_B64

    class Inst_SOP1__S_NOR_SAVEEXEC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_NOR_SAVEEXEC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_NOR_SAVEEXEC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_NOR_SAVEEXEC_B64

    class Inst_SOP1__S_XNOR_SAVEEXEC_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_XNOR_SAVEEXEC_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_XNOR_SAVEEXEC_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_XNOR_SAVEEXEC_B64

    class Inst_SOP1__S_QUADMASK_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_QUADMASK_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_QUADMASK_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_QUADMASK_B32

    class Inst_SOP1__S_QUADMASK_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_QUADMASK_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_QUADMASK_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_QUADMASK_B64

    class Inst_SOP1__S_MOVRELS_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_MOVRELS_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_MOVRELS_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_MOVRELS_B32

    class Inst_SOP1__S_MOVRELS_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_MOVRELS_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_MOVRELS_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sdst
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_MOVRELS_B64

    class Inst_SOP1__S_MOVRELD_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_MOVRELD_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_MOVRELD_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_MOVRELD_B32

    class Inst_SOP1__S_MOVRELD_B64 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_MOVRELD_B64(InFmt_SOP1*);
        ~Inst_SOP1__S_MOVRELD_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 8;
              case 1: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_MOVRELD_B64

    class Inst_SOP1__S_CBRANCH_JOIN : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_CBRANCH_JOIN(InFmt_SOP1*);
        ~Inst_SOP1__S_CBRANCH_JOIN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_CBRANCH_JOIN

    class Inst_SOP1__S_ABS_I32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_ABS_I32(InFmt_SOP1*);
        ~Inst_SOP1__S_ABS_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_ABS_I32

    class Inst_SOP1__S_MOV_FED_B32 : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_MOV_FED_B32(InFmt_SOP1*);
        ~Inst_SOP1__S_MOV_FED_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_MOV_FED_B32

    class Inst_SOP1__S_SET_GPR_IDX_IDX : public Inst_SOP1
    {
      public:
        Inst_SOP1__S_SET_GPR_IDX_IDX(InFmt_SOP1*);
        ~Inst_SOP1__S_SET_GPR_IDX_IDX();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOP1__S_SET_GPR_IDX_IDX

    class Inst_SOPC__S_CMP_EQ_I32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_EQ_I32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_EQ_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_EQ_I32

    class Inst_SOPC__S_CMP_LG_I32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_LG_I32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_LG_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_LG_I32

    class Inst_SOPC__S_CMP_GT_I32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_GT_I32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_GT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_GT_I32

    class Inst_SOPC__S_CMP_GE_I32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_GE_I32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_GE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_GE_I32

    class Inst_SOPC__S_CMP_LT_I32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_LT_I32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_LT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_LT_I32

    class Inst_SOPC__S_CMP_LE_I32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_LE_I32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_LE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_LE_I32

    class Inst_SOPC__S_CMP_EQ_U32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_EQ_U32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_EQ_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_EQ_U32

    class Inst_SOPC__S_CMP_LG_U32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_LG_U32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_LG_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_LG_U32

    class Inst_SOPC__S_CMP_GT_U32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_GT_U32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_GT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_GT_U32

    class Inst_SOPC__S_CMP_GE_U32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_GE_U32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_GE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_GE_U32

    class Inst_SOPC__S_CMP_LT_U32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_LT_U32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_LT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_LT_U32

    class Inst_SOPC__S_CMP_LE_U32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_LE_U32(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_LE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_LE_U32

    class Inst_SOPC__S_BITCMP0_B32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_BITCMP0_B32(InFmt_SOPC*);
        ~Inst_SOPC__S_BITCMP0_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_BITCMP0_B32

    class Inst_SOPC__S_BITCMP1_B32 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_BITCMP1_B32(InFmt_SOPC*);
        ~Inst_SOPC__S_BITCMP1_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_BITCMP1_B32

    class Inst_SOPC__S_BITCMP0_B64 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_BITCMP0_B64(InFmt_SOPC*);
        ~Inst_SOPC__S_BITCMP0_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_BITCMP0_B64

    class Inst_SOPC__S_BITCMP1_B64 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_BITCMP1_B64(InFmt_SOPC*);
        ~Inst_SOPC__S_BITCMP1_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_BITCMP1_B64

    class Inst_SOPC__S_SETVSKIP : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_SETVSKIP(InFmt_SOPC*);
        ~Inst_SOPC__S_SETVSKIP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_SETVSKIP

    class Inst_SOPC__S_SET_GPR_IDX_ON : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_SET_GPR_IDX_ON(InFmt_SOPC*);
        ~Inst_SOPC__S_SET_GPR_IDX_ON();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //simm4
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //simm4
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //simm4
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_SET_GPR_IDX_ON

    class Inst_SOPC__S_CMP_EQ_U64 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_EQ_U64(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_EQ_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_EQ_U64

    class Inst_SOPC__S_CMP_LG_U64 : public Inst_SOPC
    {
      public:
        Inst_SOPC__S_CMP_LG_U64(InFmt_SOPC*);
        ~Inst_SOPC__S_CMP_LG_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 8;
              case 1: //ssrc_1
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPC__S_CMP_LG_U64

    class Inst_SOPP__S_NOP : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_NOP(InFmt_SOPP*);
        ~Inst_SOPP__S_NOP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_NOP

    class Inst_SOPP__S_ENDPGM : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_ENDPGM(InFmt_SOPP*);
        ~Inst_SOPP__S_ENDPGM();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_ENDPGM

    class Inst_SOPP__S_BRANCH : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_BRANCH(InFmt_SOPP*);
        ~Inst_SOPP__S_BRANCH();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_BRANCH

    class Inst_SOPP__S_WAKEUP : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_WAKEUP(InFmt_SOPP*);
        ~Inst_SOPP__S_WAKEUP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_WAKEUP

    class Inst_SOPP__S_CBRANCH_SCC0 : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_SCC0(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_SCC0();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_SCC0

    class Inst_SOPP__S_CBRANCH_SCC1 : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_SCC1(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_SCC1();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_SCC1

    class Inst_SOPP__S_CBRANCH_VCCZ : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_VCCZ(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_VCCZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              case 1:
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              case 1:
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              case 1:
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_VCCZ

    class Inst_SOPP__S_CBRANCH_VCCNZ : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_VCCNZ(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_VCCNZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              case 1:
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              case 1:
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              case 1:
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_VCCNZ

    class Inst_SOPP__S_CBRANCH_EXECZ : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_EXECZ(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_EXECZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_EXECZ

    class Inst_SOPP__S_CBRANCH_EXECNZ : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_EXECNZ(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_EXECNZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_EXECNZ

    class Inst_SOPP__S_BARRIER : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_BARRIER(InFmt_SOPP*);
        ~Inst_SOPP__S_BARRIER();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_BARRIER

    class Inst_SOPP__S_SETKILL : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_SETKILL(InFmt_SOPP*);
        ~Inst_SOPP__S_SETKILL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_SETKILL

    class Inst_SOPP__S_WAITCNT : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_WAITCNT(InFmt_SOPP*);
        ~Inst_SOPP__S_WAITCNT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_WAITCNT

    class Inst_SOPP__S_SETHALT : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_SETHALT(InFmt_SOPP*);
        ~Inst_SOPP__S_SETHALT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_SETHALT

    class Inst_SOPP__S_SLEEP : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_SLEEP(InFmt_SOPP*);
        ~Inst_SOPP__S_SLEEP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_SLEEP

    class Inst_SOPP__S_SETPRIO : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_SETPRIO(InFmt_SOPP*);
        ~Inst_SOPP__S_SETPRIO();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_SETPRIO

    class Inst_SOPP__S_SENDMSG : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_SENDMSG(InFmt_SOPP*);
        ~Inst_SOPP__S_SENDMSG();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_SENDMSG

    class Inst_SOPP__S_SENDMSGHALT : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_SENDMSGHALT(InFmt_SOPP*);
        ~Inst_SOPP__S_SENDMSGHALT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_SENDMSGHALT

    class Inst_SOPP__S_TRAP : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_TRAP(InFmt_SOPP*);
        ~Inst_SOPP__S_TRAP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_TRAP

    class Inst_SOPP__S_ICACHE_INV : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_ICACHE_INV(InFmt_SOPP*);
        ~Inst_SOPP__S_ICACHE_INV();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_ICACHE_INV

    class Inst_SOPP__S_INCPERFLEVEL : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_INCPERFLEVEL(InFmt_SOPP*);
        ~Inst_SOPP__S_INCPERFLEVEL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_INCPERFLEVEL

    class Inst_SOPP__S_DECPERFLEVEL : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_DECPERFLEVEL(InFmt_SOPP*);
        ~Inst_SOPP__S_DECPERFLEVEL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_DECPERFLEVEL

    class Inst_SOPP__S_TTRACEDATA : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_TTRACEDATA(InFmt_SOPP*);
        ~Inst_SOPP__S_TTRACEDATA();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_TTRACEDATA

    class Inst_SOPP__S_CBRANCH_CDBGSYS : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_CDBGSYS(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_CDBGSYS();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_CDBGSYS

    class Inst_SOPP__S_CBRANCH_CDBGUSER : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_CDBGUSER(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_CDBGUSER();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_CDBGUSER

    class Inst_SOPP__S_CBRANCH_CDBGSYS_OR_USER : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_CDBGSYS_OR_USER(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_CDBGSYS_OR_USER();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_CDBGSYS_OR_USER

    class Inst_SOPP__S_CBRANCH_CDBGSYS_AND_USER : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_CBRANCH_CDBGSYS_AND_USER(InFmt_SOPP*);
        ~Inst_SOPP__S_CBRANCH_CDBGSYS_AND_USER();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //label
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_CBRANCH_CDBGSYS_AND_USER

    class Inst_SOPP__S_ENDPGM_SAVED : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_ENDPGM_SAVED(InFmt_SOPP*);
        ~Inst_SOPP__S_ENDPGM_SAVED();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_ENDPGM_SAVED

    class Inst_SOPP__S_SET_GPR_IDX_OFF : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_SET_GPR_IDX_OFF(InFmt_SOPP*);
        ~Inst_SOPP__S_SET_GPR_IDX_OFF();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_SET_GPR_IDX_OFF

    class Inst_SOPP__S_SET_GPR_IDX_MODE : public Inst_SOPP
    {
      public:
        Inst_SOPP__S_SET_GPR_IDX_MODE(InFmt_SOPP*);
        ~Inst_SOPP__S_SET_GPR_IDX_MODE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //simm16
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SOPP__S_SET_GPR_IDX_MODE

    class Inst_SMEM__S_LOAD_DWORD : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_LOAD_DWORD(InFmt_SMEM*);
        ~Inst_SMEM__S_LOAD_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 8;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_LOAD_DWORD

    class Inst_SMEM__S_LOAD_DWORDX2 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_LOAD_DWORDX2(InFmt_SMEM*);
        ~Inst_SMEM__S_LOAD_DWORDX2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 8;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_LOAD_DWORDX2

    class Inst_SMEM__S_LOAD_DWORDX4 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_LOAD_DWORDX4(InFmt_SMEM*);
        ~Inst_SMEM__S_LOAD_DWORDX4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 8;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_LOAD_DWORDX4

    class Inst_SMEM__S_LOAD_DWORDX8 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_LOAD_DWORDX8(InFmt_SMEM*);
        ~Inst_SMEM__S_LOAD_DWORDX8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 8;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_LOAD_DWORDX8

    class Inst_SMEM__S_LOAD_DWORDX16 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_LOAD_DWORDX16(InFmt_SMEM*);
        ~Inst_SMEM__S_LOAD_DWORDX16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 8;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 64;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_LOAD_DWORDX16

    class Inst_SMEM__S_BUFFER_LOAD_DWORD : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_BUFFER_LOAD_DWORD(InFmt_SMEM*);
        ~Inst_SMEM__S_BUFFER_LOAD_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 16;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_BUFFER_LOAD_DWORD

    class Inst_SMEM__S_BUFFER_LOAD_DWORDX2 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_BUFFER_LOAD_DWORDX2(InFmt_SMEM*);
        ~Inst_SMEM__S_BUFFER_LOAD_DWORDX2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 16;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_BUFFER_LOAD_DWORDX2

    class Inst_SMEM__S_BUFFER_LOAD_DWORDX4 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_BUFFER_LOAD_DWORDX4(InFmt_SMEM*);
        ~Inst_SMEM__S_BUFFER_LOAD_DWORDX4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 16;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_BUFFER_LOAD_DWORDX4

    class Inst_SMEM__S_BUFFER_LOAD_DWORDX8 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_BUFFER_LOAD_DWORDX8(InFmt_SMEM*);
        ~Inst_SMEM__S_BUFFER_LOAD_DWORDX8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 16;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_BUFFER_LOAD_DWORDX8

    class Inst_SMEM__S_BUFFER_LOAD_DWORDX16 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_BUFFER_LOAD_DWORDX16(InFmt_SMEM*);
        ~Inst_SMEM__S_BUFFER_LOAD_DWORDX16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return 16;
              case 1: //offset
                return 4;
              case 2: //sgpr_dst
                return 64;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return true;
              case 1: //offset
                return true;
              case 2: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_base
                return false;
              case 1: //offset
                return false;
              case 2: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_BUFFER_LOAD_DWORDX16

    class Inst_SMEM__S_STORE_DWORD : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_STORE_DWORD(InFmt_SMEM*);
        ~Inst_SMEM__S_STORE_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return 4;
              case 1: //sgpr_base
                return 8;
              case 2: //offset
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return true;
              case 1: //sgpr_base
                return true;
              case 2: //offset
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return false;
              case 1: //sgpr_base
                return false;
              case 2: //offset
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_STORE_DWORD

    class Inst_SMEM__S_STORE_DWORDX2 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_STORE_DWORDX2(InFmt_SMEM*);
        ~Inst_SMEM__S_STORE_DWORDX2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return 8;
              case 1: //sgpr_base
                return 8;
              case 2: //offset
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return true;
              case 1: //sgpr_base
                return true;
              case 2: //offset
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return false;
              case 1: //sgpr_base
                return false;
              case 2: //offset
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_STORE_DWORDX2

    class Inst_SMEM__S_STORE_DWORDX4 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_STORE_DWORDX4(InFmt_SMEM*);
        ~Inst_SMEM__S_STORE_DWORDX4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return 16;
              case 1: //sgpr_base
                return 8;
              case 2: //offset
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return true;
              case 1: //sgpr_base
                return true;
              case 2: //offset
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return false;
              case 1: //sgpr_base
                return false;
              case 2: //offset
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_STORE_DWORDX4

    class Inst_SMEM__S_BUFFER_STORE_DWORD : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_BUFFER_STORE_DWORD(InFmt_SMEM*);
        ~Inst_SMEM__S_BUFFER_STORE_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return 4;
              case 1: //sgpr_base
                return 16;
              case 2: //offset
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return true;
              case 1: //sgpr_base
                return true;
              case 2: //offset
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return false;
              case 1: //sgpr_base
                return false;
              case 2: //offset
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_BUFFER_STORE_DWORD

    class Inst_SMEM__S_BUFFER_STORE_DWORDX2 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_BUFFER_STORE_DWORDX2(InFmt_SMEM*);
        ~Inst_SMEM__S_BUFFER_STORE_DWORDX2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return 8;
              case 1: //sgpr_base
                return 16;
              case 2: //offset
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return true;
              case 1: //sgpr_base
                return true;
              case 2: //offset
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return false;
              case 1: //sgpr_base
                return false;
              case 2: //offset
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_BUFFER_STORE_DWORDX2

    class Inst_SMEM__S_BUFFER_STORE_DWORDX4 : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_BUFFER_STORE_DWORDX4(InFmt_SMEM*);
        ~Inst_SMEM__S_BUFFER_STORE_DWORDX4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return 16;
              case 1: //sgpr_base
                return 16;
              case 2: //offset
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return true;
              case 1: //sgpr_base
                return true;
              case 2: //offset
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_data
                return false;
              case 1: //sgpr_base
                return false;
              case 2: //offset
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_BUFFER_STORE_DWORDX4

    class Inst_SMEM__S_DCACHE_INV : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_DCACHE_INV(InFmt_SMEM*);
        ~Inst_SMEM__S_DCACHE_INV();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_DCACHE_INV

    class Inst_SMEM__S_DCACHE_WB : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_DCACHE_WB(InFmt_SMEM*);
        ~Inst_SMEM__S_DCACHE_WB();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_DCACHE_WB

    class Inst_SMEM__S_DCACHE_INV_VOL : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_DCACHE_INV_VOL(InFmt_SMEM*);
        ~Inst_SMEM__S_DCACHE_INV_VOL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_DCACHE_INV_VOL

    class Inst_SMEM__S_DCACHE_WB_VOL : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_DCACHE_WB_VOL(InFmt_SMEM*);
        ~Inst_SMEM__S_DCACHE_WB_VOL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_DCACHE_WB_VOL

    class Inst_SMEM__S_MEMTIME : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_MEMTIME(InFmt_SMEM*);
        ~Inst_SMEM__S_MEMTIME();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_MEMTIME

    class Inst_SMEM__S_MEMREALTIME : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_MEMREALTIME(InFmt_SMEM*);
        ~Inst_SMEM__S_MEMREALTIME();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_MEMREALTIME

    class Inst_SMEM__S_ATC_PROBE : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_ATC_PROBE(InFmt_SMEM*);
        ~Inst_SMEM__S_ATC_PROBE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //perm_rwx
                return 32;
              case 1: //sgpr_base
                return 8;
              case 2: //offset
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //perm_rwx
                return true;
              case 1: //sgpr_base
                return true;
              case 2: //offset
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //perm_rwx
                return false;
              case 1: //sgpr_base
                return false;
              case 2: //offset
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_ATC_PROBE

    class Inst_SMEM__S_ATC_PROBE_BUFFER : public Inst_SMEM
    {
      public:
        Inst_SMEM__S_ATC_PROBE_BUFFER(InFmt_SMEM*);
        ~Inst_SMEM__S_ATC_PROBE_BUFFER();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //perm_rwx
                return 32;
              case 1: //sgpr_base
                return 16;
              case 2: //offset
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //perm_rwx
                return true;
              case 1: //sgpr_base
                return true;
              case 2: //offset
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //perm_rwx
                return false;
              case 1: //sgpr_base
                return false;
              case 2: //offset
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_SMEM__S_ATC_PROBE_BUFFER

    class Inst_VOP2__V_CNDMASK_B32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_CNDMASK_B32(InFmt_VOP2*);
        ~Inst_VOP2__V_CNDMASK_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_CNDMASK_B32

    class Inst_VOP2__V_ADD_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_ADD_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_ADD_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_ADD_F32

    class Inst_VOP2__V_SUB_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUB_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_SUB_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUB_F32

    class Inst_VOP2__V_SUBREV_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUBREV_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_SUBREV_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUBREV_F32

    class Inst_VOP2__V_MUL_LEGACY_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MUL_LEGACY_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_MUL_LEGACY_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MUL_LEGACY_F32

    class Inst_VOP2__V_MUL_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MUL_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_MUL_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MUL_F32

    class Inst_VOP2__V_MUL_I32_I24 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MUL_I32_I24(InFmt_VOP2*);
        ~Inst_VOP2__V_MUL_I32_I24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MUL_I32_I24

    class Inst_VOP2__V_MUL_HI_I32_I24 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MUL_HI_I32_I24(InFmt_VOP2*);
        ~Inst_VOP2__V_MUL_HI_I32_I24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MUL_HI_I32_I24

    class Inst_VOP2__V_MUL_U32_U24 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MUL_U32_U24(InFmt_VOP2*);
        ~Inst_VOP2__V_MUL_U32_U24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MUL_U32_U24

    class Inst_VOP2__V_MUL_HI_U32_U24 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MUL_HI_U32_U24(InFmt_VOP2*);
        ~Inst_VOP2__V_MUL_HI_U32_U24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MUL_HI_U32_U24

    class Inst_VOP2__V_MIN_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MIN_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_MIN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MIN_F32

    class Inst_VOP2__V_MAX_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MAX_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_MAX_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MAX_F32

    class Inst_VOP2__V_MIN_I32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MIN_I32(InFmt_VOP2*);
        ~Inst_VOP2__V_MIN_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MIN_I32

    class Inst_VOP2__V_MAX_I32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MAX_I32(InFmt_VOP2*);
        ~Inst_VOP2__V_MAX_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MAX_I32

    class Inst_VOP2__V_MIN_U32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MIN_U32(InFmt_VOP2*);
        ~Inst_VOP2__V_MIN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MIN_U32

    class Inst_VOP2__V_MAX_U32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MAX_U32(InFmt_VOP2*);
        ~Inst_VOP2__V_MAX_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MAX_U32

    class Inst_VOP2__V_LSHRREV_B32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_LSHRREV_B32(InFmt_VOP2*);
        ~Inst_VOP2__V_LSHRREV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_LSHRREV_B32

    class Inst_VOP2__V_ASHRREV_I32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_ASHRREV_I32(InFmt_VOP2*);
        ~Inst_VOP2__V_ASHRREV_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_ASHRREV_I32

    class Inst_VOP2__V_LSHLREV_B32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_LSHLREV_B32(InFmt_VOP2*);
        ~Inst_VOP2__V_LSHLREV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_LSHLREV_B32

    class Inst_VOP2__V_AND_B32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_AND_B32(InFmt_VOP2*);
        ~Inst_VOP2__V_AND_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_AND_B32

    class Inst_VOP2__V_OR_B32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_OR_B32(InFmt_VOP2*);
        ~Inst_VOP2__V_OR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_OR_B32

    class Inst_VOP2__V_XOR_B32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_XOR_B32(InFmt_VOP2*);
        ~Inst_VOP2__V_XOR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_XOR_B32

    class Inst_VOP2__V_MAC_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MAC_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_MAC_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MAC_F32

    class Inst_VOP2__V_MADMK_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MADMK_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_MADMK_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MADMK_F32

    class Inst_VOP2__V_MADAK_F32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MADAK_F32(InFmt_VOP2*);
        ~Inst_VOP2__V_MADAK_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MADAK_F32

    class Inst_VOP2__V_ADD_U32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_ADD_U32(InFmt_VOP2*);
        ~Inst_VOP2__V_ADD_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              case 3: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              case 3: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              case 3: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_ADD_U32

    class Inst_VOP2__V_SUB_U32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUB_U32(InFmt_VOP2*);
        ~Inst_VOP2__V_SUB_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              case 3: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              case 3: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              case 3: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUB_U32

    class Inst_VOP2__V_SUBREV_U32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUBREV_U32(InFmt_VOP2*);
        ~Inst_VOP2__V_SUBREV_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              case 3: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              case 3: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              case 3: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUBREV_U32

    class Inst_VOP2__V_ADDC_U32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_ADDC_U32(InFmt_VOP2*);
        ~Inst_VOP2__V_ADDC_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              case 3: //vdst
                return 4;
              case 4: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return true;
              case 3: //vdst
                return false;
              case 4: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return false;
              case 3: //vdst
                return true;
              case 4: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_ADDC_U32

    class Inst_VOP2__V_SUBB_U32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUBB_U32(InFmt_VOP2*);
        ~Inst_VOP2__V_SUBB_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              case 3: //vdst
                return 4;
              case 4: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return true;
              case 3: //vdst
                return false;
              case 4: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return false;
              case 3: //vdst
                return true;
              case 4: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUBB_U32

    class Inst_VOP2__V_SUBBREV_U32 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUBBREV_U32(InFmt_VOP2*);
        ~Inst_VOP2__V_SUBBREV_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              case 3: //vdst
                return 4;
              case 4: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return true;
              case 3: //vdst
                return false;
              case 4: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return false;
              case 3: //vdst
                return true;
              case 4: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUBBREV_U32

    class Inst_VOP2__V_ADD_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_ADD_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_ADD_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_ADD_F16

    class Inst_VOP2__V_SUB_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUB_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_SUB_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUB_F16

    class Inst_VOP2__V_SUBREV_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUBREV_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_SUBREV_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUBREV_F16

    class Inst_VOP2__V_MUL_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MUL_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_MUL_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MUL_F16

    class Inst_VOP2__V_MAC_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MAC_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_MAC_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MAC_F16

    class Inst_VOP2__V_MADMK_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MADMK_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_MADMK_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //src_2
                return 2;
              case 3: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MADMK_F16

    class Inst_VOP2__V_MADAK_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MADAK_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_MADAK_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //src_2
                return 2;
              case 3: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MADAK_F16

    class Inst_VOP2__V_ADD_U16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_ADD_U16(InFmt_VOP2*);
        ~Inst_VOP2__V_ADD_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_ADD_U16

    class Inst_VOP2__V_SUB_U16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUB_U16(InFmt_VOP2*);
        ~Inst_VOP2__V_SUB_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUB_U16

    class Inst_VOP2__V_SUBREV_U16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_SUBREV_U16(InFmt_VOP2*);
        ~Inst_VOP2__V_SUBREV_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_SUBREV_U16

    class Inst_VOP2__V_MUL_LO_U16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MUL_LO_U16(InFmt_VOP2*);
        ~Inst_VOP2__V_MUL_LO_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MUL_LO_U16

    class Inst_VOP2__V_LSHLREV_B16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_LSHLREV_B16(InFmt_VOP2*);
        ~Inst_VOP2__V_LSHLREV_B16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_LSHLREV_B16

    class Inst_VOP2__V_LSHRREV_B16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_LSHRREV_B16(InFmt_VOP2*);
        ~Inst_VOP2__V_LSHRREV_B16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_LSHRREV_B16

    class Inst_VOP2__V_ASHRREV_I16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_ASHRREV_I16(InFmt_VOP2*);
        ~Inst_VOP2__V_ASHRREV_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_ASHRREV_I16

    class Inst_VOP2__V_MAX_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MAX_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_MAX_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MAX_F16

    class Inst_VOP2__V_MIN_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MIN_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_MIN_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MIN_F16

    class Inst_VOP2__V_MAX_U16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MAX_U16(InFmt_VOP2*);
        ~Inst_VOP2__V_MAX_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MAX_U16

    class Inst_VOP2__V_MAX_I16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MAX_I16(InFmt_VOP2*);
        ~Inst_VOP2__V_MAX_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MAX_I16

    class Inst_VOP2__V_MIN_U16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MIN_U16(InFmt_VOP2*);
        ~Inst_VOP2__V_MIN_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MIN_U16

    class Inst_VOP2__V_MIN_I16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_MIN_I16(InFmt_VOP2*);
        ~Inst_VOP2__V_MIN_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_MIN_I16

    class Inst_VOP2__V_LDEXP_F16 : public Inst_VOP2
    {
      public:
        Inst_VOP2__V_LDEXP_F16(InFmt_VOP2*);
        ~Inst_VOP2__V_LDEXP_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP2__V_LDEXP_F16

    class Inst_VOP1__V_NOP : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_NOP(InFmt_VOP1*);
        ~Inst_VOP1__V_NOP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_NOP

    class Inst_VOP1__V_MOV_B32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_MOV_B32(InFmt_VOP1*);
        ~Inst_VOP1__V_MOV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_MOV_B32

    class Inst_VOP1__V_READFIRSTLANE_B32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_READFIRSTLANE_B32(InFmt_VOP1*);
        ~Inst_VOP1__V_READFIRSTLANE_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vsrc
                return 4;
              case 1: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vsrc
                return true;
              case 1: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vsrc
                return false;
              case 1: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_READFIRSTLANE_B32

    class Inst_VOP1__V_CVT_I32_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_I32_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_I32_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_I32_F64

    class Inst_VOP1__V_CVT_F64_I32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F64_I32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F64_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F64_I32

    class Inst_VOP1__V_CVT_F32_I32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F32_I32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F32_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F32_I32

    class Inst_VOP1__V_CVT_F32_U32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F32_U32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F32_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F32_U32

    class Inst_VOP1__V_CVT_U32_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_U32_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_U32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_U32_F32

    class Inst_VOP1__V_CVT_I32_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_I32_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_I32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_I32_F32

    class Inst_VOP1__V_MOV_FED_B32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_MOV_FED_B32(InFmt_VOP1*);
        ~Inst_VOP1__V_MOV_FED_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_MOV_FED_B32

    class Inst_VOP1__V_CVT_F16_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F16_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F16_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F16_F32

    class Inst_VOP1__V_CVT_F32_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F32_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F32_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F32_F16

    class Inst_VOP1__V_CVT_RPI_I32_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_RPI_I32_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_RPI_I32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_RPI_I32_F32

    class Inst_VOP1__V_CVT_FLR_I32_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_FLR_I32_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_FLR_I32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_FLR_I32_F32

    class Inst_VOP1__V_CVT_OFF_F32_I4 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_OFF_F32_I4(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_OFF_F32_I4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_OFF_F32_I4

    class Inst_VOP1__V_CVT_F32_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F32_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F32_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F32_F64

    class Inst_VOP1__V_CVT_F64_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F64_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F64_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F64_F32

    class Inst_VOP1__V_CVT_F32_UBYTE0 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F32_UBYTE0(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F32_UBYTE0();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F32_UBYTE0

    class Inst_VOP1__V_CVT_F32_UBYTE1 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F32_UBYTE1(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F32_UBYTE1();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F32_UBYTE1

    class Inst_VOP1__V_CVT_F32_UBYTE2 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F32_UBYTE2(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F32_UBYTE2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F32_UBYTE2

    class Inst_VOP1__V_CVT_F32_UBYTE3 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F32_UBYTE3(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F32_UBYTE3();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F32_UBYTE3

    class Inst_VOP1__V_CVT_U32_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_U32_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_U32_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_U32_F64

    class Inst_VOP1__V_CVT_F64_U32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F64_U32(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F64_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F64_U32

    class Inst_VOP1__V_TRUNC_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_TRUNC_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_TRUNC_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_TRUNC_F64

    class Inst_VOP1__V_CEIL_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CEIL_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_CEIL_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CEIL_F64

    class Inst_VOP1__V_RNDNE_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RNDNE_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_RNDNE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RNDNE_F64

    class Inst_VOP1__V_FLOOR_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FLOOR_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_FLOOR_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FLOOR_F64

    class Inst_VOP1__V_FRACT_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FRACT_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_FRACT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FRACT_F32

    class Inst_VOP1__V_TRUNC_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_TRUNC_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_TRUNC_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_TRUNC_F32

    class Inst_VOP1__V_CEIL_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CEIL_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_CEIL_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CEIL_F32

    class Inst_VOP1__V_RNDNE_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RNDNE_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_RNDNE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RNDNE_F32

    class Inst_VOP1__V_FLOOR_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FLOOR_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_FLOOR_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FLOOR_F32

    class Inst_VOP1__V_EXP_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_EXP_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_EXP_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_EXP_F32

    class Inst_VOP1__V_LOG_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_LOG_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_LOG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_LOG_F32

    class Inst_VOP1__V_RCP_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RCP_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_RCP_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RCP_F32

    class Inst_VOP1__V_RCP_IFLAG_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RCP_IFLAG_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_RCP_IFLAG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RCP_IFLAG_F32

    class Inst_VOP1__V_RSQ_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RSQ_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_RSQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RSQ_F32

    class Inst_VOP1__V_RCP_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RCP_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_RCP_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RCP_F64

    class Inst_VOP1__V_RSQ_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RSQ_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_RSQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RSQ_F64

    class Inst_VOP1__V_SQRT_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_SQRT_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_SQRT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_SQRT_F32

    class Inst_VOP1__V_SQRT_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_SQRT_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_SQRT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_SQRT_F64

    class Inst_VOP1__V_SIN_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_SIN_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_SIN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_SIN_F32

    class Inst_VOP1__V_COS_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_COS_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_COS_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_COS_F32

    class Inst_VOP1__V_NOT_B32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_NOT_B32(InFmt_VOP1*);
        ~Inst_VOP1__V_NOT_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_NOT_B32

    class Inst_VOP1__V_BFREV_B32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_BFREV_B32(InFmt_VOP1*);
        ~Inst_VOP1__V_BFREV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_BFREV_B32

    class Inst_VOP1__V_FFBH_U32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FFBH_U32(InFmt_VOP1*);
        ~Inst_VOP1__V_FFBH_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FFBH_U32

    class Inst_VOP1__V_FFBL_B32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FFBL_B32(InFmt_VOP1*);
        ~Inst_VOP1__V_FFBL_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FFBL_B32

    class Inst_VOP1__V_FFBH_I32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FFBH_I32(InFmt_VOP1*);
        ~Inst_VOP1__V_FFBH_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FFBH_I32

    class Inst_VOP1__V_FREXP_EXP_I32_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FREXP_EXP_I32_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_FREXP_EXP_I32_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FREXP_EXP_I32_F64

    class Inst_VOP1__V_FREXP_MANT_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FREXP_MANT_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_FREXP_MANT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FREXP_MANT_F64

    class Inst_VOP1__V_FRACT_F64 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FRACT_F64(InFmt_VOP1*);
        ~Inst_VOP1__V_FRACT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FRACT_F64

    class Inst_VOP1__V_FREXP_EXP_I32_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FREXP_EXP_I32_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_FREXP_EXP_I32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FREXP_EXP_I32_F32

    class Inst_VOP1__V_FREXP_MANT_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FREXP_MANT_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_FREXP_MANT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FREXP_MANT_F32

    class Inst_VOP1__V_CLREXCP : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CLREXCP(InFmt_VOP1*);
        ~Inst_VOP1__V_CLREXCP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CLREXCP

    class Inst_VOP1__V_CVT_F16_U16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F16_U16(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F16_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F16_U16

    class Inst_VOP1__V_CVT_F16_I16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_F16_I16(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_F16_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_F16_I16

    class Inst_VOP1__V_CVT_U16_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_U16_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_U16_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_U16_F16

    class Inst_VOP1__V_CVT_I16_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CVT_I16_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_CVT_I16_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CVT_I16_F16

    class Inst_VOP1__V_RCP_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RCP_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_RCP_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RCP_F16

    class Inst_VOP1__V_SQRT_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_SQRT_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_SQRT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_SQRT_F16

    class Inst_VOP1__V_RSQ_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RSQ_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_RSQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RSQ_F16

    class Inst_VOP1__V_LOG_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_LOG_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_LOG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_LOG_F16

    class Inst_VOP1__V_EXP_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_EXP_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_EXP_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_EXP_F16

    class Inst_VOP1__V_FREXP_MANT_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FREXP_MANT_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_FREXP_MANT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FREXP_MANT_F16

    class Inst_VOP1__V_FREXP_EXP_I16_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FREXP_EXP_I16_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_FREXP_EXP_I16_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FREXP_EXP_I16_F16

    class Inst_VOP1__V_FLOOR_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FLOOR_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_FLOOR_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FLOOR_F16

    class Inst_VOP1__V_CEIL_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_CEIL_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_CEIL_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_CEIL_F16

    class Inst_VOP1__V_TRUNC_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_TRUNC_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_TRUNC_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_TRUNC_F16

    class Inst_VOP1__V_RNDNE_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_RNDNE_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_RNDNE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_RNDNE_F16

    class Inst_VOP1__V_FRACT_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_FRACT_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_FRACT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_FRACT_F16

    class Inst_VOP1__V_SIN_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_SIN_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_SIN_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_SIN_F16

    class Inst_VOP1__V_COS_F16 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_COS_F16(InFmt_VOP1*);
        ~Inst_VOP1__V_COS_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_COS_F16

    class Inst_VOP1__V_EXP_LEGACY_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_EXP_LEGACY_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_EXP_LEGACY_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_EXP_LEGACY_F32

    class Inst_VOP1__V_LOG_LEGACY_F32 : public Inst_VOP1
    {
      public:
        Inst_VOP1__V_LOG_LEGACY_F32(InFmt_VOP1*);
        ~Inst_VOP1__V_LOG_LEGACY_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP1__V_LOG_LEGACY_F32

    class Inst_VOPC__V_CMP_CLASS_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_CLASS_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_CLASS_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_CLASS_F32

    class Inst_VOPC__V_CMPX_CLASS_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_CLASS_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_CLASS_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_CLASS_F32

    class Inst_VOPC__V_CMP_CLASS_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_CLASS_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_CLASS_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: // vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_CLASS_F64

    class Inst_VOPC__V_CMPX_CLASS_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_CLASS_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_CLASS_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_CLASS_F64

    class Inst_VOPC__V_CMP_CLASS_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_CLASS_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_CLASS_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_CLASS_F16

    class Inst_VOPC__V_CMPX_CLASS_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_CLASS_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_CLASS_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_CLASS_F16

    class Inst_VOPC__V_CMP_F_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_F16

    class Inst_VOPC__V_CMP_LT_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_F16

    class Inst_VOPC__V_CMP_EQ_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_F16

    class Inst_VOPC__V_CMP_LE_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_F16

    class Inst_VOPC__V_CMP_GT_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_F16

    class Inst_VOPC__V_CMP_LG_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LG_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LG_F16

    class Inst_VOPC__V_CMP_GE_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_F16

    class Inst_VOPC__V_CMP_O_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_O_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_O_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_O_F16

    class Inst_VOPC__V_CMP_U_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_U_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_U_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_U_F16

    class Inst_VOPC__V_CMP_NGE_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NGE_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NGE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NGE_F16

    class Inst_VOPC__V_CMP_NLG_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLG_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLG_F16

    class Inst_VOPC__V_CMP_NGT_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NGT_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NGT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NGT_F16

    class Inst_VOPC__V_CMP_NLE_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLE_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLE_F16

    class Inst_VOPC__V_CMP_NEQ_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NEQ_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NEQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NEQ_F16

    class Inst_VOPC__V_CMP_NLT_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLT_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLT_F16

    class Inst_VOPC__V_CMP_TRU_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_TRU_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_TRU_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_TRU_F16

    class Inst_VOPC__V_CMPX_F_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_F16

    class Inst_VOPC__V_CMPX_LT_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_F16

    class Inst_VOPC__V_CMPX_EQ_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_F16

    class Inst_VOPC__V_CMPX_LE_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_F16

    class Inst_VOPC__V_CMPX_GT_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_F16

    class Inst_VOPC__V_CMPX_LG_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LG_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LG_F16

    class Inst_VOPC__V_CMPX_GE_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_F16

    class Inst_VOPC__V_CMPX_O_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_O_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_O_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_O_F16

    class Inst_VOPC__V_CMPX_U_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_U_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_U_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_U_F16

    class Inst_VOPC__V_CMPX_NGE_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NGE_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NGE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NGE_F16

    class Inst_VOPC__V_CMPX_NLG_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLG_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLG_F16

    class Inst_VOPC__V_CMPX_NGT_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NGT_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NGT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NGT_F16

    class Inst_VOPC__V_CMPX_NLE_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLE_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLE_F16

    class Inst_VOPC__V_CMPX_NEQ_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NEQ_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NEQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NEQ_F16

    class Inst_VOPC__V_CMPX_NLT_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLT_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLT_F16

    class Inst_VOPC__V_CMPX_TRU_F16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_TRU_F16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_TRU_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_TRU_F16

    class Inst_VOPC__V_CMP_F_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_F32

    class Inst_VOPC__V_CMP_LT_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_F32

    class Inst_VOPC__V_CMP_EQ_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_F32

    class Inst_VOPC__V_CMP_LE_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_F32

    class Inst_VOPC__V_CMP_GT_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_F32

    class Inst_VOPC__V_CMP_LG_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LG_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LG_F32

    class Inst_VOPC__V_CMP_GE_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_F32

    class Inst_VOPC__V_CMP_O_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_O_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_O_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_O_F32

    class Inst_VOPC__V_CMP_U_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_U_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_U_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_U_F32

    class Inst_VOPC__V_CMP_NGE_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NGE_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NGE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NGE_F32

    class Inst_VOPC__V_CMP_NLG_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLG_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLG_F32

    class Inst_VOPC__V_CMP_NGT_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NGT_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NGT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NGT_F32

    class Inst_VOPC__V_CMP_NLE_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLE_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLE_F32

    class Inst_VOPC__V_CMP_NEQ_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NEQ_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NEQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NEQ_F32

    class Inst_VOPC__V_CMP_NLT_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLT_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLT_F32

    class Inst_VOPC__V_CMP_TRU_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_TRU_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_TRU_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_TRU_F32

    class Inst_VOPC__V_CMPX_F_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_F32

    class Inst_VOPC__V_CMPX_LT_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_F32

    class Inst_VOPC__V_CMPX_EQ_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_F32

    class Inst_VOPC__V_CMPX_LE_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_F32

    class Inst_VOPC__V_CMPX_GT_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_F32

    class Inst_VOPC__V_CMPX_LG_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LG_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LG_F32

    class Inst_VOPC__V_CMPX_GE_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_F32

    class Inst_VOPC__V_CMPX_O_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_O_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_O_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_O_F32

    class Inst_VOPC__V_CMPX_U_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_U_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_U_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_U_F32

    class Inst_VOPC__V_CMPX_NGE_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NGE_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NGE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NGE_F32

    class Inst_VOPC__V_CMPX_NLG_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLG_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLG_F32

    class Inst_VOPC__V_CMPX_NGT_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NGT_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NGT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NGT_F32

    class Inst_VOPC__V_CMPX_NLE_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLE_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLE_F32

    class Inst_VOPC__V_CMPX_NEQ_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NEQ_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NEQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NEQ_F32

    class Inst_VOPC__V_CMPX_NLT_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLT_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLT_F32

    class Inst_VOPC__V_CMPX_TRU_F32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_TRU_F32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_TRU_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_TRU_F32

    class Inst_VOPC__V_CMP_F_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_F64

    class Inst_VOPC__V_CMP_LT_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_F64

    class Inst_VOPC__V_CMP_EQ_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_F64

    class Inst_VOPC__V_CMP_LE_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_F64

    class Inst_VOPC__V_CMP_GT_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_F64

    class Inst_VOPC__V_CMP_LG_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LG_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LG_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LG_F64

    class Inst_VOPC__V_CMP_GE_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_F64

    class Inst_VOPC__V_CMP_O_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_O_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_O_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_O_F64

    class Inst_VOPC__V_CMP_U_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_U_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_U_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_U_F64

    class Inst_VOPC__V_CMP_NGE_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NGE_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NGE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NGE_F64

    class Inst_VOPC__V_CMP_NLG_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLG_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLG_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLG_F64

    class Inst_VOPC__V_CMP_NGT_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NGT_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NGT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NGT_F64

    class Inst_VOPC__V_CMP_NLE_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLE_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLE_F64

    class Inst_VOPC__V_CMP_NEQ_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NEQ_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NEQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NEQ_F64

    class Inst_VOPC__V_CMP_NLT_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NLT_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NLT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NLT_F64

    class Inst_VOPC__V_CMP_TRU_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_TRU_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_TRU_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_TRU_F64

    class Inst_VOPC__V_CMPX_F_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_F64

    class Inst_VOPC__V_CMPX_LT_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_F64

    class Inst_VOPC__V_CMPX_EQ_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_F64

    class Inst_VOPC__V_CMPX_LE_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_F64

    class Inst_VOPC__V_CMPX_GT_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_F64

    class Inst_VOPC__V_CMPX_LG_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LG_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LG_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LG_F64

    class Inst_VOPC__V_CMPX_GE_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_F64

    class Inst_VOPC__V_CMPX_O_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_O_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_O_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_O_F64

    class Inst_VOPC__V_CMPX_U_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_U_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_U_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_U_F64

    class Inst_VOPC__V_CMPX_NGE_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NGE_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NGE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NGE_F64

    class Inst_VOPC__V_CMPX_NLG_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLG_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLG_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLG_F64

    class Inst_VOPC__V_CMPX_NGT_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NGT_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NGT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NGT_F64

    class Inst_VOPC__V_CMPX_NLE_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLE_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLE_F64

    class Inst_VOPC__V_CMPX_NEQ_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NEQ_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NEQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NEQ_F64

    class Inst_VOPC__V_CMPX_NLT_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NLT_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NLT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NLT_F64

    class Inst_VOPC__V_CMPX_TRU_F64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_TRU_F64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_TRU_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_TRU_F64

    class Inst_VOPC__V_CMP_F_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_I16

    class Inst_VOPC__V_CMP_LT_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_I16

    class Inst_VOPC__V_CMP_EQ_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_I16

    class Inst_VOPC__V_CMP_LE_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_I16

    class Inst_VOPC__V_CMP_GT_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_I16

    class Inst_VOPC__V_CMP_NE_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NE_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NE_I16

    class Inst_VOPC__V_CMP_GE_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_I16

    class Inst_VOPC__V_CMP_T_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_T_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_T_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_T_I16

    class Inst_VOPC__V_CMP_F_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_U16

    class Inst_VOPC__V_CMP_LT_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_U16

    class Inst_VOPC__V_CMP_EQ_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_U16

    class Inst_VOPC__V_CMP_LE_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_U16

    class Inst_VOPC__V_CMP_GT_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_U16

    class Inst_VOPC__V_CMP_NE_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NE_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NE_U16

    class Inst_VOPC__V_CMP_GE_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_U16

    class Inst_VOPC__V_CMP_T_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_T_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_T_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_T_U16

    class Inst_VOPC__V_CMPX_F_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_I16

    class Inst_VOPC__V_CMPX_LT_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_I16

    class Inst_VOPC__V_CMPX_EQ_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_I16

    class Inst_VOPC__V_CMPX_LE_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_I16

    class Inst_VOPC__V_CMPX_GT_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_I16

    class Inst_VOPC__V_CMPX_NE_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NE_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NE_I16

    class Inst_VOPC__V_CMPX_GE_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_I16

    class Inst_VOPC__V_CMPX_T_I16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_T_I16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_T_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_T_I16

    class Inst_VOPC__V_CMPX_F_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_U16

    class Inst_VOPC__V_CMPX_LT_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_U16

    class Inst_VOPC__V_CMPX_EQ_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_U16

    class Inst_VOPC__V_CMPX_LE_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_U16

    class Inst_VOPC__V_CMPX_GT_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_U16

    class Inst_VOPC__V_CMPX_NE_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NE_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NE_U16

    class Inst_VOPC__V_CMPX_GE_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_U16

    class Inst_VOPC__V_CMPX_T_U16 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_T_U16(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_T_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_T_U16

    class Inst_VOPC__V_CMP_F_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_I32

    class Inst_VOPC__V_CMP_LT_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_I32

    class Inst_VOPC__V_CMP_EQ_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_I32

    class Inst_VOPC__V_CMP_LE_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_I32

    class Inst_VOPC__V_CMP_GT_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_I32

    class Inst_VOPC__V_CMP_NE_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NE_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NE_I32

    class Inst_VOPC__V_CMP_GE_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_I32

    class Inst_VOPC__V_CMP_T_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_T_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_T_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_T_I32

    class Inst_VOPC__V_CMP_F_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_U32

    class Inst_VOPC__V_CMP_LT_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_U32

    class Inst_VOPC__V_CMP_EQ_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_U32

    class Inst_VOPC__V_CMP_LE_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_U32

    class Inst_VOPC__V_CMP_GT_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_U32

    class Inst_VOPC__V_CMP_NE_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NE_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NE_U32

    class Inst_VOPC__V_CMP_GE_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_U32

    class Inst_VOPC__V_CMP_T_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_T_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_T_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_T_U32

    class Inst_VOPC__V_CMPX_F_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_I32

    class Inst_VOPC__V_CMPX_LT_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_I32

    class Inst_VOPC__V_CMPX_EQ_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_I32

    class Inst_VOPC__V_CMPX_LE_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_I32

    class Inst_VOPC__V_CMPX_GT_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_I32

    class Inst_VOPC__V_CMPX_NE_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NE_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NE_I32

    class Inst_VOPC__V_CMPX_GE_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_I32

    class Inst_VOPC__V_CMPX_T_I32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_T_I32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_T_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_T_I32

    class Inst_VOPC__V_CMPX_F_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_U32

    class Inst_VOPC__V_CMPX_LT_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_U32

    class Inst_VOPC__V_CMPX_EQ_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_U32

    class Inst_VOPC__V_CMPX_LE_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_U32

    class Inst_VOPC__V_CMPX_GT_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_U32

    class Inst_VOPC__V_CMPX_NE_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NE_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NE_U32

    class Inst_VOPC__V_CMPX_GE_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_U32

    class Inst_VOPC__V_CMPX_T_U32 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_T_U32(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_T_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_T_U32

    class Inst_VOPC__V_CMP_F_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_I64

    class Inst_VOPC__V_CMP_LT_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_I64

    class Inst_VOPC__V_CMP_EQ_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_I64

    class Inst_VOPC__V_CMP_LE_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_I64

    class Inst_VOPC__V_CMP_GT_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_I64

    class Inst_VOPC__V_CMP_NE_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NE_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NE_I64

    class Inst_VOPC__V_CMP_GE_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_I64

    class Inst_VOPC__V_CMP_T_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_T_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_T_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_T_I64

    class Inst_VOPC__V_CMP_F_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_F_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_F_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_F_U64

    class Inst_VOPC__V_CMP_LT_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LT_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LT_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LT_U64

    class Inst_VOPC__V_CMP_EQ_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_EQ_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_EQ_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_EQ_U64

    class Inst_VOPC__V_CMP_LE_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_LE_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_LE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_LE_U64

    class Inst_VOPC__V_CMP_GT_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GT_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GT_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GT_U64

    class Inst_VOPC__V_CMP_NE_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_NE_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_NE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_NE_U64

    class Inst_VOPC__V_CMP_GE_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_GE_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_GE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_GE_U64

    class Inst_VOPC__V_CMP_T_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMP_T_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMP_T_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMP_T_U64

    class Inst_VOPC__V_CMPX_F_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_I64

    class Inst_VOPC__V_CMPX_LT_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_I64

    class Inst_VOPC__V_CMPX_EQ_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_I64

    class Inst_VOPC__V_CMPX_LE_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_I64

    class Inst_VOPC__V_CMPX_GT_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_I64

    class Inst_VOPC__V_CMPX_NE_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NE_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NE_I64

    class Inst_VOPC__V_CMPX_GE_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_I64

    class Inst_VOPC__V_CMPX_T_I64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_T_I64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_T_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_T_I64

    class Inst_VOPC__V_CMPX_F_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_F_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_F_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_F_U64

    class Inst_VOPC__V_CMPX_LT_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LT_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LT_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LT_U64

    class Inst_VOPC__V_CMPX_EQ_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_EQ_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_EQ_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_EQ_U64

    class Inst_VOPC__V_CMPX_LE_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_LE_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_LE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_LE_U64

    class Inst_VOPC__V_CMPX_GT_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GT_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GT_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GT_U64

    class Inst_VOPC__V_CMPX_NE_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_NE_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_NE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_NE_U64

    class Inst_VOPC__V_CMPX_GE_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_GE_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_GE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_GE_U64

    class Inst_VOPC__V_CMPX_T_U64 : public Inst_VOPC
    {
      public:
        Inst_VOPC__V_CMPX_T_U64(InFmt_VOPC*);
        ~Inst_VOPC__V_CMPX_T_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOPC__V_CMPX_T_U64

    class Inst_VINTRP__V_INTERP_P1_F32 : public Inst_VINTRP
    {
      public:
        Inst_VINTRP__V_INTERP_P1_F32(InFmt_VINTRP*);
        ~Inst_VINTRP__V_INTERP_P1_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return 4;
              case 1: //attr
                return 16;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VINTRP__V_INTERP_P1_F32

    class Inst_VINTRP__V_INTERP_P2_F32 : public Inst_VINTRP
    {
      public:
        Inst_VINTRP__V_INTERP_P2_F32(InFmt_VINTRP*);
        ~Inst_VINTRP__V_INTERP_P2_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return 4;
              case 1: //attr
                return 16;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VINTRP__V_INTERP_P2_F32

    class Inst_VINTRP__V_INTERP_MOV_F32 : public Inst_VINTRP
    {
      public:
        Inst_VINTRP__V_INTERP_MOV_F32(InFmt_VINTRP*);
        ~Inst_VINTRP__V_INTERP_MOV_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //param
                return 4;
              case 1: //attr
                return 16;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //param
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //param
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VINTRP__V_INTERP_MOV_F32

    class Inst_VOP3__V_CMP_CLASS_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_CLASS_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_CLASS_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_CLASS_F32

    class Inst_VOP3__V_CMPX_CLASS_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_CLASS_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_CLASS_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_CLASS_F32

    class Inst_VOP3__V_CMP_CLASS_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_CLASS_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_CLASS_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_CLASS_F64

    class Inst_VOP3__V_CMPX_CLASS_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_CLASS_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_CLASS_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_CLASS_F64

    class Inst_VOP3__V_CMP_CLASS_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_CLASS_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_CLASS_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_CLASS_F16

    class Inst_VOP3__V_CMPX_CLASS_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_CLASS_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_CLASS_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_CLASS_F16

    class Inst_VOP3__V_CMP_F_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_F16

    class Inst_VOP3__V_CMP_LT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_F16

    class Inst_VOP3__V_CMP_EQ_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_F16

    class Inst_VOP3__V_CMP_LE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_F16

    class Inst_VOP3__V_CMP_GT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_F16

    class Inst_VOP3__V_CMP_LG_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LG_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LG_F16

    class Inst_VOP3__V_CMP_GE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_F16

    class Inst_VOP3__V_CMP_O_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_O_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_O_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_O_F16

    class Inst_VOP3__V_CMP_U_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_U_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_U_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_U_F16

    class Inst_VOP3__V_CMP_NGE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NGE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NGE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NGE_F16

    class Inst_VOP3__V_CMP_NLG_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLG_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLG_F16

    class Inst_VOP3__V_CMP_NGT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NGT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NGT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NGT_F16

    class Inst_VOP3__V_CMP_NLE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLE_F16

    class Inst_VOP3__V_CMP_NEQ_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NEQ_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NEQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NEQ_F16

    class Inst_VOP3__V_CMP_NLT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLT_F16

    class Inst_VOP3__V_CMP_TRU_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_TRU_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_TRU_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_TRU_F16

    class Inst_VOP3__V_CMPX_F_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_F16

    class Inst_VOP3__V_CMPX_LT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_F16

    class Inst_VOP3__V_CMPX_EQ_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_F16

    class Inst_VOP3__V_CMPX_LE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_F16

    class Inst_VOP3__V_CMPX_GT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_F16

    class Inst_VOP3__V_CMPX_LG_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LG_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LG_F16

    class Inst_VOP3__V_CMPX_GE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_F16

    class Inst_VOP3__V_CMPX_O_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_O_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_O_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_O_F16

    class Inst_VOP3__V_CMPX_U_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_U_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_U_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_U_F16

    class Inst_VOP3__V_CMPX_NGE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NGE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NGE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NGE_F16

    class Inst_VOP3__V_CMPX_NLG_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLG_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLG_F16

    class Inst_VOP3__V_CMPX_NGT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NGT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NGT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NGT_F16

    class Inst_VOP3__V_CMPX_NLE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLE_F16

    class Inst_VOP3__V_CMPX_NEQ_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NEQ_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NEQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NEQ_F16

    class Inst_VOP3__V_CMPX_NLT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLT_F16

    class Inst_VOP3__V_CMPX_TRU_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_TRU_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_TRU_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_TRU_F16

    class Inst_VOP3__V_CMP_F_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_F32

    class Inst_VOP3__V_CMP_LT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_F32

    class Inst_VOP3__V_CMP_EQ_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_F32

    class Inst_VOP3__V_CMP_LE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_F32

    class Inst_VOP3__V_CMP_GT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_F32

    class Inst_VOP3__V_CMP_LG_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LG_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LG_F32

    class Inst_VOP3__V_CMP_GE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_F32

    class Inst_VOP3__V_CMP_O_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_O_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_O_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_O_F32

    class Inst_VOP3__V_CMP_U_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_U_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_U_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_U_F32

    class Inst_VOP3__V_CMP_NGE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NGE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NGE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NGE_F32

    class Inst_VOP3__V_CMP_NLG_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLG_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLG_F32

    class Inst_VOP3__V_CMP_NGT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NGT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NGT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NGT_F32

    class Inst_VOP3__V_CMP_NLE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLE_F32

    class Inst_VOP3__V_CMP_NEQ_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NEQ_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NEQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NEQ_F32

    class Inst_VOP3__V_CMP_NLT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLT_F32

    class Inst_VOP3__V_CMP_TRU_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_TRU_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_TRU_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_TRU_F32

    class Inst_VOP3__V_CMPX_F_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_F32

    class Inst_VOP3__V_CMPX_LT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_F32

    class Inst_VOP3__V_CMPX_EQ_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_F32

    class Inst_VOP3__V_CMPX_LE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_F32

    class Inst_VOP3__V_CMPX_GT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_F32

    class Inst_VOP3__V_CMPX_LG_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LG_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LG_F32

    class Inst_VOP3__V_CMPX_GE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_F32

    class Inst_VOP3__V_CMPX_O_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_O_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_O_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_O_F32

    class Inst_VOP3__V_CMPX_U_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_U_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_U_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_U_F32

    class Inst_VOP3__V_CMPX_NGE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NGE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NGE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NGE_F32

    class Inst_VOP3__V_CMPX_NLG_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLG_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLG_F32

    class Inst_VOP3__V_CMPX_NGT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NGT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NGT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NGT_F32

    class Inst_VOP3__V_CMPX_NLE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLE_F32

    class Inst_VOP3__V_CMPX_NEQ_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NEQ_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NEQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NEQ_F32

    class Inst_VOP3__V_CMPX_NLT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLT_F32

    class Inst_VOP3__V_CMPX_TRU_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_TRU_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_TRU_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_TRU_F32

    class Inst_VOP3__V_CMP_F_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_F64

    class Inst_VOP3__V_CMP_LT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_F64

    class Inst_VOP3__V_CMP_EQ_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_F64

    class Inst_VOP3__V_CMP_LE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_F64

    class Inst_VOP3__V_CMP_GT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_F64

    class Inst_VOP3__V_CMP_LG_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LG_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LG_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LG_F64

    class Inst_VOP3__V_CMP_GE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_F64

    class Inst_VOP3__V_CMP_O_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_O_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_O_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_O_F64

    class Inst_VOP3__V_CMP_U_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_U_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_U_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_U_F64

    class Inst_VOP3__V_CMP_NGE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NGE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NGE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NGE_F64

    class Inst_VOP3__V_CMP_NLG_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLG_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLG_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLG_F64

    class Inst_VOP3__V_CMP_NGT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NGT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NGT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NGT_F64

    class Inst_VOP3__V_CMP_NLE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLE_F64

    class Inst_VOP3__V_CMP_NEQ_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NEQ_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NEQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NEQ_F64

    class Inst_VOP3__V_CMP_NLT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NLT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NLT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NLT_F64

    class Inst_VOP3__V_CMP_TRU_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_TRU_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_TRU_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_TRU_F64

    class Inst_VOP3__V_CMPX_F_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_F64

    class Inst_VOP3__V_CMPX_LT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_F64

    class Inst_VOP3__V_CMPX_EQ_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_F64

    class Inst_VOP3__V_CMPX_LE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_F64

    class Inst_VOP3__V_CMPX_GT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_F64

    class Inst_VOP3__V_CMPX_LG_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LG_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LG_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LG_F64

    class Inst_VOP3__V_CMPX_GE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_F64

    class Inst_VOP3__V_CMPX_O_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_O_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_O_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_O_F64

    class Inst_VOP3__V_CMPX_U_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_U_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_U_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_U_F64

    class Inst_VOP3__V_CMPX_NGE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NGE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NGE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NGE_F64

    class Inst_VOP3__V_CMPX_NLG_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLG_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLG_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLG_F64

    class Inst_VOP3__V_CMPX_NGT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NGT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NGT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NGT_F64

    class Inst_VOP3__V_CMPX_NLE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLE_F64

    class Inst_VOP3__V_CMPX_NEQ_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NEQ_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NEQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NEQ_F64

    class Inst_VOP3__V_CMPX_NLT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NLT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NLT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NLT_F64

    class Inst_VOP3__V_CMPX_TRU_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_TRU_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_TRU_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_TRU_F64

    class Inst_VOP3__V_CMP_F_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_I16

    class Inst_VOP3__V_CMP_LT_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_I16

    class Inst_VOP3__V_CMP_EQ_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_I16

    class Inst_VOP3__V_CMP_LE_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_I16

    class Inst_VOP3__V_CMP_GT_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_I16

    class Inst_VOP3__V_CMP_NE_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NE_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NE_I16

    class Inst_VOP3__V_CMP_GE_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_I16

    class Inst_VOP3__V_CMP_T_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_T_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_T_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_T_I16

    class Inst_VOP3__V_CMP_F_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_U16

    class Inst_VOP3__V_CMP_LT_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_U16

    class Inst_VOP3__V_CMP_EQ_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_U16

    class Inst_VOP3__V_CMP_LE_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_U16

    class Inst_VOP3__V_CMP_GT_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_U16

    class Inst_VOP3__V_CMP_NE_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NE_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NE_U16

    class Inst_VOP3__V_CMP_GE_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_U16

    class Inst_VOP3__V_CMP_T_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_T_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_T_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_T_U16

    class Inst_VOP3__V_CMPX_F_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_I16

    class Inst_VOP3__V_CMPX_LT_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_I16

    class Inst_VOP3__V_CMPX_EQ_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_I16

    class Inst_VOP3__V_CMPX_LE_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_I16

    class Inst_VOP3__V_CMPX_GT_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_I16

    class Inst_VOP3__V_CMPX_NE_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NE_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NE_I16

    class Inst_VOP3__V_CMPX_GE_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_I16

    class Inst_VOP3__V_CMPX_T_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_T_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_T_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_T_I16

    class Inst_VOP3__V_CMPX_F_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_U16

    class Inst_VOP3__V_CMPX_LT_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_U16

    class Inst_VOP3__V_CMPX_EQ_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_U16

    class Inst_VOP3__V_CMPX_LE_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_U16

    class Inst_VOP3__V_CMPX_GT_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_U16

    class Inst_VOP3__V_CMPX_NE_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NE_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NE_U16

    class Inst_VOP3__V_CMPX_GE_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_U16

    class Inst_VOP3__V_CMPX_T_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_T_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_T_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_T_U16

    class Inst_VOP3__V_CMP_F_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_I32

    class Inst_VOP3__V_CMP_LT_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_I32

    class Inst_VOP3__V_CMP_EQ_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_I32

    class Inst_VOP3__V_CMP_LE_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_I32

    class Inst_VOP3__V_CMP_GT_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_I32

    class Inst_VOP3__V_CMP_NE_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NE_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NE_I32

    class Inst_VOP3__V_CMP_GE_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_I32

    class Inst_VOP3__V_CMP_T_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_T_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_T_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_T_I32

    class Inst_VOP3__V_CMP_F_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_U32

    class Inst_VOP3__V_CMP_LT_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_U32

    class Inst_VOP3__V_CMP_EQ_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_U32

    class Inst_VOP3__V_CMP_LE_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_U32

    class Inst_VOP3__V_CMP_GT_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_U32

    class Inst_VOP3__V_CMP_NE_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NE_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NE_U32

    class Inst_VOP3__V_CMP_GE_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_U32

    class Inst_VOP3__V_CMP_T_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_T_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_T_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_T_U32

    class Inst_VOP3__V_CMPX_F_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_I32

    class Inst_VOP3__V_CMPX_LT_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_I32

    class Inst_VOP3__V_CMPX_EQ_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_I32

    class Inst_VOP3__V_CMPX_LE_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_I32

    class Inst_VOP3__V_CMPX_GT_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_I32

    class Inst_VOP3__V_CMPX_NE_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NE_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NE_I32

    class Inst_VOP3__V_CMPX_GE_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_I32

    class Inst_VOP3__V_CMPX_T_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_T_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_T_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_T_I32

    class Inst_VOP3__V_CMPX_F_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_U32

    class Inst_VOP3__V_CMPX_LT_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_U32

    class Inst_VOP3__V_CMPX_EQ_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_U32

    class Inst_VOP3__V_CMPX_LE_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_U32

    class Inst_VOP3__V_CMPX_GT_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_U32

    class Inst_VOP3__V_CMPX_NE_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NE_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NE_U32

    class Inst_VOP3__V_CMPX_GE_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_U32

    class Inst_VOP3__V_CMPX_T_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_T_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_T_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_T_U32

    class Inst_VOP3__V_CMP_F_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_I64

    class Inst_VOP3__V_CMP_LT_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_I64

    class Inst_VOP3__V_CMP_EQ_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_I64

    class Inst_VOP3__V_CMP_LE_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_I64

    class Inst_VOP3__V_CMP_GT_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_I64

    class Inst_VOP3__V_CMP_NE_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NE_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NE_I64

    class Inst_VOP3__V_CMP_GE_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_I64

    class Inst_VOP3__V_CMP_T_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_T_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_T_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_T_I64

    class Inst_VOP3__V_CMP_F_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_F_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_F_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_F_U64

    class Inst_VOP3__V_CMP_LT_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LT_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LT_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LT_U64

    class Inst_VOP3__V_CMP_EQ_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_EQ_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_EQ_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_EQ_U64

    class Inst_VOP3__V_CMP_LE_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_LE_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_LE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_LE_U64

    class Inst_VOP3__V_CMP_GT_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GT_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GT_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GT_U64

    class Inst_VOP3__V_CMP_NE_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_NE_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_NE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_NE_U64

    class Inst_VOP3__V_CMP_GE_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_GE_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_GE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_GE_U64

    class Inst_VOP3__V_CMP_T_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMP_T_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMP_T_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMP_T_U64

    class Inst_VOP3__V_CMPX_F_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_I64

    class Inst_VOP3__V_CMPX_LT_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_I64

    class Inst_VOP3__V_CMPX_EQ_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_I64

    class Inst_VOP3__V_CMPX_LE_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_I64

    class Inst_VOP3__V_CMPX_GT_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_I64

    class Inst_VOP3__V_CMPX_NE_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NE_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NE_I64

    class Inst_VOP3__V_CMPX_GE_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_I64

    class Inst_VOP3__V_CMPX_T_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_T_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_T_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_T_I64

    class Inst_VOP3__V_CMPX_F_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_F_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_F_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_F_U64

    class Inst_VOP3__V_CMPX_LT_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LT_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LT_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LT_U64

    class Inst_VOP3__V_CMPX_EQ_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_EQ_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_EQ_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_EQ_U64

    class Inst_VOP3__V_CMPX_LE_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_LE_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_LE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_LE_U64

    class Inst_VOP3__V_CMPX_GT_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GT_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GT_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GT_U64

    class Inst_VOP3__V_CMPX_NE_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_NE_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_NE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_NE_U64

    class Inst_VOP3__V_CMPX_GE_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_GE_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_GE_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_GE_U64

    class Inst_VOP3__V_CMPX_T_U64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CMPX_T_U64(InFmt_VOP3*);
        ~Inst_VOP3__V_CMPX_T_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //sdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CMPX_T_U64

    class Inst_VOP3__V_CNDMASK_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CNDMASK_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_CNDMASK_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //carryin
                return 8;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //carryin
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //carryin
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CNDMASK_B32

    class Inst_VOP3__V_ADD_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ADD_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_ADD_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ADD_F32

    class Inst_VOP3__V_SUB_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SUB_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_SUB_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUB_F32

    class Inst_VOP3__V_SUBREV_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SUBREV_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_SUBREV_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUBREV_F32

    class Inst_VOP3__V_MUL_LEGACY_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_LEGACY_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_LEGACY_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_LEGACY_F32

    class Inst_VOP3__V_MUL_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_F32

    class Inst_VOP3__V_MUL_I32_I24 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_I32_I24(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_I32_I24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_I32_I24

    class Inst_VOP3__V_MUL_HI_I32_I24 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_HI_I32_I24(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_HI_I32_I24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_HI_I32_I24

    class Inst_VOP3__V_MUL_U32_U24 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_U32_U24(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_U32_U24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_U32_U24

    class Inst_VOP3__V_MUL_HI_U32_U24 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_HI_U32_U24(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_HI_U32_U24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_HI_U32_U24

    class Inst_VOP3__V_MIN_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN_F32

    class Inst_VOP3__V_MAX_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX_F32

    class Inst_VOP3__V_MIN_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN_I32

    class Inst_VOP3__V_MAX_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX_I32

    class Inst_VOP3__V_MIN_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN_U32

    class Inst_VOP3__V_MAX_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX_U32

    class Inst_VOP3__V_LSHRREV_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LSHRREV_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_LSHRREV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LSHRREV_B32

    class Inst_VOP3__V_ASHRREV_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ASHRREV_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_ASHRREV_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ASHRREV_I32

    class Inst_VOP3__V_LSHLREV_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LSHLREV_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_LSHLREV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LSHLREV_B32

    class Inst_VOP3__V_AND_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_AND_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_AND_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_AND_B32

    class Inst_VOP3__V_OR_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_OR_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_OR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_OR_B32

    class Inst_VOP3__V_XOR_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_XOR_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_XOR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_XOR_B32

    class Inst_VOP3__V_MAC_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAC_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAC_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAC_F32

    class Inst_VOP3__V_ADD_U32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_ADD_U32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_ADD_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              case 3: //carryout
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              case 3: //carryout
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              case 3: //carryout
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ADD_U32

    class Inst_VOP3__V_SUB_U32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_SUB_U32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_SUB_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              case 3: //carryout
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              case 3: //carryout
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              case 3: //carryout
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUB_U32

    class Inst_VOP3__V_SUBREV_U32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_SUBREV_U32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_SUBREV_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              case 3: //carryout
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              case 3: //carryout
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              case 3: //carryout
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUBREV_U32

    class Inst_VOP3__V_ADDC_U32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_ADDC_U32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_ADDC_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //carryin
                return 8;
              case 3: //vdst
                return 4;
              case 4: //carryout
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //carryin
                return true;
              case 3: //vdst
                return false;
              case 4: //carryout
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //carryin
                return false;
              case 3: //vdst
                return true;
              case 4: //carryout
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ADDC_U32

    class Inst_VOP3__V_SUBB_U32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_SUBB_U32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_SUBB_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //carryin
                return 8;
              case 3: //vdst
                return 4;
              case 4: //carryout
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //carryin
                return true;
              case 3: //vdst
                return false;
              case 4: //carryout
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //carryin
                return false;
              case 3: //vdst
                return true;
              case 4: //carryout
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUBB_U32

    class Inst_VOP3__V_SUBBREV_U32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_SUBBREV_U32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_SUBBREV_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //carryin
                return 8;
              case 3: //vdst
                return 4;
              case 4: //carryout
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //carryin
                return true;
              case 3: //vdst
                return false;
              case 4: //carryout
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //carryin
                return false;
              case 3: //vdst
                return true;
              case 4: //carryout
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUBBREV_U32

    class Inst_VOP3__V_ADD_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ADD_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_ADD_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ADD_F16

    class Inst_VOP3__V_SUB_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SUB_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_SUB_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUB_F16

    class Inst_VOP3__V_SUBREV_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SUBREV_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_SUBREV_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUBREV_F16

    class Inst_VOP3__V_MUL_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_F16

    class Inst_VOP3__V_MAC_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAC_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_MAC_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAC_F16

    class Inst_VOP3__V_ADD_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ADD_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_ADD_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ADD_U16

    class Inst_VOP3__V_SUB_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SUB_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_SUB_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUB_U16

    class Inst_VOP3__V_SUBREV_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SUBREV_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_SUBREV_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SUBREV_U16

    class Inst_VOP3__V_MUL_LO_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_LO_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_LO_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_LO_U16

    class Inst_VOP3__V_LSHLREV_B16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LSHLREV_B16(InFmt_VOP3*);
        ~Inst_VOP3__V_LSHLREV_B16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LSHLREV_B16

    class Inst_VOP3__V_LSHRREV_B16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LSHRREV_B16(InFmt_VOP3*);
        ~Inst_VOP3__V_LSHRREV_B16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LSHRREV_B16

    class Inst_VOP3__V_ASHRREV_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ASHRREV_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_ASHRREV_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ASHRREV_I16

    class Inst_VOP3__V_MAX_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX_F16

    class Inst_VOP3__V_MIN_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN_F16

    class Inst_VOP3__V_MAX_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX_U16

    class Inst_VOP3__V_MAX_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX_I16

    class Inst_VOP3__V_MIN_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN_U16

    class Inst_VOP3__V_MIN_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN_I16

    class Inst_VOP3__V_LDEXP_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LDEXP_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_LDEXP_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LDEXP_F16

    class Inst_VOP3__V_NOP : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_NOP(InFmt_VOP3*);
        ~Inst_VOP3__V_NOP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_NOP

    class Inst_VOP3__V_MOV_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MOV_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_MOV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MOV_B32

    class Inst_VOP3__V_CVT_I32_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_I32_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_I32_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_I32_F64

    class Inst_VOP3__V_CVT_F64_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F64_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F64_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F64_I32

    class Inst_VOP3__V_CVT_F32_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F32_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F32_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F32_I32

    class Inst_VOP3__V_CVT_F32_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F32_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F32_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F32_U32

    class Inst_VOP3__V_CVT_U32_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_U32_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_U32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_U32_F32

    class Inst_VOP3__V_CVT_I32_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_I32_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_I32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_I32_F32

    class Inst_VOP3__V_MOV_FED_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MOV_FED_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_MOV_FED_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MOV_FED_B32

    class Inst_VOP3__V_CVT_F16_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F16_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F16_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F16_F32

    class Inst_VOP3__V_CVT_F32_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F32_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F32_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F32_F16

    class Inst_VOP3__V_CVT_RPI_I32_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_RPI_I32_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_RPI_I32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_RPI_I32_F32

    class Inst_VOP3__V_CVT_FLR_I32_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_FLR_I32_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_FLR_I32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_FLR_I32_F32

    class Inst_VOP3__V_CVT_OFF_F32_I4 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_OFF_F32_I4(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_OFF_F32_I4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_OFF_F32_I4

    class Inst_VOP3__V_CVT_F32_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F32_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F32_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F32_F64

    class Inst_VOP3__V_CVT_F64_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F64_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F64_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F64_F32

    class Inst_VOP3__V_CVT_F32_UBYTE0 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F32_UBYTE0(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F32_UBYTE0();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F32_UBYTE0

    class Inst_VOP3__V_CVT_F32_UBYTE1 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F32_UBYTE1(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F32_UBYTE1();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F32_UBYTE1

    class Inst_VOP3__V_CVT_F32_UBYTE2 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F32_UBYTE2(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F32_UBYTE2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F32_UBYTE2

    class Inst_VOP3__V_CVT_F32_UBYTE3 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F32_UBYTE3(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F32_UBYTE3();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F32_UBYTE3

    class Inst_VOP3__V_CVT_U32_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_U32_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_U32_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_U32_F64

    class Inst_VOP3__V_CVT_F64_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F64_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F64_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F64_U32

    class Inst_VOP3__V_TRUNC_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_TRUNC_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_TRUNC_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_TRUNC_F64

    class Inst_VOP3__V_CEIL_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CEIL_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_CEIL_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CEIL_F64

    class Inst_VOP3__V_RNDNE_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RNDNE_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_RNDNE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RNDNE_F64

    class Inst_VOP3__V_FLOOR_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FLOOR_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_FLOOR_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FLOOR_F64

    class Inst_VOP3__V_FRACT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FRACT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_FRACT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FRACT_F32

    class Inst_VOP3__V_TRUNC_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_TRUNC_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_TRUNC_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_TRUNC_F32

    class Inst_VOP3__V_CEIL_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CEIL_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CEIL_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CEIL_F32

    class Inst_VOP3__V_RNDNE_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RNDNE_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_RNDNE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RNDNE_F32

    class Inst_VOP3__V_FLOOR_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FLOOR_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_FLOOR_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FLOOR_F32

    class Inst_VOP3__V_EXP_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_EXP_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_EXP_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_EXP_F32

    class Inst_VOP3__V_LOG_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LOG_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_LOG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LOG_F32

    class Inst_VOP3__V_RCP_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RCP_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_RCP_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RCP_F32

    class Inst_VOP3__V_RCP_IFLAG_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RCP_IFLAG_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_RCP_IFLAG_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RCP_IFLAG_F32

    class Inst_VOP3__V_RSQ_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RSQ_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_RSQ_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RSQ_F32

    class Inst_VOP3__V_RCP_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RCP_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_RCP_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RCP_F64

    class Inst_VOP3__V_RSQ_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RSQ_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_RSQ_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RSQ_F64

    class Inst_VOP3__V_SQRT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SQRT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_SQRT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SQRT_F32

    class Inst_VOP3__V_SQRT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SQRT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_SQRT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SQRT_F64

    class Inst_VOP3__V_SIN_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SIN_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_SIN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SIN_F32

    class Inst_VOP3__V_COS_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_COS_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_COS_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_COS_F32

    class Inst_VOP3__V_NOT_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_NOT_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_NOT_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_NOT_B32

    class Inst_VOP3__V_BFREV_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_BFREV_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_BFREV_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_BFREV_B32

    class Inst_VOP3__V_FFBH_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FFBH_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_FFBH_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FFBH_U32

    class Inst_VOP3__V_FFBL_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FFBL_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_FFBL_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FFBL_B32

    class Inst_VOP3__V_FFBH_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FFBH_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_FFBH_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FFBH_I32

    class Inst_VOP3__V_FREXP_EXP_I32_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FREXP_EXP_I32_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_FREXP_EXP_I32_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FREXP_EXP_I32_F64

    class Inst_VOP3__V_FREXP_MANT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FREXP_MANT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_FREXP_MANT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FREXP_MANT_F64

    class Inst_VOP3__V_FRACT_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FRACT_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_FRACT_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 8;
              case 1: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FRACT_F64

    class Inst_VOP3__V_FREXP_EXP_I32_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FREXP_EXP_I32_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_FREXP_EXP_I32_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FREXP_EXP_I32_F32

    class Inst_VOP3__V_FREXP_MANT_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FREXP_MANT_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_FREXP_MANT_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FREXP_MANT_F32

    class Inst_VOP3__V_CLREXCP : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CLREXCP(InFmt_VOP3*);
        ~Inst_VOP3__V_CLREXCP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CLREXCP

    class Inst_VOP3__V_CVT_F16_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F16_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F16_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F16_U16

    class Inst_VOP3__V_CVT_F16_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_F16_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_F16_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_F16_I16

    class Inst_VOP3__V_CVT_U16_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_U16_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_U16_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_U16_F16

    class Inst_VOP3__V_CVT_I16_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_I16_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_I16_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_I16_F16

    class Inst_VOP3__V_RCP_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RCP_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_RCP_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RCP_F16

    class Inst_VOP3__V_SQRT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SQRT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_SQRT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SQRT_F16

    class Inst_VOP3__V_RSQ_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RSQ_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_RSQ_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RSQ_F16

    class Inst_VOP3__V_LOG_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LOG_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_LOG_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LOG_F16

    class Inst_VOP3__V_EXP_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_EXP_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_EXP_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_EXP_F16

    class Inst_VOP3__V_FREXP_MANT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FREXP_MANT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_FREXP_MANT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FREXP_MANT_F16

    class Inst_VOP3__V_FREXP_EXP_I16_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FREXP_EXP_I16_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_FREXP_EXP_I16_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FREXP_EXP_I16_F16

    class Inst_VOP3__V_FLOOR_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FLOOR_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_FLOOR_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FLOOR_F16

    class Inst_VOP3__V_CEIL_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CEIL_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_CEIL_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CEIL_F16

    class Inst_VOP3__V_TRUNC_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_TRUNC_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_TRUNC_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_TRUNC_F16

    class Inst_VOP3__V_RNDNE_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_RNDNE_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_RNDNE_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_RNDNE_F16

    class Inst_VOP3__V_FRACT_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FRACT_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_FRACT_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FRACT_F16

    class Inst_VOP3__V_SIN_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SIN_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_SIN_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SIN_F16

    class Inst_VOP3__V_COS_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_COS_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_COS_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 2;
              case 1: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_COS_F16

    class Inst_VOP3__V_EXP_LEGACY_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_EXP_LEGACY_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_EXP_LEGACY_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_EXP_LEGACY_F32

    class Inst_VOP3__V_LOG_LEGACY_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LOG_LEGACY_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_LOG_LEGACY_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return 4;
              case 1: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return true;
              case 1: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src
                return false;
              case 1: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LOG_LEGACY_F32

    class Inst_VOP3__V_MAD_LEGACY_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAD_LEGACY_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAD_LEGACY_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_LEGACY_F32

    class Inst_VOP3__V_MAD_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAD_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAD_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_F32

    class Inst_VOP3__V_MAD_I32_I24 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAD_I32_I24(InFmt_VOP3*);
        ~Inst_VOP3__V_MAD_I32_I24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_I32_I24

    class Inst_VOP3__V_MAD_U32_U24 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAD_U32_U24(InFmt_VOP3*);
        ~Inst_VOP3__V_MAD_U32_U24();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_U32_U24

    class Inst_VOP3__V_CUBEID_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CUBEID_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CUBEID_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CUBEID_F32

    class Inst_VOP3__V_CUBESC_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CUBESC_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CUBESC_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CUBESC_F32

    class Inst_VOP3__V_CUBETC_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CUBETC_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CUBETC_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CUBETC_F32

    class Inst_VOP3__V_CUBEMA_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CUBEMA_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CUBEMA_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CUBEMA_F32

    class Inst_VOP3__V_BFE_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_BFE_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_BFE_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_BFE_U32

    class Inst_VOP3__V_BFE_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_BFE_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_BFE_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_BFE_I32

    class Inst_VOP3__V_BFI_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_BFI_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_BFI_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_BFI_B32

    class Inst_VOP3__V_FMA_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FMA_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_FMA_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FMA_F32

    class Inst_VOP3__V_FMA_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FMA_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_FMA_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //src_2
                return 8;
              case 3: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FMA_F64

    class Inst_VOP3__V_LERP_U8 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LERP_U8(InFmt_VOP3*);
        ~Inst_VOP3__V_LERP_U8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LERP_U8

    class Inst_VOP3__V_ALIGNBIT_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ALIGNBIT_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_ALIGNBIT_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ALIGNBIT_B32

    class Inst_VOP3__V_ALIGNBYTE_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ALIGNBYTE_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_ALIGNBYTE_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ALIGNBYTE_B32

    class Inst_VOP3__V_MIN3_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN3_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN3_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN3_F32

    class Inst_VOP3__V_MIN3_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN3_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN3_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN3_I32

    class Inst_VOP3__V_MIN3_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN3_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN3_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN3_U32

    class Inst_VOP3__V_MAX3_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX3_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX3_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX3_F32

    class Inst_VOP3__V_MAX3_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX3_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX3_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX3_I32

    class Inst_VOP3__V_MAX3_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX3_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX3_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX3_U32

    class Inst_VOP3__V_MED3_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MED3_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_MED3_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MED3_F32

    class Inst_VOP3__V_MED3_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MED3_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_MED3_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MED3_I32

    class Inst_VOP3__V_MED3_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MED3_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_MED3_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MED3_U32

    class Inst_VOP3__V_SAD_U8 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SAD_U8(InFmt_VOP3*);
        ~Inst_VOP3__V_SAD_U8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SAD_U8

    class Inst_VOP3__V_SAD_HI_U8 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SAD_HI_U8(InFmt_VOP3*);
        ~Inst_VOP3__V_SAD_HI_U8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SAD_HI_U8

    class Inst_VOP3__V_SAD_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SAD_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_SAD_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SAD_U16

    class Inst_VOP3__V_SAD_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_SAD_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_SAD_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_SAD_U32

    class Inst_VOP3__V_CVT_PK_U8_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_PK_U8_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_PK_U8_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_PK_U8_F32

    class Inst_VOP3__V_DIV_FIXUP_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_DIV_FIXUP_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_DIV_FIXUP_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_DIV_FIXUP_F32

    class Inst_VOP3__V_DIV_FIXUP_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_DIV_FIXUP_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_DIV_FIXUP_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //src_2
                return 8;
              case 3: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_DIV_FIXUP_F64

    class Inst_VOP3__V_DIV_SCALE_F32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_DIV_SCALE_F32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_DIV_SCALE_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              case 4: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              case 4: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              case 4: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_DIV_SCALE_F32

    class Inst_VOP3__V_DIV_SCALE_F64 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_DIV_SCALE_F64(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_DIV_SCALE_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //src_2
                return 8;
              case 3: //vdst
                return 8;
              case 4: //vcc
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              case 4: //vcc
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              case 4: //vcc
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_DIV_SCALE_F64

    class Inst_VOP3__V_DIV_FMAS_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_DIV_FMAS_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_DIV_FMAS_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3:
                return 8;
              case 4: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3:
                return true;
              case 4: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3:
                return false;
              case 4: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_DIV_FMAS_F32

    class Inst_VOP3__V_DIV_FMAS_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_DIV_FMAS_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_DIV_FMAS_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //src_2
                return 8;
              case 3: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_DIV_FMAS_F64

    class Inst_VOP3__V_MSAD_U8 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MSAD_U8(InFmt_VOP3*);
        ~Inst_VOP3__V_MSAD_U8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MSAD_U8

    class Inst_VOP3__V_QSAD_PK_U16_U8 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_QSAD_PK_U16_U8(InFmt_VOP3*);
        ~Inst_VOP3__V_QSAD_PK_U16_U8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 8;
              case 3: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_QSAD_PK_U16_U8

    class Inst_VOP3__V_MQSAD_PK_U16_U8 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MQSAD_PK_U16_U8(InFmt_VOP3*);
        ~Inst_VOP3__V_MQSAD_PK_U16_U8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 8;
              case 3: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MQSAD_PK_U16_U8

    class Inst_VOP3__V_MQSAD_U32_U8 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MQSAD_U32_U8(InFmt_VOP3*);
        ~Inst_VOP3__V_MQSAD_U32_U8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 16;
              case 3: //vdst
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MQSAD_U32_U8

    class Inst_VOP3__V_MAD_U64_U32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_MAD_U64_U32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_MAD_U64_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              case 4: //carryout
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              case 4: //carryout
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              case 4: //carryout
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_U64_U32

    class Inst_VOP3__V_MAD_I64_I32 : public Inst_VOP3_SDST_ENC
    {
      public:
        Inst_VOP3__V_MAD_I64_I32(InFmt_VOP3_SDST_ENC*);
        ~Inst_VOP3__V_MAD_I64_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 2; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              case 4: //carryout
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              case 4: //carryout
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              case 4: //carryout
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_I64_I32

    class Inst_VOP3__V_MAD_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAD_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_MAD_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //src_2
                return 2;
              case 3: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_F16

    class Inst_VOP3__V_MAD_U16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAD_U16(InFmt_VOP3*);
        ~Inst_VOP3__V_MAD_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //src_2
                return 2;
              case 3: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_U16

    class Inst_VOP3__V_MAD_I16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAD_I16(InFmt_VOP3*);
        ~Inst_VOP3__V_MAD_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //src_2
                return 2;
              case 3: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAD_I16

    class Inst_VOP3__V_PERM_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_PERM_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_PERM_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //src_2
                return 4;
              case 3: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        // From the GCN3 ISA SPEC:
        // byte permute(byte in[8], byte sel) {
        //     if (sel>=13) then return 0xff;
        //     elsif (sel==12) then return 0x00;
        //     elsif (sel==11) then return in[7][7] * 0xff;
        //     elsif (sel==10) then return in[5][7] * 0xff;
        //     elsif (sel==9) then return in[3][7] * 0xff;
        //     elsif (sel==8) then return in[1][7] * 0xff;
        //     else return in[sel];
        //     }
        // NOTE: I interpret the in[x][7] notation to mean "the high order
        // bit of byte x".
        uint8_t
        permute(uint64_t in_dword2x, uint32_t sel)
        {
            assert (sel < 256);
            uint8_t *in = reinterpret_cast<uint8_t*>(&in_dword2x);
            DPRINTF(GCN3, "in_dword2x = 0x%08x\n", in_dword2x);
            DPRINTF(GCN3, "Selecting %x using index %d\n", in[sel], sel);
            if (sel >= 13) return 0xFF;
            else if (sel == 12) return 0;
            else if (sel == 11) return (in[7] & 0x80) ? 0xFF : 0;
            else if (sel == 10) return (in[5] & 0x80) ? 0xFF : 0;
            else if (sel == 9) return (in[3] & 0x80) ? 0xFF : 0;
            else if (sel == 8) return (in[1] & 0x80) ? 0xFF : 0;
            else return in[sel];
        }

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_PERM_B32

    class Inst_VOP3__V_FMA_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_FMA_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_FMA_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //src_2
                return 2;
              case 3: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_FMA_F16

    class Inst_VOP3__V_DIV_FIXUP_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_DIV_FIXUP_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_DIV_FIXUP_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 2;
              case 1: //src_1
                return 2;
              case 2: //src_2
                return 2;
              case 3: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //src_2
                return true;
              case 3: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //src_2
                return false;
              case 3: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_DIV_FIXUP_F16

    class Inst_VOP3__V_CVT_PKACCUM_U8_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_PKACCUM_U8_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_PKACCUM_U8_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_PKACCUM_U8_F32

    class Inst_VOP3__V_INTERP_P1_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_INTERP_P1_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_INTERP_P1_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return 4;
              case 1: //attr
                return 32;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_INTERP_P1_F32

    class Inst_VOP3__V_INTERP_P2_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_INTERP_P2_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_INTERP_P2_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return 4;
              case 1: //attr
                return 32;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_INTERP_P2_F32

    class Inst_VOP3__V_INTERP_MOV_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_INTERP_MOV_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_INTERP_MOV_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //param
                return 4;
              case 1: //attr
                return 32;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //param
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //param
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_INTERP_MOV_F32

    class Inst_VOP3__V_INTERP_P1LL_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_INTERP_P1LL_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_INTERP_P1LL_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return 4;
              case 1: //attr
                return 2;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_INTERP_P1LL_F16

    class Inst_VOP3__V_INTERP_P1LV_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_INTERP_P1LV_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_INTERP_P1LV_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return 4;
              case 1: //attr
                return 2;
              case 2: //vgpr_add
                return 2;
              case 3: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_add
                return true;
              case 3: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_add
                return false;
              case 3: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_INTERP_P1LV_F16

    class Inst_VOP3__V_INTERP_P2_F16 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_INTERP_P2_F16(InFmt_VOP3*);
        ~Inst_VOP3__V_INTERP_P2_F16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return 4;
              case 1: //attr
                return 2;
              case 2: //vgpr_add
                return 4;
              case 3: //vgpr_dst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return true;
              case 1: //attr
                return true;
              case 2: //vgpr_add
                return true;
              case 3: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_ij
                return false;
              case 1: //attr
                return false;
              case 2: //vgpr_add
                return false;
              case 3: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_INTERP_P2_F16

    class Inst_VOP3__V_ADD_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ADD_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_ADD_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ADD_F64

    class Inst_VOP3__V_MUL_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_F64

    class Inst_VOP3__V_MIN_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MIN_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_MIN_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MIN_F64

    class Inst_VOP3__V_MAX_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MAX_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_MAX_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 8;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MAX_F64

    class Inst_VOP3__V_LDEXP_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LDEXP_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_LDEXP_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LDEXP_F64

    class Inst_VOP3__V_MUL_LO_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_LO_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_LO_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_LO_U32

    class Inst_VOP3__V_MUL_HI_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_HI_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_HI_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_HI_U32

    class Inst_VOP3__V_MUL_HI_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MUL_HI_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_MUL_HI_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MUL_HI_I32

    class Inst_VOP3__V_LDEXP_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LDEXP_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_LDEXP_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LDEXP_F32

    class Inst_VOP3__V_READLANE_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_READLANE_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_READLANE_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vsrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //sdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vsrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //sdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vsrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //sdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_READLANE_B32

    class Inst_VOP3__V_WRITELANE_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_WRITELANE_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_WRITELANE_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return 4;
              case 1: //ssrc_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return true;
              case 1: //ssrc_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //ssrc_0
                return false;
              case 1: //ssrc_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_WRITELANE_B32

    class Inst_VOP3__V_BCNT_U32_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_BCNT_U32_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_BCNT_U32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_BCNT_U32_B32

    class Inst_VOP3__V_MBCNT_LO_U32_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MBCNT_LO_U32_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_MBCNT_LO_U32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MBCNT_LO_U32_B32

    class Inst_VOP3__V_MBCNT_HI_U32_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_MBCNT_HI_U32_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_MBCNT_HI_U32_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_MBCNT_HI_U32_B32

    class Inst_VOP3__V_LSHLREV_B64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LSHLREV_B64(InFmt_VOP3*);
        ~Inst_VOP3__V_LSHLREV_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 8;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LSHLREV_B64

    class Inst_VOP3__V_LSHRREV_B64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_LSHRREV_B64(InFmt_VOP3*);
        ~Inst_VOP3__V_LSHRREV_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 8;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_LSHRREV_B64

    class Inst_VOP3__V_ASHRREV_I64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_ASHRREV_I64(InFmt_VOP3*);
        ~Inst_VOP3__V_ASHRREV_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 8;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_ASHRREV_I64

    class Inst_VOP3__V_TRIG_PREOP_F64 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_TRIG_PREOP_F64(InFmt_VOP3*);
        ~Inst_VOP3__V_TRIG_PREOP_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 8;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_TRIG_PREOP_F64

    class Inst_VOP3__V_BFM_B32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_BFM_B32(InFmt_VOP3*);
        ~Inst_VOP3__V_BFM_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_BFM_B32

    class Inst_VOP3__V_CVT_PKNORM_I16_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_PKNORM_I16_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_PKNORM_I16_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_PKNORM_I16_F32

    class Inst_VOP3__V_CVT_PKNORM_U16_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_PKNORM_U16_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_PKNORM_U16_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_PKNORM_U16_F32

    class Inst_VOP3__V_CVT_PKRTZ_F16_F32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_PKRTZ_F16_F32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_PKRTZ_F16_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_PKRTZ_F16_F32

    class Inst_VOP3__V_CVT_PK_U16_U32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_PK_U16_U32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_PK_U16_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_PK_U16_U32

    class Inst_VOP3__V_CVT_PK_I16_I32 : public Inst_VOP3
    {
      public:
        Inst_VOP3__V_CVT_PK_I16_I32(InFmt_VOP3*);
        ~Inst_VOP3__V_CVT_PK_I16_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return 4;
              case 1: //src_1
                return 4;
              case 2: //vdst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return true;
              case 1: //src_1
                return true;
              case 2: //vdst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //src_0
                return false;
              case 1: //src_1
                return false;
              case 2: //vdst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_VOP3__V_CVT_PK_I16_I32

    class Inst_DS__DS_ADD_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_U32(InFmt_DS*);
        ~Inst_DS__DS_ADD_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_U32

    class Inst_DS__DS_SUB_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_SUB_U32(InFmt_DS*);
        ~Inst_DS__DS_SUB_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_SUB_U32

    class Inst_DS__DS_RSUB_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_RSUB_U32(InFmt_DS*);
        ~Inst_DS__DS_RSUB_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_RSUB_U32

    class Inst_DS__DS_INC_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_INC_U32(InFmt_DS*);
        ~Inst_DS__DS_INC_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_INC_U32

    class Inst_DS__DS_DEC_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_DEC_U32(InFmt_DS*);
        ~Inst_DS__DS_DEC_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_DEC_U32

    class Inst_DS__DS_MIN_I32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_I32(InFmt_DS*);
        ~Inst_DS__DS_MIN_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_I32

    class Inst_DS__DS_MAX_I32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_I32(InFmt_DS*);
        ~Inst_DS__DS_MAX_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_I32

    class Inst_DS__DS_MIN_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_U32(InFmt_DS*);
        ~Inst_DS__DS_MIN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_U32

    class Inst_DS__DS_MAX_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_U32(InFmt_DS*);
        ~Inst_DS__DS_MAX_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_U32

    class Inst_DS__DS_AND_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_AND_B32(InFmt_DS*);
        ~Inst_DS__DS_AND_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_AND_B32

    class Inst_DS__DS_OR_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_OR_B32(InFmt_DS*);
        ~Inst_DS__DS_OR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_OR_B32

    class Inst_DS__DS_XOR_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_XOR_B32(InFmt_DS*);
        ~Inst_DS__DS_XOR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_XOR_B32

    class Inst_DS__DS_MSKOR_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MSKOR_B32(InFmt_DS*);
        ~Inst_DS__DS_MSKOR_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MSKOR_B32

    class Inst_DS__DS_WRITE_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE_B32(InFmt_DS*);
        ~Inst_DS__DS_WRITE_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE_B32

    class Inst_DS__DS_WRITE2_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE2_B32(InFmt_DS*);
        ~Inst_DS__DS_WRITE2_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_d1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE2_B32

    class Inst_DS__DS_WRITE2ST64_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE2ST64_B32(InFmt_DS*);
        ~Inst_DS__DS_WRITE2ST64_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_d1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE2ST64_B32

    class Inst_DS__DS_CMPST_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_CMPST_B32(InFmt_DS*);
        ~Inst_DS__DS_CMPST_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CMPST_B32

    class Inst_DS__DS_CMPST_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_CMPST_F32(InFmt_DS*);
        ~Inst_DS__DS_CMPST_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CMPST_F32

    class Inst_DS__DS_MIN_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_F32(InFmt_DS*);
        ~Inst_DS__DS_MIN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_F32

    class Inst_DS__DS_MAX_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_F32(InFmt_DS*);
        ~Inst_DS__DS_MAX_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_F32

    class Inst_DS__DS_NOP : public Inst_DS
    {
      public:
        Inst_DS__DS_NOP(InFmt_DS*);
        ~Inst_DS__DS_NOP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_NOP

    class Inst_DS__DS_ADD_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_F32(InFmt_DS*);
        ~Inst_DS__DS_ADD_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_F32

    class Inst_DS__DS_WRITE_B8 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE_B8(InFmt_DS*);
        ~Inst_DS__DS_WRITE_B8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 1;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE_B8

    class Inst_DS__DS_WRITE_B16 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE_B16(InFmt_DS*);
        ~Inst_DS__DS_WRITE_B16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE_B16

    class Inst_DS__DS_ADD_RTN_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_RTN_U32(InFmt_DS*);
        ~Inst_DS__DS_ADD_RTN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_RTN_U32

    class Inst_DS__DS_SUB_RTN_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_SUB_RTN_U32(InFmt_DS*);
        ~Inst_DS__DS_SUB_RTN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_SUB_RTN_U32

    class Inst_DS__DS_RSUB_RTN_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_RSUB_RTN_U32(InFmt_DS*);
        ~Inst_DS__DS_RSUB_RTN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_RSUB_RTN_U32

    class Inst_DS__DS_INC_RTN_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_INC_RTN_U32(InFmt_DS*);
        ~Inst_DS__DS_INC_RTN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_INC_RTN_U32

    class Inst_DS__DS_DEC_RTN_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_DEC_RTN_U32(InFmt_DS*);
        ~Inst_DS__DS_DEC_RTN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_DEC_RTN_U32

    class Inst_DS__DS_MIN_RTN_I32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_RTN_I32(InFmt_DS*);
        ~Inst_DS__DS_MIN_RTN_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_RTN_I32

    class Inst_DS__DS_MAX_RTN_I32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_RTN_I32(InFmt_DS*);
        ~Inst_DS__DS_MAX_RTN_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_RTN_I32

    class Inst_DS__DS_MIN_RTN_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_RTN_U32(InFmt_DS*);
        ~Inst_DS__DS_MIN_RTN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_RTN_U32

    class Inst_DS__DS_MAX_RTN_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_RTN_U32(InFmt_DS*);
        ~Inst_DS__DS_MAX_RTN_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_RTN_U32

    class Inst_DS__DS_AND_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_AND_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_AND_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_AND_RTN_B32

    class Inst_DS__DS_OR_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_OR_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_OR_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_OR_RTN_B32

    class Inst_DS__DS_XOR_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_XOR_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_XOR_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_XOR_RTN_B32

    class Inst_DS__DS_MSKOR_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MSKOR_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_MSKOR_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MSKOR_RTN_B32

    class Inst_DS__DS_WRXCHG_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRXCHG_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_WRXCHG_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRXCHG_RTN_B32

    class Inst_DS__DS_WRXCHG2_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRXCHG2_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_WRXCHG2_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRXCHG2_RTN_B32

    class Inst_DS__DS_WRXCHG2ST64_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRXCHG2ST64_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_WRXCHG2ST64_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRXCHG2ST64_RTN_B32

    class Inst_DS__DS_CMPST_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_CMPST_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_CMPST_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CMPST_RTN_B32

    class Inst_DS__DS_CMPST_RTN_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_CMPST_RTN_F32(InFmt_DS*);
        ~Inst_DS__DS_CMPST_RTN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CMPST_RTN_F32

    class Inst_DS__DS_MIN_RTN_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_RTN_F32(InFmt_DS*);
        ~Inst_DS__DS_MIN_RTN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_RTN_F32

    class Inst_DS__DS_MAX_RTN_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_RTN_F32(InFmt_DS*);
        ~Inst_DS__DS_MAX_RTN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_RTN_F32

    class Inst_DS__DS_WRAP_RTN_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRAP_RTN_B32(InFmt_DS*);
        ~Inst_DS__DS_WRAP_RTN_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRAP_RTN_B32

    class Inst_DS__DS_ADD_RTN_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_RTN_F32(InFmt_DS*);
        ~Inst_DS__DS_ADD_RTN_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_RTN_F32

    class Inst_DS__DS_READ_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ_B32(InFmt_DS*);
        ~Inst_DS__DS_READ_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ_B32

    class Inst_DS__DS_READ2_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ2_B32(InFmt_DS*);
        ~Inst_DS__DS_READ2_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ2_B32

    class Inst_DS__DS_READ2ST64_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ2ST64_B32(InFmt_DS*);
        ~Inst_DS__DS_READ2ST64_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ2ST64_B32

    class Inst_DS__DS_READ_I8 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ_I8(InFmt_DS*);
        ~Inst_DS__DS_READ_I8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 1;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ_I8

    class Inst_DS__DS_READ_U8 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ_U8(InFmt_DS*);
        ~Inst_DS__DS_READ_U8();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 1;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ_U8

    class Inst_DS__DS_READ_I16 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ_I16(InFmt_DS*);
        ~Inst_DS__DS_READ_I16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ_I16

    class Inst_DS__DS_READ_U16 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ_U16(InFmt_DS*);
        ~Inst_DS__DS_READ_U16();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ_U16

    class Inst_DS__DS_SWIZZLE_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_SWIZZLE_B32(InFmt_DS*);
        ~Inst_DS__DS_SWIZZLE_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_SWIZZLE_B32

    class Inst_DS__DS_PERMUTE_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_PERMUTE_B32(InFmt_DS*);
        ~Inst_DS__DS_PERMUTE_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_PERMUTE_B32

    class Inst_DS__DS_BPERMUTE_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_BPERMUTE_B32(InFmt_DS*);
        ~Inst_DS__DS_BPERMUTE_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 4;
              case 2: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_BPERMUTE_B32

    class Inst_DS__DS_ADD_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_U64(InFmt_DS*);
        ~Inst_DS__DS_ADD_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_U64

    class Inst_DS__DS_SUB_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_SUB_U64(InFmt_DS*);
        ~Inst_DS__DS_SUB_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_SUB_U64

    class Inst_DS__DS_RSUB_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_RSUB_U64(InFmt_DS*);
        ~Inst_DS__DS_RSUB_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_RSUB_U64

    class Inst_DS__DS_INC_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_INC_U64(InFmt_DS*);
        ~Inst_DS__DS_INC_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_INC_U64

    class Inst_DS__DS_DEC_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_DEC_U64(InFmt_DS*);
        ~Inst_DS__DS_DEC_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_DEC_U64

    class Inst_DS__DS_MIN_I64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_I64(InFmt_DS*);
        ~Inst_DS__DS_MIN_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_I64

    class Inst_DS__DS_MAX_I64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_I64(InFmt_DS*);
        ~Inst_DS__DS_MAX_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_I64

    class Inst_DS__DS_MIN_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_U64(InFmt_DS*);
        ~Inst_DS__DS_MIN_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_U64

    class Inst_DS__DS_MAX_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_U64(InFmt_DS*);
        ~Inst_DS__DS_MAX_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_U64

    class Inst_DS__DS_AND_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_AND_B64(InFmt_DS*);
        ~Inst_DS__DS_AND_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_AND_B64

    class Inst_DS__DS_OR_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_OR_B64(InFmt_DS*);
        ~Inst_DS__DS_OR_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_OR_B64

    class Inst_DS__DS_XOR_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_XOR_B64(InFmt_DS*);
        ~Inst_DS__DS_XOR_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_XOR_B64

    class Inst_DS__DS_MSKOR_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MSKOR_B64(InFmt_DS*);
        ~Inst_DS__DS_MSKOR_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MSKOR_B64

    class Inst_DS__DS_WRITE_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE_B64(InFmt_DS*);
        ~Inst_DS__DS_WRITE_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE_B64

    class Inst_DS__DS_WRITE2_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE2_B64(InFmt_DS*);
        ~Inst_DS__DS_WRITE2_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_d1
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE2_B64

    class Inst_DS__DS_WRITE2ST64_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE2ST64_B64(InFmt_DS*);
        ~Inst_DS__DS_WRITE2ST64_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE2ST64_B64

    class Inst_DS__DS_CMPST_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_CMPST_B64(InFmt_DS*);
        ~Inst_DS__DS_CMPST_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CMPST_B64

    class Inst_DS__DS_CMPST_F64 : public Inst_DS
    {
      public:
        Inst_DS__DS_CMPST_F64(InFmt_DS*);
        ~Inst_DS__DS_CMPST_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CMPST_F64

    class Inst_DS__DS_MIN_F64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_F64(InFmt_DS*);
        ~Inst_DS__DS_MIN_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_F64

    class Inst_DS__DS_MAX_F64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_F64(InFmt_DS*);
        ~Inst_DS__DS_MAX_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_F64

    class Inst_DS__DS_ADD_RTN_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_RTN_U64(InFmt_DS*);
        ~Inst_DS__DS_ADD_RTN_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_RTN_U64

    class Inst_DS__DS_SUB_RTN_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_SUB_RTN_U64(InFmt_DS*);
        ~Inst_DS__DS_SUB_RTN_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_SUB_RTN_U64

    class Inst_DS__DS_RSUB_RTN_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_RSUB_RTN_U64(InFmt_DS*);
        ~Inst_DS__DS_RSUB_RTN_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_RSUB_RTN_U64

    class Inst_DS__DS_INC_RTN_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_INC_RTN_U64(InFmt_DS*);
        ~Inst_DS__DS_INC_RTN_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_INC_RTN_U64

    class Inst_DS__DS_DEC_RTN_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_DEC_RTN_U64(InFmt_DS*);
        ~Inst_DS__DS_DEC_RTN_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_DEC_RTN_U64

    class Inst_DS__DS_MIN_RTN_I64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_RTN_I64(InFmt_DS*);
        ~Inst_DS__DS_MIN_RTN_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_RTN_I64

    class Inst_DS__DS_MAX_RTN_I64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_RTN_I64(InFmt_DS*);
        ~Inst_DS__DS_MAX_RTN_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_RTN_I64

    class Inst_DS__DS_MIN_RTN_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_RTN_U64(InFmt_DS*);
        ~Inst_DS__DS_MIN_RTN_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_RTN_U64

    class Inst_DS__DS_MAX_RTN_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_RTN_U64(InFmt_DS*);
        ~Inst_DS__DS_MAX_RTN_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_RTN_U64

    class Inst_DS__DS_AND_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_AND_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_AND_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_AND_RTN_B64

    class Inst_DS__DS_OR_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_OR_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_OR_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_OR_RTN_B64

    class Inst_DS__DS_XOR_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_XOR_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_XOR_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_XOR_RTN_B64

    class Inst_DS__DS_MSKOR_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MSKOR_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_MSKOR_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MSKOR_RTN_B64

    class Inst_DS__DS_WRXCHG_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRXCHG_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_WRXCHG_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRXCHG_RTN_B64

    class Inst_DS__DS_WRXCHG2_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRXCHG2_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_WRXCHG2_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRXCHG2_RTN_B64

    class Inst_DS__DS_WRXCHG2ST64_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRXCHG2ST64_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_WRXCHG2ST64_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRXCHG2ST64_RTN_B64

    class Inst_DS__DS_CMPST_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_CMPST_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_CMPST_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CMPST_RTN_B64

    class Inst_DS__DS_CMPST_RTN_F64 : public Inst_DS
    {
      public:
        Inst_DS__DS_CMPST_RTN_F64(InFmt_DS*);
        ~Inst_DS__DS_CMPST_RTN_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d1
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d1
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d1
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CMPST_RTN_F64

    class Inst_DS__DS_MIN_RTN_F64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_RTN_F64(InFmt_DS*);
        ~Inst_DS__DS_MIN_RTN_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_RTN_F64

    class Inst_DS__DS_MAX_RTN_F64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_RTN_F64(InFmt_DS*);
        ~Inst_DS__DS_MAX_RTN_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_RTN_F64

    class Inst_DS__DS_READ_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ_B64(InFmt_DS*);
        ~Inst_DS__DS_READ_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ_B64

    class Inst_DS__DS_READ2_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ2_B64(InFmt_DS*);
        ~Inst_DS__DS_READ2_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ2_B64

    class Inst_DS__DS_READ2ST64_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ2ST64_B64(InFmt_DS*);
        ~Inst_DS__DS_READ2ST64_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ2ST64_B64

    class Inst_DS__DS_CONDXCHG32_RTN_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_CONDXCHG32_RTN_B64(InFmt_DS*);
        ~Inst_DS__DS_CONDXCHG32_RTN_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 8;
              case 2: //vgpr_rtn
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              case 2: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              case 2: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CONDXCHG32_RTN_B64

    class Inst_DS__DS_ADD_SRC2_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_SRC2_U32(InFmt_DS*);
        ~Inst_DS__DS_ADD_SRC2_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_SRC2_U32

    class Inst_DS__DS_SUB_SRC2_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_SUB_SRC2_U32(InFmt_DS*);
        ~Inst_DS__DS_SUB_SRC2_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_SUB_SRC2_U32

    class Inst_DS__DS_RSUB_SRC2_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_RSUB_SRC2_U32(InFmt_DS*);
        ~Inst_DS__DS_RSUB_SRC2_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_RSUB_SRC2_U32

    class Inst_DS__DS_INC_SRC2_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_INC_SRC2_U32(InFmt_DS*);
        ~Inst_DS__DS_INC_SRC2_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_INC_SRC2_U32

    class Inst_DS__DS_DEC_SRC2_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_DEC_SRC2_U32(InFmt_DS*);
        ~Inst_DS__DS_DEC_SRC2_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_DEC_SRC2_U32

    class Inst_DS__DS_MIN_SRC2_I32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_SRC2_I32(InFmt_DS*);
        ~Inst_DS__DS_MIN_SRC2_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_SRC2_I32

    class Inst_DS__DS_MAX_SRC2_I32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_SRC2_I32(InFmt_DS*);
        ~Inst_DS__DS_MAX_SRC2_I32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_SRC2_I32

    class Inst_DS__DS_MIN_SRC2_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_SRC2_U32(InFmt_DS*);
        ~Inst_DS__DS_MIN_SRC2_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_SRC2_U32

    class Inst_DS__DS_MAX_SRC2_U32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_SRC2_U32(InFmt_DS*);
        ~Inst_DS__DS_MAX_SRC2_U32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_SRC2_U32

    class Inst_DS__DS_AND_SRC2_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_AND_SRC2_B32(InFmt_DS*);
        ~Inst_DS__DS_AND_SRC2_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_AND_SRC2_B32

    class Inst_DS__DS_OR_SRC2_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_OR_SRC2_B32(InFmt_DS*);
        ~Inst_DS__DS_OR_SRC2_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_OR_SRC2_B32

    class Inst_DS__DS_XOR_SRC2_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_XOR_SRC2_B32(InFmt_DS*);
        ~Inst_DS__DS_XOR_SRC2_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_XOR_SRC2_B32

    class Inst_DS__DS_WRITE_SRC2_B32 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE_SRC2_B32(InFmt_DS*);
        ~Inst_DS__DS_WRITE_SRC2_B32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE_SRC2_B32

    class Inst_DS__DS_MIN_SRC2_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_SRC2_F32(InFmt_DS*);
        ~Inst_DS__DS_MIN_SRC2_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_SRC2_F32

    class Inst_DS__DS_MAX_SRC2_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_SRC2_F32(InFmt_DS*);
        ~Inst_DS__DS_MAX_SRC2_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_SRC2_F32

    class Inst_DS__DS_ADD_SRC2_F32 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_SRC2_F32(InFmt_DS*);
        ~Inst_DS__DS_ADD_SRC2_F32();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_SRC2_F32

    class Inst_DS__DS_GWS_SEMA_RELEASE_ALL : public Inst_DS
    {
      public:
        Inst_DS__DS_GWS_SEMA_RELEASE_ALL(InFmt_DS*);
        ~Inst_DS__DS_GWS_SEMA_RELEASE_ALL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_GWS_SEMA_RELEASE_ALL

    class Inst_DS__DS_GWS_INIT : public Inst_DS
    {
      public:
        Inst_DS__DS_GWS_INIT(InFmt_DS*);
        ~Inst_DS__DS_GWS_INIT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_GWS_INIT

    class Inst_DS__DS_GWS_SEMA_V : public Inst_DS
    {
      public:
        Inst_DS__DS_GWS_SEMA_V(InFmt_DS*);
        ~Inst_DS__DS_GWS_SEMA_V();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_GWS_SEMA_V

    class Inst_DS__DS_GWS_SEMA_BR : public Inst_DS
    {
      public:
        Inst_DS__DS_GWS_SEMA_BR(InFmt_DS*);
        ~Inst_DS__DS_GWS_SEMA_BR();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_GWS_SEMA_BR

    class Inst_DS__DS_GWS_SEMA_P : public Inst_DS
    {
      public:
        Inst_DS__DS_GWS_SEMA_P(InFmt_DS*);
        ~Inst_DS__DS_GWS_SEMA_P();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_GWS_SEMA_P

    class Inst_DS__DS_GWS_BARRIER : public Inst_DS
    {
      public:
        Inst_DS__DS_GWS_BARRIER(InFmt_DS*);
        ~Inst_DS__DS_GWS_BARRIER();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return 4;
              case 1: //vgpr_d0
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d0
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_GWS_BARRIER

    class Inst_DS__DS_CONSUME : public Inst_DS
    {
      public:
        Inst_DS__DS_CONSUME(InFmt_DS*);
        ~Inst_DS__DS_CONSUME();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_CONSUME

    class Inst_DS__DS_APPEND : public Inst_DS
    {
      public:
        Inst_DS__DS_APPEND(InFmt_DS*);
        ~Inst_DS__DS_APPEND();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_APPEND

    class Inst_DS__DS_ORDERED_COUNT : public Inst_DS
    {
      public:
        Inst_DS__DS_ORDERED_COUNT(InFmt_DS*);
        ~Inst_DS__DS_ORDERED_COUNT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ORDERED_COUNT

    class Inst_DS__DS_ADD_SRC2_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_ADD_SRC2_U64(InFmt_DS*);
        ~Inst_DS__DS_ADD_SRC2_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_ADD_SRC2_U64

    class Inst_DS__DS_SUB_SRC2_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_SUB_SRC2_U64(InFmt_DS*);
        ~Inst_DS__DS_SUB_SRC2_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_SUB_SRC2_U64

    class Inst_DS__DS_RSUB_SRC2_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_RSUB_SRC2_U64(InFmt_DS*);
        ~Inst_DS__DS_RSUB_SRC2_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_RSUB_SRC2_U64

    class Inst_DS__DS_INC_SRC2_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_INC_SRC2_U64(InFmt_DS*);
        ~Inst_DS__DS_INC_SRC2_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_INC_SRC2_U64

    class Inst_DS__DS_DEC_SRC2_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_DEC_SRC2_U64(InFmt_DS*);
        ~Inst_DS__DS_DEC_SRC2_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_DEC_SRC2_U64

    class Inst_DS__DS_MIN_SRC2_I64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_SRC2_I64(InFmt_DS*);
        ~Inst_DS__DS_MIN_SRC2_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_SRC2_I64

    class Inst_DS__DS_MAX_SRC2_I64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_SRC2_I64(InFmt_DS*);
        ~Inst_DS__DS_MAX_SRC2_I64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_SRC2_I64

    class Inst_DS__DS_MIN_SRC2_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_SRC2_U64(InFmt_DS*);
        ~Inst_DS__DS_MIN_SRC2_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_SRC2_U64

    class Inst_DS__DS_MAX_SRC2_U64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_SRC2_U64(InFmt_DS*);
        ~Inst_DS__DS_MAX_SRC2_U64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_SRC2_U64

    class Inst_DS__DS_AND_SRC2_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_AND_SRC2_B64(InFmt_DS*);
        ~Inst_DS__DS_AND_SRC2_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_AND_SRC2_B64

    class Inst_DS__DS_OR_SRC2_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_OR_SRC2_B64(InFmt_DS*);
        ~Inst_DS__DS_OR_SRC2_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_OR_SRC2_B64

    class Inst_DS__DS_XOR_SRC2_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_XOR_SRC2_B64(InFmt_DS*);
        ~Inst_DS__DS_XOR_SRC2_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_XOR_SRC2_B64

    class Inst_DS__DS_WRITE_SRC2_B64 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE_SRC2_B64(InFmt_DS*);
        ~Inst_DS__DS_WRITE_SRC2_B64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE_SRC2_B64

    class Inst_DS__DS_MIN_SRC2_F64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MIN_SRC2_F64(InFmt_DS*);
        ~Inst_DS__DS_MIN_SRC2_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MIN_SRC2_F64

    class Inst_DS__DS_MAX_SRC2_F64 : public Inst_DS
    {
      public:
        Inst_DS__DS_MAX_SRC2_F64(InFmt_DS*);
        ~Inst_DS__DS_MAX_SRC2_F64();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_MAX_SRC2_F64

    class Inst_DS__DS_WRITE_B96 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE_B96(InFmt_DS*);
        ~Inst_DS__DS_WRITE_B96();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE_B96

    class Inst_DS__DS_WRITE_B128 : public Inst_DS
    {
      public:
        Inst_DS__DS_WRITE_B128(InFmt_DS*);
        ~Inst_DS__DS_WRITE_B128();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_d0
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_d0
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_d0
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_WRITE_B128

    class Inst_DS__DS_READ_B96 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ_B96(InFmt_DS*);
        ~Inst_DS__DS_READ_B96();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ_B96

    class Inst_DS__DS_READ_B128 : public Inst_DS
    {
      public:
        Inst_DS__DS_READ_B128(InFmt_DS*);
        ~Inst_DS__DS_READ_B128();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //vgpr_rtn
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //vgpr_rtn
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //vgpr_rtn
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_DS__DS_READ_B128

    class Inst_MUBUF__BUFFER_LOAD_FORMAT_X : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_FORMAT_X(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_FORMAT_X();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_FORMAT_X

    class Inst_MUBUF__BUFFER_LOAD_FORMAT_XY : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_FORMAT_XY(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_FORMAT_XY();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_FORMAT_XY

    class Inst_MUBUF__BUFFER_LOAD_FORMAT_XYZ : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_FORMAT_XYZ(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_FORMAT_XYZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_FORMAT_XYZ

    class Inst_MUBUF__BUFFER_LOAD_FORMAT_XYZW : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_FORMAT_XYZW(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_FORMAT_XYZW();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_FORMAT_XYZW

    class Inst_MUBUF__BUFFER_STORE_FORMAT_X : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_FORMAT_X(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_FORMAT_X();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 4;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_FORMAT_X

    class Inst_MUBUF__BUFFER_STORE_FORMAT_XY : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_FORMAT_XY(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_FORMAT_XY();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 8;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_FORMAT_XY

    class Inst_MUBUF__BUFFER_STORE_FORMAT_XYZ : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_FORMAT_XYZ(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_FORMAT_XYZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 12;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_FORMAT_XYZ

    class Inst_MUBUF__BUFFER_STORE_FORMAT_XYZW : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_FORMAT_XYZW(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_FORMAT_XYZW();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 16;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_FORMAT_XYZW

    class Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_X : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_X(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_X();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_X

    class Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XY : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XY(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XY();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XY

    class Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XYZ : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XYZ(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XYZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XYZ

    class Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XYZW : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XYZW(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XYZW();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_FORMAT_D16_XYZW

    class Inst_MUBUF__BUFFER_STORE_FORMAT_D16_X : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_FORMAT_D16_X(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_FORMAT_D16_X();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 4;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_FORMAT_D16_X

    class Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XY : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XY(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XY();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 8;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XY

    class Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XYZ : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XYZ(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XYZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 12;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XYZ

    class Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XYZW : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XYZW(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XYZW();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 16;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_FORMAT_D16_XYZW

    class Inst_MUBUF__BUFFER_LOAD_UBYTE : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_UBYTE(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_UBYTE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 4;
              case 1: //vgpr_a
                if (instData.OFFEN && instData.IDXEN) {
                    // if we need an idx and offset from a
                    // VGPR, we'll read VGPR[VADDR] and
                    // VGPR[VADDR + 1], otherwise we just
                    // read VGPR[VADDR]
                    return 8;
                } else {
                    return 4;
                }
              case 2: //sgpr_r
                return 16;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_UBYTE

    class Inst_MUBUF__BUFFER_LOAD_SBYTE : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_SBYTE(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_SBYTE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_SBYTE

    class Inst_MUBUF__BUFFER_LOAD_USHORT : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_USHORT(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_USHORT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_USHORT

    class Inst_MUBUF__BUFFER_LOAD_SSHORT : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_SSHORT(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_SSHORT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_SSHORT

    class Inst_MUBUF__BUFFER_LOAD_DWORD : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_DWORD(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_DWORD

    class Inst_MUBUF__BUFFER_LOAD_DWORDX2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_DWORDX2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_DWORDX2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_DWORDX2

    class Inst_MUBUF__BUFFER_LOAD_DWORDX3 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_DWORDX3(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_DWORDX3();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_DWORDX3

    class Inst_MUBUF__BUFFER_LOAD_DWORDX4 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_LOAD_DWORDX4(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_LOAD_DWORDX4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_LOAD_DWORDX4

    class Inst_MUBUF__BUFFER_STORE_BYTE : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_BYTE(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_BYTE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 4;
              case 1: //vgpr_a
                if (instData.OFFEN && instData.IDXEN) {
                    // if we need an idx and offset from a
                    // VGPR, we'll read VGPR[VADDR] and
                    // VGPR[VADDR + 1], otherwise we just
                    // read VGPR[VADDR]
                    return 8;
                } else {
                    return 4;
                }
              case 2: //sgpr_r
                return 16;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_BYTE

    class Inst_MUBUF__BUFFER_STORE_SHORT : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_SHORT(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_SHORT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 4;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 16;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_SHORT

    class Inst_MUBUF__BUFFER_STORE_DWORD : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_DWORD(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 4;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 16;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_DWORD

    class Inst_MUBUF__BUFFER_STORE_DWORDX2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_DWORDX2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_DWORDX2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 8;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 16;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_DWORDX2

    class Inst_MUBUF__BUFFER_STORE_DWORDX3 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_DWORDX3(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_DWORDX3();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 12;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 16;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_DWORDX3

    class Inst_MUBUF__BUFFER_STORE_DWORDX4 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_DWORDX4(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_DWORDX4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return 16;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 16;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_s
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_DWORDX4

    class Inst_MUBUF__BUFFER_STORE_LDS_DWORD : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_STORE_LDS_DWORD(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_STORE_LDS_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_r
                return 16;
              case 1: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_r
                return true;
              case 1: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //sgpr_r
                return false;
              case 1: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_STORE_LDS_DWORD

    class Inst_MUBUF__BUFFER_WBINVL1 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_WBINVL1(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_WBINVL1();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_WBINVL1

    class Inst_MUBUF__BUFFER_WBINVL1_VOL : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_WBINVL1_VOL(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_WBINVL1_VOL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 0; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_WBINVL1_VOL

    class Inst_MUBUF__BUFFER_ATOMIC_SWAP : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_SWAP(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_SWAP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_SWAP

    class Inst_MUBUF__BUFFER_ATOMIC_CMPSWAP : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_CMPSWAP(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_CMPSWAP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_CMPSWAP

    class Inst_MUBUF__BUFFER_ATOMIC_ADD : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_ADD(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_ADD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_ADD

    class Inst_MUBUF__BUFFER_ATOMIC_SUB : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_SUB(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_SUB();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_SUB

    class Inst_MUBUF__BUFFER_ATOMIC_SMIN : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_SMIN(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_SMIN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_SMIN

    class Inst_MUBUF__BUFFER_ATOMIC_UMIN : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_UMIN(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_UMIN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_UMIN

    class Inst_MUBUF__BUFFER_ATOMIC_SMAX : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_SMAX(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_SMAX();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_SMAX

    class Inst_MUBUF__BUFFER_ATOMIC_UMAX : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_UMAX(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_UMAX();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_UMAX

    class Inst_MUBUF__BUFFER_ATOMIC_AND : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_AND(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_AND();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_AND

    class Inst_MUBUF__BUFFER_ATOMIC_OR : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_OR(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_OR();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_OR

    class Inst_MUBUF__BUFFER_ATOMIC_XOR : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_XOR(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_XOR();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_XOR

    class Inst_MUBUF__BUFFER_ATOMIC_INC : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_INC(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_INC();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_INC

    class Inst_MUBUF__BUFFER_ATOMIC_DEC : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_DEC(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_DEC();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_DEC

    class Inst_MUBUF__BUFFER_ATOMIC_SWAP_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_SWAP_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_SWAP_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_SWAP_X2

    class Inst_MUBUF__BUFFER_ATOMIC_CMPSWAP_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_CMPSWAP_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_CMPSWAP_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_CMPSWAP_X2

    class Inst_MUBUF__BUFFER_ATOMIC_ADD_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_ADD_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_ADD_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_ADD_X2

    class Inst_MUBUF__BUFFER_ATOMIC_SUB_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_SUB_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_SUB_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_SUB_X2

    class Inst_MUBUF__BUFFER_ATOMIC_SMIN_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_SMIN_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_SMIN_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_SMIN_X2

    class Inst_MUBUF__BUFFER_ATOMIC_UMIN_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_UMIN_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_UMIN_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_UMIN_X2

    class Inst_MUBUF__BUFFER_ATOMIC_SMAX_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_SMAX_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_SMAX_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_SMAX_X2

    class Inst_MUBUF__BUFFER_ATOMIC_UMAX_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_UMAX_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_UMAX_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_UMAX_X2

    class Inst_MUBUF__BUFFER_ATOMIC_AND_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_AND_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_AND_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_AND_X2

    class Inst_MUBUF__BUFFER_ATOMIC_OR_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_OR_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_OR_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_OR_X2

    class Inst_MUBUF__BUFFER_ATOMIC_XOR_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_XOR_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_XOR_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_XOR_X2

    class Inst_MUBUF__BUFFER_ATOMIC_INC_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_INC_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_INC_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_INC_X2

    class Inst_MUBUF__BUFFER_ATOMIC_DEC_X2 : public Inst_MUBUF
    {
      public:
        Inst_MUBUF__BUFFER_ATOMIC_DEC_X2(InFmt_MUBUF*);
        ~Inst_MUBUF__BUFFER_ATOMIC_DEC_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 16;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MUBUF__BUFFER_ATOMIC_DEC_X2

    class Inst_MTBUF__TBUFFER_LOAD_FORMAT_X : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_LOAD_FORMAT_X(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_LOAD_FORMAT_X();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_LOAD_FORMAT_X

    class Inst_MTBUF__TBUFFER_LOAD_FORMAT_XY : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_LOAD_FORMAT_XY(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_LOAD_FORMAT_XY();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_LOAD_FORMAT_XY

    class Inst_MTBUF__TBUFFER_LOAD_FORMAT_XYZ : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_LOAD_FORMAT_XYZ(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_LOAD_FORMAT_XYZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_LOAD_FORMAT_XYZ

    class Inst_MTBUF__TBUFFER_LOAD_FORMAT_XYZW : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_LOAD_FORMAT_XYZW(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_LOAD_FORMAT_XYZW();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_LOAD_FORMAT_XYZW

    class Inst_MTBUF__TBUFFER_STORE_FORMAT_X : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_STORE_FORMAT_X(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_STORE_FORMAT_X();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 32;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_STORE_FORMAT_X

    class Inst_MTBUF__TBUFFER_STORE_FORMAT_XY : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_STORE_FORMAT_XY(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_STORE_FORMAT_XY();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 8;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_STORE_FORMAT_XY

    class Inst_MTBUF__TBUFFER_STORE_FORMAT_XYZ : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_STORE_FORMAT_XYZ(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_STORE_FORMAT_XYZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 12;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_STORE_FORMAT_XYZ

    class Inst_MTBUF__TBUFFER_STORE_FORMAT_XYZW : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_STORE_FORMAT_XYZW(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_STORE_FORMAT_XYZW();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 16;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_STORE_FORMAT_XYZW

    class Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_X : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_X(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_X();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_X

    class Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XY : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XY(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XY();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XY

    class Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XYZ : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XYZ(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XYZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XYZ

    class Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XYZW : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XYZW(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XYZW();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 8;
              case 1: //sgpr_r
                return 4;
              case 2: //sgpr_o
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_o
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_o
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_LOAD_FORMAT_D16_XYZW

    class Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_X : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_X(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_X();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 32;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_X

    class Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XY : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XY(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XY();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 8;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XY

    class Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XYZ : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XYZ(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XYZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 12;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XYZ

    class Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XYZW : public Inst_MTBUF
    {
      public:
        Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XYZW(InFmt_MTBUF*);
        ~Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XYZW();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 16;
              case 1: //vgpr_a
                return 8;
              case 2: //sgpr_r
                return 4;
              case 3: //sgpr_o
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              case 3: //sgpr_o
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              case 3: //sgpr_o
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MTBUF__TBUFFER_STORE_FORMAT_D16_XYZW

    class Inst_MIMG__IMAGE_LOAD : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_LOAD(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_LOAD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 16;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_LOAD

    class Inst_MIMG__IMAGE_LOAD_MIP : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_LOAD_MIP(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_LOAD_MIP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 16;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_LOAD_MIP

    class Inst_MIMG__IMAGE_LOAD_PCK : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_LOAD_PCK(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_LOAD_PCK();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 16;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_LOAD_PCK

    class Inst_MIMG__IMAGE_LOAD_PCK_SGN : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_LOAD_PCK_SGN(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_LOAD_PCK_SGN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 16;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_LOAD_PCK_SGN

    class Inst_MIMG__IMAGE_LOAD_MIP_PCK : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_LOAD_MIP_PCK(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_LOAD_MIP_PCK();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 16;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_LOAD_MIP_PCK

    class Inst_MIMG__IMAGE_LOAD_MIP_PCK_SGN : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_LOAD_MIP_PCK_SGN(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_LOAD_MIP_PCK_SGN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 16;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_LOAD_MIP_PCK_SGN

    class Inst_MIMG__IMAGE_STORE : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_STORE(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_STORE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 16;
              case 1: //vgpr_a
                return 16;
              case 2: //sgpr_r
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_STORE

    class Inst_MIMG__IMAGE_STORE_MIP : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_STORE_MIP(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_STORE_MIP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 16;
              case 1: //vgpr_a
                return 16;
              case 2: //sgpr_r
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_STORE_MIP

    class Inst_MIMG__IMAGE_STORE_PCK : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_STORE_PCK(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_STORE_PCK();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 16;
              case 1: //vgpr_a
                return 16;
              case 2: //sgpr_r
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_STORE_PCK

    class Inst_MIMG__IMAGE_STORE_MIP_PCK : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_STORE_MIP_PCK(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_STORE_MIP_PCK();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return 16;
              case 1: //vgpr_a
                return 16;
              case 2: //sgpr_r
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return true;
              case 1: //vgpr_a
                return true;
              case 2: //sgpr_r
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_d
                return false;
              case 1: //vgpr_a
                return false;
              case 2: //sgpr_r
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_STORE_MIP_PCK

    class Inst_MIMG__IMAGE_GET_RESINFO : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GET_RESINFO(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GET_RESINFO();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 16;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GET_RESINFO

    class Inst_MIMG__IMAGE_ATOMIC_SWAP : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_SWAP(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_SWAP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_SWAP

    class Inst_MIMG__IMAGE_ATOMIC_CMPSWAP : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_CMPSWAP(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_CMPSWAP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_CMPSWAP

    class Inst_MIMG__IMAGE_ATOMIC_ADD : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_ADD(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_ADD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_ADD

    class Inst_MIMG__IMAGE_ATOMIC_SUB : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_SUB(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_SUB();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_SUB

    class Inst_MIMG__IMAGE_ATOMIC_SMIN : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_SMIN(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_SMIN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_SMIN

    class Inst_MIMG__IMAGE_ATOMIC_UMIN : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_UMIN(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_UMIN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_UMIN

    class Inst_MIMG__IMAGE_ATOMIC_SMAX : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_SMAX(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_SMAX();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_SMAX

    class Inst_MIMG__IMAGE_ATOMIC_UMAX : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_UMAX(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_UMAX();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_UMAX

    class Inst_MIMG__IMAGE_ATOMIC_AND : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_AND(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_AND();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_AND

    class Inst_MIMG__IMAGE_ATOMIC_OR : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_OR(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_OR();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_OR

    class Inst_MIMG__IMAGE_ATOMIC_XOR : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_XOR(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_XOR();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_XOR

    class Inst_MIMG__IMAGE_ATOMIC_INC : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_INC(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_INC();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_INC

    class Inst_MIMG__IMAGE_ATOMIC_DEC : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_ATOMIC_DEC(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_ATOMIC_DEC();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 32;
              case 1: //sgpr_r
                return 32;
              case 2: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_ATOMIC_DEC

    class Inst_MIMG__IMAGE_SAMPLE : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE

    class Inst_MIMG__IMAGE_SAMPLE_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_CL

    class Inst_MIMG__IMAGE_SAMPLE_D : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_D(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_D();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_D

    class Inst_MIMG__IMAGE_SAMPLE_D_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_D_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_D_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_D_CL

    class Inst_MIMG__IMAGE_SAMPLE_L : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_L(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_L();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_L

    class Inst_MIMG__IMAGE_SAMPLE_B : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_B(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_B();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_B

    class Inst_MIMG__IMAGE_SAMPLE_B_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_B_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_B_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_B_CL

    class Inst_MIMG__IMAGE_SAMPLE_LZ : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_LZ(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_LZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_LZ

    class Inst_MIMG__IMAGE_SAMPLE_C : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C

    class Inst_MIMG__IMAGE_SAMPLE_C_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_CL

    class Inst_MIMG__IMAGE_SAMPLE_C_D : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_D(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_D();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_D

    class Inst_MIMG__IMAGE_SAMPLE_C_D_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_D_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_D_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_D_CL

    class Inst_MIMG__IMAGE_SAMPLE_C_L : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_L(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_L();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_L

    class Inst_MIMG__IMAGE_SAMPLE_C_B : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_B(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_B();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_B

    class Inst_MIMG__IMAGE_SAMPLE_C_B_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_B_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_B_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_B_CL

    class Inst_MIMG__IMAGE_SAMPLE_C_LZ : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_LZ(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_LZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_LZ

    class Inst_MIMG__IMAGE_SAMPLE_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_O

    class Inst_MIMG__IMAGE_SAMPLE_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_CL_O

    class Inst_MIMG__IMAGE_SAMPLE_D_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_D_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_D_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_D_O

    class Inst_MIMG__IMAGE_SAMPLE_D_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_D_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_D_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_D_CL_O

    class Inst_MIMG__IMAGE_SAMPLE_L_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_L_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_L_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_L_O

    class Inst_MIMG__IMAGE_SAMPLE_B_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_B_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_B_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_B_O

    class Inst_MIMG__IMAGE_SAMPLE_B_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_B_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_B_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_B_CL_O

    class Inst_MIMG__IMAGE_SAMPLE_LZ_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_LZ_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_LZ_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_LZ_O

    class Inst_MIMG__IMAGE_SAMPLE_C_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_O

    class Inst_MIMG__IMAGE_SAMPLE_C_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_CL_O

    class Inst_MIMG__IMAGE_SAMPLE_C_D_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_D_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_D_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_D_O

    class Inst_MIMG__IMAGE_SAMPLE_C_D_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_D_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_D_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_D_CL_O

    class Inst_MIMG__IMAGE_SAMPLE_C_L_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_L_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_L_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_L_O

    class Inst_MIMG__IMAGE_SAMPLE_C_B_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_B_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_B_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_B_O

    class Inst_MIMG__IMAGE_SAMPLE_C_B_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_B_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_B_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_B_CL_O

    class Inst_MIMG__IMAGE_SAMPLE_C_LZ_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_LZ_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_LZ_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_LZ_O

    class Inst_MIMG__IMAGE_GATHER4 : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4

    class Inst_MIMG__IMAGE_GATHER4_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_CL

    class Inst_MIMG__IMAGE_GATHER4_L : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_L(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_L();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_L

    class Inst_MIMG__IMAGE_GATHER4_B : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_B(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_B();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_B

    class Inst_MIMG__IMAGE_GATHER4_B_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_B_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_B_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_B_CL

    class Inst_MIMG__IMAGE_GATHER4_LZ : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_LZ(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_LZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_LZ

    class Inst_MIMG__IMAGE_GATHER4_C : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C

    class Inst_MIMG__IMAGE_GATHER4_C_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_CL

    class Inst_MIMG__IMAGE_GATHER4_C_L : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_L(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_L();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_L

    class Inst_MIMG__IMAGE_GATHER4_C_B : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_B(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_B();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_B

    class Inst_MIMG__IMAGE_GATHER4_C_B_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_B_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_B_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_B_CL

    class Inst_MIMG__IMAGE_GATHER4_C_LZ : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_LZ(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_LZ();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_LZ

    class Inst_MIMG__IMAGE_GATHER4_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_O

    class Inst_MIMG__IMAGE_GATHER4_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_CL_O

    class Inst_MIMG__IMAGE_GATHER4_L_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_L_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_L_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_L_O

    class Inst_MIMG__IMAGE_GATHER4_B_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_B_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_B_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_B_O

    class Inst_MIMG__IMAGE_GATHER4_B_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_B_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_B_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_B_CL_O

    class Inst_MIMG__IMAGE_GATHER4_LZ_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_LZ_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_LZ_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_LZ_O

    class Inst_MIMG__IMAGE_GATHER4_C_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_O

    class Inst_MIMG__IMAGE_GATHER4_C_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_CL_O

    class Inst_MIMG__IMAGE_GATHER4_C_L_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_L_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_L_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_L_O

    class Inst_MIMG__IMAGE_GATHER4_C_B_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_B_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_B_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_B_O

    class Inst_MIMG__IMAGE_GATHER4_C_B_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_B_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_B_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_B_CL_O

    class Inst_MIMG__IMAGE_GATHER4_C_LZ_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GATHER4_C_LZ_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GATHER4_C_LZ_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GATHER4_C_LZ_O

    class Inst_MIMG__IMAGE_GET_LOD : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_GET_LOD(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_GET_LOD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_GET_LOD

    class Inst_MIMG__IMAGE_SAMPLE_CD : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_CD(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_CD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_CD

    class Inst_MIMG__IMAGE_SAMPLE_CD_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_CD_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_CD_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_CD_CL

    class Inst_MIMG__IMAGE_SAMPLE_C_CD : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_CD(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_CD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_CD

    class Inst_MIMG__IMAGE_SAMPLE_C_CD_CL : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_CD_CL(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_CD_CL();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_CD_CL

    class Inst_MIMG__IMAGE_SAMPLE_CD_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_CD_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_CD_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_CD_O

    class Inst_MIMG__IMAGE_SAMPLE_CD_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_CD_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_CD_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_CD_CL_O

    class Inst_MIMG__IMAGE_SAMPLE_C_CD_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_CD_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_CD_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_CD_O

    class Inst_MIMG__IMAGE_SAMPLE_C_CD_CL_O : public Inst_MIMG
    {
      public:
        Inst_MIMG__IMAGE_SAMPLE_C_CD_CL_O(InFmt_MIMG*);
        ~Inst_MIMG__IMAGE_SAMPLE_C_CD_CL_O();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 3; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return 4;
              case 1: //sgpr_r
                return 32;
              case 2: //sgpr_s
                return 4;
              case 3: //vgpr_d
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return true;
              case 1: //sgpr_r
                return true;
              case 2: //sgpr_s
                return true;
              case 3: //vgpr_d
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_a
                return false;
              case 1: //sgpr_r
                return false;
              case 2: //sgpr_s
                return false;
              case 3: //vgpr_d
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_MIMG__IMAGE_SAMPLE_C_CD_CL_O

    class Inst_EXP__EXP : public Inst_EXP
    {
      public:
        Inst_EXP__EXP(InFmt_EXP*);
        ~Inst_EXP__EXP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 4; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //
                return 32;
              case 1: //
                return 32;
              case 2: //
                return 32;
              case 3: //
                return 32;
              case 4: //
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //
                return true;
              case 1: //
                return true;
              case 2: //
                return true;
              case 3: //
                return true;
              case 4: //
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //
                return false;
              case 1: //
                return false;
              case 2: //
                return false;
              case 3: //
                return false;
              case 4: //
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_EXP__EXP

    class Inst_FLAT__FLAT_LOAD_UBYTE : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_LOAD_UBYTE(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_LOAD_UBYTE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_dst
                return 1;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_LOAD_UBYTE

    class Inst_FLAT__FLAT_LOAD_SBYTE : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_LOAD_SBYTE(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_LOAD_SBYTE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_LOAD_SBYTE

    class Inst_FLAT__FLAT_LOAD_USHORT : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_LOAD_USHORT(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_LOAD_USHORT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_dst
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_LOAD_USHORT

    class Inst_FLAT__FLAT_LOAD_SSHORT : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_LOAD_SSHORT(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_LOAD_SSHORT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_LOAD_SSHORT

    class Inst_FLAT__FLAT_LOAD_DWORD : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_LOAD_DWORD(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_LOAD_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_LOAD_DWORD

    class Inst_FLAT__FLAT_LOAD_DWORDX2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_LOAD_DWORDX2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_LOAD_DWORDX2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_LOAD_DWORDX2

    class Inst_FLAT__FLAT_LOAD_DWORDX3 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_LOAD_DWORDX3(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_LOAD_DWORDX3();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_dst
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_LOAD_DWORDX3

    class Inst_FLAT__FLAT_LOAD_DWORDX4 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_LOAD_DWORDX4(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_LOAD_DWORDX4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 1; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_dst
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_LOAD_DWORDX4

    class Inst_FLAT__FLAT_STORE_BYTE : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_STORE_BYTE(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_STORE_BYTE();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 1;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_STORE_BYTE

    class Inst_FLAT__FLAT_STORE_SHORT : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_STORE_SHORT(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_STORE_SHORT();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 2;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_STORE_SHORT

    class Inst_FLAT__FLAT_STORE_DWORD : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_STORE_DWORD(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_STORE_DWORD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_STORE_DWORD

    class Inst_FLAT__FLAT_STORE_DWORDX2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_STORE_DWORDX2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_STORE_DWORDX2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_STORE_DWORDX2

    class Inst_FLAT__FLAT_STORE_DWORDX3 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_STORE_DWORDX3(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_STORE_DWORDX3();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 12;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_STORE_DWORDX3

    class Inst_FLAT__FLAT_STORE_DWORDX4 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_STORE_DWORDX4(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_STORE_DWORDX4();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 0; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 16;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_STORE_DWORDX4

    class Inst_FLAT__FLAT_ATOMIC_SWAP : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_SWAP(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_SWAP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 4;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_SWAP

    class Inst_FLAT__FLAT_ATOMIC_CMPSWAP : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_CMPSWAP(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_CMPSWAP();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_CMPSWAP

    class Inst_FLAT__FLAT_ATOMIC_ADD : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_ADD(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_ADD();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 4;
              case 2: //vgpr_dst
                return 4;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_ADD

    class Inst_FLAT__FLAT_ATOMIC_SUB : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_SUB(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_SUB();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_SUB

    class Inst_FLAT__FLAT_ATOMIC_SMIN : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_SMIN(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_SMIN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_SMIN

    class Inst_FLAT__FLAT_ATOMIC_UMIN : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_UMIN(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_UMIN();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_UMIN

    class Inst_FLAT__FLAT_ATOMIC_SMAX : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_SMAX(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_SMAX();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_SMAX

    class Inst_FLAT__FLAT_ATOMIC_UMAX : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_UMAX(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_UMAX();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_UMAX

    class Inst_FLAT__FLAT_ATOMIC_AND : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_AND(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_AND();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_AND

    class Inst_FLAT__FLAT_ATOMIC_OR : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_OR(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_OR();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_OR

    class Inst_FLAT__FLAT_ATOMIC_XOR : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_XOR(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_XOR();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_XOR

    class Inst_FLAT__FLAT_ATOMIC_INC : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_INC(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_INC();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_INC

    class Inst_FLAT__FLAT_ATOMIC_DEC : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_DEC(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_DEC();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 32;
              case 2: //vgpr_dst
                return 32;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_DEC

    class Inst_FLAT__FLAT_ATOMIC_SWAP_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_SWAP_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_SWAP_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_SWAP_X2

    class Inst_FLAT__FLAT_ATOMIC_CMPSWAP_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_CMPSWAP_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_CMPSWAP_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 16;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_CMPSWAP_X2

    class Inst_FLAT__FLAT_ATOMIC_ADD_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_ADD_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_ADD_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
        void initiateAcc(GPUDynInstPtr) override;
        void completeAcc(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_ADD_X2

    class Inst_FLAT__FLAT_ATOMIC_SUB_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_SUB_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_SUB_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_SUB_X2

    class Inst_FLAT__FLAT_ATOMIC_SMIN_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_SMIN_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_SMIN_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_SMIN_X2

    class Inst_FLAT__FLAT_ATOMIC_UMIN_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_UMIN_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_UMIN_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_UMIN_X2

    class Inst_FLAT__FLAT_ATOMIC_SMAX_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_SMAX_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_SMAX_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_SMAX_X2

    class Inst_FLAT__FLAT_ATOMIC_UMAX_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_UMAX_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_UMAX_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_UMAX_X2

    class Inst_FLAT__FLAT_ATOMIC_AND_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_AND_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_AND_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_AND_X2

    class Inst_FLAT__FLAT_ATOMIC_OR_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_OR_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_OR_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_OR_X2

    class Inst_FLAT__FLAT_ATOMIC_XOR_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_XOR_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_XOR_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_XOR_X2

    class Inst_FLAT__FLAT_ATOMIC_INC_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_INC_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_INC_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_INC_X2

    class Inst_FLAT__FLAT_ATOMIC_DEC_X2 : public Inst_FLAT
    {
      public:
        Inst_FLAT__FLAT_ATOMIC_DEC_X2(InFmt_FLAT*);
        ~Inst_FLAT__FLAT_ATOMIC_DEC_X2();

        int
        getNumOperands() override
        {
            return numDstRegOperands() + numSrcRegOperands();
        } // getNumOperands

        int numDstRegOperands() override { return 1; }
        int numSrcRegOperands() override { return 2; }

        int
        getOperandSize(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return 8;
              case 1: //vgpr_src
                return 8;
              case 2: //vgpr_dst
                return 8;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return -1;
            }
        } // getOperandSize

        bool
        isSrcOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return true;
              case 1: //vgpr_src
                return true;
              case 2: //vgpr_dst
                return false;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isSrcOperand

        bool
        isDstOperand(int opIdx) override
        {
            switch (opIdx) {
              case 0: //vgpr_addr
                return false;
              case 1: //vgpr_src
                return false;
              case 2: //vgpr_dst
                return true;
              default:
                fatal("op idx %i out of bounds\n", opIdx);
                return false;
            }
        } // isDstOperand

        void execute(GPUDynInstPtr) override;
    }; // Inst_FLAT__FLAT_ATOMIC_DEC_X2
} // namespace Gcn3ISA

#endif // __ARCH_GCN3_INSTS_INSTRUCTIONS_HH__
