ip7z / 7zip

7-Zip
695 stars 71 forks source link

Fails to compile with AVX512 support #27

Closed HanabishiRecca closed 4 months ago

HanabishiRecca commented 4 months ago

7zz executable (Alone2) and 7z.so library (Format7zF) fail to compile with AVX512 support enabled. E.g. when setting -march=x86-64-v4 in CFLAGS.

../../../../C/Blake2s.c: In function ‘z7_Black2sp_Prepare’:
../../../../C/Blake2s.c:2552:11: error: implicit declaration of function ‘CPU_IsSupported_AVX512F_AVX512VL’; did you mean ‘CPU_IsSupported_VAES_AVX2’? [-Wimplicit-function-declaration]
 2552 |       if (CPU_IsSupported_AVX512F_AVX512VL())
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |           CPU_IsSupported_VAES_AVX2
make: *** [../../7zip_gcc.mak:1164: _o/Blake2s.o] Error 1

Truns out this function declaration is commented out for some reason:

https://github.com/ip7z/7zip/blob/fc662341e6f85da78ada0e443f6116b978f79f22/C/CpuArch.h#L610

But still invoked in the code:

https://github.com/ip7z/7zip/blob/fc662341e6f85da78ada0e443f6116b978f79f22/C/Blake2s.c#L2552

Uncommenting it makes the build successful.

ip7z commented 4 months ago

Thanks. Another way to fix that problem is to change Blake2s.c file:

@@ -1164,7 +1164,9 @@
 #if 1 && defined(Z7_BLAKE2S_USE_AVX512_ALWAYS)
   #define MM256_ROR_EPI32  _mm256_ror_epi32
   #define Z7_MM256_ROR_EPI32_IS_SUPPORTED
+#ifdef Z7_BLAKE2S_USE_AVX2_WAY2
   #define LOAD_ROTATE_CONSTS_256
+#endif
 #else
 #ifdef Z7_BLAKE2S_USE_AVX2_WAY_SLOW
 #ifdef Z7_BLAKE2S_USE_AVX2_WAY2
@@ -2548,7 +2550,7 @@
   Z7_BLAKE2SP_FUNC_INIT func_Final = NULL;

 #if defined(MY_CPU_X86_OR_AMD64)
-    #if defined(Z7_BLAKE2S_USE_AVX512_ALWAYS)
+    #if 0 && defined(Z7_BLAKE2S_USE_AVX512_ALWAYS)
       if (CPU_IsSupported_AVX512F_AVX512VL())
     #endif
     #if defined(Z7_BLAKE2S_USE_SSE41)
HanabishiRecca commented 4 months ago

Fixed by 24.06.