Closed Bug 2075633 Opened 9 days ago Closed 4 days ago

[loong64] Implement LSX-based 128-bit SIMD

Categories

(Core :: JavaScript Engine: JIT, enhancement)

Other
Unspecified
enhancement

Tracking

()

RESOLVED FIXED
159 Branch
Tracking Status
firefox159 --- fixed

People

(Reporter: csmantle, Assigned: csmantle)

References

(Blocks 1 open bug)

Details

Attachments

(15 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
828.94 KB, image/png
Details
1.27 MB, image/png
Details
1.22 MB, image/png
Details
1.03 MB, image/png
Details

Loongson hasn't published an official ISA volume for the LoongArch SIMD Extension (LSX), but there are several sources for reference:

So an implementation is really possible. I have a stack ready locally, and it currently passes all jit-tests, jstests, and jsapi-tests on my Loongson 3B6000, as well as all JetStream Next cases and Speedometer 3. I'm sure this stack will soon be ready for review.

Note that the Simulator-loong64 support is not part of this stack. This would introduce too much work and be much more prone to coding mistakes than assembly and codegen.

Due to the various mismatches among LoongArch ISA FP behavior, IEEE Std
754-2008 and WASM semantics, it is sometimes required to manually
construct canonical QNaNs.

The implemented instructions is only ~30% of the whole LSX instruction
set, but they should be sufficient for implementing a working SIMD
backend. The selection is inspired by V8 and driven by later parts.

Link: https://github.com/loongson-community/loongarch-opcodes
("LoongArch Opcodes (unofficially compiled list)")
Link:
https://jia.je/unofficial-loongarch-intrinsics-guide/migrating_sse/
("Unofficial LoongArch Intrinsics Guide: Migrating from SSE to LSX")

These are required for compiling with ENABLE_JIT_SIMD and will be
implemented in a later part.

This allows explicit enablement of SIMD on Loong64 backend. It's not
enabled by default since most methods are stubs and will crash.

This is the heavy part. Thanks to "Unofficial LoongArch Intrinsics
Guide", the x{86,64} and arm64 backend, the precedent is rich.

Certain relaxed SIMD tests are updated to reflect LoongArch specifics,
which are captured on a Loongson 3B6000. Since we don't have
authoritative sources on how the ISA mandates the behavior, this is just
an observation.

Note that per psABI, the system vector calling convention requires three
kinds of passing method: GPR pair, one GPR plus one stack slot, and two
stack slots. This is not easily implemented. Since I don't see any
native vector calls, this is currently asserted out. For WASM-internal
calls, arguments are stored in available arg-passing FPRs (which are
aliases of the vector registers anyway) and spilled to stack when
exhausted.

Link:
https://github.com/loongson/la-abi-specs/blob/44ef5f63e1755e1a165915ea3b2d98d35f68eed0/lapcs.adoc#passing-arguments
("Procedure Call Standard for the LoongArch(tm) Architecture: Passing
arguments")

LSX feature detection differs from the previous LAM_BH and LAMCAS ones,
because it introduces extra architectural states that require explicit
kernel support to preserve context. Thus, it's not sufficient to read
them via CPUCFG (which indicates hardware support only).

Cross-domain (e.g. GPR to FPR) moves seems to be extremely slow and have
terrible IPC. Fortunately, vldi can help materializing small, repetitive
constant patterns directly in the vector register.

Link: https://areweloongyet.com/asmdb/vldiHelper ("AreWeLoongYet? - VLDI
Helper")
Link:
https://github.com/loongson-community/areweloongyet/blob/49a0f6d22506c1fbebc97da24d4c34a9cc116ee5/src/components/AsmDB/vldi.ts

Note that per LoongArch Toolchain Conventions, LSX is part of the LA64v1.0 ISA. So, it's probably okay to assume its existence on Firefox-capable platforms.

Attachment #9648847 - Attachment description: WIP: Bug 2075633 - [loong64] Part 10: Introduce vldi for loading common SIMD constants quickly. r=#spidermonkey-reviewers! → WIP: Bug 2075633 - [loong64] Part 9: Introduce vldi for loading common SIMD constants quickly. r=#spidermonkey-reviewers!
Attachment #9648846 - Attachment description: WIP: Bug 2075633 - [loong64] Part 9: Implement LSX feature detection via HWCAP. r=#spidermonkey-reviewers! → WIP: Bug 2075633 - [loong64] Part 10: Implement LSX feature detection via HWCAP. r=#spidermonkey-reviewers!
Attachment #9648838 - Attachment description: WIP: Bug 2075633 - [loong64] Part 1: Move FPUDefaultQNaN<T> to Architecture-loong64.h for reuse. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 1: Move FPUDefaultQNaN<T> to Architecture-loong64.h for reuse. r=#spidermonkey-reviewers!
Attachment #9648839 - Attachment description: WIP: Bug 2075633 - [loong64] Part 2: Add register definitions for LSX. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 2: Add register definitions for LSX. r=#spidermonkey-reviewers!
Attachment #9648840 - Attachment description: WIP: Bug 2075633 - [loong64] Part 3: Add commonly-used LSX {,dis}assembly methods. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 3: Add commonly-used LSX {,dis}assembly methods. r=#spidermonkey-reviewers!
Attachment #9648841 - Attachment description: WIP: Bug 2075633 - [loong64] Part 4: Implement frame and move operations for LSX. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 4: Implement frame and move operations for LSX. r=#spidermonkey-reviewers!
Attachment #9648842 - Attachment description: WIP: Bug 2075633 - [loong64] Part 5: Add crashing stubs for SIMD-related methods on Loong64. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 5: Add crashing stubs for SIMD-related methods on Loong64. r=#spidermonkey-reviewers!
Attachment #9648843 - Attachment description: WIP: Bug 2075633 - [loong64] Part 6: Recognize LSX memory instructions in SummarizeTrapInstruction. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 6: Recognize LSX memory instructions in SummarizeTrapInstruction. r=#spidermonkey-reviewers!
Attachment #9648844 - Attachment description: WIP: Bug 2075633 - [loong64] Part 7: Make --enable-jit-simd effective on Loong64. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 7: Make --enable-jit-simd effective on Loong64. r=#spidermonkey-reviewers!
Attachment #9648845 - Attachment description: WIP: Bug 2075633 - [loong64] Part 8: Implement SIMD-related methods and remove stubs. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 8: Implement SIMD-related methods and remove stubs. r=#spidermonkey-reviewers!
Attachment #9648847 - Attachment description: WIP: Bug 2075633 - [loong64] Part 9: Introduce vldi for loading common SIMD constants quickly. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 9: Introduce vldi for loading common SIMD constants quickly. r=#spidermonkey-reviewers!
Attachment #9648846 - Attachment description: WIP: Bug 2075633 - [loong64] Part 10: Implement LSX feature detection via HWCAP. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 10: Implement LSX feature detection via HWCAP. r=#spidermonkey-reviewers!
Attachment #9648848 - Attachment description: WIP: Bug 2075633 - [loong64] Part 11: Auto-enable SIMD by feature detection by default on Loong64. r=#spidermonkey-reviewers! → Bug 2075633 - [loong64] Part 11: Auto-enable SIMD by feature detection by default on Loong64. r=#spidermonkey-reviewers!
Pushed by webmaster@csmantle.top: https://github.com/mozilla-firefox/firefox/commit/daec05a8a2a3 https://hg.mozilla.org/integration/autoland/rev/59e8d8e0df91 [loong64] Part 1: Move FPUDefaultQNaN<T> to Architecture-loong64.h for reuse. r=yury https://github.com/mozilla-firefox/firefox/commit/27d947a0b186 https://hg.mozilla.org/integration/autoland/rev/817eeddffb76 [loong64] Part 2: Add register definitions for LSX. r=yury https://github.com/mozilla-firefox/firefox/commit/c0d12b03bfa4 https://hg.mozilla.org/integration/autoland/rev/03e3d7a16848 [loong64] Part 3: Add commonly-used LSX {,dis}assembly methods. r=yury https://github.com/mozilla-firefox/firefox/commit/59bdcf059b4e https://hg.mozilla.org/integration/autoland/rev/0cb375d2a617 [loong64] Part 4: Implement frame and move operations for LSX. r=yury https://github.com/mozilla-firefox/firefox/commit/c512b8e381ea https://hg.mozilla.org/integration/autoland/rev/151771679905 [loong64] Part 5: Add crashing stubs for SIMD-related methods on Loong64. r=yury https://github.com/mozilla-firefox/firefox/commit/51dd37c7e056 https://hg.mozilla.org/integration/autoland/rev/cf950ca03afc [loong64] Part 6: Recognize LSX memory instructions in SummarizeTrapInstruction. r=yury https://github.com/mozilla-firefox/firefox/commit/715041e3663c https://hg.mozilla.org/integration/autoland/rev/11af78c273e0 [loong64] Part 7: Make --enable-jit-simd effective on Loong64. r=yury https://github.com/mozilla-firefox/firefox/commit/89b46a893253 https://hg.mozilla.org/integration/autoland/rev/b1b934b4db4a [loong64] Part 8: Implement SIMD-related methods and remove stubs. r=yury https://github.com/mozilla-firefox/firefox/commit/a05ce9708faf https://hg.mozilla.org/integration/autoland/rev/3c951e6e80b0 [loong64] Part 9: Introduce vldi for loading common SIMD constants quickly. r=yury https://github.com/mozilla-firefox/firefox/commit/43e8a988df86 https://hg.mozilla.org/integration/autoland/rev/b14772739f76 [loong64] Part 10: Implement LSX feature detection via HWCAP. r=yury https://github.com/mozilla-firefox/firefox/commit/21e5982bcd73 https://hg.mozilla.org/integration/autoland/rev/a3a1c0922431 [loong64] Part 11: Auto-enable SIMD by feature detection by default on Loong64. r=yury
Blocks: 2076978
Blocks: 2077020
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: