Skip to content

Simplify compatibility intrinsics for x86#1924

Merged
Dead2 merged 1 commit intozlib-ng:developfrom
phprus:intrinsic-1
Jun 25, 2025
Merged

Simplify compatibility intrinsics for x86#1924
Dead2 merged 1 commit intozlib-ng:developfrom
phprus:intrinsic-1

Conversation

@phprus
Copy link
Copy Markdown
Contributor

@phprus phprus commented Jun 18, 2025

  1. Switched from Microsoft-specific intrinsic names to common (gcc, msvc, clang, intel) names.
  2. Removed macros for clang.
  3. Replaced !defined(__x86_64__) with defined(__i386__) for compatibility with MCST LCC.

Summary by CodeRabbit

  • Refactor
    • Updated naming conventions for certain internal operations to improve consistency and clarity. No changes to application behavior or user-facing functionality.

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 18, 2025

Walkthrough

This change updates intrinsic function usage and naming for 64-bit integer and __m128i conversions in x86 SIMD code. It replaces and renames functions and macros to use non-'x' suffixed versions, aligning with standard intrinsic conventions. No logic, control flow, or error handling is modified.

Changes

File(s) Change Summary
arch/x86/chorba_sse2.c Replaces _mm_cvtsi128_si64x with _mm_cvtsi128_si64 for 64-bit extraction from __m128i vectors.
arch/x86/chorba_sse41.c Replaces _mm_cvtsi64x_si128 with _mm_cvtsi64_si128 for 64-bit to __m128i conversion.
arch/x86/x86_intrins.h Renames/removes intrinsic wrappers/macros: removes 'x' suffix, updates function and macro names.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant SIMD_Utils

    Caller->>SIMD_Utils: Call _mm_cvtsi128_si64(__m128i)
    SIMD_Utils-->>Caller: Return int64_t

    Caller->>SIMD_Utils: Call _mm_cvtsi64_si128(int64_t)
    SIMD_Utils-->>Caller: Return __m128i
Loading

Possibly related PRs

Suggested labels

Build Env, Architecture

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 617c852 and 1ecbb9b.

📒 Files selected for processing (3)
  • arch/x86/chorba_sse2.c (2 hunks)
  • arch/x86/chorba_sse41.c (1 hunks)
  • arch/x86/x86_intrins.h (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: KungFuJesus
PR: zlib-ng/zlib-ng#1872
File: arch/x86/x86_intrins.h:114-117
Timestamp: 2025-02-23T16:51:54.545Z
Learning: In x86/x86_intrins.h, the Clang macros for _mm_cvtsi64x_si128 and _mm_cvtsi128_si64x don't need additional MSVC guards since MSVC's implementation is already protected by `defined(_MSC_VER) && !defined(__clang__)`, making them mutually exclusive.
arch/x86/chorba_sse2.c (1)
Learnt from: KungFuJesus
PR: zlib-ng/zlib-ng#1872
File: arch/x86/chorba_sse2.c:0-0
Timestamp: 2025-02-21T01:41:10.063Z
Learning: For SSE2 optimizations, `_mm_cvtsi128_si64` should be used instead of `_mm_extract_epi64` (SSE4.1) for extracting 64-bit values from 128-bit vectors, as it generates more efficient movq instructions.
arch/x86/x86_intrins.h (2)
Learnt from: KungFuJesus
PR: zlib-ng/zlib-ng#1872
File: arch/x86/x86_intrins.h:114-117
Timestamp: 2025-02-23T16:51:54.545Z
Learning: In x86/x86_intrins.h, the Clang macros for _mm_cvtsi64x_si128 and _mm_cvtsi128_si64x don't need additional MSVC guards since MSVC's implementation is already protected by `defined(_MSC_VER) && !defined(__clang__)`, making them mutually exclusive.
Learnt from: KungFuJesus
PR: zlib-ng/zlib-ng#1872
File: arch/x86/chorba_sse2.c:0-0
Timestamp: 2025-02-21T01:41:10.063Z
Learning: For SSE2 optimizations, `_mm_cvtsi128_si64` should be used instead of `_mm_extract_epi64` (SSE4.1) for extracting 64-bit values from 128-bit vectors, as it generates more efficient movq instructions.
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v142 Win32
🔇 Additional comments (6)
arch/x86/chorba_sse41.c (1)

96-96: LGTM! Intrinsic function name updated correctly.

The change from _mm_cvtsi64x_si128 to _mm_cvtsi64_si128 aligns with the standardization of intrinsic names across compilers and matches the corresponding function definition updates in arch/x86/x86_intrins.h.

arch/x86/chorba_sse2.c (1)

805-809: LGTM! Intrinsic function names updated consistently.

All instances of _mm_cvtsi128_si64x have been correctly updated to _mm_cvtsi128_si64 to align with the standardized intrinsic naming. The functionality remains identical, and based on retrieved learnings, _mm_cvtsi128_si64 is the preferred choice for SSE2 optimizations as it generates more efficient movq instructions.

arch/x86/x86_intrins.h (4)

101-105: LGTM! Function name standardized correctly.

The function name change from _mm_cvtsi128_si64x to _mm_cvtsi128_si64 removes the Microsoft-specific 'x' suffix, aligning with standard intrinsic conventions. The implementation using union-based conversion remains correct and safe.


107-109: LGTM! Function name standardized correctly.

The function name change from _mm_cvtsi64x_si128 to _mm_cvtsi64_si128 removes the Microsoft-specific 'x' suffix, making it compatible across multiple compilers (GCC, MSVC, Clang, Intel) as stated in the PR objectives.


113-120: LGTM! Improved compiler compatibility and consistent naming.

The changes effectively address two improvements:

  1. Better target specification: Changing from !defined(__x86_64__) to defined(__i386__) is more explicit and improves compatibility with the MCST LCC compiler
  2. Consistent intrinsic naming: Both the function name _mm_cvtsi128_si64 and macro _mm_cvtsi64_si128 now use standard naming without the 'x' suffix

The implementations remain functionally identical, ensuring no behavioral changes while improving cross-compiler compatibility.


101-120: Verify consistent usage across the codebase.

The intrinsic function names have been standardized by removing the 'x' suffix. Ensure all call sites have been updated to use the new names.

#!/bin/bash
# Description: Verify all usages of the old intrinsic names have been updated
# Expected: No occurrences of the old 'x' suffixed function names

echo "Searching for old intrinsic function names that should have been updated..."

# Search for old function names with 'x' suffix
echo "=== Searching for _mm_cvtsi64x_si128 ==="
rg "_mm_cvtsi64x_si128" --type c --type h

echo "=== Searching for _mm_cvtsi128_si64x ==="
rg "_mm_cvtsi128_si64x" --type c --type h

echo "=== Verifying new function names are used ==="
echo "Found _mm_cvtsi64_si128:"
rg "_mm_cvtsi64_si128" --type c --type h -A 1

echo "Found _mm_cvtsi128_si64:"
rg "_mm_cvtsi128_si64" --type c --type h -A 1
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment

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 auto-generate unit tests to generate unit tests for 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 Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.75%. Comparing base (617c852) to head (1ecbb9b).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1924      +/-   ##
===========================================
- Coverage    81.81%   81.75%   -0.07%     
===========================================
  Files          147      147              
  Lines        13322    13321       -1     
  Branches      2956     2955       -1     
===========================================
- Hits         10900    10891       -9     
- Misses        1513     1515       +2     
- Partials       909      915       +6     

☔ 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 Jun 20, 2025

Initially those X-suffixed versions were supposed to differentiate between versions using GPR (suffix) and MMX registers (no suffix) for 64-bit integers, but not all instructions had MMX versions, so there was two versions using GPR registers instead. As time has passed, most compilers don't even try to use MMX registers anymore as there is SSE equivalent versions and 64-bit processors have no need for MMX registers for 64-bit operations.

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 c6bfa96 into zlib-ng:develop Jun 25, 2025
141 of 146 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants