| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef jit_x86_shared_LIR_x86_shared_h |
| 8 |
#define jit_x86_shared_LIR_x86_shared_h |
| 9 |
|
| 10 |
namespace js { |
| 11 |
namespace jit { |
| 12 |
|
| 13 |
class LDivOrModConstantI : public LInstructionHelper<1, 1, 1> { |
| 14 |
const int32_t denominator_; |
| 15 |
|
| 16 |
public: |
| 17 |
LIR_HEADER(DivOrModConstantI) |
| 18 |
|
| 19 |
LDivOrModConstantI(const LAllocation& lhs, int32_t denominator, |
| 20 |
const LDefinition& temp) |
| 21 |
: LInstructionHelper(classOpcode), denominator_(denominator) { |
| 22 |
setOperand(0, lhs); |
| 23 |
setTemp(0, temp); |
| 24 |
} |
| 25 |
|
| 26 |
const LAllocation* numerator() { return getOperand(0); } |
| 27 |
int32_t denominator() const { return denominator_; } |
| 28 |
MBinaryArithInstruction* mir() const { |
| 29 |
MOZ_ASSERT(mir_->isDiv() || mir_->isMod()); |
| 30 |
return static_cast<MBinaryArithInstruction*>(mir_); |
| 31 |
} |
| 32 |
bool canBeNegativeDividend() const { |
| 33 |
if (mir_->isMod()) { |
| 34 |
return mir_->toMod()->canBeNegativeDividend(); |
| 35 |
} |
| 36 |
return mir_->toDiv()->canBeNegativeDividend(); |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
// This class performs a simple x86 'div', yielding either a quotient or |
| 41 |
// remainder depending on whether this instruction is defined to output eax |
| 42 |
// (quotient) or edx (remainder). |
| 43 |
class LUDivOrMod : public LBinaryMath<1> { |
| 44 |
public: |
| 45 |
LIR_HEADER(UDivOrMod); |
| 46 |
|
| 47 |
LUDivOrMod(const LAllocation& lhs, const LAllocation& rhs, |
| 48 |
const LDefinition& temp) |
| 49 |
: LBinaryMath(classOpcode) { |
| 50 |
setOperand(0, lhs); |
| 51 |
setOperand(1, rhs); |
| 52 |
setTemp(0, temp); |
| 53 |
} |
| 54 |
|
| 55 |
const LDefinition* remainder() { return getTemp(0); } |
| 56 |
|
| 57 |
const char* extraName() const { |
| 58 |
return mir()->isTruncated() ? "Truncated" : nullptr; |
| 59 |
} |
| 60 |
|
| 61 |
MBinaryArithInstruction* mir() const { |
| 62 |
MOZ_ASSERT(mir_->isDiv() || mir_->isMod()); |
| 63 |
return static_cast<MBinaryArithInstruction*>(mir_); |
| 64 |
} |
| 65 |
|
| 66 |
bool canBeDivideByZero() const { |
| 67 |
if (mir_->isMod()) { |
| 68 |
return mir_->toMod()->canBeDivideByZero(); |
| 69 |
} |
| 70 |
return mir_->toDiv()->canBeDivideByZero(); |
| 71 |
} |
| 72 |
|
| 73 |
bool trapOnError() const { |
| 74 |
if (mir_->isMod()) { |
| 75 |
return mir_->toMod()->trapOnError(); |
| 76 |
} |
| 77 |
return mir_->toDiv()->trapOnError(); |
| 78 |
} |
| 79 |
|
| 80 |
wasm::TrapSiteDesc trapSiteDesc() const { |
| 81 |
if (mir_->isMod()) { |
| 82 |
return mir_->toMod()->trapSiteDesc(); |
| 83 |
} |
| 84 |
return mir_->toDiv()->trapSiteDesc(); |
| 85 |
} |
| 86 |
}; |
| 87 |
|
| 88 |
class LUDivOrModConstant : public LInstructionHelper<1, 1, 1> { |
| 89 |
const uint32_t denominator_; |
| 90 |
|
| 91 |
public: |
| 92 |
LIR_HEADER(UDivOrModConstant) |
| 93 |
|
| 94 |
LUDivOrModConstant(const LAllocation& lhs, uint32_t denominator, |
| 95 |
const LDefinition& temp) |
| 96 |
: LInstructionHelper(classOpcode), denominator_(denominator) { |
| 97 |
setOperand(0, lhs); |
| 98 |
setTemp(0, temp); |
| 99 |
} |
| 100 |
|
| 101 |
const LAllocation* numerator() { return getOperand(0); } |
| 102 |
uint32_t denominator() const { return denominator_; } |
| 103 |
MBinaryArithInstruction* mir() const { |
| 104 |
MOZ_ASSERT(mir_->isDiv() || mir_->isMod()); |
| 105 |
return static_cast<MBinaryArithInstruction*>(mir_); |
| 106 |
} |
| 107 |
bool canBeNegativeDividend() const { |
| 108 |
if (mir_->isMod()) { |
| 109 |
return mir_->toMod()->canBeNegativeDividend(); |
| 110 |
} |
| 111 |
return mir_->toDiv()->canBeNegativeDividend(); |
| 112 |
} |
| 113 |
bool trapOnError() const { |
| 114 |
if (mir_->isMod()) { |
| 115 |
return mir_->toMod()->trapOnError(); |
| 116 |
} |
| 117 |
return mir_->toDiv()->trapOnError(); |
| 118 |
} |
| 119 |
wasm::TrapSiteDesc trapSiteDesc() const { |
| 120 |
if (mir_->isMod()) { |
| 121 |
return mir_->toMod()->trapSiteDesc(); |
| 122 |
} |
| 123 |
return mir_->toDiv()->trapSiteDesc(); |
| 124 |
} |
| 125 |
}; |
| 126 |
|
| 127 |
} // namespace jit |
| 128 |
} // namespace js |
| 129 |
|
| 130 |
#endif /* jit_x86_shared_LIR_x86_shared_h */ |