Files
sqisign_new/.cmake/arm_optimization.cmake

63 lines
2.1 KiB
CMake
Raw Normal View History

# SPDX-License-Identifier: Apache-2.0
# ARM架构优化配置文件
# 检查是否为ARM架构
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
# 启用NEON指令集优化
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
# ARM64架构
add_compile_options(-march=armv8-a+simd)
# 如果支持 crypto 扩展,则启用
include(CheckCSourceCompiles)
check_c_source_compiles("
#include <arm_neon.h>
int main() {
uint8x16_t a = vdupq_n_u8(0);
uint8x16_t b = vaeseq_u8(a, vdupq_n_u8(0));
return 0;
}" HAVE_ARM64_CRYPTO)
if (HAVE_ARM64_CRYPTO)
add_compile_options(-march=armv8-a+crypto)
add_compile_definitions(HAVE_ARM64_CRYPTO)
endif()
else()
# ARM32架构
add_compile_options(-march=armv7-a -mfpu=neon)
endif()
# 通用ARM优化选项
# 启用循环展开和其他优化
add_compile_options(-O3 -funroll-loops)
# 启用链接时优化(LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT result)
if(result)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
# 检查编译器是否支持 thin LTO
include(CheckCCompilerFlag)
# check_c_compiler_flag("-flto=thin" HAS_THIN_LTO)
# if(HAS_THIN_LTO)
# add_compile_options(-flto=thin)
# else()
# # 回退到普通 LTO
# add_compile_options(-flto)
# endif()
add_compile_options(-flto=auto)
endif()
# 启用快速数学运算(可能影响精度)
# add_compile_options(-ffast-math)
# 针对特定CPU的优化
# 可以根据目标设备替换为具体的CPU型号如"cortex-a72"等
add_compile_options(-mtune=cortex-a76)
message(STATUS "ARM optimizations enabled for ${CMAKE_SYSTEM_PROCESSOR}")
# 添加NEON支持的定义
add_compile_definitions(HAVE_NEON)
endif()