12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316 |
- #ifndef _ASMJIT_CORE_OPERAND_H
- #define _ASMJIT_CORE_OPERAND_H
- #include "../core/support.h"
- ASMJIT_BEGIN_NAMESPACE
- #define ASMJIT_DEFINE_REG_TRAITS(REG, REG_TYPE, GROUP, SIZE, COUNT, TYPE_ID) \
- template<> \
- struct RegTraits<REG_TYPE> { \
- typedef REG RegT; \
- \
- static constexpr uint32_t kValid = 1; \
- static constexpr uint32_t kCount = COUNT; \
- static constexpr uint32_t kTypeId = TYPE_ID; \
- \
- static constexpr uint32_t kType = REG_TYPE; \
- static constexpr uint32_t kGroup = GROUP; \
- static constexpr uint32_t kSize = SIZE; \
- \
- static constexpr uint32_t kSignature = \
- (Operand::kOpReg << Operand::kSignatureOpShift ) | \
- (kType << Operand::kSignatureRegTypeShift ) | \
- (kGroup << Operand::kSignatureRegGroupShift) | \
- (kSize << Operand::kSignatureSizeShift ) ; \
- }
- #define ASMJIT_DEFINE_ABSTRACT_REG(REG, BASE) \
- public: \
- \
- constexpr REG() noexcept \
- : BASE(kSignature, kIdBad) {} \
- \
- \
- constexpr REG(const REG& other) noexcept \
- : BASE(other) {} \
- \
- \
- constexpr REG(const BaseReg& other, uint32_t rId) noexcept \
- : BASE(other, rId) {} \
- \
- \
- constexpr REG(uint32_t signature, uint32_t rId) noexcept \
- : BASE(signature, rId) {} \
- \
- \
- inline explicit REG(Globals::NoInit_) noexcept \
- : BASE(Globals::NoInit) {} \
- \
- \
- static inline REG fromTypeAndId(uint32_t rType, uint32_t rId) noexcept { \
- return REG(signatureOf(rType), rId); \
- } \
- \
- \
- constexpr REG clone() const noexcept { return REG(*this); } \
- \
- inline REG& operator=(const REG& other) noexcept = default;
- #define ASMJIT_DEFINE_FINAL_REG(REG, BASE, TRAITS) \
- public: \
- static constexpr uint32_t kThisType = TRAITS::kType; \
- static constexpr uint32_t kThisGroup = TRAITS::kGroup; \
- static constexpr uint32_t kThisSize = TRAITS::kSize; \
- static constexpr uint32_t kSignature = TRAITS::kSignature; \
- \
- ASMJIT_DEFINE_ABSTRACT_REG(REG, BASE) \
- \
- \
- constexpr explicit REG(uint32_t rId) noexcept \
- : BASE(kSignature, rId) {}
- struct Operand_ {
-
- uint32_t _signature;
-
- uint32_t _baseId;
-
- struct MemData {
-
- uint32_t indexId;
-
- uint32_t offsetLo32;
- };
-
- union {
-
- uint32_t _data32[2];
-
- uint64_t _data64;
-
- MemData _mem;
- };
-
- enum OpType : uint32_t {
-
- kOpNone = 0,
-
- kOpReg = 1,
-
- kOpMem = 2,
-
- kOpImm = 3,
-
- kOpLabel = 4
- };
- static_assert(kOpMem == kOpReg + 1, "asmjit::Operand requires `kOpMem` to be `kOpReg+1`.");
-
- enum SignatureBits : uint32_t {
-
-
- kSignatureOpShift = 0,
- kSignatureOpMask = 0x07u << kSignatureOpShift,
-
-
- kSignatureRegTypeShift = 3,
- kSignatureRegTypeMask = 0x1Fu << kSignatureRegTypeShift,
-
-
- kSignatureRegGroupShift = 8,
- kSignatureRegGroupMask = 0x0Fu << kSignatureRegGroupShift,
-
-
- kSignatureMemBaseTypeShift = 3,
- kSignatureMemBaseTypeMask = 0x1Fu << kSignatureMemBaseTypeShift,
-
-
- kSignatureMemIndexTypeShift = 8,
- kSignatureMemIndexTypeMask = 0x1Fu << kSignatureMemIndexTypeShift,
-
-
- kSignatureMemBaseIndexShift = 3,
- kSignatureMemBaseIndexMask = 0x3FFu << kSignatureMemBaseIndexShift,
-
-
- kSignatureMemAddrTypeShift = 13,
- kSignatureMemAddrTypeMask = 0x03u << kSignatureMemAddrTypeShift,
-
-
- kSignatureMemRegHomeShift = 15,
- kSignatureMemRegHomeFlag = 0x01u << kSignatureMemRegHomeShift,
-
-
- kSignatureSizeShift = 24,
- kSignatureSizeMask = 0xFFu << kSignatureSizeShift
- };
-
-
-
- enum VirtIdConstants : uint32_t {
-
- kVirtIdMin = 256,
-
- kVirtIdMax = Globals::kInvalidId - 1,
-
- kVirtIdCount = uint32_t(kVirtIdMax - kVirtIdMin + 1)
- };
-
-
-
-
-
- static ASMJIT_INLINE bool isVirtId(uint32_t id) noexcept { return id - kVirtIdMin < uint32_t(kVirtIdCount); }
-
- static ASMJIT_INLINE uint32_t indexToVirtId(uint32_t id) noexcept { return id + kVirtIdMin; }
-
- static ASMJIT_INLINE uint32_t virtIdToIndex(uint32_t id) noexcept { return id - kVirtIdMin; }
-
-
-
-
-
- inline void _initReg(uint32_t signature, uint32_t id) noexcept {
- _signature = signature;
- _baseId = id;
- _data64 = 0;
- }
-
- inline void copyFrom(const Operand_& other) noexcept { memcpy(this, &other, sizeof(Operand_)); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- inline void reset() noexcept {
- _signature = 0;
- _baseId = 0;
- _data64 = 0;
- }
-
-
-
- constexpr bool operator==(const Operand_& other) const noexcept { return isEqual(other); }
- constexpr bool operator!=(const Operand_& other) const noexcept { return !isEqual(other); }
-
-
-
-
- template<typename T>
- inline T& as() noexcept { return static_cast<T&>(*this); }
-
- template<typename T>
- inline const T& as() const noexcept { return static_cast<const T&>(*this); }
-
-
-
-
- constexpr bool hasSignature(uint32_t signature) const noexcept { return _signature == signature; }
-
- constexpr bool hasSignature(const Operand_& other) const noexcept { return _signature == other.signature(); }
-
-
-
-
-
- constexpr uint32_t signature() const noexcept { return _signature; }
-
-
-
- inline void setSignature(uint32_t signature) noexcept { _signature = signature; }
-
- template<uint32_t mask>
- constexpr bool _hasSignaturePart() const noexcept {
- return (_signature & mask) != 0;
- }
- template<uint32_t mask>
- constexpr uint32_t _getSignaturePart() const noexcept {
- return (_signature >> Support::constCtz(mask)) & (mask >> Support::constCtz(mask));
- }
- template<uint32_t mask>
- inline void _setSignaturePart(uint32_t value) noexcept {
- ASMJIT_ASSERT((value & ~(mask >> Support::constCtz(mask))) == 0);
- _signature = (_signature & ~mask) | (value << Support::constCtz(mask));
- }
-
-
- constexpr uint32_t opType() const noexcept { return _getSignaturePart<kSignatureOpMask>(); }
-
- constexpr bool isNone() const noexcept { return _signature == 0; }
-
- constexpr bool isReg() const noexcept { return opType() == kOpReg; }
-
- constexpr bool isMem() const noexcept { return opType() == kOpMem; }
-
- constexpr bool isImm() const noexcept { return opType() == kOpImm; }
-
- constexpr bool isLabel() const noexcept { return opType() == kOpLabel; }
-
- constexpr bool isPhysReg() const noexcept { return isReg() && _baseId < 0xFFu; }
-
- constexpr bool isVirtReg() const noexcept { return isReg() && _baseId > 0xFFu; }
-
- constexpr bool hasSize() const noexcept { return _hasSignaturePart<kSignatureSizeMask>(); }
-
- constexpr bool hasSize(uint32_t s) const noexcept { return size() == s; }
-
-
-
-
-
-
-
-
-
-
-
- constexpr uint32_t size() const noexcept { return _getSignaturePart<kSignatureSizeMask>(); }
-
-
-
-
-
-
-
-
-
-
-
- constexpr uint32_t id() const noexcept { return _baseId; }
-
- constexpr bool isEqual(const Operand_& other) const noexcept {
- return (_signature == other._signature) &
- (_baseId == other._baseId ) &
- (_data64 == other._data64 ) ;
- }
-
- constexpr bool isReg(uint32_t rType) const noexcept {
- return (_signature & (kSignatureOpMask | kSignatureRegTypeMask)) ==
- ((kOpReg << kSignatureOpShift) | (rType << kSignatureRegTypeShift));
- }
-
- constexpr bool isReg(uint32_t rType, uint32_t rId) const noexcept {
- return isReg(rType) && id() == rId;
- }
-
- constexpr bool isRegOrMem() const noexcept {
- return Support::isBetween<uint32_t>(opType(), kOpReg, kOpMem);
- }
-
- };
- class Operand : public Operand_ {
- public:
-
-
-
- constexpr Operand() noexcept
- : Operand_{ kOpNone, 0u, {{ 0u, 0u }}} {}
-
- constexpr Operand(const Operand& other) noexcept = default;
-
- constexpr explicit Operand(const Operand_& other)
- : Operand_(other) {}
-
- constexpr Operand(Globals::Init_, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3) noexcept
- : Operand_{ u0, u1, {{ u2, u3 }}} {}
-
- inline explicit Operand(Globals::NoInit_) noexcept {}
-
-
-
- inline Operand& operator=(const Operand& other) noexcept = default;
- inline Operand& operator=(const Operand_& other) noexcept { return operator=(static_cast<const Operand&>(other)); }
-
-
-
-
- constexpr Operand clone() const noexcept { return Operand(*this); }
-
- };
- static_assert(sizeof(Operand) == 16, "asmjit::Operand must be exactly 16 bytes long");
- namespace Globals {
-
- static constexpr const Operand none;
- }
- class Label : public Operand {
- public:
-
- enum LabelType : uint32_t {
-
- kTypeAnonymous = 0,
-
- kTypeLocal = 1,
-
- kTypeGlobal = 2,
-
- kTypeCount = 3
- };
-
- enum {
-
-
-
-
-
- kLabelTag = 0x1
- };
-
-
-
- constexpr Label() noexcept
- : Operand(Globals::Init, kOpLabel, Globals::kInvalidId, 0, 0) {}
-
- constexpr Label(const Label& other) noexcept
- : Operand(other) {}
-
- constexpr explicit Label(uint32_t id) noexcept
- : Operand(Globals::Init, kOpLabel, id, 0, 0) {}
- inline explicit Label(Globals::NoInit_) noexcept
- : Operand(Globals::NoInit) {}
-
- inline void reset() noexcept {
- _signature = kOpLabel;
- _baseId = Globals::kInvalidId;
- _data64 = 0;
- }
-
-
-
- inline Label& operator=(const Label& other) noexcept = default;
-
-
-
-
- constexpr bool isValid() const noexcept { return _baseId != Globals::kInvalidId; }
-
- inline void setId(uint32_t id) noexcept { _baseId = id; }
-
- };
- struct BaseRegTraits {
-
- static constexpr uint32_t kValid = 0;
-
- static constexpr uint32_t kCount = 0;
-
- static constexpr uint32_t kTypeId = 0;
-
- static constexpr uint32_t kType = 0;
-
- static constexpr uint32_t kGroup = 0;
-
- static constexpr uint32_t kSize = 0;
-
- static constexpr uint32_t kSignature = Operand::kOpReg;
- };
- struct RegInfo {
- inline void reset() noexcept { _signature = 0; }
- inline void setSignature(uint32_t signature) noexcept { _signature = signature; }
- template<uint32_t mask>
- constexpr uint32_t _getSignaturePart() const noexcept {
- return (_signature >> Support::constCtz(mask)) & (mask >> Support::constCtz(mask));
- }
- constexpr bool isValid() const noexcept { return _signature != 0; }
- constexpr uint32_t signature() const noexcept { return _signature; }
- constexpr uint32_t opType() const noexcept { return _getSignaturePart<Operand::kSignatureOpMask>(); }
- constexpr uint32_t group() const noexcept { return _getSignaturePart<Operand::kSignatureRegGroupMask>(); }
- constexpr uint32_t type() const noexcept { return _getSignaturePart<Operand::kSignatureRegTypeMask>(); }
- constexpr uint32_t size() const noexcept { return _getSignaturePart<Operand::kSignatureSizeMask>(); }
- uint32_t _signature;
- };
- class BaseReg : public Operand {
- public:
-
-
-
-
-
- enum RegType : uint32_t {
-
- kTypeNone = 0,
-
-
- kTypeGp8Lo = 2,
-
- kTypeGp8Hi = 3,
-
- kTypeGp16 = 4,
-
- kTypeGp32 = 5,
-
- kTypeGp64 = 6,
-
- kTypeVec32 = 7,
-
- kTypeVec64 = 8,
-
- kTypeVec128 = 9,
-
- kTypeVec256 = 10,
-
- kTypeVec512 = 11,
-
- kTypeVec1024 = 12,
-
- kTypeOther0 = 13,
-
- kTypeOther1 = 14,
-
- kTypeIP = 15,
-
- kTypeCustom = 16,
-
- kTypeMax = 31
- };
-
- enum RegGroup : uint32_t {
-
- kGroupGp = 0,
-
- kGroupVec = 1,
-
- kGroupOther0 = 2,
-
- kGroupOther1 = 3,
-
- kGroupVirt = 4,
-
- kGroupCount = 16
- };
- enum Id : uint32_t {
-
- kIdBad = 0xFFu
- };
- static constexpr uint32_t kSignature = kOpReg;
-
-
-
- constexpr BaseReg() noexcept
- : Operand(Globals::Init, kSignature, kIdBad, 0, 0) {}
-
- constexpr BaseReg(const BaseReg& other) noexcept
- : Operand(other) {}
-
- constexpr BaseReg(const BaseReg& other, uint32_t rId) noexcept
- : Operand(Globals::Init, other._signature, rId, 0, 0) {}
-
- constexpr BaseReg(uint32_t signature, uint32_t rId) noexcept
- : Operand(Globals::Init, signature, rId, 0, 0) {}
- inline explicit BaseReg(Globals::NoInit_) noexcept
- : Operand(Globals::NoInit) {}
-
-
-
- inline BaseReg& operator=(const BaseReg& other) noexcept = default;
-
-
-
-
-
-
-
-
-
-
-
-
- constexpr bool isSame(const BaseReg& other) const noexcept {
- return (_signature == other._signature) &
- (_baseId == other._baseId ) ;
- }
-
- constexpr bool isValid() const noexcept { return (_signature != 0) & (_baseId != kIdBad); }
-
- constexpr bool isPhysReg() const noexcept { return _baseId < kIdBad; }
-
- constexpr bool isVirtReg() const noexcept { return _baseId > kIdBad; }
-
- constexpr bool isType(uint32_t type) const noexcept { return (_signature & kSignatureRegTypeMask) == (type << kSignatureRegTypeShift); }
-
- constexpr bool isGroup(uint32_t group) const noexcept { return (_signature & kSignatureRegGroupMask) == (group << kSignatureRegGroupShift); }
-
- constexpr bool isGp() const noexcept { return isGroup(kGroupGp); }
-
- constexpr bool isVec() const noexcept { return isGroup(kGroupVec); }
- using Operand_::isReg;
-
- constexpr bool isReg(uint32_t rType) const noexcept { return isType(rType); }
-
- constexpr bool isReg(uint32_t rType, uint32_t rId) const noexcept { return isType(rType) && id() == rId; }
-
- constexpr uint32_t type() const noexcept { return _getSignaturePart<kSignatureRegTypeMask>(); }
-
- constexpr uint32_t group() const noexcept { return _getSignaturePart<kSignatureRegGroupMask>(); }
-
- constexpr BaseReg clone() const noexcept { return BaseReg(*this); }
-
-
-
- template<typename RegT>
- constexpr RegT cloneAs() const noexcept { return RegT(RegT::kSignature, id()); }
-
-
-
- template<typename RegT>
- constexpr RegT cloneAs(const RegT& other) const noexcept { return RegT(other.signature(), id()); }
-
- inline void setId(uint32_t rId) noexcept { _baseId = rId; }
-
- template<typename RegT>
- inline void setSignatureT() noexcept { _signature = RegT::kSignature; }
-
- inline void setSignatureAndId(uint32_t signature, uint32_t rId) noexcept {
- _signature = signature;
- _baseId = rId;
- }
-
-
-
- static inline bool isGp(const Operand_& op) noexcept {
-
- const uint32_t kSgn = (kOpReg << kSignatureOpShift ) |
- (kGroupGp << kSignatureRegGroupShift) ;
- return (op.signature() & (kSignatureOpMask | kSignatureRegGroupMask)) == kSgn;
- }
-
- static inline bool isVec(const Operand_& op) noexcept {
-
- const uint32_t kSgn = (kOpReg << kSignatureOpShift ) |
- (kGroupVec << kSignatureRegGroupShift) ;
- return (op.signature() & (kSignatureOpMask | kSignatureRegGroupMask)) == kSgn;
- }
- static inline bool isGp(const Operand_& op, uint32_t rId) noexcept { return isGp(op) & (op.id() == rId); }
- static inline bool isVec(const Operand_& op, uint32_t rId) noexcept { return isVec(op) & (op.id() == rId); }
-
- };
- struct RegOnly {
-
- uint32_t _signature;
-
- uint32_t _id;
-
-
-
- inline void init(uint32_t signature, uint32_t id) noexcept {
- _signature = signature;
- _id = id;
- }
- inline void init(const BaseReg& reg) noexcept { init(reg.signature(), reg.id()); }
- inline void init(const RegOnly& reg) noexcept { init(reg.signature(), reg.id()); }
-
- inline void reset() noexcept { init(0, 0); }
-
-
-
-
- constexpr bool isNone() const noexcept { return _signature == 0; }
-
- constexpr bool isReg() const noexcept { return _signature != 0; }
-
- constexpr bool isPhysReg() const noexcept { return _id < BaseReg::kIdBad; }
-
- constexpr bool isVirtReg() const noexcept { return _id > BaseReg::kIdBad; }
-
- constexpr uint32_t signature() const noexcept { return _signature; }
-
-
-
-
-
- constexpr uint32_t id() const noexcept { return _id; }
-
- inline void setId(uint32_t id) noexcept { _id = id; }
-
-
-
- template<uint32_t mask>
- constexpr uint32_t _getSignaturePart() const noexcept {
- return (_signature >> Support::constCtz(mask)) & (mask >> Support::constCtz(mask));
- }
-
-
- constexpr uint32_t type() const noexcept { return _getSignaturePart<Operand::kSignatureRegTypeMask>(); }
-
- constexpr uint32_t group() const noexcept { return _getSignaturePart<Operand::kSignatureRegGroupMask>(); }
-
-
-
-
- template<typename RegT>
- constexpr RegT toReg() const noexcept { return RegT(_signature, _id); }
-
- };
- class BaseMem : public Operand {
- public:
- enum AddrType : uint32_t {
- kAddrTypeDefault = 0,
- kAddrTypeAbs = 1,
- kAddrTypeRel = 2
- };
-
- enum SignatureMem : uint32_t {
- kSignatureMemAbs = kAddrTypeAbs << kSignatureMemAddrTypeShift,
- kSignatureMemRel = kAddrTypeRel << kSignatureMemAddrTypeShift
- };
-
-
- struct Decomposed {
- uint32_t baseType;
- uint32_t baseId;
- uint32_t indexType;
- uint32_t indexId;
- int32_t offset;
- uint32_t size;
- uint32_t flags;
- };
-
-
-
-
- constexpr BaseMem() noexcept
- : Operand(Globals::Init, kOpMem, 0, 0, 0) {}
-
- constexpr BaseMem(const BaseMem& other) noexcept
- : Operand(other) {}
-
-
- constexpr BaseMem(Globals::Init_, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3) noexcept
- : Operand(Globals::Init, u0, u1, u2, u3) {}
- constexpr BaseMem(const Decomposed& d) noexcept
- : Operand(Globals::Init,
- kOpMem | (d.baseType << kSignatureMemBaseTypeShift )
- | (d.indexType << kSignatureMemIndexTypeShift)
- | (d.size << kSignatureSizeShift )
- | d.flags,
- d.baseId,
- d.indexId,
- uint32_t(d.offset)) {}
-
-
- inline explicit BaseMem(Globals::NoInit_) noexcept
- : Operand(Globals::NoInit) {}
-
- inline void reset() noexcept {
- _signature = kOpMem;
- _baseId = 0;
- _data64 = 0;
- }
-
-
-
- inline BaseMem& operator=(const BaseMem& other) noexcept { copyFrom(other); return *this; }
-
-
-
-
- constexpr BaseMem clone() const noexcept { return BaseMem(*this); }
- constexpr uint32_t addrType() const noexcept { return _getSignaturePart<kSignatureMemAddrTypeMask>(); }
- inline void setAddrType(uint32_t addrType) noexcept { _setSignaturePart<kSignatureMemAddrTypeMask>(addrType); }
- inline void resetAddrType() noexcept { _setSignaturePart<kSignatureMemAddrTypeMask>(0); }
- constexpr bool isAbs() const noexcept { return addrType() == kAddrTypeAbs; }
- inline void setAbs() noexcept { setAddrType(kAddrTypeAbs); }
- constexpr bool isRel() const noexcept { return addrType() == kAddrTypeRel; }
- inline void setRel() noexcept { setAddrType(kAddrTypeRel); }
- constexpr bool isRegHome() const noexcept { return _hasSignaturePart<kSignatureMemRegHomeFlag>(); }
- inline void setRegHome() noexcept { _signature |= kSignatureMemRegHomeFlag; }
- inline void clearRegHome() noexcept { _signature &= ~kSignatureMemRegHomeFlag; }
-
- constexpr bool hasBase() const noexcept { return (_signature & kSignatureMemBaseTypeMask) != 0; }
-
- constexpr bool hasIndex() const noexcept { return (_signature & kSignatureMemIndexTypeMask) != 0; }
-
- constexpr bool hasBaseOrIndex() const noexcept { return (_signature & kSignatureMemBaseIndexMask) != 0; }
-
- constexpr bool hasBaseAndIndex() const noexcept { return (_signature & kSignatureMemBaseTypeMask) != 0 && (_signature & kSignatureMemIndexTypeMask) != 0; }
-
- constexpr bool hasBaseReg() const noexcept { return (_signature & kSignatureMemBaseTypeMask) > (Label::kLabelTag << kSignatureMemBaseTypeShift); }
-
- constexpr bool hasBaseLabel() const noexcept { return (_signature & kSignatureMemBaseTypeMask) == (Label::kLabelTag << kSignatureMemBaseTypeShift); }
-
- constexpr bool hasIndexReg() const noexcept { return (_signature & kSignatureMemIndexTypeMask) > (Label::kLabelTag << kSignatureMemIndexTypeShift); }
-
-
-
-
-
-
- constexpr uint32_t baseType() const noexcept { return _getSignaturePart<kSignatureMemBaseTypeMask>(); }
-
-
- constexpr uint32_t indexType() const noexcept { return _getSignaturePart<kSignatureMemIndexTypeMask>(); }
-
- constexpr uint32_t baseAndIndexTypes() const noexcept { return _getSignaturePart<kSignatureMemBaseIndexMask>(); }
-
-
-
-
-
- constexpr uint32_t baseId() const noexcept { return _baseId; }
-
- constexpr uint32_t indexId() const noexcept { return _mem.indexId; }
-
- inline void setBaseId(uint32_t rId) noexcept { _baseId = rId; }
-
- inline void setIndexId(uint32_t rId) noexcept { _mem.indexId = rId; }
-
- inline void setBase(const BaseReg& base) noexcept { return _setBase(base.type(), base.id()); }
-
- inline void setIndex(const BaseReg& index) noexcept { return _setIndex(index.type(), index.id()); }
- inline void _setBase(uint32_t rType, uint32_t rId) noexcept {
- _setSignaturePart<kSignatureMemBaseTypeMask>(rType);
- _baseId = rId;
- }
- inline void _setIndex(uint32_t rType, uint32_t rId) noexcept {
- _setSignaturePart<kSignatureMemIndexTypeMask>(rType);
- _mem.indexId = rId;
- }
-
- inline void resetBase() noexcept { _setBase(0, 0); }
-
- inline void resetIndex() noexcept { _setIndex(0, 0); }
-
- inline void setSize(uint32_t size) noexcept { _setSignaturePart<kSignatureSizeMask>(size); }
-
-
-
- constexpr bool isOffset64Bit() const noexcept { return baseType() == 0; }
-
- constexpr bool hasOffset() const noexcept {
- return (_mem.offsetLo32 | uint32_t(_baseId & Support::bitMaskFromBool<uint32_t>(isOffset64Bit()))) != 0;
- }
-
- constexpr int64_t offset() const noexcept {
- return isOffset64Bit() ? int64_t(uint64_t(_mem.offsetLo32) | (uint64_t(_baseId) << 32))
- : int64_t(int32_t(_mem.offsetLo32));
- }
-
- constexpr int32_t offsetLo32() const noexcept { return int32_t(_mem.offsetLo32); }
-
-
-
-
- constexpr int32_t offsetHi32() const noexcept { return int32_t(_baseId); }
-
-
-
-
-
-
-
- inline void setOffset(int64_t offset) noexcept {
- uint32_t lo = uint32_t(uint64_t(offset) & 0xFFFFFFFFu);
- uint32_t hi = uint32_t(uint64_t(offset) >> 32);
- uint32_t hiMsk = Support::bitMaskFromBool<uint32_t>(isOffset64Bit());
- _mem.offsetLo32 = lo;
- _baseId = (hi & hiMsk) | (_baseId & ~hiMsk);
- }
-
- inline void setOffsetLo32(int32_t offset) noexcept { _mem.offsetLo32 = uint32_t(offset); }
-
-
-
-
-
-
- inline void addOffset(int64_t offset) noexcept {
- if (isOffset64Bit()) {
- int64_t result = offset + int64_t(uint64_t(_mem.offsetLo32) | (uint64_t(_baseId) << 32));
- _mem.offsetLo32 = uint32_t(uint64_t(result) & 0xFFFFFFFFu);
- _baseId = uint32_t(uint64_t(result) >> 32);
- }
- else {
- _mem.offsetLo32 += uint32_t(uint64_t(offset) & 0xFFFFFFFFu);
- }
- }
-
-
- inline void addOffsetLo32(int32_t offset) noexcept { _mem.offsetLo32 += uint32_t(offset); }
-
- inline void resetOffset() noexcept { setOffset(0); }
-
-
- inline void resetOffsetLo32() noexcept { setOffsetLo32(0); }
-
- };
- class Imm : public Operand {
- public:
-
-
-
- constexpr Imm() noexcept
- : Operand(Globals::Init, kOpImm, 0, 0, 0) {}
-
- constexpr Imm(const Imm& other) noexcept
- : Operand(other) {}
-
- constexpr explicit Imm(int64_t val) noexcept
- : Operand(Globals::Init, kOpImm, 0, Support::unpackU32At0(val), Support::unpackU32At1(val)) {}
- inline explicit Imm(Globals::NoInit_) noexcept
- : Operand(Globals::NoInit) {}
-
-
-
-
- inline Imm& operator=(const Imm& other) noexcept { copyFrom(other); return *this; }
-
-
-
-
- constexpr bool isInt8() const noexcept { return Support::isInt8(int64_t(_data64)); }
-
- constexpr bool isUInt8() const noexcept { return Support::isUInt8(int64_t(_data64)); }
-
- constexpr bool isInt16() const noexcept { return Support::isInt16(int64_t(_data64)); }
-
- constexpr bool isUInt16() const noexcept { return Support::isUInt16(int64_t(_data64)); }
-
- constexpr bool isInt32() const noexcept { return Support::isInt32(int64_t(_data64)); }
-
- constexpr bool isUInt32() const noexcept { return Support::isUInt32(int64_t(_data64)); }
-
- constexpr int8_t i8() const noexcept { return int8_t(_data64 & 0xFFu); }
-
- constexpr uint8_t u8() const noexcept { return uint8_t(_data64 & 0xFFu); }
-
- constexpr int16_t i16() const noexcept { return int16_t(_data64 & 0xFFFFu);}
-
- constexpr uint16_t u16() const noexcept { return uint16_t(_data64 & 0xFFFFu);}
-
- constexpr int32_t i32() const noexcept { return int32_t(_data64 & 0xFFFFFFFFu); }
-
- constexpr int32_t i32Lo() const noexcept { return int32_t(_data64 & 0xFFFFFFFFu); }
-
- constexpr int32_t i32Hi() const noexcept { return int32_t(_data64 >> 32); }
-
- constexpr uint32_t u32() const noexcept { return uint32_t(_data64 & 0xFFFFFFFFu); }
-
- constexpr uint32_t u32Lo() const noexcept { return uint32_t(_data64 & 0xFFFFFFFFu); }
-
- constexpr uint32_t u32Hi() const noexcept { return uint32_t(_data64 >> 32); }
-
- constexpr int64_t i64() const noexcept { return int64_t(_data64); }
-
- constexpr uint64_t u64() const noexcept { return _data64; }
-
- constexpr intptr_t iptr() const noexcept { return (sizeof(intptr_t) == sizeof(int64_t)) ? intptr_t(_data64) : intptr_t(i32()); }
-
- constexpr uintptr_t uptr() const noexcept { return (sizeof(uintptr_t) == sizeof(uint64_t)) ? uintptr_t(_data64) : uintptr_t(u32()); }
-
- inline void setI8(int8_t val) noexcept { _data64 = uint64_t(int64_t(val)); }
-
- inline void setU8(uint8_t val) noexcept { _data64 = uint64_t(val); }
-
- inline void setI16(int16_t val) noexcept { _data64 = uint64_t(int64_t(val)); }
-
- inline void setU16(uint16_t val) noexcept { _data64 = uint64_t(val); }
-
- inline void setI32(int32_t val) noexcept { _data64 = uint64_t(int64_t(val)); }
-
- inline void setU32(uint32_t val) noexcept { _data64 = uint64_t(val); }
-
- inline void setI64(int64_t val) noexcept { _data64 = uint64_t(val); }
-
- inline void setU64(uint64_t val) noexcept { _data64 = val; }
-
- inline void setIPtr(intptr_t val) noexcept { _data64 = uint64_t(int64_t(val)); }
-
- inline void setUPtr(uintptr_t val) noexcept { _data64 = uint64_t(val); }
-
- template<typename T>
- inline void setValue(T val) noexcept { setI64(int64_t(Support::asNormalized(val))); }
- inline void setDouble(double d) noexcept {
- _data64 = Support::bitCast<uint64_t>(d);
- }
-
-
-
-
- constexpr Imm clone() const noexcept { return Imm(*this); }
- inline void signExtend8Bits() noexcept { _data64 = uint64_t(int64_t(i8())); }
- inline void signExtend16Bits() noexcept { _data64 = uint64_t(int64_t(i16())); }
- inline void signExtend32Bits() noexcept { _data64 = uint64_t(int64_t(i32())); }
- inline void zeroExtend8Bits() noexcept { _data64 &= 0x000000FFu; }
- inline void zeroExtend16Bits() noexcept { _data64 &= 0x0000FFFFu; }
- inline void zeroExtend32Bits() noexcept { _data64 &= 0xFFFFFFFFu; }
-
- };
- template<typename T>
- static constexpr Imm imm(T val) noexcept {
- return Imm(std::is_signed<T>::value ? int64_t(val) : int64_t(uint64_t(val)));
- }
- ASMJIT_END_NAMESPACE
- #endif
|