Skip to content

Commit

Permalink
Bug 1299014 - Move clampIntToUint8 to the generic macro assembler. r=…
Browse files Browse the repository at this point in the history
…arai

---
 js/src/jit/MacroAssembler.h                             |  6 ++++++
 js/src/jit/arm/MacroAssembler-arm-inl.h                 | 14 ++++++++++++++
 js/src/jit/arm/MacroAssembler-arm.h                     |  9 ---------
 js/src/jit/arm64/MacroAssembler-arm64-inl.h             | 17 +++++++++++++++++
 js/src/jit/arm64/MacroAssembler-arm64.h                 | 11 -----------
 js/src/jit/mips-shared/MacroAssembler-mips-shared-inl.h | 16 ++++++++++++++++
 js/src/jit/mips32/MacroAssembler-mips32.cpp             | 13 -------------
 js/src/jit/mips32/MacroAssembler-mips32.h               |  2 --
 js/src/jit/mips64/MacroAssembler-mips64.cpp             | 13 -------------
 js/src/jit/mips64/MacroAssembler-mips64.h               |  2 --
 js/src/jit/none/MacroAssembler-none.h                   |  2 --
 js/src/jit/x86-shared/MacroAssembler-x86-shared-inl.h   |  9 ++++++---
 12 files changed, 59 insertions(+), 55 deletions(-)
  • Loading branch information
heiher committed Sep 1, 2016
1 parent 758fb64 commit 0b81de7
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 55 deletions.
6 changes: 6 additions & 0 deletions js/src/jit/MacroAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,12 @@ class MacroAssembler : public MacroAssemblerSpecific
void wasmCallBuiltinInstanceMethod(const ABIArg& instanceArg,
wasm::SymbolicAddress builtin);

public:
// ========================================================================
// Clamping functions.

inline void clampIntToUint8(Register reg) PER_SHARED_ARCH;

//}}} check_macroassembler_style
public:

Expand Down
14 changes: 14 additions & 0 deletions js/src/jit/arm/MacroAssembler-arm-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,20 @@ MacroAssembler::storeFloat32x3(FloatRegister src, const BaseIndex& dest)
MOZ_CRASH("NYI");
}

// ===============================================================
// Clamping functions.

void
MacroAssembler::clampIntToUint8(Register reg)
{
// Look at (reg >> 8) if it is 0, then reg shouldn't be clamped if it is
// <0, then we want to clamp to 0, otherwise, we wish to clamp to 255
ScratchRegisterScope scratch(*this);
as_mov(scratch, asr(reg, 8), SetCC);
ma_mov(Imm32(0xff), reg, NotEqual);
ma_mov(Imm32(0), reg, Signed);
}

//}}} check_macroassembler_style
// ===============================================================

Expand Down
9 changes: 0 additions & 9 deletions js/src/jit/arm/MacroAssembler-arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1314,15 +1314,6 @@ class MacroAssemblerARMCompat : public MacroAssemblerARM
void atomicExchangeToTypedIntArray(Scalar::Type arrayType, const T& mem, Register value,
Register temp, AnyRegister output);

void clampIntToUint8(Register reg) {
// Look at (reg >> 8) if it is 0, then reg shouldn't be clamped if it is
// <0, then we want to clamp to 0, otherwise, we wish to clamp to 255
ScratchRegisterScope scratch(asMasm());
as_mov(scratch, asr(reg, 8), SetCC);
ma_mov(Imm32(0xff), reg, NotEqual);
ma_mov(Imm32(0), reg, Signed);
}

inline void incrementInt32Value(const Address& addr);

void cmp32(Register lhs, Imm32 rhs);
Expand Down
17 changes: 17 additions & 0 deletions js/src/jit/arm64/MacroAssembler-arm64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,23 @@ MacroAssembler::storeFloat32x3(FloatRegister src, const BaseIndex& dest)
MOZ_CRASH("NYI");
}

// ===============================================================
// Clamping functions.

void
MacroAssembler::clampIntToUint8(Register reg)
{
vixl::UseScratchRegisterScope temps(this);
const ARMRegister scratch32 = temps.AcquireW();
const ARMRegister reg32(reg, 32);
MOZ_ASSERT(!scratch32.Is(reg32));

Cmp(reg32, Operand(reg32, vixl::UXTB));
Csel(reg32, reg32, vixl::wzr, Assembler::GreaterThanOrEqual);
Mov(scratch32, Operand(0xff));
Csel(reg32, reg32, scratch32, Assembler::LessThanOrEqual);
}

//}}} check_macroassembler_style
// ===============================================================

Expand Down
11 changes: 0 additions & 11 deletions js/src/jit/arm64/MacroAssembler-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -2243,17 +2243,6 @@ class MacroAssemblerCompat : public vixl::MacroAssembler
void stackCheck(ImmWord limitAddr, Label* label) {
MOZ_CRASH("stackCheck");
}
void clampIntToUint8(Register reg) {
vixl::UseScratchRegisterScope temps(this);
const ARMRegister scratch32 = temps.AcquireW();
const ARMRegister reg32(reg, 32);
MOZ_ASSERT(!scratch32.Is(reg32));

Cmp(reg32, Operand(reg32, vixl::UXTB));
Csel(reg32, reg32, vixl::wzr, Assembler::GreaterThanOrEqual);
Mov(scratch32, Operand(0xff));
Csel(reg32, reg32, scratch32, Assembler::LessThanOrEqual);
}

void incrementInt32Value(const Address& addr) {
vixl::UseScratchRegisterScope temps(this);
Expand Down
16 changes: 16 additions & 0 deletions js/src/jit/mips-shared/MacroAssembler-mips-shared-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,22 @@ MacroAssembler::storeFloat32x3(FloatRegister src, const BaseIndex& dest)
MOZ_CRASH("NYI");
}

// ===============================================================
// Clamping functions.

void
MacroAssembler::clampIntToUint8(Register reg)
{
// If reg is < 0, then we want to clamp to 0.
as_slti(ScratchRegister, reg, 0);
as_movn(reg, zero, ScratchRegister);

// If reg is >= 255, then we want to clamp to 255.
ma_li(SecondScratchReg, Imm32(255));
as_slti(ScratchRegister, reg, 255);
as_movz(reg, SecondScratchReg, ScratchRegister);
}

//}}} check_macroassembler_style
// ===============================================================

Expand Down
13 changes: 0 additions & 13 deletions js/src/jit/mips32/MacroAssembler-mips32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,19 +1064,6 @@ MacroAssemblerMIPSCompat::storePtr(Register src, AbsoluteAddress dest)
storePtr(src, Address(ScratchRegister, 0));
}

void
MacroAssemblerMIPSCompat::clampIntToUint8(Register reg)
{
// If reg is < 0, then we want to clamp to 0.
as_slti(ScratchRegister, reg, 0);
as_movn(reg, zero, ScratchRegister);

// If reg is >= 255, then we want to clamp to 255.
ma_li(SecondScratchReg, Imm32(255));
as_slti(ScratchRegister, reg, 255);
as_movz(reg, SecondScratchReg, ScratchRegister);
}

// Note: this function clobbers the input register.
void
MacroAssembler::clampDoubleToUint8(FloatRegister input, Register output)
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/mips32/MacroAssembler-mips32.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,6 @@ class MacroAssemblerMIPSCompat : public MacroAssemblerMIPS
moveToDoubleHi(zero, reg);
}

void clampIntToUint8(Register reg);

void convertUInt64ToDouble(Register64 src, Register temp, FloatRegister dest);

void breakpoint();
Expand Down
13 changes: 0 additions & 13 deletions js/src/jit/mips64/MacroAssembler-mips64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,19 +1219,6 @@ MacroAssemblerMIPS64Compat::storePtr(Register src, AbsoluteAddress dest)
storePtr(src, Address(ScratchRegister, 0));
}

void
MacroAssemblerMIPS64Compat::clampIntToUint8(Register reg)
{
// If reg is < 0, then we want to clamp to 0.
as_slti(ScratchRegister, reg, 0);
as_movn(reg, zero, ScratchRegister);

// If reg is >= 255, then we want to clamp to 255.
ma_li(SecondScratchReg, Imm32(255));
as_slti(ScratchRegister, reg, 255);
as_movz(reg, SecondScratchReg, ScratchRegister);
}

// Note: this function clobbers the input register.
void
MacroAssembler::clampDoubleToUint8(FloatRegister input, Register output)
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/mips64/MacroAssembler-mips64.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,6 @@ class MacroAssemblerMIPS64Compat : public MacroAssemblerMIPS64
moveToDouble(zero, reg);
}

void clampIntToUint8(Register reg);

void convertUInt64ToDouble(Register64 src, Register temp, FloatRegister dest);

void breakpoint();
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/none/MacroAssembler-none.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ class MacroAssemblerNone : public Assembler
template <typename T, typename S> void atomicXor16(const T& value, const S& mem) { MOZ_CRASH(); }
template <typename T, typename S> void atomicXor32(const T& value, const S& mem) { MOZ_CRASH(); }

void clampIntToUint8(Register) { MOZ_CRASH(); }

Register splitTagForTest(ValueOperand) { MOZ_CRASH(); }

void boxDouble(FloatRegister, ValueOperand) { MOZ_CRASH(); }
Expand Down
9 changes: 6 additions & 3 deletions js/src/jit/x86-shared/MacroAssembler-x86-shared-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1240,14 +1240,14 @@ MacroAssembler::truncateDoubleToInt64(Address src, Address dest, Register temp)
freeStack(2*sizeof(int32_t));
}

//}}} check_macroassembler_style
// ===============================================================
// Clamping functions.

void
MacroAssemblerX86Shared::clampIntToUint8(Register reg)
MacroAssembler::clampIntToUint8(Register reg)
{
Label inRange;
asMasm().branchTest32(Assembler::Zero, reg, Imm32(0xffffff00), &inRange);
branchTest32(Assembler::Zero, reg, Imm32(0xffffff00), &inRange);
{
sarl(Imm32(31), reg);
notl(reg);
Expand All @@ -1256,6 +1256,9 @@ MacroAssemblerX86Shared::clampIntToUint8(Register reg)
bind(&inRange);
}

//}}} check_macroassembler_style
// ===============================================================

} // namespace jit
} // namespace js

Expand Down

0 comments on commit 0b81de7

Please sign in to comment.