]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Build: Enabled unaligned access by default on LoongArch loongarch_unaligned
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 21 Oct 2025 13:38:40 +0000 (16:38 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 21 Oct 2025 13:44:51 +0000 (16:44 +0300)
GCC defaults to -mno-strict-align on LoongArch and so do majority
of GNU/Linux distributions, so guessing that unaligned is fast
seems OK enough.

(CMake 4.1 added more CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID values
to detect the arch in a cleaner manner, but 4.1 is too new to require
for now.)

Co-authored-by: lichenggang <lichenggang@deepin.org>
Thanks-to: Xi Ruoyao
Closes: https://github.com/tukaani-project/xz/pull/186
cmake/tuklib_integer.cmake
m4/tuklib_integer.m4

index 7e1ed3c5f00fadf85b1350ab0c94caf1fbfd9be2..73cdaa362f93ada575db8a082f500db17490bbbc 100644 (file)
@@ -64,10 +64,17 @@ function(tuklib_integer TARGET_OR_ALL)
     #   - 32/64-bit x86 / x86-64
     #   - 32/64-bit big endian PowerPC
     #   - 64-bit little endian PowerPC
+    #   - 32/64-bit Loongarch (*)
     #   - Some 32-bit ARM
     #   - Some 64-bit ARM64 (AArch64)
     #   - Some 32/64-bit RISC-V
     #
+    # (*) Loongarch: GCC defaults to -mno-strict-align and so do
+    #     majority of GNU/Linux distributions. As of GCC 15.2, there
+    #     is no predefined macro to detect if -mstrict-align or
+    #     -mno-strict-align is in effect, so in the uncommon cases
+    #     where unaligned isn't fast, one has to manually disable it.
+    #
     # CMake doesn't provide a standardized/normalized list of processor arch
     # names. For example, x86-64 may be "x86_64" (Linux), "AMD64" (Windows),
     # or even "EM64T" (64-bit WinXP).
@@ -76,7 +83,7 @@ function(tuklib_integer TARGET_OR_ALL)
 
     # There is no ^ in the first regex branch to allow "i" at the beginning
     # so it can match "i386" to "i786", and "x86_64".
-    if(PROCESSOR MATCHES "[x34567]86|^x64|^amd64|^em64t")
+    if(PROCESSOR MATCHES "[x34567]86|^x64|^amd64|^em64t|^loongarch")
         set(FAST_UNALIGNED_GUESS ON)
 
     elseif(PROCESSOR MATCHES "^powerpc|^ppc")
index 906ecf1e40f7aab190232eb2b35bd638d64df459..a1e54d5f8e49ba54494b45855bf14eb3a617c2d4 100644 (file)
@@ -75,7 +75,12 @@ if test "x$enable_unaligned_access" = xauto ; then
        # NOTE: There might be other architectures on which unaligned access
        # is fast.
        case $host_cpu in
-               i?86|x86_64|powerpc|powerpc64|powerpc64le)
+               # LoongArch: GCC defaults to -mno-strict-align and so do
+               # majority of GNU/Linux distributions. As of GCC 15.2, there
+               # is no predefined macro to detect if -mstrict-align or
+               # -mno-strict-align is in effect, so in the uncommon cases
+               # where unaligned isn't fast, one has to manually disable it.
+               i?86|x86_64|powerpc|powerpc64|powerpc64le|loongarch*)
                        enable_unaligned_access=yes
                        ;;
                arm*|aarch64*|riscv*)