1
0
mirror of https://git.tukaani.org/xz.git synced 2025-12-17 10:58:45 +00:00

tuklib_integer/CMake: Don't run unaligned access checks unnecessarily

If the cache variable TUKLIB_FAST_UNALIGNED_ACCESS is already set,
the autodetection result isn't needed because the option() command
does nothing when the cache variable is already set.

This is largely white space change to indent the if...endif block.
This commit is contained in:
Lasse Collin 2025-12-10 19:11:27 +02:00
parent dc1a421ce3
commit f7381cf927
No known key found for this signature in database
GPG Key ID: 38EE757D69184620

View File

@ -123,6 +123,13 @@ function(tuklib_integer TARGET_OR_ALL)
endif() endif()
endif() endif()
# Autodetect if unaligned memory access is fast when the cache variable
# TUKLIB_FAST_UNALIGNED_ACCESS isn't set. The result is stored in
# FAST_UNALIGNED_GUESS. Assume that unaligned access shouldn't be used.
# Initialize the variable here so that it's never undefined in the
# option() command after the if()...endif() block.
set(FAST_UNALIGNED_GUESS OFF)
if(NOT DEFINED TUKLIB_FAST_UNALIGNED_ACCESS)
# Guess that unaligned access is fast on these archs: # Guess that unaligned access is fast on these archs:
# - 32/64-bit x86 / x86-64 # - 32/64-bit x86 / x86-64
# - 32/64-bit big endian PowerPC # - 32/64-bit big endian PowerPC
@ -144,9 +151,8 @@ function(tuklib_integer TARGET_OR_ALL)
# We use heuristics based on compiler output. # We use heuristics based on compiler output.
# #
# CMake < 4.1 doesn't provide a standardized/normalized list of arch # CMake < 4.1 doesn't provide a standardized/normalized list of arch
# names. For example, x86-64 may be "x86_64" (Linux), "AMD64" (Windows), # names. For example, x86-64 may be "x86_64" (Linux),
# or even "EM64T" (64-bit WinXP). # "AMD64" (Windows), or even "EM64T" (64-bit WinXP).
set(FAST_UNALIGNED_GUESS OFF)
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" PROCESSOR) string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" PROCESSOR)
# CMake 4.1 made CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID useful on many # CMake 4.1 made CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID useful on many
@ -160,8 +166,8 @@ function(tuklib_integer TARGET_OR_ALL)
string(TOLOWER "${PROCESSOR}" PROCESSOR) string(TOLOWER "${PROCESSOR}" PROCESSOR)
endif() endif()
# There is no ^ in the first regex branch to allow "i" at the beginning # There is no ^ in the first regex branch to allow "i" at
# so it can match "i386" to "i786", and "x86_64". # 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")
set(FAST_UNALIGNED_GUESS ON) set(FAST_UNALIGNED_GUESS ON)
@ -170,7 +176,8 @@ function(tuklib_integer TARGET_OR_ALL)
set(FAST_UNALIGNED_GUESS ON) set(FAST_UNALIGNED_GUESS ON)
endif() endif()
elseif(PROCESSOR MATCHES "^arm|^riscv" AND NOT PROCESSOR MATCHES "^arm64") elseif(PROCESSOR MATCHES "^arm|^riscv" AND
NOT PROCESSOR MATCHES "^arm64")
# On 32-bit ARM, GCC and Clang # #define __ARM_FEATURE_UNALIGNED # On 32-bit ARM, GCC and Clang # #define __ARM_FEATURE_UNALIGNED
# if and only if unaligned access is supported. # if and only if unaligned access is supported.
# #
@ -248,6 +255,7 @@ function(tuklib_integer TARGET_OR_ALL)
set(FAST_UNALIGNED_GUESS ON) set(FAST_UNALIGNED_GUESS ON)
endif() endif()
endif() endif()
endif()
option(TUKLIB_FAST_UNALIGNED_ACCESS option(TUKLIB_FAST_UNALIGNED_ACCESS
"Enable if the system supports *fast* unaligned memory access \ "Enable if the system supports *fast* unaligned memory access \