Skip to content

build(mingw): Use the portable memcchr when SSE2 is not enabled - #3500

Open
bobtista wants to merge 1 commit into
TheSuperHackers:mainfrom
bobtista:bobtista/build/mingw-memcchr-sse2
Open

bobtista wants to merge 1 commit into
TheSuperHackers:mainfrom
bobtista:bobtista/build/mingw-memcchr-sse2

Conversation

@bobtista

Copy link
Copy Markdown

stringex.h picks the SSE2 memcchr when _M_IX86 is defined. MinGW-w64 headers define _M_IX86 too, but i686 GCC does not enable SSE2 by default, so the intrinsics fail to inline and the MinGW build breaks.

Now the SSE2 version is used for MSVC x86 and x64, or when the compiler defines __SSE2__. Other builds use the portable version.

Todo:

  • Build MinGW-w64 i686
  • Build vc6 and win32

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0b91c7d8-bf38-43b4-b9c6-c3ec61d1e7f1
📥 Commits

Reviewing files that changed from the base of the PR and between 2d6761c and 239a38e.

📒 Files selected for processing (1)
  • Dependencies/Utility/Utility/stringex.h

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The SSE2 include condition in stringex.h now requires _MSC_VER with _M_IX86 or _M_X64, unless __SSE2__ is defined. Other builds use the portable implementation.

Changes

SSE2 selection

Layer / File(s) Summary
SSE2 compiler guard
Dependencies/Utility/Utility/stringex.h
The SSE2 include condition now requires _MSC_VER with _M_IX86 or _M_X64, unless __SSE2__ is defined. Other builds use the portable implementation.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix

Suggested reviewers: stephanmeesters

Merge Risk: ⚪ Minimal · up to 239a3

The compiler guard addresses the reported MinGW build failure, with no remaining issue established that should block merging.

Pre-merge checks · Passed 4
Passed Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the MinGW build fix and the use of the portable memcchr implementation when SSE2 is unavailable.
Description check Passed The description accurately explains the _M_IX86 and SSE2 issue, the implementation change, and the reported build validation.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium impact] Changes a preprocessor condition for string search optimization.

The production change appears safe to merge, with a non-blocking suggestion to align the SSE2 test check.

Findings

  1. P2 Tests keep the old check ▶

Summary

Changes memcchr selection so non-MSVC builds need __SSE2__ to use SSE2.

  • The byte scan uses SSE2 only when the compiler supports it.

Reviews (1) · Last reviewed commit: "build(mingw): Use the portable memcchr w..." · Reviewed by Greptile

#include "stringex_memcchr_x86asm.inl"
#else
#if defined(_M_IX86) || defined(_M_X64) || defined(__SSE2__)
#if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) || defined(__SSE2__)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Tests keep the old check

MemcchrSse2 still accepts _M_IX86 without _MSC_VER or __SSE2__. If MinGW headers define _M_IX86 before that test's check and SSE2 is disabled, the test still includes the unsupported SSE2 implementation, even though this header now selects portable code. Enabling tests could therefore bring back the build error. Apply the same check to stringex_memcchr_sse2_test.cpp.

#include "stringex_memcchr_x86asm.inl"
#else
#if defined(_M_IX86) || defined(_M_X64) || defined(__SSE2__)
#if (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) || defined(__SSE2__)

@Mauller Mauller Oct 13, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reverse the original ordering and it will fix the problem.

#if defined(__SSE2__) || defined(_M_X64) || ( defined(_MSC_VER) && defined(_M_IX86) )

The OR check will short circuit and return a true before checking any others.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps this can be simplified further by doing this somewhere (could be a bad idea):

#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
    #ifndef __SSE2__
        #define __SSE2__ 1
    #endif
#endif

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