Closed Bug 2089007 Opened 16 days ago Closed 7 days ago

[riscv64] Load patchable words and fixed-address call targets with fewer instructions

Categories

(Core :: JavaScript Engine: JIT, enhancement)

RISCV64
Unspecified
enhancement

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: andrew, Assigned: andrew)

References

(Blocks 1 open bug)

Details

Attachments

(2 external files)

On riscv64, a patchable ImmWord from movWithPatch and pushWithPatch is always loaded with the eight-instruction li_constant sequence, though most hold a value that would fit in the six instructions of li_ptr: the -1 placeholders that IonIC entries, IonScript and nursery labels, and IC stubs are later patched with pointers, and the -1 of a wasm::SymbolicAddress, which StaticallyLink patches with the address of a builtin. li_ptr only takes an unsigned 48-bit value. If it took a sign-extended 48-bit value, -1 would fit and every patchable word that fits could use it; ExtractLoad64Value and UpdateLoad64Value already tell the two sequences apart. Boxed GC Values never fit, as their tag sets the top bits, so they would keep li_constant, and LiPtr::update should crash rather than truncate a value that does not fit.

ma_call(ImmPtr) and ma_jump(ImmPtr) also load their target with the patchable li_ptr, though nothing patches it: the target is a RelocationKind::HARDCODED address that never moves. ma_li loads the 38-bit addresses of a Sv39 process in four instructions.

In a JetStream 3 run on a SpacemiT K3, the first change turns 244,660 of the 415,489 li_constant sequences into li_ptr (489K fewer instructions, including the 171K calls of Wasm code to builtins), and the second shortens about 550K calls and jumps by 1.2M instructions. Together they shrink JIT code by 2.5%: Ion by 3.2%, Baseline by 2.9% and Wasm by 1.6%. Most of the calls and jumps in the second change go to trampolines, which bug 2088588 reaches with pc-relative calls instead; about 71K of them are calls to C++.

Found with riscvlint, a peephole checker for RISC-V code, run over the JIT code generated during JetStream 3.

A patchable ImmWord, from movWithPatch and pushWithPatch, was always loaded
with the eight instructions of li_constant, though most hold a value that fits
in the six of li_ptr: the -1 placeholders that IonIC entries, IonScript and
nursery labels, and IC stubs are later patched with pointers, and the -1 of a
wasm::SymbolicAddress, which StaticallyLink() patches with the address of a
builtin.

Make li_ptr load a sign-extended 48-bit value, so that -1 fits, and use it for
every patchable word that fits. ExtractLoad64Value() and UpdateLoad64Value()
already tell the two sequences apart. A value patched in later has to fit as
well: GC Values never do, as their tag sets the top bits, so they keep
li_constant, and LiPtr::update() now crashes rather than truncate one that
doesn't.

In a JetStream 3 run on a SpacemiT K3 this turns 244,660 of the 415,489
li_constant sequences into li_ptr, 489K fewer instructions, among them the
171K calls of Wasm code to builtins.

Found with riscvlint.

Assignee: nobody → andrew
Status: NEW → ASSIGNED

ma_call(ImmPtr) and ma_jump(ImmPtr) loaded their target with the six
instructions of the patchable li_ptr, though nothing patches it: their targets
are RelocationKind::HARDCODED, which never move. Load it with ma_li, which needs
four instructions for the 38-bit addresses of a Sv39 process.

In a JetStream 3 run on a SpacemiT K3 this shortens about 550K calls and jumps
by 1.2M instructions in all. Most of them go to trampolines, which bug 2088588
reaches with pc-relative calls instead; about 71K are calls to C++.

Found with riscvlint.

Pushed by jdemooij@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/0137c8456764 https://hg.mozilla.org/integration/autoland/rev/fd8b8e1816f7 [riscv64] Load a patchable word that fits in 48 bits with li_ptr. r=csmantle https://github.com/mozilla-firefox/firefox/commit/4e32fee8b779 https://hg.mozilla.org/integration/autoland/rev/94d1d8b65e94 [riscv64] Load the target of a call or jump to a fixed address in as few instructions as possible. r=csmantle
Status: ASSIGNED → RESOLVED
Closed: 7 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: