Skip to content

8389223: RISC-V: Implement CRC32C intrinsic using Zbc extension - #32061

Open
cczdsq wants to merge 1 commit into
openjdk:masterfrom
cczdsq:riscv-crc32c-zbc-intrinsic
Open

8389223: RISC-V: Implement CRC32C intrinsic using Zbc extension#32061
cczdsq wants to merge 1 commit into
openjdk:masterfrom
cczdsq:riscv-crc32c-zbc-intrinsic

Conversation

@cczdsq

@cczdsq cczdsq commented Jul 28, 2026

Copy link
Copy Markdown

Hi all,

Please review this PR that implements the _updateBytesCRC32C intrinsic
for RISC-V using the Zbc extension.

JBS: https://bugs.openjdk.org/browse/JDK-8389223

Summary

Currently, CRC32C on RISC-V falls back to the generic table-based
implementation. This intrinsic accelerates java.util.zip.CRC32C
for cores with Zbc support via carry-less multiply folding.

The implementation uses a folding-based algorithm:

  • Align to 8-byte boundary with byte-wise CRC table update
  • Fold 16-byte chunks into a 128-bit accumulator using clmul/clmulh
    with precomputed fold constants (k1 = x^128 mod P, k2 = x^192 mod P)
  • Reduce 128 bits to 64 bits using the ISA-L two-constant method
  • Apply Barrett reduction (64 → 32 bits) to produce the final CRC
  • Process remaining tail bytes with byte-wise table update

The intrinsic is gated by UseZbc and UseCRC32CIntrinsics, and is
automatically enabled when the Zbc extension is detected via riscv_hwprobe.

Testing

Correctness verified with:

  • test/jdk/java/util/zip/TestCRC32C.java
  • test/hotspot/jtreg/compiler/intrinsics/zip/TestCRC32C.java
    (-m mode: 1050 cases × 20000 iterations)

Performance

JMH benchmark (org.openjdk.bench.java.util.TestCRC32C) on a RISC-V
board with Zbc support:

Data size Baseline (ops/ms) Intrinsic (ops/ms) Speedup
64 B 9,066 13,249 1.46x
128 B 5,815 11,393 1.96x
256 B 3,354 8,895 2.65x
512 B 1,785 6,024 3.37x
2 KB 470 2,165 4.61x
16 KB 60 309 5.16x
64 KB 15 78 5.26x

JMH parameters: -f 2 -wi 5 -i 5 -w 1s -r 1s, measurement error < 1%.



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)

Error

 ⚠️ OCA signatory status must be verified

Issue

  • JDK-8389223: RISC-V: Implement CRC32C intrinsic using Zbc extension (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 32061

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

Using diff file

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

@bridgekeeper bridgekeeper Bot added the oca Needs verification of OCA signatory status label Jul 28, 2026
@bridgekeeper

bridgekeeper Bot commented Jul 28, 2026

Copy link
Copy Markdown

Hi @cczdsq, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user cczdsq" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@openjdk

openjdk Bot commented Jul 28, 2026

Copy link
Copy Markdown

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

@openjdk openjdk Bot added the hotspot hotspot-dev@openjdk.org label Jul 28, 2026
@openjdk

openjdk Bot commented Jul 28, 2026

Copy link
Copy Markdown

@cczdsq 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 Jul 28, 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.

@cczdsq
cczdsq force-pushed the riscv-crc32c-zbc-intrinsic branch from ca092dd to c26b517 Compare July 28, 2026 03:35
@openjdk

openjdk Bot commented Jul 28, 2026

Copy link
Copy Markdown

@cczdsq Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org oca Needs verification of OCA signatory status

Development

Successfully merging this pull request may close these issues.

1 participant