Scalar replace subarray instructions
Categories
(Core :: JavaScript Engine: JIT, enhancement, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox143 | --- | fixed |
People
(Reporter: anba, Assigned: anba)
References
(Blocks 1 open bug)
Details
Attachments
(12 external files)
Support scalar replacement of subarray for the following instructions:
- Simple array buffer view instructions (
MArrayBufferViewByteOffset,MArrayBufferViewLength,MTypedArrayElementSize). MTypedArrayFillto support the patternta.subarray(...).fill(value). (Used in JetStream3 "bigint-noble-secp256k1", "bigint-noble-ed25519", and "tfjs-wasm".)MTypedArraySetto support the patternsta.subarray(...).set(src)(used in JetStream3 "8bitbench-wasm") andta.set(src.subarray(...), ...)(used in JetStream3 "pdfjs", "mandreel", "sqlite3-wasm", "bigint-noble-secp256k1", "bigint-noble-ed25519", "tfjs-wasm", "tsf-wasm", "zlib-wasm", "gcc-loops-wasm")MTypedArraySubarrayto support chainedsubarraycalls. (Used for example insanitizeGlyphin pdfjs.)
NOTE: Code patterns mentioned above were found through grep and don't reflect actually executed code. See table below for actual calls to subarray in JetStream 3.
Calls to inlined subarray from JetStream3 benchmarks, recording every 250th call:
| Name | subarray from Baseline |
subarray from Ion (no EA) |
subarray from Ion (with EA) |
|---|---|---|---|
| 8bitbench-wasm | 1250 | 0 | 0 |
| bigint-noble-ed25519 | 500 | 5000 | 0 |
| bigint-noble-secp256k1 | 7750 | 51500 | 3750 |
| pdfjs | 750 | 3750 | 3750 |
| tfjs-wasm | 11500 | 1750 | 0 |
| tfjs-wasm-simd | 11500 | 1750 | 0 |
| tsf-wasm | 2750 | 13500 | 0 |
| zlib-wasm | 500 | 1750 | 0 |
Notes:
- Remaining
subarrayin bigint-noble-secp256k1 escape when callingbytesToNumberfromfromCompressedHex,fromUncompressedHex, andparseDERInt. - I haven't investigated why tfjs-wasm(-simd) has a high number of `subarray calls from Baseline.
| Assignee | ||
Comment 1•1 year ago
|
||
Make MTypedArraySubarray recoverable in preparation for scalar replacement
support.
Recovering is almost trivial except for the special case when the underlying
buffer was detached after the subarray call. In that case the recover code
has to create a TypedArray with a detached ArrayBuffer, which is normally not
an allowed operation.
| Assignee | ||
Comment 2•1 year ago
|
||
Add MToIntegerIndex which computes the result of js::ToIntegerIndex.
Used in the next part.
| Assignee | ||
Comment 3•1 year ago
|
||
Using the actual start index and length simplifies scalar replacement in the
next parts.
| Assignee | ||
Comment 4•1 year ago
|
||
Add a template object to replace shape guards during scalar replacement.
| Assignee | ||
Comment 5•1 year ago
|
||
New instruction to represent MArrayBufferViewElements with an offset applied.
Used in the next part.
| Assignee | ||
Comment 6•1 year ago
|
||
Handle MGuardShape and MUnbox which are both replaced with the
MTypedArraySubarray instruction itself.
| Assignee | ||
Comment 7•1 year ago
|
||
MGuardHasAttachedArrayBuffer is replaced with a guard on subarray->object().
| Assignee | ||
Comment 8•1 year ago
|
||
Add scalar replacement support for:
MArrayBufferViewByteOffsetMArrayBufferViewLengthMTypedArrayElementSize
Replacing MGuardHasAttachedArrayBuffer with a guard on the subarray's object
(see part 7) means we can no longer just compare the current instruction's operand
with SubarrayReplacer::subarray_, but instead also have to check for new
MGuardHasAttachedArrayBuffer instructions.
Example: ta.subarray(0, 2).fill(0)
SSA graph:
27 TypedArraySubarray GuardHasAttachedArrayBuffer#19 ToIntegerIndex#23 Sub#26
...
38 GuardShape TypedArraySubarray#27
39 GuardHasAttachedArrayBuffer GuardShape#38
...
41 Constant 0x0
42 ArrayBufferViewLength GuardHasAttachedArrayBuffer#39
43 TypedArrayFill GuardHasAttachedArrayBuffer#39 TruncateToInt32#40 Constant#41 ArrayBufferViewLength#42
GuardHasAttachedArrayBuffer#39 is replaced with a new guard on the subarray's
object, so when we replace ArrayBufferViewLength#42, we have to account for
the replaced guard.
| Assignee | ||
Comment 9•1 year ago
|
||
Add a five operands instruction class.
Used in the next part.
| Assignee | ||
Comment 10•1 year ago
|
||
TypedArray.prototype.fill has start and end parameters, but unfortunately
JetStream 3 benchmarks instead use ta.subarray(start).fill(0)!
| Assignee | ||
Comment 11•1 year ago
|
||
There are three cases to consider:
subarrayis the target object inset:ta.subarray(...).set(...)
In this case we just need to adjust the set offset parameter to include
the subarray start parameter.
subarrayis the source object inset: ta.set(src.subarray(...), ...)`
This case requires a new instruction to pass through the subarray start and
length operands.
subarrayis both the target and source object.
This is case is a no-op instruction.
| Assignee | ||
Comment 12•1 year ago
|
||
This case just requires adding both start operands.
Updated•1 year ago
|
Updated•1 year ago
|
Comment 13•1 year ago
|
||
Comment 14•1 year ago
|
||
Comment 15•1 year ago
|
||
| Assignee | ||
Comment 16•1 year ago
|
||
The pdfpaint issue was caused by a bug in part 2.
Comment 17•1 year ago
|
||
Comment 18•1 year ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/dc3600d8005d
https://hg.mozilla.org/mozilla-central/rev/e85e249f2ded
https://hg.mozilla.org/mozilla-central/rev/834436b34477
https://hg.mozilla.org/mozilla-central/rev/3df8edb665bb
https://hg.mozilla.org/mozilla-central/rev/03e311b45ee8
https://hg.mozilla.org/mozilla-central/rev/ffe53d696cf7
https://hg.mozilla.org/mozilla-central/rev/d8f5e7f22a92
https://hg.mozilla.org/mozilla-central/rev/3235237d70a9
https://hg.mozilla.org/mozilla-central/rev/f4f05dfb4927
https://hg.mozilla.org/mozilla-central/rev/c055a1519ceb
https://hg.mozilla.org/mozilla-central/rev/0d91709aabe9
https://hg.mozilla.org/mozilla-central/rev/021ef054533f
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Description
•