xtensor-stack / xsimd

C++ wrappers for SIMD intrinsics and parallelized, optimized mathematical functions (SSE, AVX, AVX512, NEON, SVE))
https://xsimd.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.15k stars 253 forks source link

Build fail on windows with MSVC (v13) #1037

Closed Nosenzor closed 1 month ago

Nosenzor commented 2 months ago

I've found this issue when using xsimdthrough vcpkg.

I've filed a bug in vcpkg too, but i thought i should open it here too.

D:\a\FW\builds\ninja-release-vcpkg\vcpkg_installed\x64-windows\include\xsimd\arch\generic./xsimd_generic_details.hpp(207,22): error C2187: syntax error: 'char' was unexpected here
D:\a\FW\builds\ninja-release-vcpkg\vcpkg_installed\x64-windows\include\xsimd\arch\generic./xsimd_generic_details.hpp(207,28): error C3878: syntax error: unexpected token '=' following 'simple_declaration'
D:\a\FW\builds\ninja-release-vcpkg\vcpkg_installed\x64-windows\include\xsimd\arch\generic./xsimd_generic_details.hpp(207,28): note: error recovery skipped: '='
D:\a\FW\builds\ninja-release-vcpkg\vcpkg_installed\x64-windows\include\xsimd\arch\generic./xsimd_generic_details.hpp(211,76): error C2760: syntax error: ')' was unexpected here; expected 'expression'
D:\a\FW\builds\ninja-release-vcpkg\vcpkg_installed\x64-windows\include\xsimd\arch\generic./xsimd_generic_details.hpp(211,76): error C2760: syntax error: ')' was unexpected here; expected ';'
D:\a\FW\builds\ninja-release-vcpkg\vcpkg_installed\x64-windows\include\xsimd\arch\generic./xsimd_generic_details.hpp(211,76): error C3878: syntax error: unexpected token ')' following 'jump_statement'
D:\a\FW\builds\ninja-release-vcpkg\vcpkg_installed\x64-windows\include\xsimd\arch\generic./xsimd_generic_details.hpp(211,76): 
serge-sans-paille commented 1 month ago

Can you provide a simple reproducer? Maybe on godbolt?

Nosenzor commented 1 month ago

I did that if it can help it's a copy of my code that use xsimd: https://godbolt.org/z/ofvzT1Ejv On godbolt it compiles with gcc and clang but not with MSVC but i'm not sure it is the same issue. Also note that vcpkg team is able to reproduce the error, maybe there's a port error?
When I compile on a windows computer i had to comment those lines (fortunately it works without it in my case.: Is this a function that has changed recently ?

            // Provide a generic float -> uint32_t cast only if we have a
            // non-generic float -> int32_t fast_cast
            // template <class A, class _ = decltype(fast_cast(std::declval<batch<float, A> const&>(), std::declval<batch<int32_t, A> const&>(), A {}))>
            // XSIMD_INLINE batch<uint32_t, A> fast_cast(batch<float, A> const& v, batch<uint32_t, A> const&, requires_arch<generic>) noexcept
            // {
            //     auto is_large = v >= batch<float, A>(1u << 31);
            //     auto small = bitwise_cast<float>(batch_cast<int32_t>(v));
            //     auto large = bitwise_cast<float>(
            //         batch_cast<int32_t>(v - batch<float, A>(1u << 31))
            //         ^ batch<int32_t, A>(1u << 31));
            //     return bitwise_cast<uint32_t>(select(is_large, large, small));
            // }
Nekto89 commented 1 month ago

it's caused by #define small char https://learn.microsoft.com/uk-ua/windows/win32/midl/-char

As a workaround you can try defining

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

before including Windows headers if you don't use anything from there. Or do undefs after Windows headers but before including xsimd

#ifdef small
#undef small
#endif
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#include <xsimd/xsimd.hpp>
Nosenzor commented 1 month ago

Ooh no... not this stupid thing from ms again ! I've been caught so many time by min max macros but never by the small one. The turnaround would work for me but you should integrate that in a release update.

Nosenzor commented 1 month ago

BTW i don't have windows specif headers, but those define are somewhere set by the compiler. There's q NOMINMAX to set in cmake but not sure it works for small.