Files
sqisign_new/.cmake/arm_optimization.cmake
StarsAC 601f0b7d0a feat(cmake): 添加 ARM 架构优化配置文件
新增 `.cmake/arm_optimization.cmake` 文件,用于检测 ARM 架构并应用相应编译优化。
包括 NEON 指令集支持、ARM64 的 crypto 扩展检查、LTO 优化以及针对特定 CPU 的调优选项。
同时在 `CMakeLists.txt` 中包含该优化配置,并更新基准测试脚本中的构建目录路径。
2025-11-25 22:58:37 +08:00

63 lines
2.1 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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()