Closed Bug 2034367 Opened 5 months ago Closed 5 months ago

Improve performance of wasm wide-arithmetic on x86_64

Categories

(Core :: JavaScript: WebAssembly, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox152 --- fixed

People

(Reporter: jseward, Assigned: jseward)

References

(Blocks 2 open bugs)

Details

Attachments

(2 files)

Our initial implementation of i64.{add,sub}128 and i64.mul_wide_{u,s} can be
slow, especially on x86_64, per numbers at [1]. We should investigate and
improve.

[1] https://github.com/WebAssembly/wide-arithmetic/issues/7#issuecomment-4292562703

Reworks the x64 sequence for {M,L}MulI64WideHI64. Improves
performance for https://github.com/alexcrichton/wasm-benchmark-i128
on Intel Tiger Lake by 3.5%.

Summary: Investigate/fix poor performance of initial implementation of wasm wide-arithmetic → Improve performance of wasm wide-arithmetic on x86_64

This patch:

  • Reworks the x64 sequence for MacroAssembler::wasmMulI64WideHI64 and hence for
    {M,L}MulI64WideHI64. Specifically, MacroAssembler::wasmMulI64WideHI64 no
    longer tries to preserve RAX and RDX; those registers are trashed and instead
    the problem of preserving them is given to the Ion register allocator / to
    the baseline "manual" allocator.

    This makes the sequences shorter and allows removal of the "xchg"
    instruction, which (judging from Agner Fog's latency tables) is a limiting
    factor on ILP.

    No change for any non-x86_64 targets.

  • Adds a foldsTo method for MWasmAddSubI128HI64. This doesn't see much
    action, but can fold out 0 + x and x + 0 cases.

Performance for https://github.com/alexcrichton/wasm-benchmark-i128 on Intel
Tiger Lake is improved by 3.5%, mostly via improved IPC.

Blocks: 2037383
Status: NEW → RESOLVED
Closed: 5 months ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch
QA Whiteboard: [qa-triage-done-c153/b152]
Regressions: 2042770
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: