]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
CMake: Add manual support for 32-bit x86 assembly files
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 23 May 2024 12:15:18 +0000 (15:15 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 23 May 2024 12:40:51 +0000 (15:40 +0300)
One has to pass -DENABLE_X86_ASM=ON to cmake to enable the
CRC assembly code. Autodetection isn't done. Looking at
CMAKE_SYSTEM_PROCESSOR might not work as it comes from uname
unless cross-compilation is done using a CMake toolchain file.

On top of this, if the code is run on modern processors that support
the CLMUL instruction, then the C code should be faster (but then
one should also be using a x86-64 build if possible).

(cherry picked from commit 24387c234b4eed1ef9a7eaa107391740b4095568)

CMakeLists.txt

index 445822b8ec585d93dd4de18139eab9c5bf30ca58..59ecf010be99e3910f17b5e70363517825e79f68 100644 (file)
 #
 # A few things are still missing compared to the Autotools-based build:
 #
-#   - 32-bit x86 assembly code for CRC32 and CRC64 isn't used.
+#   - 32-bit x86 assembly code for CRC32 and CRC64 isn't used by default.
+#     Use the option -DENABLE_X86_ASM=ON on the CMake command line to
+#     enable the assembly files. They are compatible with Linux, *BSDs,
+#     Cygwin, MinGW-w64, and Darwin. They are NOT compatible with MSVC.
+#
+#     NOTE: The C code includes a generic version compatible with all
+#     processors and CLMUL version that requires a new enough processor
+#     with the PCLMULQDQ instruction. If the 32-bit x86 assembly files
+#     are used, the CLMUL version in the C code is NOT built. On modern
+#     processors with CLMUL support, the C code should be faster than
+#     the assembly code while on old processors the assembly code wins.
 #
 #   - External SHA-256 code isn't supported but it's disabled by
 #     default in the Autotools build too (--enable-external-sha256).
@@ -149,6 +159,14 @@ endif()
 set(CMAKE_C_STANDARD 99)
 set(CMAKE_C_STANDARD_REQUIRED ON)
 
+# Support 32-bit x86 assembly files.
+if(NOT MSVC)
+    option(ENABLE_X86_ASM "Enable 32-bit x86 assembly code" OFF)
+    if(ENABLE_X86_ASM)
+        enable_language(ASM)
+    endif()
+endif()
+
 # On Apple OSes, don't build executables as bundles:
 set(CMAKE_MACOSX_BUNDLE OFF)
 
@@ -482,11 +500,16 @@ if(ENABLE_SMALL)
     target_sources(liblzma PRIVATE src/liblzma/check/crc32_small.c)
 else()
     target_sources(liblzma PRIVATE
-        src/liblzma/check/crc32_fast.c
         src/liblzma/check/crc32_table.c
         src/liblzma/check/crc32_table_be.h
         src/liblzma/check/crc32_table_le.h
     )
+
+    if(ENABLE_X86_ASM)
+        target_sources(liblzma PRIVATE src/liblzma/check/crc32_x86.S)
+    else()
+        target_sources(liblzma PRIVATE src/liblzma/check/crc32_fast.c)
+    endif()
 endif()
 
 if("crc64" IN_LIST ADDITIONAL_CHECK_TYPES)
@@ -496,11 +519,16 @@ if("crc64" IN_LIST ADDITIONAL_CHECK_TYPES)
         target_sources(liblzma PRIVATE src/liblzma/check/crc64_small.c)
     else()
         target_sources(liblzma PRIVATE
-            src/liblzma/check/crc64_fast.c
             src/liblzma/check/crc64_table.c
             src/liblzma/check/crc64_table_be.h
             src/liblzma/check/crc64_table_le.h
         )
+
+        if(ENABLE_X86_ASM)
+            target_sources(liblzma PRIVATE src/liblzma/check/crc64_x86.S)
+        else()
+            target_sources(liblzma PRIVATE src/liblzma/check/crc64_fast.c)
+        endif()
     endif()
 endif()