-
-
Notifications
You must be signed in to change notification settings - Fork 69
BLD: Add MSVC build support on windows #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Using as HEAD: cfe57c4 I fix a few typos: -#if defined(__INTEL_COMPILER) and !defined(__SANITIZE_ADDRESS__)
+#if defined(__INTEL_COMPILER) && !defined(__SANITIZE_ADDRESS__) -#elif __GNUC__ >= 8 and !defined(__SANITIZE_ADDRESS__)
+#elif __GNUC__ >= 8 && !defined(__SANITIZE_ADDRESS__) Then I open the cl /nologo /c /arch:AVX2 /I../src /std:c++17 x86simdsort-avx2.cpp
cl /nologo /c /arch:AVX512 /I../src /std:c++17 x86simdsort-skx.cpp
cl /nologo /c /arch:AVX512 /I../src /std:c++17 x86simdsort-icl.cpp
cl /nologo /c /arch:AVX512 /I../src /std:c++17 x86simdsort-spr.cpp The first 2 compile, but the last 2 do not. See compilation logs attached: This is the reason why I fell back to The here you mention you could build the library with MSVC. What compiler flags and compiler version do you use? Hope this helps. |
4dc9609 fixes this error.
This is specific to _Float16 dispatch, if MSVC doesn't support it, then nothing much we can do about it. I would recommend using meson to build the library though, _Float16 is an optional requirement, meson build will auto detect if your compiler supports it and skips it if it doesn't.
This is what worked for me:
|
@fabiocannizzo c1994cc adds a CI job to build with MSVC and that runs successfully. There are a few warnings that we can work on fixing (see #222) but I don't think that's gating the build itself. Does this address your concerns of building with MSVC? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request adds Microsoft Visual C++ (MSVC) compiler support for the x86 SIMD sort library on Windows platforms. The changes enable cross-platform compatibility by providing MSVC-specific compiler flags and CPU feature detection while maintaining compatibility with existing GCC/Clang builds.
- Introduced MSVC-specific compiler flags (
/arch:AVX2
,/arch:AVX512
) to replace GCC/Clang march flags - Added cross-platform CPU feature detection abstraction using MSVC intrinsics or GCC builtins
- Updated build system to conditionally apply compiler-specific configurations
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
meson.build | Added compiler argument validation for GCC/Clang and formatting improvements |
lib/x86simdsortcpuid.h | New header providing cross-platform CPU feature detection abstraction |
lib/x86simdsort.h | Added MSVC-compatible symbol visibility macros and improved code formatting |
lib/x86simdsort.cpp | Updated to use abstracted CPU detection functions and MSVC-compatible constructor attributes |
lib/x86simdsort-icl.cpp | Added MSVC-specific include guard for AVX512 headers |
lib/meson.build | Replaced conditional compilation with MSVC/GCC compiler flag selection |
.github/workflows/c-cpp.yml | Added Windows MSVC CI build job and simplified existing test configurations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@@ -1,3 +1,4 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Adding a blank line at the beginning of the file serves no functional purpose and deviates from standard file formatting practices. Consider removing this empty line.
Copilot uses AI. Check for mistakes.
#include <string> | ||
#include <unordered_map> | ||
|
||
static std::unordered_map<std::string, bool> xss_cpu_features; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a static global variable in a header file can lead to multiple definition issues when the header is included in multiple translation units. Consider using a function-local static variable or moving this to the implementation file.
Copilot uses AI. Check for mistakes.
int nIds = cpuInfo[0]; | ||
__cpuid(cpuInfo, 1); | ||
bool osxsave = (cpuInfo[2] & (1 << 27)) != 0; | ||
bool avx = (cpuInfo[2] & (1 << 28)) != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables nIds
, osxsave
, and avx
are defined but never used in the function. Consider removing these unused variables to improve code clarity.
int nIds = cpuInfo[0]; | |
__cpuid(cpuInfo, 1); | |
bool osxsave = (cpuInfo[2] & (1 << 27)) != 0; | |
bool avx = (cpuInfo[2] & (1 << 28)) != 0; | |
__cpuid(cpuInfo, 1); |
Copilot uses AI. Check for mistakes.
@r-devulap : thank you for this work. |
This pull request improves cross-platform support and CPU feature detection for the x86 SIMD sort library, primarily targeting compatibility with Microsoft's Visual C++ (MSVC) compiler. The changes ensure that both build configuration and runtime CPU feature checks work correctly on MSVC, while maintaining compatibility with other compilers.
Build system compatibility:
lib/meson.build
to use MSVC-specific compiler flags (/arch:AVX2
and/arch:AVX512
) instead of the GCC/Clang flags (-march=...
), ensuring correct SIMD instruction set selection on Windows/MSVC. [1] [2] [3] [4]CPU feature detection abstraction:
lib/x86simdsortcpuid.h
to abstract CPU feature detection, using MSVC intrinsics for runtime checks and caching results, while falling back to__builtin_cpu_supports
for other compilers.__builtin_cpu_supports
and__builtin_cpu_init
inlib/x86simdsort.cpp
with the newxss_cpu_supports
andxss_cpu_init
functions/macros, ensuring consistent feature detection across platforms. [1] [2] [3]Symbol visibility and constructor attribute compatibility:
XSS_EXPORT_SYMBOL
,XSS_HIDE_SYMBOL
, andXSS_ATTRIBUTE_CONSTRUCTOR
macros inlib/x86simdsort.h
andlib/x86simdsort.cpp
to handle symbol visibility and static initialization attributes for both MSVC and non-MSVC compilers. [1] [2]Code style and correctness:
object_qsort
for clarity and correctness.Miscellaneous:
meson.build
for style consistency.