Closed Bug 2045021 Opened 4 months ago Closed 4 months ago

Add support for zbs, zfa, zfhmin, and zicond extensions

Categories

(Core :: JavaScript Engine: JIT, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
153 Branch
Tracking Status
firefox153 --- fixed

People

(Reporter: anba, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(9 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

Add support for zbs, zfa, zfhmin, and zicond extensions, which are mandatory extensions in RVA22U64 resp. RVA23U64, so are likely supported by most systems.

Also add #define USE_HWPROBE to avoid repeating the condition when hardware
probes can be used.

The new --riscv-ext shell option is similar to the --arm-hwcap option for
ARM32 and allows specifying the RISCV ISA or profile. The option is a simplified
implementation of the -march option used by GCC/Clang [1].

Also removes support for the RISCV_EXT_ZBA and RISCV_EXT_ZBB environment
variables. Instead the RISCV_EXT environment variable can now be used.

[1] https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html

This allows to optimise some bit-clear/set/invert patterns to use fewer instructions.

The code was also copied from V8, but needed additional changes to work with
our float16 defined in "vm/Float16.h". (That way we don't need to copy the
Float16 implementation from V8.)

fcvt.s.h is incorrectly implemented in V8, so I had to double-check other
zfh/zfhmin instructions are correctly implemented. This also led to slightly
different code when compared to V8.

Also fixes some bugs which were found when comparing against the latest V8 code.

Also moves the scratch register for RoundHelper, so we don't unnecessarily
reserve it.

Adds computeAddress to avoid duplicating more code to compute addresses.

Moves the implementation for cmp32Move32 into the cpp-file to avoid generating
too large inline methods.

Zicond actually allows even more concise instructions sequences for some code
patterns. For example the C++ code x ? x : y can be implemented as just:

czero.nez   a2, a1, a0
add         a0, a0, a2

I haven't implemented this, because we should first check which code patterns
can actually be generated by the JIT compiler.

It seems that I'm having some trouble locally applying some of the patches:

$ moz-phab patch D304798
Nothing changed.ment.. |
Patching revisions: D304789 D304790 D304791 D304792 D304793 D304794 D304795 D304796 D304798
Unknown revision: 0636c092d583
Cinnabar extension not enabled.
Use --apply-to to set the base commit.
$ moz-phab patch --apply-to here D304798
Nothing changed.ment.. |
Patching revisions: D304789 D304790 D304791 D304792 D304793 D304794 D304795 D304796 D304798
Warning: Target revision is empty.
Created bookmark phab-D304798
D304789 applied
D304790 applied
D304791 applied
D304792 applied
D304793 applied
D304794 applied
D304795 applied
D304796 applied
error: patch failed: js/src/jit/riscv64/MacroAssembler-riscv64.h:739
error: js/src/jit/riscv64/MacroAssembler-riscv64.h: patch does not apply

My HEAD is at cf8510b7c3bb11cf4abc2f8aa431eebdcb38b41b:

Commit ID: cf8510b7c3bb11cf4abc2f8aa431eebdcb38b41b
Change ID: mrxmynmwomssrnxuuykvwmuxkwrrmmnw
Bookmarks: main@origin
Author   : Mark Kennedy <mkennedy@mozilla.com> (2026-06-05 07:24:55)
Committer: mkennedy@mozilla.com <mkennedy@mozilla.com> (2026-06-05 07:27:09)

    Bug 2040444 - Fix back button trapping subcategory navigation on about:preferences r=tgiles

Seems to be conflicting with https://phabricator.services.mozilla.com/D304002:

$ git apply --reject ./D304798.1780731164.diff
Checking patch js/src/jit/riscv64/MacroAssembler-riscv64-inl.h...
Hunk #1 succeeded at 1411 (offset -36 lines).
Hunk #2 succeeded at 1430 (offset -36 lines).
Checking patch js/src/jit/riscv64/MacroAssembler-riscv64.h...
Hunk #1 succeeded at 334 (offset 10 lines).
error: while searching for:
  void splitTagForTest(const ValueOperand& value, ScratchTagScope& tag) {
    splitTag(value, tag);
  }

  void moveIfZero(Register dst, Register src, Register cond) {
    Label done;
    ma_b(cond, cond, &done, NonZero, ShortJump);
    mv(dst, src);
    bind(&done);
  }

  void moveIfNotZero(Register dst, Register src, Register cond) {
    Label done;
    ma_b(cond, cond, &done, Zero, ShortJump);
    mv(dst, src);
    bind(&done);
  }

error: patch failed: js/src/jit/riscv64/MacroAssembler-riscv64.h:739
Checking patch js/src/jit/riscv64/MacroAssembler-riscv64.cpp...
Hunk #1 succeeded at 368 (offset 8 lines).
Hunk #2 succeeded at 654 (offset 8 lines).
Hunk #3 succeeded at 727 (offset 8 lines).
Applied patch js/src/jit/riscv64/MacroAssembler-riscv64-inl.h cleanly.
Applying patch js/src/jit/riscv64/MacroAssembler-riscv64.h with 1 reject...
Hunk #1 applied cleanly.
Rejected hunk #2.
Applied patch js/src/jit/riscv64/MacroAssembler-riscv64.cpp cleanly.

I've rebased the patches, it should work now. Thanks for the heads-up!

Severity: -- → S3
Priority: -- → P1
Severity: S3 → N/A
Pushed by andre.bargull@gmail.com: https://github.com/mozilla-firefox/firefox/commit/91f15e576fa0 https://hg.mozilla.org/integration/autoland/rev/0b9c9b3e669c Part 1: Move RVFlags to Architecture-riscv64 to match other architectures. r=jandem https://github.com/mozilla-firefox/firefox/commit/45655600fd14 https://hg.mozilla.org/integration/autoland/rev/aaf8014ed329 Part 2: Allow to set extensions through shell options. r=jandem https://github.com/mozilla-firefox/firefox/commit/c9695a69dd62 https://hg.mozilla.org/integration/autoland/rev/89d049ee0a7b Part 3: Use Zbs instructions for bitwise instructions when applicable. r=jandem https://github.com/mozilla-firefox/firefox/commit/5a9e5c310b96 https://hg.mozilla.org/integration/autoland/rev/10ba15e10994 Part 4: Add assembler support for zfa, zfh, and zicond extensions. r=jandem https://github.com/mozilla-firefox/firefox/commit/c454e9fbb202 https://hg.mozilla.org/integration/autoland/rev/356343929431 Part 5: Add disassembler support for zfa, zfh, and zicond extensions. r=jandem https://github.com/mozilla-firefox/firefox/commit/af175146c2bb https://hg.mozilla.org/integration/autoland/rev/ea56bb6d2ea6 Part 6: Add simulator support for zfa, zfh, and zicond extensions. r=jandem https://github.com/mozilla-firefox/firefox/commit/ccc650ad4c2c https://hg.mozilla.org/integration/autoland/rev/dd4152e5d10e Part 7: Use Zfa instructions when applicable. r=jandem https://github.com/mozilla-firefox/firefox/commit/e7a2228baf4f https://hg.mozilla.org/integration/autoland/rev/d1a02b3bdd8a Part 8: Use Zfhmin instructions when applicable. r=jandem https://github.com/mozilla-firefox/firefox/commit/f881f3541bf1 https://hg.mozilla.org/integration/autoland/rev/3e1f20b3f830 Part 9: Use Zicond instructions when applicable. r=jandem
Blocks: 2046847
QA Whiteboard: [qa-triage-done-c154/b153]
Regressions: 2056501
See Also: → 2061654
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: