Skip to content

Commit

Permalink
Bug 1727254 - Introduce template to capture pattern common to all div…
Browse files Browse the repository at this point in the history
…ide instructions in baseline compiler. r=yury

All the divide instructions have common patterns for checking for
division-by-zero and overflow.  These patterns can be captured
using a template + static functions for emitting the actual
code.

Differential Revision: https://phabricator.services.mozilla.com/D125965
  • Loading branch information
Lars T Hansen committed Sep 20, 2021
1 parent 3637a45 commit e4c8acd
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 100 deletions.
32 changes: 14 additions & 18 deletions js/src/wasm/WasmBCClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,15 @@ struct BaseCompiler final {
[[nodiscard]] bool addInterruptCheck();

// Check that the value is not zero, trap if it is.
void checkDivideByZeroI32(RegI32 rhs);
void checkDivideByZeroI64(RegI64 r);
void checkDivideByZero(RegI32 rhs);
void checkDivideByZero(RegI64 r);

// Check that a signed division will not overflow, trap or flush-to-zero if it
// will according to `zeroOnOverflow`.
void checkDivideSignedOverflowI32(RegI32 rhs, RegI32 srcDest, Label* done,
bool zeroOnOverflow);
void checkDivideSignedOverflowI64(RegI64 rhs, RegI64 srcDest, Label* done,
bool zeroOnOverflow);
void checkDivideSignedOverflow(RegI32 rhs, RegI32 srcDest, Label* done,
bool zeroOnOverflow);
void checkDivideSignedOverflow(RegI64 rhs, RegI64 srcDest, Label* done,
bool zeroOnOverflow);

// Emit a jump table to be used by tableSwitch()
void jumpTable(const LabelVector& labels, Label* theTable);
Expand Down Expand Up @@ -1019,17 +1019,12 @@ struct BaseCompiler final {
//
// Code generators for actual operations.

void quotientI32(RegI32 rhs, RegI32 lhsDest, RegI32 reserved,
IsUnsigned isUnsigned, bool isConst, int32_t c);
void remainderI32(RegI32 rhs, RegI32 lhsDest, RegI32 reserved,
IsUnsigned isUnsigned, bool isConst, int32_t c);

#ifndef RABALDR_INT_DIV_I64_CALLOUT
void quotientI64(RegI64 rhs, RegI64 srcDest, RegI64 reserved,
IsUnsigned isUnsigned, bool isConst, int64_t c);
void remainderI64(RegI64 rhs, RegI64 srcDest, RegI64 reserved,
IsUnsigned isUnsigned, bool isConst, int64_t c);
#endif
template <typename RegType, typename IntType>
void quotientOrRemainder(RegType rs, RegType rsd, RegType reserved,
IsUnsigned isUnsigned, ZeroOnOverflow zeroOnOverflow,
bool isConst, IntType c,
void (*operate)(MacroAssembler&, RegType, RegType,
RegType, IsUnsigned));

[[nodiscard]] bool truncateF32ToI32(RegF32 src, RegI32 dest,
TruncFlags flags);
Expand Down Expand Up @@ -1117,7 +1112,8 @@ struct BaseCompiler final {
void popAndAllocateForDivAndRemI32(RegI32* r0, RegI32* r1, RegI32* reserved);
void popAndAllocateForMulI64(RegI64* r0, RegI64* r1, RegI32* temp);
#ifndef RABALDR_INT_DIV_I64_CALLOUT
void popAndAllocateForDivAndRemI64(RegI64* r0, RegI64* r1, RegI64* reserved);
void popAndAllocateForDivAndRemI64(RegI64* r0, RegI64* r1, RegI64* reserved,
IsRemainder isRemainder);
#endif
RegI32 popI32RhsForShift();
RegI32 popI32RhsForShiftI64();
Expand Down
1 change: 1 addition & 0 deletions js/src/wasm/WasmBCDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ using HandleNaNSpecially = bool;
using InvertBranch = bool;
using IsKnownNotZero = bool;
using IsUnsigned = bool;
using IsRemainder = bool;
using NeedsBoundsCheck = bool;
using WantResult = bool;
using ZeroOnOverflow = bool;
Expand Down
Loading

0 comments on commit e4c8acd

Please sign in to comment.