Skip to content

Commit 47e3bae

Browse files
committed
BBQJIT Splat 0/-1 should emit only one instruction
https://bugs.webkit.org/show_bug.cgi?id=257051 Reviewed by Yusuke Suzuki. According to WebAssembly/design#1476 at least one person wants to encode vector 0 as Splat i32.const 0 since the former's encoding is 18 bytes whereas the latter is 5 bytes. As such, we should emit Splat i32.const 0/-1 as the optimal code in BBQJIT. * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJIT::addSIMDSplat): Canonical link: https://commits.webkit.org/264280@main
1 parent 1b1a76c commit 47e3bae

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Source/JavaScriptCore/wasm/WasmBBQJIT.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -7460,6 +7460,54 @@ class BBQJIT {
74607460
{
74617461
Location valueLocation;
74627462
if (value.isConst()) {
7463+
auto moveZeroToVector = [&] () -> PartialResult {
7464+
result = topValue(TypeKind::V128);
7465+
Location resultLocation = allocate(result);
7466+
m_jit.moveZeroToVector(resultLocation.asFPR());
7467+
LOG_INSTRUCTION("VectorSplat", lane, value, valueLocation, RESULT(result));
7468+
return { };
7469+
};
7470+
7471+
auto moveOnesToVector = [&] () -> PartialResult {
7472+
result = topValue(TypeKind::V128);
7473+
Location resultLocation = allocate(result);
7474+
#if CPU(X86_64)
7475+
m_jit.compareIntegerVector(RelationalCondition::Equal, SIMDInfo { SIMDLane::i32x4, SIMDSignMode::Unsigned }, resultLocation.asFPR(), resultLocation.asFPR(), resultLocation.asFPR(), wasmScratchFPR);
7476+
#else
7477+
m_jit.compareIntegerVector(RelationalCondition::Equal, SIMDInfo { SIMDLane::i32x4, SIMDSignMode::Unsigned }, resultLocation.asFPR(), resultLocation.asFPR(), resultLocation.asFPR());
7478+
#endif
7479+
LOG_INSTRUCTION("VectorSplat", lane, value, valueLocation, RESULT(result));
7480+
return { };
7481+
};
7482+
7483+
switch (lane) {
7484+
case SIMDLane::i8x16:
7485+
case SIMDLane::i16x8:
7486+
case SIMDLane::i32x4:
7487+
case SIMDLane::f32x4: {
7488+
// In theory someone could encode only the bottom bits for the i8x16/i16x8 cases but that would
7489+
// require more bytes in the wasm encoding than just encoding 0/-1, so we don't worry about that.
7490+
if (!value.asI32())
7491+
return moveZeroToVector();
7492+
if (value.asI32() == -1)
7493+
return moveOnesToVector();
7494+
break;
7495+
}
7496+
case SIMDLane::i64x2:
7497+
case SIMDLane::f64x2: {
7498+
if (!value.asI64())
7499+
return moveZeroToVector();
7500+
if (value.asI64() == -1)
7501+
return moveOnesToVector();
7502+
break;
7503+
}
7504+
7505+
default:
7506+
RELEASE_ASSERT_NOT_REACHED();
7507+
break;
7508+
7509+
}
7510+
74637511
if (value.isFloat()) {
74647512
ScratchScope<0, 1> scratches(*this);
74657513
valueLocation = Location::fromFPR(scratches.fpr(0));

0 commit comments

Comments
 (0)