From 450c84c9906185dfa0ae47b68a03361d7f0187e7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 9 Mar 2016 02:20:00 -0500 Subject: emitter: Remove unimplemented prototype --- src/common/x64/emitter.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/common/x64/emitter.h b/src/common/x64/emitter.h index 2dd0dc94e..05a269859 100644 --- a/src/common/x64/emitter.h +++ b/src/common/x64/emitter.h @@ -175,7 +175,6 @@ struct OpArg void WriteRex(XEmitter *emit, int opBits, int bits, int customOp = -1) const; void WriteVex(XEmitter* emit, X64Reg regOp1, X64Reg regOp2, int L, int pp, int mmmmm, int W = 0) const; void WriteRest(XEmitter *emit, int extraBytes=0, X64Reg operandReg=INVALID_REG, bool warn_64bit_offset = true) const; - void WriteFloatModRM(XEmitter *emit, FloatOp op); void WriteSingleByteOp(XEmitter *emit, u8 op, X64Reg operandReg, int bits); // This one is public - must be written to u64 offset; // use RIP-relative as much as possible - 64-bit immediates are not available. -- cgit v1.2.3 From 77bcdafc94927afeb4555be42d4b638dfb1470f2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 9 Mar 2016 02:25:00 -0500 Subject: emitter: friend class OpArg with XEmitter --- src/common/x64/emitter.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/common/x64/emitter.h b/src/common/x64/emitter.h index 05a269859..0efc0d202 100644 --- a/src/common/x64/emitter.h +++ b/src/common/x64/emitter.h @@ -157,6 +157,8 @@ class XEmitter; // RIP addressing does not benefit from micro op fusion on Core arch struct OpArg { + friend class XEmitter; + OpArg() {} // dummy op arg, used for storage OpArg(u64 _offset, int _scale, X64Reg rmReg = RAX, X64Reg scaledReg = RAX) { @@ -176,9 +178,6 @@ struct OpArg void WriteVex(XEmitter* emit, X64Reg regOp1, X64Reg regOp2, int L, int pp, int mmmmm, int W = 0) const; void WriteRest(XEmitter *emit, int extraBytes=0, X64Reg operandReg=INVALID_REG, bool warn_64bit_offset = true) const; void WriteSingleByteOp(XEmitter *emit, u8 op, X64Reg operandReg, int bits); - // This one is public - must be written to - u64 offset; // use RIP-relative as much as possible - 64-bit immediates are not available. - u16 operandReg; void WriteNormalOp(XEmitter *emit, bool toRM, NormalOp op, const OpArg &operand, int bits) const; bool IsImm() const {return scale == SCALE_IMM8 || scale == SCALE_IMM16 || scale == SCALE_IMM32 || scale == SCALE_IMM64;} @@ -240,6 +239,8 @@ private: u8 scale; u16 offsetOrBaseReg; u16 indexReg; + u64 offset; // use RIP-relative as much as possible - 64-bit immediates are not available. + u16 operandReg; }; inline OpArg M(const void *ptr) {return OpArg((u64)ptr, (int)SCALE_RIP);} -- cgit v1.2.3 From 6085b419e51ea652ab030bd6a4ab3b89c993dd90 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 9 Mar 2016 02:30:13 -0500 Subject: emitter: constexpr-ify OpArg --- src/common/x64/emitter.h | 60 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/common/x64/emitter.h b/src/common/x64/emitter.h index 0efc0d202..5e228f159 100644 --- a/src/common/x64/emitter.h +++ b/src/common/x64/emitter.h @@ -159,34 +159,35 @@ struct OpArg { friend class XEmitter; - OpArg() {} // dummy op arg, used for storage - OpArg(u64 _offset, int _scale, X64Reg rmReg = RAX, X64Reg scaledReg = RAX) + constexpr OpArg() = default; // dummy op arg, used for storage + constexpr OpArg(u64 offset_, int scale_, X64Reg rmReg = RAX, X64Reg scaledReg = RAX) + : scale(static_cast(scale_)) + , offsetOrBaseReg(static_cast(rmReg)) + , indexReg(static_cast(scaledReg)) + , offset(offset_) { - operandReg = 0; - scale = (u8)_scale; - offsetOrBaseReg = (u16)rmReg; - indexReg = (u16)scaledReg; - //if scale == 0 never mind offsetting - offset = _offset; } - bool operator==(const OpArg &b) const + + constexpr bool operator==(const OpArg &b) const { - return operandReg == b.operandReg && scale == b.scale && offsetOrBaseReg == b.offsetOrBaseReg && - indexReg == b.indexReg && offset == b.offset; + return operandReg == b.operandReg && + scale == b.scale && + offsetOrBaseReg == b.offsetOrBaseReg && + indexReg == b.indexReg && + offset == b.offset; } + void WriteRex(XEmitter *emit, int opBits, int bits, int customOp = -1) const; void WriteVex(XEmitter* emit, X64Reg regOp1, X64Reg regOp2, int L, int pp, int mmmmm, int W = 0) const; void WriteRest(XEmitter *emit, int extraBytes=0, X64Reg operandReg=INVALID_REG, bool warn_64bit_offset = true) const; void WriteSingleByteOp(XEmitter *emit, u8 op, X64Reg operandReg, int bits); - void WriteNormalOp(XEmitter *emit, bool toRM, NormalOp op, const OpArg &operand, int bits) const; - bool IsImm() const {return scale == SCALE_IMM8 || scale == SCALE_IMM16 || scale == SCALE_IMM32 || scale == SCALE_IMM64;} - bool IsSimpleReg() const {return scale == SCALE_NONE;} - bool IsSimpleReg(X64Reg reg) const + + constexpr bool IsImm() const { return scale == SCALE_IMM8 || scale == SCALE_IMM16 || scale == SCALE_IMM32 || scale == SCALE_IMM64; } + constexpr bool IsSimpleReg() const { return scale == SCALE_NONE; } + constexpr bool IsSimpleReg(X64Reg reg) const { - if (!IsSimpleReg()) - return false; - return GetSimpleReg() == reg; + return IsSimpleReg() && GetSimpleReg() == reg; } bool CanDoOpWith(const OpArg &other) const @@ -218,16 +219,15 @@ struct OpArg } } - X64Reg GetSimpleReg() const + constexpr X64Reg GetSimpleReg() const { - if (scale == SCALE_NONE) - return (X64Reg)offsetOrBaseReg; - else - return INVALID_REG; + return scale == SCALE_NONE + ? static_cast(offsetOrBaseReg) + : INVALID_REG; } - u32 GetImmValue() const { - return (u32)offset; + constexpr u32 GetImmValue() const { + return static_cast(offset); } // For loops. @@ -236,11 +236,11 @@ struct OpArg } private: - u8 scale; - u16 offsetOrBaseReg; - u16 indexReg; - u64 offset; // use RIP-relative as much as possible - 64-bit immediates are not available. - u16 operandReg; + u8 scale = 0; + u16 offsetOrBaseReg = 0; + u16 indexReg = 0; + u64 offset = 0; // use RIP-relative as much as possible - 64-bit immediates are not available. + u16 operandReg = 0; }; inline OpArg M(const void *ptr) {return OpArg((u64)ptr, (int)SCALE_RIP);} -- cgit v1.2.3 From e66a6a2a1b14cc000fd0443f6554365534098be5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 9 Mar 2016 02:33:37 -0500 Subject: emitter: Get rid of CanDoOpWith This was removed in Dolphin as there were no particular uses for it. I'm sure the same will apply to citra. --- src/common/x64/emitter.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src') diff --git a/src/common/x64/emitter.h b/src/common/x64/emitter.h index 5e228f159..a1d8ab31f 100644 --- a/src/common/x64/emitter.h +++ b/src/common/x64/emitter.h @@ -190,13 +190,6 @@ struct OpArg return IsSimpleReg() && GetSimpleReg() == reg; } - bool CanDoOpWith(const OpArg &other) const - { - if (IsSimpleReg()) return true; - if (!IsSimpleReg() && !other.IsSimpleReg() && !other.IsImm()) return false; - return true; - } - int GetImmBits() const { switch (scale) -- cgit v1.2.3 From 1351c0ce9f2029f695ee47605c99655f078d3c01 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 9 Mar 2016 02:38:28 -0500 Subject: emitter: constexpr-ify helper functions --- src/common/x64/emitter.h | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/common/x64/emitter.h b/src/common/x64/emitter.h index a1d8ab31f..865b724a8 100644 --- a/src/common/x64/emitter.h +++ b/src/common/x64/emitter.h @@ -236,43 +236,41 @@ private: u16 operandReg = 0; }; -inline OpArg M(const void *ptr) {return OpArg((u64)ptr, (int)SCALE_RIP);} template -inline OpArg M(const T *ptr) {return OpArg((u64)(const void *)ptr, (int)SCALE_RIP);} -inline OpArg R(X64Reg value) {return OpArg(0, SCALE_NONE, value);} -inline OpArg MatR(X64Reg value) {return OpArg(0, SCALE_ATREG, value);} +inline OpArg M(const T *ptr) { return OpArg(reinterpret_cast(ptr), static_cast(SCALE_RIP)); } +constexpr OpArg R(X64Reg value) { return OpArg(0, SCALE_NONE, value); } +constexpr OpArg MatR(X64Reg value) { return OpArg(0, SCALE_ATREG, value); } -inline OpArg MDisp(X64Reg value, int offset) +constexpr OpArg MDisp(X64Reg value, int offset) { - return OpArg((u32)offset, SCALE_ATREG, value); + return OpArg(static_cast(offset), SCALE_ATREG, value); } -inline OpArg MComplex(X64Reg base, X64Reg scaled, int scale, int offset) +constexpr OpArg MComplex(X64Reg base, X64Reg scaled, int scale, int offset) { return OpArg(offset, scale, base, scaled); } -inline OpArg MScaled(X64Reg scaled, int scale, int offset) +constexpr OpArg MScaled(X64Reg scaled, int scale, int offset) { - if (scale == SCALE_1) - return OpArg(offset, SCALE_ATREG, scaled); - else - return OpArg(offset, scale | 0x20, RAX, scaled); + return scale == SCALE_1 + ? OpArg(offset, SCALE_ATREG, scaled) + : OpArg(offset, scale | 0x20, RAX, scaled); } -inline OpArg MRegSum(X64Reg base, X64Reg offset) +constexpr OpArg MRegSum(X64Reg base, X64Reg offset) { return MComplex(base, offset, 1, 0); } -inline OpArg Imm8 (u8 imm) {return OpArg(imm, SCALE_IMM8);} -inline OpArg Imm16(u16 imm) {return OpArg(imm, SCALE_IMM16);} //rarely used -inline OpArg Imm32(u32 imm) {return OpArg(imm, SCALE_IMM32);} -inline OpArg Imm64(u64 imm) {return OpArg(imm, SCALE_IMM64);} -inline OpArg UImmAuto(u32 imm) { +constexpr OpArg Imm8 (u8 imm) { return OpArg(imm, SCALE_IMM8); } +constexpr OpArg Imm16(u16 imm) { return OpArg(imm, SCALE_IMM16); } //rarely used +constexpr OpArg Imm32(u32 imm) { return OpArg(imm, SCALE_IMM32); } +constexpr OpArg Imm64(u64 imm) { return OpArg(imm, SCALE_IMM64); } +constexpr OpArg UImmAuto(u32 imm) { return OpArg(imm, imm >= 128 ? SCALE_IMM32 : SCALE_IMM8); } -inline OpArg SImmAuto(s32 imm) { +constexpr OpArg SImmAuto(s32 imm) { return OpArg(imm, (imm >= 128 || imm < -128) ? SCALE_IMM32 : SCALE_IMM8); } -- cgit v1.2.3 From e3f9d09b28f662c699d14706f738c5f7881bf13c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 9 Mar 2016 02:41:07 -0500 Subject: emitter: templatize ImmPtr --- src/common/x64/emitter.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/common/x64/emitter.h b/src/common/x64/emitter.h index 865b724a8..7c6548fb5 100644 --- a/src/common/x64/emitter.h +++ b/src/common/x64/emitter.h @@ -274,11 +274,15 @@ constexpr OpArg SImmAuto(s32 imm) { return OpArg(imm, (imm >= 128 || imm < -128) ? SCALE_IMM32 : SCALE_IMM8); } +template +OpArg ImmPtr(const T* imm) +{ #ifdef _ARCH_64 -inline OpArg ImmPtr(const void* imm) {return Imm64((u64)imm);} + return Imm64(reinterpret_cast(imm)); #else -inline OpArg ImmPtr(const void* imm) {return Imm32((u32)imm);} + return Imm32(reinterpret_cast(imm)); #endif +} inline u32 PtrOffset(const void* ptr, const void* base) { -- cgit v1.2.3