Skip to content

Remove volatile keyword from ARM inline assembler#1908

Merged
Dead2 merged 1 commit intozlib-ng:developfrom
ccawley2011:arm-asm-volatile
Jul 11, 2025
Merged

Remove volatile keyword from ARM inline assembler#1908
Dead2 merged 1 commit intozlib-ng:developfrom
ccawley2011:arm-asm-volatile

Conversation

@ccawley2011
Copy link
Copy Markdown
Contributor

@ccawley2011 ccawley2011 commented Apr 29, 2025

Specifying the volatile keyword prevents the inlined assembler from being reordered by the compiler.

Summary by CodeRabbit

  • Refactor
    • Updated inline assembly statements by removing the __volatile__ qualifier in various ARM intrinsic functions and configuration checks. No changes to user-facing features or exported interfaces.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 29, 2025

Walkthrough

The changes systematically remove the __volatile__ qualifier from inline assembly statements across several components related to ARM architecture support. This adjustment is applied in the ARM ACLE intrinsic function definitions, CMake compiler detection macros, and embedded C test code within the configure script. The logic, operands, and outputs of the inline assembly instructions remain unchanged, and there are no modifications to function signatures, control flow, or error handling.

Changes

File(s) Change Summary
arch/arm/acle_intrins.h Removed __volatile__ from all inline assembly statements in ARM ACLE intrinsic functions.
cmake/detect-intrinsics.cmake Removed __volatile__ from inline assembly in macros checking ARMv8 and ARMv6 compiler intrinsics.
configure Removed __volatile__ from inline assembly in C test code for ARMv8 and ARMv6 instruction checks.

Sequence Diagram(s)

Not applicable; the changes only affect inline assembly qualifiers and do not alter control flow or introduce new features.


📜 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 dd15e04 and 15e0cff.

📒 Files selected for processing (3)
  • arch/arm/acle_intrins.h (2 hunks)
  • cmake/detect-intrinsics.cmake (2 hunks)
  • configure (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (24)
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC No CTZLL
  • GitHub Check: Ubuntu GCC Compat Symbol Prefix
🔇 Additional comments (3)
arch/arm/acle_intrins.h (1)

22-22: Removing __volatile__ qualifier from ARM inline assembly is appropriate.

The removal of the __volatile__ qualifier from ARM inline assembly statements in these ACLE intrinsic functions allows the compiler more freedom to optimize the code. This change is consistent with modern compiler optimization practices, as the volatile keyword unnecessarily restricts compiler optimizations by forcing it to maintain the exact instruction sequence as written.

Also applies to: 28-28, 34-34, 40-40, 46-46, 52-52, 58-58, 79-79

cmake/detect-intrinsics.cmake (1)

34-37: Consistent removal of __volatile__ qualifier in compiler detection code.

Removing the __volatile__ qualifier from the ARM inline assembly in these compiler detection macros ensures consistency with the changes in the actual implementation. This change in the detection code is important to match the behavior in the main codebase, ensuring that tests accurately reflect how the code will be compiled.

Also applies to: 78-78

configure (1)

1291-1294: Correctly aligned __volatile__ removal in configure script.

The removal of the __volatile__ qualifier from the ARM inline assembly in the configure script's test code maintains consistency with the changes in the main header files and CMake detection code. This ensures that the runtime detection matches the compilation behavior.

Also applies to: 1389-1389

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.72%. Comparing base (dd15e04) to head (15e0cff).
Report is 14 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1908   +/-   ##
========================================
  Coverage    81.71%   81.72%           
========================================
  Files          147      147           
  Lines        13308    13308           
  Branches      2951     2951           
========================================
+ Hits         10875    10876    +1     
+ Misses        1526     1486   -40     
- Partials       907      946   +39     

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

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Apr 30, 2025

The whole point of using inline assembly is that compiler doesn't understand the intrinsics, so it shouldn't try to reorder the instruction(s) either. Any compiler that has knowledge of the effects of the instruction(s) should already implement the intrinsics correctly.

@nmoinvaz nmoinvaz added cleanup Improving maintainability or removing code. Architecture Architecture specific labels May 12, 2025
@ccawley2011
Copy link
Copy Markdown
Contributor Author

I encountered this while working on new optimisations, where using volatile causes it to load and store temporary variables on the stack during a loop, while removing it allows instructions to be reordered to avoid that. volatile isn't necessary here, I just didn't realise what it was for when I wrote the ARMv6 slide_hash code.

Copy link
Copy Markdown
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

@Dead2 Dead2 merged commit f7ea8cc into zlib-ng:develop Jul 11, 2025
137 of 142 checks passed
@ccawley2011 ccawley2011 deleted the arm-asm-volatile branch July 11, 2025 14:53
@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 cleanup Improving maintainability or removing code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants