commit bdb1c980261cfddaae0e69035910538fa191d4cb
parent 7bf2612d5fc80eb3735ef2288e36a1d6da235732
Author: André Bargull <andre.bargull@gmail.com>
Date: Tue, 11 Nov 2025 12:29:35 +0000
Bug 1998452: Avoid REX prefix for And with unsigned 32-bit immediate. r=spidermonkey-reviewers,iain
Not emitting the REX prefix saves a byte.
Differential Revision: https://phabricator.services.mozilla.com/D271434
Diffstat:
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/js/src/jit/x64/MacroAssembler-x64-inl.h b/js/src/jit/x64/MacroAssembler-x64-inl.h
@@ -84,18 +84,28 @@ void MacroAssembler::notPtr(Register reg) { notq(reg); }
void MacroAssembler::andPtr(Register src, Register dest) { andq(src, dest); }
-void MacroAssembler::andPtr(Imm32 imm, Register dest) { andq(imm, dest); }
+void MacroAssembler::andPtr(Imm32 imm, Register dest) {
+ if (imm.value >= 0) {
+ andl(imm, dest);
+ } else {
+ andq(imm, dest);
+ }
+}
void MacroAssembler::andPtr(Imm32 imm, Register src, Register dest) {
if (src != dest) {
movq(src, dest);
}
- andq(imm, dest);
+ andPtr(imm, dest);
}
void MacroAssembler::and64(Imm64 imm, Register64 dest) {
if (INT32_MIN <= int64_t(imm.value) && int64_t(imm.value) <= INT32_MAX) {
- andq(Imm32(imm.value), dest.reg);
+ if (int32_t(imm.value) >= 0) {
+ andl(Imm32(imm.value), dest.reg);
+ } else {
+ andq(Imm32(imm.value), dest.reg);
+ }
} else {
ScratchRegisterScope scratch(*this);
movq(ImmWord(uintptr_t(imm.value)), scratch);
diff --git a/js/src/jit/x64/MacroAssembler-x64.cpp b/js/src/jit/x64/MacroAssembler-x64.cpp
@@ -1578,7 +1578,7 @@ void MacroAssembler::convertUInt64ToDouble(Register64 input,
mov(input.reg, scratch);
mov(input.reg, temp);
shrq(Imm32(1), scratch);
- andq(Imm32(1), temp);
+ andl(Imm32(1), temp);
orq(temp, scratch);
vcvtsq2sd(scratch, output, output);
@@ -1608,7 +1608,7 @@ void MacroAssembler::convertUInt64ToFloat32(Register64 input,
mov(input.reg, scratch);
mov(input.reg, temp);
shrq(Imm32(1), scratch);
- andq(Imm32(1), temp);
+ andl(Imm32(1), temp);
orq(temp, scratch);
vcvtsq2ss(scratch, output, output);