这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@KungFuJesus
Copy link
Contributor

@KungFuJesus KungFuJesus commented Nov 28, 2024

It's unclear if raspberry pi OS's shipped GCC doesn't properly detect ACLE or not (/proc/cpuinfo claims to support AES), but in any case, the preprocessor macro for that flag is not defined with -march=native on a raspberry pi 5. Unfortunately that means when built "WITH_NATIVE", we do not get a fast CRC function. The CRC32 preprocessor macro IS defined, and the auto detection when built without NATIVE support does properly get dispatched to. Since we only need the scalar CRC32 and not the polynomial stuff anyhow, let's make it be an || condition and not a && one.

Summary by CodeRabbit

  • New Features

    • Enhanced flexibility in the compilation of the native_crc32 feature, allowing for broader compatibility with ARM architectures.
  • Bug Fixes

    • Resolved issues with the conditional compilation directives to ensure proper definition under varied ARM feature sets.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes in this pull request involve modifications to the conditional compilation directives in the arch/arm/arm_functions.h file. The preprocessor condition for defining native_crc32 has been altered to allow for more flexible compilation based on the presence of either __ARM_ACLE or __ARM_FEATURE_CRC32. This adjustment broadens the scenarios under which native_crc32 can be defined without altering any function signatures or logic.

Changes

File Change Summary
arch/arm/arm_functions.h Updated preprocessor condition for native_crc32: changed from #if defined(__ARM_ACLE) && defined(__ARM_FEATURE_CRC32) to `#if defined(__ARM_ACLE)

Suggested labels

optimization

Suggested reviewers

  • Dead2

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed5ac8 and 7339907.

📒 Files selected for processing (1)
  • arch/arm/arm_functions.h (1 hunks)
🔇 Additional comments (1)
arch/arm/arm_functions.h (1)

59-62: LGTM! The condition change correctly addresses the CRC detection issue.

The modification to use an OR condition (defined(__ARM_ACLE) || defined(__ARM_FEATURE_CRC32)) while maintaining the outer defined(ARM_ACLE) check is a good solution. This allows the CRC32 functionality to be enabled when either feature is detected, fixing the Raspberry Pi OS issue without compromising safety.

Let's verify there are no conflicting CRC-related conditions elsewhere:

✅ Verification successful

The CRC32 condition change is safe and consistent with other architecture-specific implementations

The verification shows that each architecture (ARM, x86, s390, POWER) has its own unique set of conditions for enabling native CRC32 implementations, tailored to their specific features:

  • s390: Checks for S390_CRC32_VX, __zarch__, and __VX__
  • POWER: Requires POWER8_VSX_CRC32, _ARCH_PWR8, and __VSX__
  • x86: Uses different conditions for PCLMULQDQ variants
  • ARM: Our modified condition using ARM_ACLE && (__ARM_ACLE || __ARM_FEATURE_CRC32)

The change is consistent with the pattern where each architecture defines its own appropriate detection logic, and there are no conflicting conditions that would be affected by this modification.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other CRC-related preprocessor conditions that might need similar updates

# Search for CRC-related preprocessor conditions
rg -n "defined.*CRC32|defined.*ACLE" --type c --type cpp --type h

# Search for native_crc32 usage
rg -n "native_crc32"

Length of output: 3003


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

It's unclear if raspberry pi OS's shipped GCC doesn't properly detect
ACLE or not (/proc/cpuinfo claims to support AES), but in any case, the
preprocessor macro for that flag is not defined with -march=native on a
raspberry pi 5. Unfortunately that means when built "WITH_NATIVE", we do
not get a fast CRC function.  The CRC32 preprocessor macro _IS_ defined,
and the auto detection when built without NATIVE support does properly
get dispatched to. Since we only need the scalar CRC32 and not the polynomial
stuff anyhow, let's make it be an || condition and not a && one.
@codecov
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 32.21%. Comparing base (0ed5ac8) to head (7339907).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1818      +/-   ##
===========================================
+ Coverage    32.18%   32.21%   +0.03%     
===========================================
  Files           67       67              
  Lines         5752     5752              
  Branches      1237     1237              
===========================================
+ Hits          1851     1853       +2     
  Misses        3644     3644              
+ Partials       257      255       -2     

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

@mtl1979
Copy link
Collaborator

mtl1979 commented Nov 29, 2024

As far as I know -march=native is not fully supported on ARM, so that's why the preprocessor macro for ACLE isn't defined. For some targets, gcc will print error when -march=native is used, for others it will be silently ignored.

@Dead2 Dead2 changed the title Fix native detection of CRC instruction Fix native detection of ARM CRC instruction Nov 29, 2024
Copy link
Member

@Dead2 Dead2 left a comment

Choose a reason for hiding this comment

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

LGTM

@nmoinvaz nmoinvaz added Build Env Architecture Architecture specific labels Nov 29, 2024
@Dead2 Dead2 merged commit 785444d into zlib-ng:develop Dec 1, 2024
142 of 150 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 11, 2024
@Dead2 Dead2 mentioned this pull request Dec 31, 2024
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.

4 participants