← All issues

[JSC] Add String#lastIndexOf optimizations

5efecc3

Source/WTF/wtf/SIMDHelpers.h

+ALWAYS_INLINE uint8_t findLastNonZeroIndex(SIMDRegister<uint8_t, N> mask)
+{
+ for (int i = N - 1; i >= 0; --i)
+ if (mask[i])
+ return static_cast<uint8_t>(i);
+ return UINT8_MAX;
+}

Adds JIT intrinsic support for String.prototype.lastIndexOf across DFG and FTL, mirroring the existing indexOf infrastructure. Introduces a StringLastIndexOf DFG node, FTL B3 lowering, and SIMD-accelerated reverse string search (SIMD::reverseFind, findLastNonZeroIndex) in WTF. The fromIndex semantics differ from forward search: NaN maps to +Infinity (not 0), and the search scans backward from min(fromIndex, len - searchLen).

Substantial new JIT code surface — new node semantics, new SIMD primitives, and fromIndex boundary logic that differs non-trivially from the forward-search path.

🔒

New SIMD reverse-scan kernel and JIT fast path with non-trivial fromIndex boundary semantics — several edge cases warrant security investigation.

Subscribe to read more