Skip to content

[configure] Add support for RISC-V ZBC extension#1917

Merged
Dead2 merged 1 commit intozlib-ng:developfrom
mtl1979:configure-zbc
May 28, 2025
Merged

[configure] Add support for RISC-V ZBC extension#1917
Dead2 merged 1 commit intozlib-ng:developfrom
mtl1979:configure-zbc

Conversation

@mtl1979
Copy link
Copy Markdown
Collaborator

@mtl1979 mtl1979 commented May 20, 2025

This should allow pkgcheck CI to pass for RISC-V

  • arch/riscv/riscv_features.c needs both RVV and ZBC in -march if enabled

Summary by CodeRabbit

  • New Features

    • Added build and configuration support for the RISC-V ZBC (Bitmanip) instruction set extension.
    • Introduced a new option to disable ZBC support during configuration (--without-zbc).
    • Automatically detects and enables ZBC support if available, including new compilation flags and object files.
  • Chores

    • Enhanced build scripts to check for required Linux headers and propagate new configuration flags.
    • Restricted runtime checks for RISC-V Vector Extension (RVV) features to builds with RVV enabled.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 20, 2025

"""

Walkthrough

The build system was updated to add support for the RISC-V ZBC (Bitmanip) instruction set extension. This includes new Makefile rules and object files for ZBC-specific code, new compiler flag variables, and enhancements to the configure script to detect ZBC support, control its inclusion, and propagate relevant flags and files into the build process. Additionally, runtime RVV feature detection code is now conditionally compiled only when RVV support is enabled.

Changes

File(s) Change Summary
arch/riscv/Makefile.in Added build rules for crc32_zbc.c, new object files, new compiler flag variables (RVVZBCFLAG, ZBCFLAG), and updated the all target to include ZBC objects.
configure Added detection and configuration for RISC-V ZBC extension, new flags (zbcflag, rvvzbcflag), --without-zbc option, compiler checks for ZBC, conditional inclusion of ZBC objects and flags in RISC-V builds, and detection of <linux/auxvec.h>.
arch/riscv/riscv_features.c Wrapped RVV runtime feature detection code inside #ifdef RISCV_RVV to conditionally compile it only when RVV support is enabled.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigureScript
    participant Compiler
    participant Makefile

    User->>ConfigureScript: Run ./configure [--without-zbc]
    ConfigureScript->>Compiler: Test for ZBC support (-march=rv64gc_zbc, clmul)
    Compiler-->>ConfigureScript: Compilation success/failure
    alt ZBC supported and enabled
        ConfigureScript->>Makefile: Set ZBC flags, add crc32_zbc objects
    else ZBC not supported or disabled
        ConfigureScript->>Makefile: Do not set ZBC flags or objects
    end
    User->>Makefile: Run make
    Makefile->>Compiler: Build with/without ZBC objects and flags
Loading

Possibly related PRs

Suggested reviewers

  • Dead2
    """

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0acad89 and 856af15.

📒 Files selected for processing (3)
  • arch/riscv/Makefile.in (2 hunks)
  • arch/riscv/riscv_features.c (2 hunks)
  • configure (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • arch/riscv/riscv_features.c
  • configure
  • arch/riscv/Makefile.in
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (4)
arch/riscv/Makefile.in (1)

18-20: Flag explosion – consider consolidating RVV/ZBC flags

RVVZBCFLAG and ZBCFLAG are useful, but we now have three almost-identical “‐march” variables (RVVFLAG, RVVZBCFLAG, ZBCFLAG).
Keeping separate variables multiplies maintenance work and increases the risk that one of them gets out of sync with configure.

If the only current user of RVVZBCFLAG is riscv_features.c, you could save complexity by:

  1. Dropping RVVZBCFLAG.
  2. Building riscv_features.c twice (once with RVVFLAG, once with ZBCFLAG) and selecting at link-time, or
  3. Using a single flag variable that configure mutates in place (RVVFLAG+="…_zbc").

Not mandatory, but worth weighing.

configure (3)

1750-1756: Quote variables in numeric tests

Bare variables can expand to the empty string and break test.
Use the POSIX-safe pattern:

-if test $buildrvv -eq 1 -a $HAVE_RVV_INTRIN -eq 1; then
+if test "$buildrvv" -eq 1 && test "$HAVE_RVV_INTRIN" -eq 1; then

The same quoting fix is needed for every occurrence of $HAVE_ZBC_EXT, $HAVE_RVV_INTRIN, etc.


952-966: Cross-platform header probe could poison CFLAGS

Including <linux/auxvec.h> unconditionally adds -DHAVE_LINUX_AUXVEC_H to every build, even non-Linux cross-targets (e.g. riscv64-elf).
That header is Linux-only and will not be found by bare-metal or BSD tool-chains, leading to later compile errors.

Consider:

  1. Guarding the test with if test "$LINUX" -eq 1; then ….
  2. Resetting the macro in non-Linux paths.

2434-2437: Sed replacement will silently drop empty flags

The two new substitutions:

/^RVVZBCFLAG *=/s#=.*#=$rvvzbcflag#
/^ZBCFLAG *=/s#=.*#=$zbcflag#

emit an empty right-hand side when the flag variable is unset, resulting in lines like RVVZBCFLAG = (note the trailing space).
Some Make versions treat “variable with just spaces” as defined, altering ifneq ($(RVVZBCFLAG),) logic.

Safer:

sed … -e "/^RVVZBCFLAG *=/s#=.*#=${rvvzbcflag:-}#"

or remove the line entirely when the feature is disabled.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 830995f and f5dff8a.

📒 Files selected for processing (2)
  • arch/riscv/Makefile.in (2 hunks)
  • configure (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (123)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: macOS Clang (Target 10.10)
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v143 Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v143 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions
  • GitHub Check: Ubuntu GCC MIPS
  • GitHub Check: Ubuntu GCC
  • GitHub Check: Ubuntu GCC ARM HF
  • GitHub Check: Ubuntu GCC -m32
🔇 Additional comments (2)
arch/riscv/Makefile.in (2)

26-27: Indentation may break Makefile parsing

The two recipe lines that were re-indented (slide_hash_rvv.*) show leading spaces instead of a TAB in the diff.
Make(1) requires a literal TAB before every recipe line; spaces result in “*** missing separator” build failures.

Please confirm those characters are still TABs in the committed file.


59-63: Missing dependency glue for the new ZBC objects

crc32_zbc.o / .lo are listed here, but nothing in this Makefile declares how they are used (e.g. they aren’t added to any libz archive or shared-object rule inside this file).

Double-check that the top-level or arch-specific Makefiles append them to ARCH_STATIC_OBJS / ARCH_SHARED_OBJS – otherwise the objects will be built but never linked.

@codecov
Copy link
Copy Markdown

codecov bot commented May 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.40%. Comparing base (830995f) to head (856af15).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1917      +/-   ##
===========================================
- Coverage    81.20%   80.40%   -0.81%     
===========================================
  Files          147      137      -10     
  Lines        13304    12991     -313     
  Branches      2948     2889      -59     
===========================================
- Hits         10804    10445     -359     
- Misses        1559     1654      +95     
+ Partials       941      892      -49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
configure (2)

124-125: ⚠️ Potential issue

Variables need default initialization

The variables rvvzbcflag and zbcflag are initialized as empty strings, but HAVE_RVV_INTRIN and HAVE_ZBC_EXT are used in conditionals without initialization.

Add safe defaults right after these variables:

rvvzbcflag=
zbcflag=
+HAVE_RVV_INTRIN=0
+HAVE_ZBC_EXT=0

This prevents test commands from failing with "unary operator expected" errors when these variables are unset.


1743-1776: 🛠️ Refactor suggestion

Test for missing quotes in conditional test

In the conditional test at line 1750, variables should be quoted to avoid syntax errors when empty.

-        if test $buildrvv -eq 1 -a "$HAVE_RVV_INTRIN" -eq 1; then
+        if test "$buildrvv" -eq 1 && test "$HAVE_RVV_INTRIN" -eq 1; then

Also, prefer && over -a for better portability and readability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between f5dff8a and f9818bc.

📒 Files selected for processing (2)
  • arch/riscv/Makefile.in (2 hunks)
  • configure (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • arch/riscv/Makefile.in
⏰ Context from checks skipped due to timeout of 90000ms (44)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows GCC
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: macOS GCC Symbol Prefix (ARM64)
🔇 Additional comments (6)
configure (6)

103-103: Looks good: Added ZBC build flag

This correctly initializes the buildzbc flag to 1 (enabled by default), following the pattern of other similar feature flags.


180-180: Command-line flag implementation looks good

The --without-zbc flag follows the same pattern as other feature flags in the configure script.

Also applies to: 218-218


952-966: Well-implemented check for linux/auxvec.h

This check follows the established pattern for header checks in the configure script.


1761-1768: Good test for ZBC extension

The test for the ZBC extension using the clmul assembly instruction is well implemented.


2169-2179: RISC-V ZBC support properly integrated

This section correctly adds ZBC support to the RISC-V architecture section, following the pattern of other extensions.


2435-2436: Makefile variable replacement correctly implemented

The ZBC flags are correctly propagated to the architecture-specific Makefile.

@mtl1979 mtl1979 force-pushed the configure-zbc branch 5 times, most recently from f927880 to 0acad89 Compare May 20, 2025 21:29
@nmoinvaz nmoinvaz added Build Env Architecture Architecture specific labels May 21, 2025
@mtl1979 mtl1979 requested a review from Dead2 May 27, 2025 15:59
@Dead2 Dead2 merged commit 2c98ece into zlib-ng:develop May 28, 2025
115 of 145 checks passed
@Dead2 Dead2 mentioned this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Architecture Architecture specific Build Env

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants