Skip to content

8391545: RISC-V: Implement Zibi extension (branch with immediate) - #32624

Closed
zangcq wants to merge 1 commit into
openjdk:masterfrom
zangcq:zibi
Closed

8391545: RISC-V: Implement Zibi extension (branch with immediate)#32624
zangcq wants to merge 1 commit into
openjdk:masterfrom
zangcq:zibi

Conversation

@zangcq

@zangcq zangcq commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Add JVM/HotSpot support for the RISC-V Zibi extension (v0.7), which
defines two B-type conditional branches that compare an integer register
against a small immediate constant:

  beqi rs1, cimm, offset   (funct3=0b010): branch if rs1 == constant
  bnei rs1, cimm, offset   (funct3=0b011): branch if rs1 != constant

Both reuse the BRANCH major opcode and the standard B-type immediate
layout; the 5-bit field that would hold rs2 carries cimm instead. The
comparison constant decodes as cimm=0 -> -1 and cimm=1..31 -> 1..31
(comparison with zero keeps using beq/bne with x0).

Spec: https://github.com/riscv/zibi/blob/main/src/unpriv/zibi.adoc

Changes:

  • Add the UseZibi flag and ext_Zibi feature detection. Auto-detection
    is left unwired because there is no hwprobe/HWCAP bit yet; enable
    with -XX:+UseZibi.
  • Add the beqi/bnei encodings plus is_zibi_cimm/encode_zibi_cimm
    helpers in the assembler.
  • Add near/far label and address forms in the MacroAssembler, with the
    far form realized by negating the condition (beqi <-> bnei) over the
    same constant.
  • Add the C2 cmpi_branch encoder helper.
  • Add immIZibi/immLZibi operands and the CmpI/CmpL near/far branch and
    loop instructs, all gated on UseZibi so codegen falls back to
    materialize-plus-reg-branch when the extension is off.

The existing conditional-branch bind/patch machinery works unchanged
because beqi/bnei share the BRANCH opcode and B-immediate layout.



Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8391545: RISC-V: Implement Zibi extension (branch with immediate) (Enhancement - P4)

Contributors

  • Pengcheng Wang <wangpengcheng.pp@bytedance.com>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/32624/head:pull/32624
$ git checkout pull/32624

Update a local copy of the PR:
$ git checkout pull/32624
$ git pull https://git.openjdk.org/jdk.git pull/32624/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 32624

View PR using the GUI difftool:
$ git pr show -t 32624

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/32624.diff

Using Webrev

Link to Webrev Comment

* RISC-V: Harden Zibi tests against unsupported hardware
* RISC-V: Verify Zibi branch codegen in TestZibiBranch
* RISC-V: Implement Zibi extension (branch with immediate)

Co-authored-by: Pengcheng Wang <wangpengcheng.pp@bytedance.com>
@bridgekeeper

bridgekeeper Bot commented Sep 1, 2026

Copy link
Copy Markdown

👋 Welcome back zangcq! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Sep 1, 2026

Copy link
Copy Markdown

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@zangcq

zangcq commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

/contributor add Pengcheng Wang wangpengcheng.pp@bytedance.com

@openjdk

openjdk Bot commented Sep 1, 2026

Copy link
Copy Markdown

@zangcq
Contributor Pengcheng Wang <wangpengcheng.pp@bytedance.com> successfully added.

@openjdk openjdk Bot added the hotspot hotspot-dev@openjdk.org label Sep 1, 2026
@openjdk

openjdk Bot commented Sep 1, 2026

Copy link
Copy Markdown

@zangcq The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk

openjdk Bot commented Sep 1, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot. This can be overridden with the /reviewers command.

@zangcq

zangcq commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

/issue JDK-8391545

@openjdk openjdk Bot changed the title RISC-V: Implement Zibi extension (branch with immediate) 8391545: RISC-V: Implement Zibi extension (branch with immediate) Sep 1, 2026
@openjdk

openjdk Bot commented Sep 1, 2026

Copy link
Copy Markdown

@zangcq The primary solved issue for a PR is set through the PR title. Since the current title does not contain an issue reference, it will now be updated.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Sep 1, 2026
@mlbridge

mlbridge Bot commented Sep 1, 2026

Copy link
Copy Markdown

Webrevs

@RealFYang

RealFYang commented Sep 2, 2026

Copy link
Copy Markdown
Member

But Zibi is still unratified? If true, I would suggest wait a while for SPEC ratification.

@zangcq

zangcq commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Yes, Zibi is still unratified — currently at v0.7 (experimental). The ISA Manual integration PR (riscv/riscv-isa-manual#3343) was opened on 2026-08-24 and has not yet been merged. Thanks for your suggestion.

@zangcq zangcq closed this Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants