Bug 1435220 - Clean up MASM APIs for wasm truncation checks. r=bbouvier

Several things happening here:
1) Rename the APIs to include the word 'Check' and shorten the names slightly
2) Implement for ARM and implement stubs for ARM64
3) Clean up Rabaldr's use of these functions, which was a little messy

--HG--
extra : source : 271c7c15fab7a6e9bbee8ecb5fc930f66b25a6c8
This commit is contained in:
Lars T Hansen 2018-02-02 13:17:02 +01:00
Родитель 15dc879760
Коммит feb0563930
6 изменённых файлов: 105 добавлений и 64 удалений

Просмотреть файл

@ -1520,15 +1520,15 @@ class MacroAssembler : public MacroAssemblerSpecific
// wasm specific methods, used in both the wasm baseline compiler and ion.
void wasmTruncateDoubleToUInt32(FloatRegister input, Register output, Label* oolEntry) PER_ARCH;
void wasmTruncateDoubleToInt32(FloatRegister input, Register output, Label* oolEntry) PER_SHARED_ARCH;
void outOfLineWasmTruncateDoubleToInt32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
DEFINED_ON(x86_shared);
void oolWasmTruncateCheckF64ToI32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
DEFINED_ON(arm, arm64, x86_shared);
void wasmTruncateFloat32ToUInt32(FloatRegister input, Register output, Label* oolEntry) PER_ARCH;
void wasmTruncateFloat32ToInt32(FloatRegister input, Register output, Label* oolEntry) PER_SHARED_ARCH;
void outOfLineWasmTruncateFloat32ToInt32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
DEFINED_ON(x86_shared);
void oolWasmTruncateCheckF32ToI32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
DEFINED_ON(arm, arm64, x86_shared);
void wasmTruncateDoubleToInt64(FloatRegister input, Register64 output, Label* oolEntry,
Label* oolRejoin, FloatRegister tempDouble)
@ -1536,9 +1536,9 @@ class MacroAssembler : public MacroAssemblerSpecific
void wasmTruncateDoubleToUInt64(FloatRegister input, Register64 output, Label* oolEntry,
Label* oolRejoin, FloatRegister tempDouble)
DEFINED_ON(arm64, x86, x64);
void outOfLineWasmTruncateDoubleToInt64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
DEFINED_ON(x86_shared);
void oolWasmTruncateCheckF64ToI64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
DEFINED_ON(arm, arm64, x86_shared);
void wasmTruncateFloat32ToInt64(FloatRegister input, Register64 output, Label* oolEntry,
Label* oolRejoin, FloatRegister tempDouble)
@ -1546,9 +1546,9 @@ class MacroAssembler : public MacroAssemblerSpecific
void wasmTruncateFloat32ToUInt64(FloatRegister input, Register64 output, Label* oolEntry,
Label* oolRejoin, FloatRegister tempDouble)
DEFINED_ON(arm64, x86, x64);
void outOfLineWasmTruncateFloat32ToInt64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
DEFINED_ON(x86_shared);
void oolWasmTruncateCheckF32ToI64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
DEFINED_ON(arm, arm64, x86_shared);
// This function takes care of loading the callee's TLS and pinned regs but
// it is the caller's responsibility to save/restore TLS or pinned regs.

Просмотреть файл

@ -4918,6 +4918,38 @@ MacroAssembler::wasmTruncateFloat32ToInt32(FloatRegister input, Register output,
wasmTruncateToInt32(input, output, MIRType::Float32, /* isUnsigned= */ false, oolEntry);
}
void
MacroAssembler::oolWasmTruncateCheckF32ToI32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
outOfLineWasmTruncateToIntCheck(input, MIRType::Float32, MIRType::Int32, isUnsigned,
rejoin, off);
}
void
MacroAssembler::oolWasmTruncateCheckF64ToI32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
outOfLineWasmTruncateToIntCheck(input, MIRType::Double, MIRType::Int32, isUnsigned,
rejoin, off);
}
void
MacroAssembler::oolWasmTruncateCheckF32ToI64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
outOfLineWasmTruncateToIntCheck(input, MIRType::Float32, MIRType::Int64, isUnsigned,
rejoin, off);
}
void
MacroAssembler::oolWasmTruncateCheckF64ToI64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
outOfLineWasmTruncateToIntCheck(input, MIRType::Double, MIRType::Int64, isUnsigned,
rejoin, off);
}
void
MacroAssembler::wasmLoad(const wasm::MemoryAccessDesc& access, Register memoryBase, Register ptr,
Register ptrScratch, AnyRegister output)

Просмотреть файл

@ -929,6 +929,34 @@ MacroAssembler::wasmTruncateFloat32ToUInt64(FloatRegister input, Register64 outp
MOZ_CRASH("NYI");
}
void
MacroAssembler::oolWasmTruncateCheckF32ToI32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
MOZ_CRASH("NYI");
}
void
MacroAssembler::oolWasmTruncateCheckF64ToI32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
MOZ_CRASH("NYI");
}
void
MacroAssembler::oolWasmTruncateCheckF32ToI64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
MOZ_CRASH("NYI");
}
void
MacroAssembler::oolWasmTruncateCheckF64ToI64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
MOZ_CRASH("NYI");
}
// ========================================================================
// Convert floating point.

Просмотреть файл

@ -4358,16 +4358,16 @@ CodeGeneratorX86Shared::visitOutOfLineWasmTruncateCheck(OutOfLineWasmTruncateChe
if (fromType == MIRType::Float32) {
if (toType == MIRType::Int32)
masm.outOfLineWasmTruncateFloat32ToInt32(input, isUnsigned, off, oolRejoin);
masm.oolWasmTruncateCheckF32ToI32(input, isUnsigned, off, oolRejoin);
else if (toType == MIRType::Int64)
masm.outOfLineWasmTruncateFloat32ToInt64(input, isUnsigned, off, oolRejoin);
masm.oolWasmTruncateCheckF32ToI64(input, isUnsigned, off, oolRejoin);
else
MOZ_CRASH("unexpected type");
} else if (fromType == MIRType::Double) {
if (toType == MIRType::Int32)
masm.outOfLineWasmTruncateDoubleToInt32(input, isUnsigned, off, oolRejoin);
masm.oolWasmTruncateCheckF64ToI32(input, isUnsigned, off, oolRejoin);
else if (toType == MIRType::Int64)
masm.outOfLineWasmTruncateDoubleToInt64(input, isUnsigned, off, oolRejoin);
masm.oolWasmTruncateCheckF64ToI64(input, isUnsigned, off, oolRejoin);
else
MOZ_CRASH("unexpected type");
} else {

Просмотреть файл

@ -717,8 +717,8 @@ MacroAssembler::wasmTruncateFloat32ToInt32(FloatRegister input, Register output,
}
void
MacroAssembler::outOfLineWasmTruncateDoubleToInt32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
MacroAssembler::oolWasmTruncateCheckF64ToI32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
AutoHandleWasmTruncateToIntErrors traps(*this, off);
@ -740,8 +740,8 @@ MacroAssembler::outOfLineWasmTruncateDoubleToInt32(FloatRegister input, bool isU
}
void
MacroAssembler::outOfLineWasmTruncateFloat32ToInt32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
MacroAssembler::oolWasmTruncateCheckF32ToI32(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
AutoHandleWasmTruncateToIntErrors traps(*this, off);
@ -761,8 +761,8 @@ MacroAssembler::outOfLineWasmTruncateFloat32ToInt32(FloatRegister input, bool is
}
void
MacroAssembler::outOfLineWasmTruncateDoubleToInt64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
MacroAssembler::oolWasmTruncateCheckF64ToI64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
AutoHandleWasmTruncateToIntErrors traps(*this, off);
@ -788,8 +788,8 @@ MacroAssembler::outOfLineWasmTruncateDoubleToInt64(FloatRegister input, bool isU
}
void
MacroAssembler::outOfLineWasmTruncateFloat32ToInt64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
MacroAssembler::oolWasmTruncateCheckF32ToI64(FloatRegister input, bool isUnsigned,
wasm::BytecodeOffset off, Label* rejoin)
{
AutoHandleWasmTruncateToIntErrors traps(*this, off);

Просмотреть файл

@ -3578,40 +3578,33 @@ class BaseCompiler final : public BaseCompilerInterface
#endif
}
class OutOfLineTruncateF32OrF64ToI32 : public OutOfLineCode
class OutOfLineTruncateCheckF32OrF64ToI32 : public OutOfLineCode
{
AnyReg src;
RegI32 dest;
bool isUnsigned;
BytecodeOffset off;
public:
OutOfLineTruncateF32OrF64ToI32(AnyReg src, RegI32 dest, bool isUnsigned, BytecodeOffset off)
OutOfLineTruncateCheckF32OrF64ToI32(AnyReg src, bool isUnsigned, BytecodeOffset off)
: src(src),
dest(dest),
isUnsigned(isUnsigned),
off(off)
{}
virtual void generate(MacroAssembler* masm) override {
bool isFloat = src.tag == AnyReg::F32;
FloatRegister fsrc = isFloat ? static_cast<FloatRegister>(src.f32())
: static_cast<FloatRegister>(src.f64());
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
if (isFloat)
masm->outOfLineWasmTruncateFloat32ToInt32(fsrc, isUnsigned, off, rejoin());
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_ARM) || \
defined(JS_CODEGEN_ARM64)
if (src.tag == AnyReg::F32)
masm->oolWasmTruncateCheckF32ToI32(src.f32(), isUnsigned, off, rejoin());
else if (src.tag == AnyReg::F64)
masm->oolWasmTruncateCheckF64ToI32(src.f64(), isUnsigned, off, rejoin());
else
masm->outOfLineWasmTruncateDoubleToInt32(fsrc, isUnsigned, off, rejoin());
#elif defined(JS_CODEGEN_ARM)
masm->outOfLineWasmTruncateToIntCheck(fsrc,
isFloat ? MIRType::Float32 : MIRType::Double,
MIRType::Int32, isUnsigned, rejoin(), off);
MOZ_CRASH("unexpected type");
#else
(void)src;
(void)isUnsigned;
(void)off;
(void)isFloat;
(void)fsrc;
MOZ_CRASH("BaseCompiler platform hook: OutOfLineTruncateF32OrF64ToI32 wasm");
MOZ_CRASH("BaseCompiler platform hook: OutOfLineTruncateCheckF32OrF64ToI32 wasm");
#endif
}
};
@ -3619,10 +3612,9 @@ class BaseCompiler final : public BaseCompilerInterface
MOZ_MUST_USE bool truncateF32ToI32(RegF32 src, RegI32 dest, bool isUnsigned) {
BytecodeOffset off = bytecodeOffset();
OutOfLineCode* ool =
addOutOfLineCode(new(alloc_) OutOfLineTruncateF32OrF64ToI32(AnyReg(src),
dest,
isUnsigned,
off));
addOutOfLineCode(new(alloc_) OutOfLineTruncateCheckF32OrF64ToI32(AnyReg(src),
isUnsigned,
off));
if (!ool)
return false;
if (isUnsigned)
@ -3636,10 +3628,9 @@ class BaseCompiler final : public BaseCompilerInterface
MOZ_MUST_USE bool truncateF64ToI32(RegF64 src, RegI32 dest, bool isUnsigned) {
BytecodeOffset off = bytecodeOffset();
OutOfLineCode* ool =
addOutOfLineCode(new(alloc_) OutOfLineTruncateF32OrF64ToI32(AnyReg(src),
dest,
isUnsigned,
off));
addOutOfLineCode(new(alloc_) OutOfLineTruncateCheckF32OrF64ToI32(AnyReg(src),
isUnsigned,
off));
if (!ool)
return false;
if (isUnsigned)
@ -3650,8 +3641,6 @@ class BaseCompiler final : public BaseCompilerInterface
return true;
}
// This does not generate a value; if the truncation failed then it traps.
class OutOfLineTruncateCheckF32OrF64ToI64 : public OutOfLineCode
{
AnyReg src;
@ -3666,20 +3655,12 @@ class BaseCompiler final : public BaseCompilerInterface
{}
virtual void generate(MacroAssembler* masm) override {
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_ARM) || \
defined(JS_CODEGEN_ARM64)
if (src.tag == AnyReg::F32)
masm->outOfLineWasmTruncateFloat32ToInt64(src.f32(), isUnsigned, off, rejoin());
masm->oolWasmTruncateCheckF32ToI64(src.f32(), isUnsigned, off, rejoin());
else if (src.tag == AnyReg::F64)
masm->outOfLineWasmTruncateDoubleToInt64(src.f64(), isUnsigned, off, rejoin());
else
MOZ_CRASH("unexpected type");
#elif defined(JS_CODEGEN_ARM)
if (src.tag == AnyReg::F32)
masm->outOfLineWasmTruncateToIntCheck(src.f32(), MIRType::Float32,
MIRType::Int64, isUnsigned, rejoin(), off);
else if (src.tag == AnyReg::F64)
masm->outOfLineWasmTruncateToIntCheck(src.f64(), MIRType::Double, MIRType::Int64,
isUnsigned, rejoin(), off);
masm->oolWasmTruncateCheckF64ToI64(src.f64(), isUnsigned, off, rejoin());
else
MOZ_CRASH("unexpected type");
#else