weidai11 / cryptopp

free C++ class library of cryptographic schemes
https://cryptopp.com
Other
4.67k stars 1.47k forks source link

Fatal Error compiling under MSVC with avx2 enabled (/arch:AVX2) #1198

Closed krawq closed 1 year ago

krawq commented 1 year ago

OS: Windows 11 x64 Cryptopp version : Last vcpkg available version 8.7.0#3 Build: Last MSVC (2022 17.5) x64 Error : \include\cryptopp\misc.h(83): fatal error C1083: Cannot open include file: 'x86intrin.h': No such file or directory

issue with this:

#if defined(__BMI__)
# include <x86intrin.h>
# include <immintrin.h>
#endif  // GCC and BMI

The x86intrin.h header is not provided by MSVC. The _BMI_variable is not specific to GCC because the qsimd.h header file on MSVC defines this:

#  ifdef __AVX2__
// MSVC defines __AVX2__ with /arch:AVX2
#    define __F16C__                        1
#    define __RDRND__                       1
#    define __FMA__                         1
#    define __BMI__                         1          **>> Here its set to 1**
#    define __BMI2__                        1
#    define __MOVBE__                       1
#    define __LZCNT__                       1
#  endif

Fix :

#if defined(__BMI__)
#if defined(__GNUC__)
# include <x86intrin.h>
#endif
# include <immintrin.h>
#endif  // GCC and BMI
noloader commented 1 year ago

The BMI variable is not specific to GCC because the qsimd.h header file on MSVC defines this

Hmmm... that's new. I did not know MSVC defined GCC defines nowadays.

I'll get it fixed this weekend.

cryptopp $ grep 'x86intrin.h' *.h *.cpp
misc.h:# include <x86intrin.h>
blake2b_simd.cpp:#  include <x86intrin.h>
blake2s_simd.cpp:#  include <x86intrin.h>
chacha_simd.cpp:#  include <x86intrin.h>
cham_simd.cpp:#  include <x86intrin.h>
keccak_simd.cpp:#  include <x86intrin.h>
lea_simd.cpp:#  include <x86intrin.h>
lsh256_avx.cpp:# include <x86intrin.h>
lsh256_sse.cpp:# include <x86intrin.h>
lsh512_avx.cpp:# include <x86intrin.h>
lsh512_sse.cpp:# include <x86intrin.h>
simon128_simd.cpp:#  include <x86intrin.h>
speck128_simd.cpp:#  include <x86intrin.h>
noloader commented 1 year ago

Thanks again @krawq.

This should be cleared at Commit ddb8f36e8894.