Issue #3049 - Fix loongarch64 wasm baseline integration

This commit is contained in:
Basilisk-Dev 2026-04-25 02:29:26 -04:00 • committed by wuggy
commit 448d6362ad

View file

@ -2404,7 +2404,11 @@ class BaseCompiler
defined(JS_CODEGEN_LOONGARCH64) defined(JS_CODEGEN_LOONGARCH64)
for (uint32_t i = 0; i < labels.length(); i++) { for (uint32_t i = 0; i < labels.length(); i++) {
CodeLabel cl; CodeLabel cl;
# if defined(JS_CODEGEN_LOONGARCH64)
masm.writeCodePointer(&cl);
# else
masm.writeCodePointer(cl.patchAt()); masm.writeCodePointer(cl.patchAt());
# endif
cl.target()->bind(labels[i]->offset()); cl.target()->bind(labels[i]->offset());
masm.addCodeLabel(cl); masm.addCodeLabel(cl);
} }
@ -2449,7 +2453,7 @@ class BaseCompiler
SecondScratchRegisterScope target(masm); SecondScratchRegisterScope target(masm);
CodeLabel tableCl; CodeLabel tableCl;
masm.mov(tableCl.patchAt(), scratch); masm.ma_li(scratch, tableCl.patchAt());
tableCl.target()->bind(theTable->offset()); tableCl.target()->bind(theTable->offset());
masm.addCodeLabel(tableCl); masm.addCodeLabel(tableCl);
@ -2875,6 +2879,15 @@ class BaseCompiler
} }
}; };
#if defined(JS_CODEGEN_LOONGARCH64)
void branchDoubleToTrap(DoubleCondition cond, FloatRegister lhs,
FloatRegister rhs, Trap trapKind) {
Label trapLabel;
masm.branchDouble(cond, lhs, rhs, &trapLabel);
masm.bindLater(&trapLabel, trap(trapKind));
}
#endif
MOZ_MUST_USE bool truncateF32ToI32(RegF32 src, RegI32 dest, bool isUnsigned) { MOZ_MUST_USE bool truncateF32ToI32(RegF32 src, RegI32 dest, bool isUnsigned) {
TrapOffset off = trapOffset(); TrapOffset off = trapOffset();
OutOfLineCode* ool; OutOfLineCode* ool;
@ -2899,17 +2912,17 @@ class BaseCompiler
RegF64 doubleInput = needF64(); RegF64 doubleInput = needF64();
ScratchF64 scratch(*this); ScratchF64 scratch(*this);
masm.convertFloat32ToDouble(src.reg, doubleInput.reg); masm.convertFloat32ToDouble(src.reg, doubleInput.reg);
masm.branchDouble(Assembler::DoubleUnordered, doubleInput.reg, doubleInput.reg, branchDoubleToTrap(Assembler::DoubleUnordered, doubleInput.reg,
trap(Trap::InvalidConversionToInteger)); doubleInput.reg, Trap::InvalidConversionToInteger);
masm.loadConstantDouble(isUnsigned ? -1.0 : double(INT32_MIN), scratch); masm.loadConstantDouble(isUnsigned ? -1.0 : double(INT32_MIN), scratch);
masm.branchDouble(isUnsigned ? Assembler::DoubleLessThanOrEqual branchDoubleToTrap(isUnsigned ? Assembler::DoubleLessThanOrEqual
: Assembler::DoubleLessThan, : Assembler::DoubleLessThan,
doubleInput.reg, scratch, trap(Trap::IntegerOverflow)); doubleInput.reg, scratch, Trap::IntegerOverflow);
masm.loadConstantDouble(isUnsigned ? double(UINT32_MAX) + 1.0 masm.loadConstantDouble(isUnsigned ? double(UINT32_MAX) + 1.0
: double(INT32_MAX) + 1.0, : double(INT32_MAX) + 1.0,
scratch); scratch);
masm.branchDouble(Assembler::DoubleGreaterThanOrEqual, doubleInput.reg, scratch, branchDoubleToTrap(Assembler::DoubleGreaterThanOrEqual, doubleInput.reg,
trap(Trap::IntegerOverflow)); scratch, Trap::IntegerOverflow);
sync(); sync();
RegI32 temp = needI32(); RegI32 temp = needI32();
@ -2919,6 +2932,7 @@ class BaseCompiler
masm.storeCallInt32Result(dest.reg); masm.storeCallInt32Result(dest.reg);
freeI32(temp); freeI32(temp);
freeF64(doubleInput); freeF64(doubleInput);
return true;
#else #else
MOZ_CRASH("BaseCompiler platform hook: truncateF32ToI32 wasm"); MOZ_CRASH("BaseCompiler platform hook: truncateF32ToI32 wasm");
#endif #endif
@ -2949,17 +2963,17 @@ class BaseCompiler
masm.wasmTruncateDoubleToInt32(src.reg, dest.reg, ool->entry()); masm.wasmTruncateDoubleToInt32(src.reg, dest.reg, ool->entry());
#elif defined(JS_CODEGEN_LOONGARCH64) #elif defined(JS_CODEGEN_LOONGARCH64)
ScratchF64 scratch(*this); ScratchF64 scratch(*this);
masm.branchDouble(Assembler::DoubleUnordered, src.reg, src.reg, branchDoubleToTrap(Assembler::DoubleUnordered, src.reg, src.reg,
trap(Trap::InvalidConversionToInteger)); Trap::InvalidConversionToInteger);
masm.loadConstantDouble(isUnsigned ? -1.0 : double(INT32_MIN), scratch); masm.loadConstantDouble(isUnsigned ? -1.0 : double(INT32_MIN), scratch);
masm.branchDouble(isUnsigned ? Assembler::DoubleLessThanOrEqual branchDoubleToTrap(isUnsigned ? Assembler::DoubleLessThanOrEqual
: Assembler::DoubleLessThan, : Assembler::DoubleLessThan,
src.reg, scratch, trap(Trap::IntegerOverflow)); src.reg, scratch, Trap::IntegerOverflow);
masm.loadConstantDouble(isUnsigned ? double(UINT32_MAX) + 1.0 masm.loadConstantDouble(isUnsigned ? double(UINT32_MAX) + 1.0
: double(INT32_MAX) + 1.0, : double(INT32_MAX) + 1.0,
scratch); scratch);
masm.branchDouble(Assembler::DoubleGreaterThanOrEqual, src.reg, scratch, branchDoubleToTrap(Assembler::DoubleGreaterThanOrEqual, src.reg, scratch,
trap(Trap::IntegerOverflow)); Trap::IntegerOverflow);
sync(); sync();
RegI32 temp = needI32(); RegI32 temp = needI32();
@ -2968,6 +2982,7 @@ class BaseCompiler
masm.callWithABI(SymbolicAddress::ToInt32); masm.callWithABI(SymbolicAddress::ToInt32);
masm.storeCallInt32Result(dest.reg); masm.storeCallInt32Result(dest.reg);
freeI32(temp); freeI32(temp);
return true;
#else #else
MOZ_CRASH("BaseCompiler platform hook: truncateF64ToI32 wasm"); MOZ_CRASH("BaseCompiler platform hook: truncateF64ToI32 wasm");
#endif #endif
@ -3036,15 +3051,15 @@ class BaseCompiler
RegF64 doubleInput = needF64(); RegF64 doubleInput = needF64();
ScratchF64 scratch(*this); ScratchF64 scratch(*this);
masm.convertFloat32ToDouble(src.reg, doubleInput.reg); masm.convertFloat32ToDouble(src.reg, doubleInput.reg);
masm.branchDouble(Assembler::DoubleUnordered, doubleInput.reg, doubleInput.reg, branchDoubleToTrap(Assembler::DoubleUnordered, doubleInput.reg,
trap(Trap::InvalidConversionToInteger)); doubleInput.reg, Trap::InvalidConversionToInteger);
masm.loadConstantDouble(isUnsigned ? -1.0 : double(INT64_MIN), scratch); masm.loadConstantDouble(isUnsigned ? -1.0 : double(INT64_MIN), scratch);
masm.branchDouble(isUnsigned ? Assembler::DoubleLessThanOrEqual branchDoubleToTrap(isUnsigned ? Assembler::DoubleLessThanOrEqual
: Assembler::DoubleLessThan, : Assembler::DoubleLessThan,
doubleInput.reg, scratch, trap(Trap::IntegerOverflow)); doubleInput.reg, scratch, Trap::IntegerOverflow);
masm.loadConstantDouble(isUnsigned ? double(UINT64_MAX) : double(INT64_MAX), scratch); masm.loadConstantDouble(isUnsigned ? double(UINT64_MAX) : double(INT64_MAX), scratch);
masm.branchDouble(Assembler::DoubleGreaterThanOrEqual, doubleInput.reg, scratch, branchDoubleToTrap(Assembler::DoubleGreaterThanOrEqual, doubleInput.reg,
trap(Trap::IntegerOverflow)); scratch, Trap::IntegerOverflow);
sync(); sync();
RegI32 callTemp = needI32(); RegI32 callTemp = needI32();
@ -3078,15 +3093,15 @@ class BaseCompiler
ool->rejoin(), temp.reg); ool->rejoin(), temp.reg);
# elif defined(JS_CODEGEN_LOONGARCH64) # elif defined(JS_CODEGEN_LOONGARCH64)
ScratchF64 scratch(*this); ScratchF64 scratch(*this);
masm.branchDouble(Assembler::DoubleUnordered, src.reg, src.reg, branchDoubleToTrap(Assembler::DoubleUnordered, src.reg, src.reg,
trap(Trap::InvalidConversionToInteger)); Trap::InvalidConversionToInteger);
masm.loadConstantDouble(isUnsigned ? -1.0 : double(INT64_MIN), scratch); masm.loadConstantDouble(isUnsigned ? -1.0 : double(INT64_MIN), scratch);
masm.branchDouble(isUnsigned ? Assembler::DoubleLessThanOrEqual branchDoubleToTrap(isUnsigned ? Assembler::DoubleLessThanOrEqual
: Assembler::DoubleLessThan, : Assembler::DoubleLessThan,
src.reg, scratch, trap(Trap::IntegerOverflow)); src.reg, scratch, Trap::IntegerOverflow);
masm.loadConstantDouble(isUnsigned ? double(UINT64_MAX) : double(INT64_MAX), scratch); masm.loadConstantDouble(isUnsigned ? double(UINT64_MAX) : double(INT64_MAX), scratch);
masm.branchDouble(Assembler::DoubleGreaterThanOrEqual, src.reg, scratch, branchDoubleToTrap(Assembler::DoubleGreaterThanOrEqual, src.reg, scratch,
trap(Trap::IntegerOverflow)); Trap::IntegerOverflow);
sync(); sync();
RegI32 callTemp = needI32(); RegI32 callTemp = needI32();