commit 3a48a0424663e45ef94324391a07093513533b43
parent 5f94800ce6841cba208fda2cefa3b35603147591
Author: André Bargull <andre.bargull@gmail.com>
Date: Mon, 27 Oct 2025 15:22:13 +0000
Bug 1996345 - Part 2: Split codegen for CodeGenerator::visitMulI64. r=spidermonkey-reviewers,iain
Split into separate implementations for x86 and x64 in preparation for part 4.
Differential Revision: https://phabricator.services.mozilla.com/D270022
Diffstat:
3 files changed, 78 insertions(+), 39 deletions(-)
diff --git a/js/src/jit/x64/CodeGenerator-x64.cpp b/js/src/jit/x64/CodeGenerator-x64.cpp
@@ -122,6 +122,45 @@ void CodeGenerator::visitUnbox(LUnbox* unbox) {
}
}
+void CodeGenerator::visitMulI64(LMulI64* lir) {
+ Register64 lhs = ToRegister64(lir->lhs());
+ LInt64Allocation rhs = lir->rhs();
+
+ MOZ_ASSERT(ToOutRegister64(lir) == lhs);
+
+ if (IsConstant(rhs)) {
+ int64_t constant = ToInt64(rhs);
+ switch (constant) {
+ case -1:
+ masm.neg64(lhs);
+ return;
+ case 0:
+ masm.xor64(lhs, lhs);
+ return;
+ case 1:
+ // nop
+ return;
+ case 2:
+ masm.add64(lhs, lhs);
+ return;
+ default:
+ if (constant > 0) {
+ // Use shift if constant is power of 2.
+ int32_t shift = mozilla::FloorLog2(constant);
+ if (int64_t(1) << shift == constant) {
+ masm.lshift64(Imm32(shift), lhs);
+ return;
+ }
+ }
+ Register temp = ToTempRegisterOrInvalid(lir->temp0());
+ masm.mul64(Imm64(constant), lhs, temp);
+ }
+ } else {
+ Register temp = ToTempRegisterOrInvalid(lir->temp0());
+ masm.mul64(ToOperandOrRegister64(rhs), lhs, temp);
+ }
+}
+
void CodeGenerator::visitDivOrModI64(LDivOrModI64* lir) {
Register lhs = ToRegister(lir->lhs());
Register rhs = ToRegister(lir->rhs());
diff --git a/js/src/jit/x86-shared/CodeGenerator-x86-shared.cpp b/js/src/jit/x86-shared/CodeGenerator-x86-shared.cpp
@@ -872,45 +872,6 @@ void CodeGenerator::visitMulI(LMulI* ins) {
}
}
-void CodeGenerator::visitMulI64(LMulI64* lir) {
- Register64 lhs = ToRegister64(lir->lhs());
- LInt64Allocation rhs = lir->rhs();
-
- MOZ_ASSERT(ToOutRegister64(lir) == lhs);
-
- if (IsConstant(rhs)) {
- int64_t constant = ToInt64(rhs);
- switch (constant) {
- case -1:
- masm.neg64(lhs);
- return;
- case 0:
- masm.xor64(lhs, lhs);
- return;
- case 1:
- // nop
- return;
- case 2:
- masm.add64(lhs, lhs);
- return;
- default:
- if (constant > 0) {
- // Use shift if constant is power of 2.
- int32_t shift = mozilla::FloorLog2(constant);
- if (int64_t(1) << shift == constant) {
- masm.lshift64(Imm32(shift), lhs);
- return;
- }
- }
- Register temp = ToTempRegisterOrInvalid(lir->temp0());
- masm.mul64(Imm64(constant), lhs, temp);
- }
- } else {
- Register temp = ToTempRegisterOrInvalid(lir->temp0());
- masm.mul64(ToOperandOrRegister64(rhs), lhs, temp);
- }
-}
-
void CodeGenerator::visitUDivOrMod(LUDivOrMod* ins) {
Register lhs = ToRegister(ins->lhs());
Register rhs = ToRegister(ins->rhs());
diff --git a/js/src/jit/x86/CodeGenerator-x86.cpp b/js/src/jit/x86/CodeGenerator-x86.cpp
@@ -813,6 +813,45 @@ void CodeGeneratorX86::visitOutOfLineTruncateFloat32(
masm.jump(ool->rejoin());
}
+void CodeGenerator::visitMulI64(LMulI64* lir) {
+ Register64 lhs = ToRegister64(lir->lhs());
+ LInt64Allocation rhs = lir->rhs();
+
+ MOZ_ASSERT(ToOutRegister64(lir) == lhs);
+
+ if (IsConstant(rhs)) {
+ int64_t constant = ToInt64(rhs);
+ switch (constant) {
+ case -1:
+ masm.neg64(lhs);
+ return;
+ case 0:
+ masm.xor64(lhs, lhs);
+ return;
+ case 1:
+ // nop
+ return;
+ case 2:
+ masm.add64(lhs, lhs);
+ return;
+ default:
+ if (constant > 0) {
+ // Use shift if constant is power of 2.
+ int32_t shift = mozilla::FloorLog2(constant);
+ if (int64_t(1) << shift == constant) {
+ masm.lshift64(Imm32(shift), lhs);
+ return;
+ }
+ }
+ Register temp = ToTempRegisterOrInvalid(lir->temp0());
+ masm.mul64(Imm64(constant), lhs, temp);
+ }
+ } else {
+ Register temp = ToTempRegisterOrInvalid(lir->temp0());
+ masm.mul64(ToOperandOrRegister64(rhs), lhs, temp);
+ }
+}
+
void CodeGenerator::visitDivOrModI64(LDivOrModI64* lir) {
MOZ_ASSERT(gen->compilingWasm());
MOZ_ASSERT(ToRegister(lir->instance()) == InstanceReg);