Skip to content

Commit

Permalink
Bug 1944011 - Part 44: Generate boilerplate for LModI. r=iain
Browse files Browse the repository at this point in the history
Needs a temp register on non-ARM targets, except for that difference the
definition can be shared.

Differential Revision: https://phabricator.services.mozilla.com/D235857
  • Loading branch information
anba committed Jan 31, 2025
1 parent eb91f70 commit 768cac5
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 118 deletions.
10 changes: 9 additions & 1 deletion js/src/jit/LIROps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4895,7 +4895,15 @@
extra_name: true

- name: ModI
gen_boilerplate: false
result_type: WordSized
operands:
lhs: WordSized
rhs: WordSized
#if !defined(JS_CODEGEN_ARM) && !defined(JS_CODEGEN_ARM64)
num_temps: 1
#endif
mir_op: Mod
extra_name: true

- name: DivPowTwoI
gen_boilerplate: false
Expand Down
13 changes: 0 additions & 13 deletions js/src/jit/arm/LIR-arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,6 @@ class LDivPowTwoI : public LInstructionHelper<1, 1, 0> {
MDiv* mir() const { return mir_->toDiv(); }
};

class LModI : public LBinaryMath<0> {
public:
LIR_HEADER(ModI);

LModI(const LAllocation& lhs, const LAllocation& rhs)
: LBinaryMath(classOpcode) {
setOperand(0, lhs);
setOperand(1, rhs);
}

MMod* mir() const { return mir_->toMod(); }
};

class LMulI : public LBinaryMath<0> {
public:
LIR_HEADER(MulI);
Expand Down
13 changes: 0 additions & 13 deletions js/src/jit/arm64/LIR-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ class LDivPowTwoI : public LInstructionHelper<1, 1, 0> {
MDiv* mir() const { return mir_->toDiv(); }
};

class LModI : public LBinaryMath<0> {
public:
LIR_HEADER(ModI);

LModI(const LAllocation& lhs, const LAllocation& rhs)
: LBinaryMath(classOpcode) {
setOperand(0, lhs);
setOperand(1, rhs);
}

MMod* mir() const { return mir_->toMod(); }
};

class LMulI : public LBinaryMath<0> {
public:
LIR_HEADER(MulI);
Expand Down
16 changes: 0 additions & 16 deletions js/src/jit/loong64/LIR-loong64.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ class LDivPowTwoI : public LInstructionHelper<1, 1, 1> {
MDiv* mir() const { return mir_->toDiv(); }
};

class LModI : public LBinaryMath<1> {
public:
LIR_HEADER(ModI);

LModI(const LAllocation& lhs, const LAllocation& rhs,
const LDefinition& callTemp)
: LBinaryMath(classOpcode) {
setOperand(0, lhs);
setOperand(1, rhs);
setTemp(0, callTemp);
}

const LDefinition* callTemp() { return getTemp(0); }
MMod* mir() const { return mir_->toMod(); }
};

class LMulI : public LBinaryMath<0> {
public:
LIR_HEADER(MulI);
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/mips-shared/CodeGenerator-mips-shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ void CodeGenerator::visitModI(LModI* ins) {
Register lhs = ToRegister(ins->lhs());
Register rhs = ToRegister(ins->rhs());
Register dest = ToRegister(ins->output());
Register callTemp = ToRegister(ins->callTemp());
Register callTemp = ToRegister(ins->temp0());
MMod* mir = ins->mir();
Label done;

Expand Down
16 changes: 0 additions & 16 deletions js/src/jit/mips-shared/LIR-mips-shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ class LDivPowTwoI : public LInstructionHelper<1, 1, 1> {
MDiv* mir() const { return mir_->toDiv(); }
};

class LModI : public LBinaryMath<1> {
public:
LIR_HEADER(ModI);

LModI(const LAllocation& lhs, const LAllocation& rhs,
const LDefinition& callTemp)
: LBinaryMath(classOpcode) {
setOperand(0, lhs);
setOperand(1, rhs);
setTemp(0, callTemp);
}

const LDefinition* callTemp() { return getTemp(0); }
MMod* mir() const { return mir_->toMod(); }
};

class LMulI : public LBinaryMath<0> {
public:
LIR_HEADER(MulI);
Expand Down
10 changes: 0 additions & 10 deletions js/src/jit/none/LIR-none.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ class LDivPowTwoI : public LInstructionHelper<1, 1, 0> {
int32_t shift() { MOZ_CRASH(); }
MDiv* mir() const { MOZ_CRASH(); }
};
class LModI : public LBinaryMath<1> {
public:
LModI(const LAllocation&, const LAllocation&, const LDefinition&)
: LBinaryMath(Opcode::Invalid) {
MOZ_CRASH();
}

const LDefinition* callTemp() { MOZ_CRASH(); }
MMod* mir() const { MOZ_CRASH(); }
};

class LMulI : public LInstruction {};

Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/riscv64/CodeGenerator-riscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ void CodeGenerator::visitModI(LModI* ins) {
Register lhs = ToRegister(ins->lhs());
Register rhs = ToRegister(ins->rhs());
Register dest = ToRegister(ins->output());
Register callTemp = ToRegister(ins->callTemp());
Register callTemp = ToRegister(ins->temp0());
MMod* mir = ins->mir();
Label done, prevent;

Expand Down
16 changes: 0 additions & 16 deletions js/src/jit/riscv64/LIR-riscv64.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ class LDivPowTwoI : public LInstructionHelper<1, 1, 1> {
MDiv* mir() const { return mir_->toDiv(); }
};

class LModI : public LBinaryMath<1> {
public:
LIR_HEADER(ModI);

LModI(const LAllocation& lhs, const LAllocation& rhs,
const LDefinition& callTemp)
: LBinaryMath(classOpcode) {
setOperand(0, lhs);
setOperand(1, rhs);
setTemp(0, callTemp);
}

const LDefinition* callTemp() { return getTemp(0); }
MMod* mir() const { return mir_->toMod(); }
};

class LMulI : public LBinaryMath<0> {
public:
LIR_HEADER(MulI);
Expand Down
4 changes: 4 additions & 0 deletions js/src/jit/shared/LIR-shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,10 @@ const char* LDivI::extraName() const {
}
return mir()->canBeNegativeOverflow() ? "NegativeOverflow" : nullptr;
}

const char* LModI::extraName() const {
return mir()->isTruncated() ? "Truncated" : nullptr;
}
#endif

} // namespace jit
Expand Down
10 changes: 0 additions & 10 deletions js/src/jit/wasm32/LIR-wasm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ class LDivPowTwoI : public LInstructionHelper<1, 1, 0> {
int32_t shift() { MOZ_CRASH(); }
MDiv* mir() const { MOZ_CRASH(); }
};
class LModI : public LBinaryMath<1> {
public:
LModI(const LAllocation&, const LAllocation&, const LDefinition&)
: LBinaryMath(Opcode::Invalid) {
MOZ_CRASH();
}

const LDefinition* callTemp() { MOZ_CRASH(); }
MMod* mir() const { MOZ_CRASH(); }
};

class LMulI : public LInstruction {};

Expand Down
4 changes: 2 additions & 2 deletions js/src/jit/x86-shared/CodeGenerator-x86-shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,15 +1365,15 @@ void CodeGeneratorX86Shared::visitModOverflowCheck(ModOverflowCheck* ool) {
}

void CodeGenerator::visitModI(LModI* ins) {
Register remainder = ToRegister(ins->remainder());
Register remainder = ToRegister(ins->output());
Register lhs = ToRegister(ins->lhs());
Register rhs = ToRegister(ins->rhs());

// Required to use idiv.
MOZ_ASSERT_IF(lhs != rhs, rhs != eax);
MOZ_ASSERT(rhs != edx);
MOZ_ASSERT(remainder == edx);
MOZ_ASSERT(ToRegister(ins->getTemp(0)) == eax);
MOZ_ASSERT(ToRegister(ins->temp0()) == eax);

Label done;
ReturnZero* ool = nullptr;
Expand Down
19 changes: 0 additions & 19 deletions js/src/jit/x86-shared/LIR-x86-shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,6 @@ class LDivOrModConstantI : public LInstructionHelper<1, 1, 1> {
}
};

class LModI : public LBinaryMath<1> {
public:
LIR_HEADER(ModI)

LModI(const LAllocation& lhs, const LAllocation& rhs, const LDefinition& temp)
: LBinaryMath(classOpcode) {
setOperand(0, lhs);
setOperand(1, rhs);
setTemp(0, temp);
}

const char* extraName() const {
return mir()->isTruncated() ? "Truncated" : nullptr;
}

const LDefinition* remainder() { return getDef(0); }
MMod* mir() const { return mir_->toMod(); }
};

// This class performs a simple x86 'div', yielding either a quotient or
// remainder depending on whether this instruction is defined to output eax
// (quotient) or edx (remainder).
Expand Down

0 comments on commit 768cac5

Please sign in to comment.