mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-01 10:13:43 +01:00
Arm64Emitter: Add some helper functions to add / sub by immediate
This commit is contained in:
1 parent
e7e58591da
commit
feec574ece
2 files changed
+55
-3
No files matched your search
+51
-3
@@ -40,6 +40,19 @@ bool IsPowerOfTwo(uint64_t x) {
|
||||
|
||||
#define V8_UINT64_C(x) ((uint64_t)(x))
|
||||
|
||||
static bool IsImmArithmetic(uint64_t input, u32 *val, bool *shift) {
|
||||
if (input < 4096) {
|
||||
*val = input;
|
||||
*shift = false;
|
||||
return true;
|
||||
} else if ((input & 0xFFF000) == input) {
|
||||
*val = input >> 12;
|
||||
*shift = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsImmLogical(uint64_t value,
|
||||
unsigned int width,
|
||||
unsigned int *n,
|
||||
@@ -3065,7 +3078,7 @@ void ARM64XEmitter::ANDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
||||
if (IsImmLogical(imm, Is64Bit(Rn) ? 64 : 32, &n, &imm_s, &imm_r)) {
|
||||
AND(Rd, Rn, imm_r, imm_s);
|
||||
} else {
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ANDSI2R - failed to construct immediate value from %08x, need scratch", (u32)imm)
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ANDSI2R - failed to construct immediate value from %08x, need scratch", (u32)imm);
|
||||
MOVI2R(scratch, imm);
|
||||
AND(Rd, Rn, scratch);
|
||||
}
|
||||
@@ -3076,7 +3089,7 @@ void ARM64XEmitter::ORI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) {
|
||||
if (IsImmLogical(imm, Is64Bit(Rn) ? 64 : 32, &n, &imm_s, &imm_r)) {
|
||||
ORR(Rd, Rn, imm_r, imm_s);
|
||||
} else {
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ORI2R - failed to construct immediate value from %08x, need scratch", (u32)imm)
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ORI2R - failed to construct immediate value from %08x, need scratch", (u32)imm);
|
||||
MOVI2R(scratch, imm);
|
||||
ORR(Rd, Rn, scratch);
|
||||
}
|
||||
@@ -3087,11 +3100,46 @@ void ARM64XEmitter::ANDSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
||||
if (IsImmLogical(imm, Is64Bit(Rn) ? 64 : 32, &n, &imm_s, &imm_r)) {
|
||||
ANDS(Rd, Rn, imm_r, imm_s);
|
||||
} else {
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ANDSI2R - failed to construct immediate value from %08x, need scratch", (u32)imm)
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ANDSI2R - failed to construct immediate value from %08x, need scratch", (u32)imm);
|
||||
MOVI2R(scratch, imm);
|
||||
ANDS(Rd, Rn, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
void ARM64XEmitter::ADDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) {
|
||||
u32 val;
|
||||
bool shift;
|
||||
if (IsImmArithmetic(imm, &val, &shift)) {
|
||||
ADD(Rd, Rn, val, shift);
|
||||
} else {
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ANDSI2R - failed to construct immediate value from %08x, need scratch", (u32)imm);
|
||||
MOVI2R(scratch, imm);
|
||||
ADD(Rd, Rn, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
void ARM64XEmitter::SUBI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) {
|
||||
u32 val;
|
||||
bool shift;
|
||||
if (IsImmArithmetic(imm, &val, &shift)) {
|
||||
SUB(Rd, Rn, val, shift);
|
||||
} else {
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ANDSI2R - failed to construct immediate value from %08x, need scratch", (u32)imm);
|
||||
MOVI2R(scratch, imm);
|
||||
SUB(Rd, Rn, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
void ARM64XEmitter::SUBSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) {
|
||||
u32 val;
|
||||
bool shift;
|
||||
if (IsImmArithmetic(imm, &val, &shift)) {
|
||||
SUBS(Rd, Rn, val, shift);
|
||||
} else {
|
||||
_assert_msg_(JIT, scratch != INVALID_REG, "ANDSI2R - failed to construct immediate value from %08x, need scratch", (u32)imm);
|
||||
MOVI2R(scratch, imm);
|
||||
SUBS(Rd, Rn, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -649,6 +649,10 @@ public:
|
||||
void TSTI2R(ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG) { ANDSI2R(Is64Bit(Rn) ? SP : WSP, Rn, imm, scratch); }
|
||||
void ORI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG);
|
||||
|
||||
void ADDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG);
|
||||
void SUBI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG);
|
||||
void SUBSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG);
|
||||
|
||||
// ABI related
|
||||
void ABI_PushRegisters(BitSet32 registers);
|
||||
void ABI_PopRegisters(BitSet32 registers, BitSet32 ignore_mask = BitSet32(0));
|
||||
|
||||
Reference in new issue
Block a user