From 85c406c2ba1ce38b77d4cedc5d05247d57da2fe0 Mon Sep 17 00:00:00 2001 From: kobalicek Date: Sun, 18 Jan 2015 22:10:36 +0100 Subject: [PATCH] Added casting methods to X86GpReg, X86XmmReg, X86YmmReg, and X86ZmmReg. --- src/asmjit/x86/x86compiler.h | 35 +++++++++++++--------- src/asmjit/x86/x86operand.h | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/asmjit/x86/x86compiler.h b/src/asmjit/x86/x86compiler.h index a2aa17d..9e935c0 100644 --- a/src/asmjit/x86/x86compiler.h +++ b/src/asmjit/x86/x86compiler.h @@ -710,6 +710,10 @@ struct X86GpVar : public X86Var { // [Construction / Destruction] // -------------------------------------------------------------------------- +protected: + ASMJIT_INLINE X86GpVar(const X86GpVar& other, uint32_t reg, uint32_t size) : X86Var(other, reg, size) {} + +public: //! Create a new uninitialized `X86GpVar` instance. ASMJIT_INLINE X86GpVar() : X86Var() {} @@ -742,18 +746,18 @@ struct X86GpVar : public X86Var { // [X86GpVar Cast] // -------------------------------------------------------------------------- - //! Cast this variable to 8-bit (LO) part of variable + //! Cast this variable to 8-bit (LO) part of variable. ASMJIT_INLINE X86GpVar r8() const { return X86GpVar(*this, kX86RegTypeGpbLo, 1); } - //! Cast this variable to 8-bit (LO) part of variable + //! Cast this variable to 8-bit (LO) part of variable. ASMJIT_INLINE X86GpVar r8Lo() const { return X86GpVar(*this, kX86RegTypeGpbLo, 1); } - //! Cast this variable to 8-bit (HI) part of variable + //! Cast this variable to 8-bit (HI) part of variable. ASMJIT_INLINE X86GpVar r8Hi() const { return X86GpVar(*this, kX86RegTypeGpbHi, 1); } - //! Cast this variable to 16-bit part of variable + //! Cast this variable to 16-bit part of variable. ASMJIT_INLINE X86GpVar r16() const { return X86GpVar(*this, kX86RegTypeGpw, 2); } - //! Cast this variable to 32-bit part of variable + //! Cast this variable to 32-bit part of variable. ASMJIT_INLINE X86GpVar r32() const { return X86GpVar(*this, kX86RegTypeGpd, 4); } - //! Cast this variable to 64-bit part of variable + //! Cast this variable to 64-bit part of variable. ASMJIT_INLINE X86GpVar r64() const { return X86GpVar(*this, kX86RegTypeGpq, 8); } // -------------------------------------------------------------------------- @@ -764,13 +768,6 @@ struct X86GpVar : public X86Var { ASMJIT_INLINE bool operator==(const X86GpVar& other) const { return X86Var::operator==(other); } ASMJIT_INLINE bool operator!=(const X86GpVar& other) const { return X86Var::operator!=(other); } - - // -------------------------------------------------------------------------- - // [Private] - // -------------------------------------------------------------------------- - -protected: - ASMJIT_INLINE X86GpVar(const X86GpVar& other, uint32_t reg, uint32_t size) : X86Var(other, reg, size) {} }; // ============================================================================ @@ -857,6 +854,12 @@ struct X86XmmVar : public X86Var { X86Var::reset(); } + // -------------------------------------------------------------------------- + // [X86XmmVar Cast] + // -------------------------------------------------------------------------- + + // TODO: + // -------------------------------------------------------------------------- // [Operator Overload] // -------------------------------------------------------------------------- @@ -904,6 +907,12 @@ struct X86YmmVar : public X86Var { X86Var::reset(); } + // -------------------------------------------------------------------------- + // [X86YmmVar Cast] + // -------------------------------------------------------------------------- + + // TODO: + // -------------------------------------------------------------------------- // [Operator Overload] // -------------------------------------------------------------------------- diff --git a/src/asmjit/x86/x86operand.h b/src/asmjit/x86/x86operand.h index 124cd6f..7d573fd 100644 --- a/src/asmjit/x86/x86operand.h +++ b/src/asmjit/x86/x86operand.h @@ -789,6 +789,24 @@ struct X86GpReg : public X86Reg { // -------------------------------------------------------------------------- ASMJIT_REG_OP(X86GpReg) + + // -------------------------------------------------------------------------- + // [X86GpReg Cast] + // -------------------------------------------------------------------------- + + //! Cast this register to 8-bit (LO) part. + ASMJIT_INLINE X86GpReg r8() const { return X86GpReg(kX86RegTypeGpbLo, getRegIndex(), 1); } + //! Cast this register to 8-bit (LO) part. + ASMJIT_INLINE X86GpReg r8Lo() const { return X86GpReg(kX86RegTypeGpbLo, getRegIndex(), 1); } + //! Cast this register to 8-bit (HI) part. + ASMJIT_INLINE X86GpReg r8Hi() const { return X86GpReg(kX86RegTypeGpbHi, getRegIndex(), 1); } + + //! Cast this register to 16-bit. + ASMJIT_INLINE X86GpReg r16() const { return X86GpReg(kX86RegTypeGpw, getRegIndex(), 2); } + //! Cast this register to 32-bit. + ASMJIT_INLINE X86GpReg r32() const { return X86GpReg(kX86RegTypeGpd, getRegIndex(), 4); } + //! Cast this register to 64-bit. + ASMJIT_INLINE X86GpReg r64() const { return X86GpReg(kX86RegTypeGpq, getRegIndex(), 8); } }; // ============================================================================ @@ -979,6 +997,17 @@ struct X86XmmReg : public X86Reg { // -------------------------------------------------------------------------- ASMJIT_REG_OP(X86XmmReg) + + // -------------------------------------------------------------------------- + // [X86XmmReg Cast] + // -------------------------------------------------------------------------- + + //! Cast this register to Xmm (clone). + ASMJIT_INLINE X86XmmReg xmm() const { return X86XmmReg(kX86RegTypeXmm, getRegIndex(), 16); } + //! Cast this register to Ymm. + ASMJIT_INLINE X86YmmReg ymm() const; + //! Cast this register to Zmm. + ASMJIT_INLINE X86ZmmReg zmm() const; }; // ============================================================================ @@ -1029,8 +1058,21 @@ struct X86YmmReg : public X86Reg { // -------------------------------------------------------------------------- ASMJIT_REG_OP(X86YmmReg) + + // -------------------------------------------------------------------------- + // [X86YmmReg Cast] + // -------------------------------------------------------------------------- + + //! Cast this register to Xmm. + ASMJIT_INLINE X86XmmReg xmm() const { return X86XmmReg(kX86RegTypeXmm, getRegIndex(), 16); } + //! Cast this register to Ymm (clone). + ASMJIT_INLINE X86YmmReg ymm() const { return X86YmmReg(kX86RegTypeYmm, getRegIndex(), 32); } + //! Cast this register to Zmm. + ASMJIT_INLINE X86ZmmReg zmm() const; }; +ASMJIT_INLINE X86YmmReg X86XmmReg::ymm() const { return X86YmmReg(kX86RegTypeYmm, getRegIndex(), 32); } + // ============================================================================ // [asmjit::X86ZmmReg] // ============================================================================ @@ -1057,8 +1099,22 @@ struct X86ZmmReg : public X86Reg { // -------------------------------------------------------------------------- ASMJIT_REG_OP(X86ZmmReg) + + // -------------------------------------------------------------------------- + // [X86ZmmReg Cast] + // -------------------------------------------------------------------------- + + //! Cast this register to Xmm. + ASMJIT_INLINE X86XmmReg xmm() const { return X86XmmReg(kX86RegTypeXmm, getRegIndex(), 16); } + //! Cast this register to Ymm. + ASMJIT_INLINE X86YmmReg ymm() const { return X86YmmReg(kX86RegTypeYmm, getRegIndex(), 32); } + //! Cast this register to Zmm (clone). + ASMJIT_INLINE X86ZmmReg zmm() const { return X86ZmmReg(kX86RegTypeZmm, getRegIndex(), 64); } }; +ASMJIT_INLINE X86ZmmReg X86XmmReg::zmm() const { return X86ZmmReg(kX86RegTypeZmm, getRegIndex(), 64); } +ASMJIT_INLINE X86ZmmReg X86YmmReg::zmm() const { return X86ZmmReg(kX86RegTypeZmm, getRegIndex(), 64); } + // ============================================================================ // [asmjit::X86Mem] // ============================================================================