Skip to content

Commit

Permalink
BBQJIT Splat 0/-1 should emit only one instruction
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kmiller68 committed May 19, 2023
1 parent 1b1a76c commit 47e3bae
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Source/JavaScriptCore/wasm/WasmBBQJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7460,6 +7460,54 @@ class BBQJIT {
{
Location valueLocation;
if (value.isConst()) {
auto moveZeroToVector = [&] () -> PartialResult {
result = topValue(TypeKind::V128);
Location resultLocation = allocate(result);
m_jit.moveZeroToVector(resultLocation.asFPR());
LOG_INSTRUCTION("VectorSplat", lane, value, valueLocation, RESULT(result));
return { };
};

auto moveOnesToVector = [&] () -> PartialResult {
result = topValue(TypeKind::V128);
Location resultLocation = allocate(result);
#if CPU(X86_64)
m_jit.compareIntegerVector(RelationalCondition::Equal, SIMDInfo { SIMDLane::i32x4, SIMDSignMode::Unsigned }, resultLocation.asFPR(), resultLocation.asFPR(), resultLocation.asFPR(), wasmScratchFPR);
#else
m_jit.compareIntegerVector(RelationalCondition::Equal, SIMDInfo { SIMDLane::i32x4, SIMDSignMode::Unsigned }, resultLocation.asFPR(), resultLocation.asFPR(), resultLocation.asFPR());
#endif
LOG_INSTRUCTION("VectorSplat", lane, value, valueLocation, RESULT(result));
return { };
};

switch (lane) {
case SIMDLane::i8x16:
case SIMDLane::i16x8:
case SIMDLane::i32x4:
case SIMDLane::f32x4: {
// In theory someone could encode only the bottom bits for the i8x16/i16x8 cases but that would
// require more bytes in the wasm encoding than just encoding 0/-1, so we don't worry about that.
if (!value.asI32())
return moveZeroToVector();
if (value.asI32() == -1)
return moveOnesToVector();
break;
}
case SIMDLane::i64x2:
case SIMDLane::f64x2: {
if (!value.asI64())
return moveZeroToVector();
if (value.asI64() == -1)
return moveOnesToVector();
break;
}

default:
RELEASE_ASSERT_NOT_REACHED();
break;

}

if (value.isFloat()) {
ScratchScope<0, 1> scratches(*this);
valueLocation = Location::fromFPR(scratches.fpr(0));
Expand Down

0 comments on commit 47e3bae

Please sign in to comment.