mirror of
https://github.com/google/cpu_features.git
synced 2025-07-01 13:21:13 +02:00

committed by
GitHub

parent
d395dfa026
commit
20fa92a02a
@ -48,24 +48,24 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
|
|||||||
set(PROCESSOR_IS_POWER TRUE)
|
set(PROCESSOR_IS_POWER TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
macro(add_arch_sources HDRS_LIST_NAME SRCS_LIST_NAME)
|
macro(add_cpu_features_headers_and_sources HDRS_LIST_NAME SRCS_LIST_NAME)
|
||||||
list(APPEND ${HDRS_LIST_NAME} include/cpu_features_macros.h)
|
list(APPEND ${HDRS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/cpu_features_macros.h)
|
||||||
if(PROCESSOR_IS_MIPS)
|
if(PROCESSOR_IS_MIPS)
|
||||||
list(APPEND ${HDRS_LIST_NAME} include/cpuinfo_mips.h)
|
list(APPEND ${HDRS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/cpuinfo_mips.h)
|
||||||
list(APPEND ${SRCS_LIST_NAME} src/cpuinfo_mips.c)
|
list(APPEND ${SRCS_LIST_NAME} ${PROJECT_SOURCE_DIR}/src/cpuinfo_mips.c)
|
||||||
elseif(PROCESSOR_IS_ARM)
|
elseif(PROCESSOR_IS_ARM)
|
||||||
list(APPEND ${HDRS_LIST_NAME} include/cpuinfo_arm.h)
|
list(APPEND ${HDRS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/cpuinfo_arm.h)
|
||||||
list(APPEND ${SRCS_LIST_NAME} src/cpuinfo_arm.c)
|
list(APPEND ${SRCS_LIST_NAME} ${PROJECT_SOURCE_DIR}/src/cpuinfo_arm.c)
|
||||||
elseif(PROCESSOR_IS_AARCH64)
|
elseif(PROCESSOR_IS_AARCH64)
|
||||||
list(APPEND ${HDRS_LIST_NAME} include/cpuinfo_aarch64.h)
|
list(APPEND ${HDRS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/cpuinfo_aarch64.h)
|
||||||
list(APPEND ${SRCS_LIST_NAME} src/cpuinfo_aarch64.c)
|
list(APPEND ${SRCS_LIST_NAME} ${PROJECT_SOURCE_DIR}/src/cpuinfo_aarch64.c)
|
||||||
elseif(PROCESSOR_IS_X86)
|
elseif(PROCESSOR_IS_X86)
|
||||||
list(APPEND ${HDRS_LIST_NAME} include/cpuinfo_x86.h)
|
list(APPEND ${HDRS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/cpuinfo_x86.h)
|
||||||
list(APPEND ${HDRS_LIST_NAME} include/internal/cpuid_x86.h)
|
list(APPEND ${SRCS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/internal/cpuid_x86.h)
|
||||||
list(APPEND ${SRCS_LIST_NAME} src/cpuinfo_x86.c)
|
list(APPEND ${SRCS_LIST_NAME} ${PROJECT_SOURCE_DIR}/src/cpuinfo_x86.c)
|
||||||
elseif(PROCESSOR_IS_POWER)
|
elseif(PROCESSOR_IS_POWER)
|
||||||
list(APPEND ${HDRS_LIST_NAME} include/cpuinfo_ppc.h)
|
list(APPEND ${HDRS_LIST_NAME} ${PROJECT_SOURCE_DIR}/include/cpuinfo_ppc.h)
|
||||||
list(APPEND ${SRCS_LIST_NAME} src/cpuinfo_ppc.c)
|
list(APPEND ${SRCS_LIST_NAME} ${PROJECT_SOURCE_DIR}/src/cpuinfo_ppc.c)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Unsupported architectures ${CMAKE_SYSTEM_PROCESSOR}")
|
message(FATAL_ERROR "Unsupported architectures ${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
endif()
|
endif()
|
||||||
@ -76,13 +76,13 @@ endmacro()
|
|||||||
#
|
#
|
||||||
|
|
||||||
add_library(utils OBJECT
|
add_library(utils OBJECT
|
||||||
include/internal/bit_utils.h
|
${PROJECT_SOURCE_DIR}/include/internal/bit_utils.h
|
||||||
include/internal/filesystem.h
|
${PROJECT_SOURCE_DIR}/include/internal/filesystem.h
|
||||||
include/internal/stack_line_reader.h
|
${PROJECT_SOURCE_DIR}/include/internal/stack_line_reader.h
|
||||||
include/internal/string_view.h
|
${PROJECT_SOURCE_DIR}/include/internal/string_view.h
|
||||||
src/filesystem.c
|
${PROJECT_SOURCE_DIR}/src/filesystem.c
|
||||||
src/stack_line_reader.c
|
${PROJECT_SOURCE_DIR}/src/stack_line_reader.c
|
||||||
src/string_view.c
|
${PROJECT_SOURCE_DIR}/src/string_view.c
|
||||||
)
|
)
|
||||||
setup_include_and_definitions(utils)
|
setup_include_and_definitions(utils)
|
||||||
|
|
||||||
@ -92,10 +92,10 @@ setup_include_and_definitions(utils)
|
|||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
add_library(unix_based_hardware_detection OBJECT
|
add_library(unix_based_hardware_detection OBJECT
|
||||||
include/internal/hwcaps.h
|
${PROJECT_SOURCE_DIR}/include/internal/hwcaps.h
|
||||||
include/internal/unix_features_aggregator.h
|
${PROJECT_SOURCE_DIR}/include/internal/unix_features_aggregator.h
|
||||||
src/hwcaps.c
|
${PROJECT_SOURCE_DIR}/src/hwcaps.c
|
||||||
src/unix_features_aggregator.c
|
${PROJECT_SOURCE_DIR}/src/unix_features_aggregator.c
|
||||||
)
|
)
|
||||||
setup_include_and_definitions(unix_based_hardware_detection)
|
setup_include_and_definitions(unix_based_hardware_detection)
|
||||||
check_include_file(dlfcn.h HAVE_DLFCN_H)
|
check_include_file(dlfcn.h HAVE_DLFCN_H)
|
||||||
@ -113,48 +113,33 @@ endif()
|
|||||||
#
|
#
|
||||||
set (CPU_FEATURES_HDRS)
|
set (CPU_FEATURES_HDRS)
|
||||||
set (CPU_FEATURES_SRCS)
|
set (CPU_FEATURES_SRCS)
|
||||||
add_arch_sources(CPU_FEATURES_HDRS CPU_FEATURES_SRCS)
|
add_cpu_features_headers_and_sources(CPU_FEATURES_HDRS CPU_FEATURES_SRCS)
|
||||||
list(APPEND CPU_FEATURES_SRCS $<TARGET_OBJECTS:utils>)
|
list(APPEND CPU_FEATURES_SRCS $<TARGET_OBJECTS:utils>)
|
||||||
if(NOT PROCESSOR_IS_X86 AND UNIX)
|
if(NOT PROCESSOR_IS_X86 AND UNIX)
|
||||||
list(APPEND CPU_FEATURES_SRCS $<TARGET_OBJECTS:unix_based_hardware_detection>)
|
list(APPEND CPU_FEATURES_SRCS $<TARGET_OBJECTS:unix_based_hardware_detection>)
|
||||||
endif()
|
endif()
|
||||||
add_library(cpu_features ${CPU_FEATURES_HDRS} ${CPU_FEATURES_SRCS})
|
add_library(cpu_features ${CPU_FEATURES_HDRS} ${CPU_FEATURES_SRCS})
|
||||||
|
set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${CPU_FEATURES_HDRS}")
|
||||||
setup_include_and_definitions(cpu_features)
|
setup_include_and_definitions(cpu_features)
|
||||||
target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS})
|
target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS})
|
||||||
target_include_directories(cpu_features
|
target_include_directories(cpu_features
|
||||||
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cpu_features>
|
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cpu_features>
|
||||||
)
|
)
|
||||||
|
|
||||||
#
|
#
|
||||||
# program : list_cpu_features
|
# program : list_cpu_features
|
||||||
#
|
#
|
||||||
|
|
||||||
add_executable(list_cpu_features src/utils/list_cpu_features.c)
|
add_executable(list_cpu_features ${PROJECT_SOURCE_DIR}/src/utils/list_cpu_features.c)
|
||||||
target_link_libraries(list_cpu_features PRIVATE cpu_features)
|
target_link_libraries(list_cpu_features PRIVATE cpu_features)
|
||||||
add_executable(CpuFeature::list_cpu_features ALIAS list_cpu_features)
|
add_executable(CpuFeature::list_cpu_features ALIAS list_cpu_features)
|
||||||
|
|
||||||
#
|
#
|
||||||
# library : NDK compat
|
# ndk_compat
|
||||||
#
|
#
|
||||||
if(ANDROID)
|
|
||||||
find_package(Threads)
|
|
||||||
set (NDK_COMPAT_HDRS ndk_compat/cpu-features.h)
|
|
||||||
set (NDK_COMPAT_SRCS
|
|
||||||
ndk_compat/cpu-features.c
|
|
||||||
$<TARGET_OBJECTS:utils>
|
|
||||||
$<TARGET_OBJECTS:unix_based_hardware_detection>
|
|
||||||
)
|
|
||||||
add_arch_sources(NDK_COMPAT_HDRS NDK_COMPAT_SRCS)
|
|
||||||
add_library(ndk_compat ${NDK_COMPAT_HDRS} ${NDK_COMPAT_SRCS})
|
|
||||||
setup_include_and_definitions(ndk_compat)
|
|
||||||
target_link_libraries(ndk_compat PUBLIC ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
#
|
if(ANDROID)
|
||||||
# program : NDK compat test program
|
add_subdirectory(ndk_compat)
|
||||||
#
|
|
||||||
if(ANDROID AND ENABLE_TESTING)
|
|
||||||
add_executable(ndk-compat-test ndk_compat/ndk-compat-test.c)
|
|
||||||
target_link_libraries(ndk-compat-test PRIVATE ndk_compat)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -205,7 +190,7 @@ if(BUILD_TESTING)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Install
|
# Install cpu_features and list_cpu_features
|
||||||
#
|
#
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
@ -234,8 +219,8 @@ write_basic_package_version_file(
|
|||||||
)
|
)
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
"${PROJECT_BINARY_DIR}/CpuFeaturesConfig.cmake"
|
"${PROJECT_BINARY_DIR}/CpuFeaturesConfig.cmake"
|
||||||
"${PROJECT_BINARY_DIR}/CpuFeaturesConfigVersion.cmake"
|
"${PROJECT_BINARY_DIR}/CpuFeaturesConfigVersion.cmake"
|
||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeatures"
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeatures"
|
||||||
COMPONENT Devel
|
COMPONENT Devel
|
||||||
)
|
)
|
||||||
|
11
README.md
11
README.md
@ -9,6 +9,7 @@ instructions) at runtime.
|
|||||||
- [Code samples](#codesample)
|
- [Code samples](#codesample)
|
||||||
- [Running sample code](#usagesample)
|
- [Running sample code](#usagesample)
|
||||||
- [What's supported](#support)
|
- [What's supported](#support)
|
||||||
|
- [Android NDK's drop in replacement](#ndk)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
- [Build with cmake](#cmake)
|
- [Build with cmake](#cmake)
|
||||||
|
|
||||||
@ -132,7 +133,7 @@ flags : aes,avx,cx16,smx,sse4_1,sse4_2,ssse3
|
|||||||
<a name="support"></a>
|
<a name="support"></a>
|
||||||
## What's supported
|
## What's supported
|
||||||
|
|
||||||
| | x86³ | ARM | AArch64 | MIPSel | POWER |
|
| | x86³ | ARM | AArch64 | MIPS⁴ | POWER |
|
||||||
|---------|:----:|:-------:|:-------:|:------:|:-------:|
|
|---------|:----:|:-------:|:-------:|:------:|:-------:|
|
||||||
| Android | yes² | yes¹ | yes¹ | yes¹ | N/A |
|
| Android | yes² | yes¹ | yes¹ | yes¹ | N/A |
|
||||||
| iOS | N/A | not yet | not yet | N/A | N/A |
|
| iOS | N/A | not yet | not yet | N/A | N/A |
|
||||||
@ -151,7 +152,15 @@ flags : aes,avx,cx16,smx,sse4_1,sse4_2,ssse3
|
|||||||
3. **Microarchitecture detection.** On x86 some features are not always
|
3. **Microarchitecture detection.** On x86 some features are not always
|
||||||
implemented efficiently in hardware (e.g. AVX on Sandybridge). Exposing the
|
implemented efficiently in hardware (e.g. AVX on Sandybridge). Exposing the
|
||||||
microarchitecture allows the client to reject particular microarchitectures.
|
microarchitecture allows the client to reject particular microarchitectures.
|
||||||
|
4. All flavors of Mips are supported, little and big endian as well as 32/64
|
||||||
|
bits.
|
||||||
|
|
||||||
|
<a name="ndk"></a>
|
||||||
|
## Android NDK's drop in replacement
|
||||||
|
|
||||||
|
[cpu_features](https://github.com/google/cpu_features) is now officially
|
||||||
|
supporting Android and offers a drop in replacement of for the NDK's [cpu-features.h](https://android.googlesource.com/platform/ndk/+/master/sources/android/cpufeatures/cpu-features.h)
|
||||||
|
, see [ndk_compat](ndk_compat) folder for details.
|
||||||
|
|
||||||
<a name="license"></a>
|
<a name="license"></a>
|
||||||
## License
|
## License
|
||||||
|
3
cmake/CpuFeaturesNdkCompatConfig.cmake.in
Normal file
3
cmake/CpuFeaturesNdkCompatConfig.cmake.in
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# CpuFeaturesNdkCompat CMake configuration file
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/CpuFeaturesNdkCompatTargets.cmake")
|
59
ndk_compat/CMakeLists.txt
Normal file
59
ndk_compat/CMakeLists.txt
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
#
|
||||||
|
# library : NDK compat
|
||||||
|
#
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
set (NDK_COMPAT_HDRS cpu-features.h)
|
||||||
|
set (NDK_COMPAT_SRCS
|
||||||
|
cpu-features.c
|
||||||
|
$<TARGET_OBJECTS:utils>
|
||||||
|
$<TARGET_OBJECTS:unix_based_hardware_detection>
|
||||||
|
)
|
||||||
|
# Note that following `add_cpu_features_headers_and_sources` will use
|
||||||
|
# NDK_COMPAT_SRCS in lieu of NDK_COMPAT_HDRS because we don't want cpu_features
|
||||||
|
# headers to be installed alongside ndk_compat.
|
||||||
|
add_cpu_features_headers_and_sources(NDK_COMPAT_SRCS NDK_COMPAT_SRCS)
|
||||||
|
add_library(ndk_compat ${NDK_COMPAT_HDRS} ${NDK_COMPAT_SRCS})
|
||||||
|
setup_include_and_definitions(ndk_compat)
|
||||||
|
target_link_libraries(ndk_compat PUBLIC ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
set_target_properties(ndk_compat PROPERTIES PUBLIC_HEADER "${NDK_COMPAT_HDRS}")
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
install(TARGETS ndk_compat
|
||||||
|
EXPORT CpuFeaturesNdkCompatTargets
|
||||||
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ndk_compat
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
)
|
||||||
|
install(EXPORT CpuFeaturesNdkCompatTargets
|
||||||
|
NAMESPACE CpuFeatures::
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeaturesNdkCompat
|
||||||
|
COMPONENT Devel
|
||||||
|
)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/CpuFeaturesNdkCompatConfig.cmake.in
|
||||||
|
"${PROJECT_BINARY_DIR}/CpuFeaturesNdkCompatConfig.cmake"
|
||||||
|
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeaturesNdkCompat"
|
||||||
|
NO_SET_AND_CHECK_MACRO
|
||||||
|
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||||
|
)
|
||||||
|
write_basic_package_version_file(
|
||||||
|
"${PROJECT_BINARY_DIR}/CpuFeaturesNdkCompatConfigVersion.cmake"
|
||||||
|
COMPATIBILITY SameMajorVersion
|
||||||
|
)
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
"${PROJECT_BINARY_DIR}/CpuFeaturesNdkCompatConfig.cmake"
|
||||||
|
"${PROJECT_BINARY_DIR}/CpuFeaturesNdkCompatConfigVersion.cmake"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CpuFeaturesNdkCompat"
|
||||||
|
COMPONENT Devel
|
||||||
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# program : NDK compat test program
|
||||||
|
#
|
||||||
|
if(ENABLE_TESTING)
|
||||||
|
add_executable(ndk-compat-test ndk-compat-test.c)
|
||||||
|
target_link_libraries(ndk-compat-test PRIVATE ndk_compat)
|
||||||
|
endif()
|
@ -283,7 +283,9 @@ enum {
|
|||||||
ANDROID_CPU_MIPS_FEATURE_MSA = (1 << 1),
|
ANDROID_CPU_MIPS_FEATURE_MSA = (1 << 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Return the number of CPU cores detected on this device. */
|
/* Return the number of CPU cores detected on this device.
|
||||||
|
* Please note the current implementation supports up to 32 cpus.
|
||||||
|
*/
|
||||||
extern int android_getCpuCount(void);
|
extern int android_getCpuCount(void);
|
||||||
|
|
||||||
/* The following is used to force the CPU count and features
|
/* The following is used to force the CPU count and features
|
||||||
|
Reference in New Issue
Block a user