[x265] [PATCH v2 4/8] AArch64: Clean up CMake feature detection

Hari Limaye hari.limaye at arm.com
Tue Jul 30 15:45:28 UTC 2024


Neon is a compulsory ISA feature for AArch64, so remove test for Neon
when compiling for AArch64. SVE2 is an extension from Armv9.0-A, so use
the armv9-a architecture flag when compiling with SVE2.

Also clean up some duplicated compiler flags so that these are added in
one place, and handle cross-compilation options for feature extensions
separately. Add SVE and SVE2 assembly sources in separate, non-exclusive
conditional blocks to remove duplication, and to simplify the future
addition of new architecture features. Refactor these conditional checks
to test for the CPU_HAS_<FEAT> flag only - as this is now also set when
cross-compiling. Similarly, remove the check for CROSS_COMPILE_ARM64, as
the variable ARM64 is set via checking CMAKE_SYSTEM_PROCESSOR when cross
compiling.
---
 source/CMakeLists.txt | 73 +++++++++++++++++--------------------------
 1 file changed, 29 insertions(+), 44 deletions(-)

diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index bed98bb37..0a877f209 100755
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -82,14 +82,8 @@ elseif(ARMMATCH GREATER "-1")
     set(ARM 1)
     add_definitions(-DX265_ARCH_ARM=1 -DHAVE_ARMV6=1)
 elseif(ARM64MATCH GREATER "-1")
-    #if(CROSS_COMPILE_ARM64)
-        #message(STATUS "Cross compiling for ARM64 arch")
-    #else()
-        #set(CROSS_COMPILE_ARM64 0)
-    #endif()
     message(STATUS "Detected ARM64 target processor")
     set(ARM64 1)
-    add_definitions(-DX265_ARCH_ARM64=1 -DHAVE_NEON)
 
     # Options for cross compiling AArch64 optional extensions
     option(CROSS_COMPILE_SVE "Cross Compile for SVE Target" OFF)
@@ -265,35 +259,35 @@ if(GCC)
             set(ARM_ARGS -mcpu=native -mfloat-abi=hard -mfpu=vfp -marm)
         endif()
     endif()
-	if(ARM64 OR CROSS_COMPILE_ARM64)
-        find_package(Neon)
-        find_package(SVE)
-        find_package(SVE2)
-        if(CPU_HAS_SVE2 OR CROSS_COMPILE_SVE2)
-            message(STATUS "Found SVE2")
-	        set(ARM_ARGS -O3 -march=armv8-a+sve2 -fPIC -flax-vector-conversions)
+    if(ARM64)
+        message(STATUS "Found Neon")
+        set(CPU_HAS_NEON 1)
+        add_definitions(-DX265_ARCH_ARM64=1 -DHAVE_NEON=1)
+
+        # Handle cross-compilation options.
+        if(CROSS_COMPILE_SVE)
+            set(CPU_HAS_SVE 1)
+        endif()
+        if(CROSS_COMPILE_SVE2)
             set(CPU_HAS_SVE2 1)
-            # SVE2 implies Neon and SVE.
+            # SVE2 implies SVE.
             set(CPU_HAS_SVE 1)
-            set(CPU_HAS_NEON 1)
-            add_definitions(-DHAVE_SVE2)
-            add_definitions(-DHAVE_SVE)
-            add_definitions(-DHAVE_NEON)
-        elseif(CPU_HAS_SVE OR CROSS_COMPILE_SVE)
+        endif()
+
+        find_package(SVE)
+        find_package(SVE2)
+        if(CPU_HAS_SVE)
             message(STATUS "Found SVE")
-            set(CPU_HAS_SVE 1)
-            # SVE implies Neon.
-            set(CPU_HAS_NEON 1)
-	        set(ARM_ARGS -O3 -march=armv8-a+sve -fPIC -flax-vector-conversions)
-            add_definitions(-DHAVE_SVE)
-            add_definitions(-DHAVE_NEON)
-        elseif(CPU_HAS_NEON)
-            message(STATUS "Found NEON")
-            set(ARM_ARGS -fPIC -flax-vector-conversions)
-            add_definitions(-DHAVE_NEON)
-        else()
-            set(ARM_ARGS -fPIC -flax-vector-conversions)
-        endif()        
+            set(ARM_ARGS -O3 -march=armv8.2-a+sve)
+            add_definitions(-DHAVE_SVE=1)
+        endif()
+        if(CPU_HAS_SVE2)
+            message(STATUS "Found SVE2")
+            # SVE2 is only available from Armv9.0-A.
+            set(ARM_ARGS -O3 -march=armv9-a+sve2)
+            add_definitions(-DHAVE_SVE2=1)
+        endif()
+        set(ARM_ARGS ${ARM_ARGS} -fPIC -flax-vector-conversions)
         if(CPU_HAS_SVE)
             set(SVE_HEADER_TEST "
 #ifndef __ARM_NEON_SVE_BRIDGE
@@ -633,17 +627,7 @@ if((MSVC_IDE OR XCODE OR GCC) AND ENABLE_ASSEMBLY)
                 ARGS ${ARM_ARGS} ${ASM_FLAGS} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
                 DEPENDS ${ASM_SRC})
         endforeach()
-        if(CPU_HAS_SVE2 OR CROSS_COMPILE_SVE2)
-            foreach(ASM ${ARM_ASMS_SVE})
-                set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/aarch64/${ASM})
-                list(APPEND ASM_SRCS ${ASM_SRC})
-                list(APPEND ASM_OBJS ${ASM}.${SUFFIX})
-                add_custom_command(
-                    OUTPUT ${ASM}.${SUFFIX}
-                    COMMAND ${CMAKE_CXX_COMPILER}
-                    ARGS ${ARM_ARGS} ${ASM_FLAGS} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
-                    DEPENDS ${ASM_SRC})
-            endforeach()
+        if(CPU_HAS_SVE2)
             foreach(ASM ${ARM_ASMS_SVE2})
                 set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/aarch64/${ASM})
                 list(APPEND ASM_SRCS ${ASM_SRC})
@@ -654,7 +638,8 @@ if((MSVC_IDE OR XCODE OR GCC) AND ENABLE_ASSEMBLY)
                     ARGS ${ARM_ARGS} ${ASM_FLAGS} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}
                     DEPENDS ${ASM_SRC})
             endforeach()
-        elseif(CPU_HAS_SVE OR CROSS_COMPILE_SVE)
+        endif()
+        if(CPU_HAS_SVE)
             foreach(ASM ${ARM_ASMS_SVE})
                 set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/aarch64/${ASM})
                 list(APPEND ASM_SRCS ${ASM_SRC})
-- 
2.42.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0004-AArch64-Clean-up-CMake-feature-detection.patch
Type: text/x-patch
Size: 5758 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240730/db0a843b/attachment.bin>


More information about the x265-devel mailing list