[x265] [PATCH v2 1/6] AArch64: Refactor ISA feature detection macros
Jonathan Wright
jonathan.wright at arm.com
Wed Nov 6 15:35:00 UTC 2024
Refactor AArch64 ISA feature detection macros to allow turning
features on or off at project configuration time.
Cross-compilation options enabling Armv8.x and Armv9.x features are
now turned on by default, and must be explicitly disabled depending
on what features are supported by the target platform.
This change is also preparation for adding run-time CPU feature
detection in future patches.
---
build/README.txt | 50 ++++++++++++++++----------
source/CMakeLists.txt | 84 +++++++++++++++++++++++--------------------
2 files changed, 77 insertions(+), 57 deletions(-)
diff --git a/build/README.txt b/build/README.txt
index 14d9ff8d0..4274951e5 100644
--- a/build/README.txt
+++ b/build/README.txt
@@ -92,7 +92,7 @@ building out of a Mercurial source repository. If you are building out of
a release source package, the version will not change. If Mercurial is not
found, the version will be "unknown".
-= Build Instructions for cross-compilation for Arm AArch64 Targets=
+= Build Instructions for cross-compilation for Arm AArch64 Targets =
Cross compilation of x265 for AArch64 targets is possible on x86 platforms by
passing a toolchain file when running CMake to configure the project:
@@ -106,30 +106,42 @@ running CMake to configure the project. For example:
* cmake -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++
-If target platform supports Armv8.4 Neon DotProd instructions, the
-CROSS_COMPILE_NEON_DOTPROD CMake option should be set to ON:
+The following AArch64 ISA features are turned on by default when cross-compiling:
-* cmake -DCROSS_COMPILE_NEON_DOTPROD=ON <other configuration options...>
+* Neon DotProd, mandatory from Armv8.4
+* Neon I8MM, mandatory from Armv8.6
+* SVE, mandatory from Armv9.0
+* SVE2, mandatory from Armv9.0
-If target platform supports Armv8.6 Neon I8MM instructions, the
-CROSS_COMPILE_NEON_I8MM CMake option should be set to ON:
+If the target platform does not support Armv8.4 Neon DotProd instructions, the
+ENABLE_NEON_DOTPROD CMake option should be set to OFF:
-* cmake -DCROSS_COMPILE_NEON_I8MM=ON <other configuration options...>
+* cmake -DENABLE_NEON_DOTPROD=OFF <other configuration options...>
-If the target platform supports SVE or SVE2, CROSS_COMPILE_SVE or
-CROSS_COMPILE_SVE2 CMake options should be set to ON, respectively.
-For example, when running CMake to configure the project:
+If target platform does not support Armv8.6 Neon I8MM instructions, the
+ENABLE_NEON_I8MM CMake option should be set to OFF:
-1. cmake -DCROSS_COMPILE_SVE=ON <other configuration options...>
-2. cmake -DCROSS_COMPILE_SVE2=ON <other configuration options...>
+* cmake -DENABLE_NEON_I8MM=OFF <other configuration options...>
-Note: when the CROSS_COMPILE_SVE option is set to ON the build configuration will
-also compile for Neon DotProd and I8MM, as we impose the constraint that SVE implies
-both Neon DotProd and I8MM.
+Note: when the ENABLE_NEON_DOTPROD option is set to OFF the build configuration will
+disable Neon I8MM, as we impose the constraint that Neon DotProd implies Neon I8MM.
-Similarly when the CROSS_COMPILE_SVE2 option is set to ON the build configuration
-will also compile for Neon I8MM, as we impose the constraint that SVE2 implies Neon
-I8MM. SVE2 already implies that Neon DotProd is implemented since SVE2 is an Armv9.0
-feature which implies Armv8.5, and Neon DotProd is mandatory from Armv8.4.
+If the target platform does not support SVE, the ENABLE_SVE CMake option should be
+set to OFF:
+
+* cmake -DENABLE_SVE=OFF <other configuration options...>
+
+Note: when any of ENABLE_NEON_DOTPROD or ENABLE_NEON_I8MM are set to OFF, the build
+configuration will disable SVE, as we impose the constraint that SVE implies both
+Neon DotProd and Neon I8MM.
+
+If the target platform does not support SVE2, the ENABLE_SVE2 CMake option should be
+set to OFF:
+
+* cmake -DENABLE_SVE2=OFF <other configuration options...>
+
+Note: when any of ENABLE_NEON_DOTPROD, ENABLE_NEON_I8MM, or ENABLE_SVE are set to
+OFF, the build configuration will disable SVE2, as we impose the constraint that
+SVE2 implies Neon I8MM, as well as Neon DotProd and SVE.
Then, the normal build process can be followed.
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index 107a9d3bb..908980675 100755
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -87,11 +87,12 @@ elseif(ARM64MATCH GREATER "-1")
option(AARCH64_WARNINGS_AS_ERRORS "Build with -Werror for AArch64 Intrinsics files" OFF)
- # Options for cross compiling AArch64 optional extensions
- option(CROSS_COMPILE_SVE "Cross Compile for SVE Target" OFF)
- option(CROSS_COMPILE_SVE2 "Cross Compile for SVE2 Target" OFF)
- option(CROSS_COMPILE_NEON_DOTPROD "Cross Compile for Neon DotProd Target" OFF)
- option(CROSS_COMPILE_NEON_I8MM "Cross Compile for Neon I8MM Target" OFF)
+ # Options for manually enabling/disabling AArch64 SIMD extensions.
+ option(ENABLE_NEON "Enable Neon" ON)
+ option(ENABLE_NEON_DOTPROD "Enable Neon DotProd" ON)
+ option(ENABLE_NEON_I8MM "Enable Neon I8MM" ON)
+ option(ENABLE_SVE "Enable SVE" ON)
+ option(ENABLE_SVE2 "Enable SVE2" ON)
else()
message(STATUS "CMAKE_SYSTEM_PROCESSOR value `${CMAKE_SYSTEM_PROCESSOR}` is unknown")
message(STATUS "Please add this value near ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}")
@@ -264,34 +265,14 @@ if(GCC)
endif()
endif()
if(ARM64)
- message(STATUS "Found Neon")
set(CPU_HAS_NEON 1)
- add_definitions(-DX265_ARCH_ARM64=1 -DHAVE_NEON=1)
+ add_definitions(-DX265_ARCH_ARM64=1)
if(CROSS_COMPILE_ARM64)
- # Handle cross-compilation options.
- if(CROSS_COMPILE_NEON_DOTPROD)
- set(CPU_HAS_NEON_DOTPROD 1)
- endif()
- if(CROSS_COMPILE_NEON_I8MM)
- set(CPU_HAS_NEON_I8MM 1)
- # Impose the constraint that Neon I8MM implies Neon DotProd.
- set(CPU_HAS_NEON_DOTPROD 1)
- endif()
- if(CROSS_COMPILE_SVE)
- set(CPU_HAS_SVE 1)
- # Impose the constraint that SVE implies Neon DotProd and I8MM.
- set(CPU_HAS_NEON_DOTPROD 1)
- set(CPU_HAS_NEON_I8MM 1)
- endif()
- if(CROSS_COMPILE_SVE2)
- set(CPU_HAS_SVE2 1)
- # SVE2 implies SVE and Neon DotProd.
- set(CPU_HAS_SVE 1)
- set(CPU_HAS_NEON_DOTPROD 1)
- # Impose the constraint that SVE2 implies Neon I8MM.
- set(CPU_HAS_NEON_I8MM 1)
- endif()
+ set(CPU_HAS_NEON_DOTPROD 1)
+ set(CPU_HAS_NEON_I8MM 1)
+ set(CPU_HAS_SVE 1)
+ set(CPU_HAS_SVE2 1)
else()
if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")
find_package(NEON_DOTPROD)
@@ -303,6 +284,37 @@ if(GCC)
endif()
endif()
+ # Impose constraint that disabling one extension disables all 'higher order' ones.
+ if(NOT ENABLE_NEON)
+ message(STATUS "Disabling Neon")
+ set(CPU_HAS_NEON 0)
+ set(ENABLE_NEON_DOTPROD 0)
+ endif()
+ if(NOT ENABLE_NEON_DOTPROD)
+ message(STATUS "Disabling Neon DotProd")
+ set(CPU_HAS_NEON_DOTPROD 0)
+ set(ENABLE_NEON_I8MM 0)
+ endif()
+ if(NOT ENABLE_NEON_I8MM)
+ message(STATUS "Disabling Neon I8MM")
+ set(CPU_HAS_NEON_I8MM 0)
+ set(ENABLE_SVE 0)
+ endif()
+ if(NOT ENABLE_SVE)
+ message(STATUS "Disabling SVE")
+ set(CPU_HAS_SVE 0)
+ set(ENABLE_SVE2 0)
+ endif()
+ if(NOT ENABLE_SVE2)
+ message(STATUS "Disabling SVE2")
+ set(CPU_HAS_SVE2 0)
+ endif()
+
+ if(CPU_HAS_NEON)
+ message(STATUS "Found Neon")
+ set(ARM_ARGS -O3 -march=armv8-a)
+ add_definitions(-DHAVE_NEON=1)
+ endif()
if(CPU_HAS_NEON_DOTPROD)
# Neon DotProd is mandatory from Armv8.4.
message(STATUS "Found Neon DotProd")
@@ -312,19 +324,11 @@ if(GCC)
if(CPU_HAS_NEON_I8MM)
# Neon I8MM is mandatory from Armv8.6.
message(STATUS "Found Neon I8MM")
- # Impose the constraint that Neon I8MM implies Neon DotProd.
- if(NOT CPU_HAS_NEON_DOTPROD)
- message(FATAL_ERROR "Unsupported AArch64 feature combination (Neon I8MM without Neon DotProd)")
- endif()
set(ARM_ARGS -O3 -march=armv8.2-a+dotprod+i8mm)
add_definitions(-DHAVE_NEON_I8MM=1)
endif()
if(CPU_HAS_SVE)
message(STATUS "Found SVE")
- # Impose the constraint that SVE implies Neon I8MM.
- if(NOT CPU_HAS_NEON_I8MM)
- message(FATAL_ERROR "Unsupported AArch64 feature combination (SVE without Neon I8MM)")
- endif()
set(ARM_ARGS -O3 -march=armv8.2-a+dotprod+i8mm+sve)
add_definitions(-DHAVE_SVE=1)
endif()
@@ -462,6 +466,10 @@ endif(GCC)
find_package(Nasm)
if(ARM OR CROSS_COMPILE_ARM OR ARM64 OR CROSS_COMPILE_ARM64)
option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" ON)
+ # Force ENABLE_ASSEMBLY to be OFF when all SIMD extensions are disabled.
+ if (NOT ENABLE_NEON)
+ set(ENABLE_ASSEMBLY OFF CACHE BOOL "" FORCE)
+ endif()
elseif(NASM_FOUND AND X86)
if (NASM_VERSION_STRING VERSION_LESS "2.13.0")
message(STATUS "Nasm version ${NASM_VERSION_STRING} is too old. 2.13.0 or later required")
--
2.42.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0001-AArch64-Refactor-ISA-feature-detection-macros.patch
Type: text/x-patch
Size: 10108 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241106/8668d769/attachment.bin>
More information about the x265-devel
mailing list