2022-06-15 21:16:51 +08:00
|
|
|
## astc-encoder CMakeLists.txt: auto detect SIMD Intrinsics
|
2020-11-16 14:47:43 +08:00
|
|
|
set(lib_name astc)
|
|
|
|
set(target_name ${lib_name})
|
|
|
|
|
|
|
|
project(${lib_name})
|
|
|
|
|
2022-12-17 11:56:48 +08:00
|
|
|
# include(CheckIncludeFile)
|
|
|
|
# include(CheckCCompilerFlag)
|
|
|
|
# include(CheckCSourceCompiles)
|
|
|
|
# include(CheckCXXSourceCompiles)
|
2021-06-01 23:43:28 +08:00
|
|
|
|
2023-03-11 22:10:18 +08:00
|
|
|
include(AXPlatform)
|
2022-06-16 12:22:39 +08:00
|
|
|
|
2020-11-16 14:47:43 +08:00
|
|
|
set(${target_name}_src
|
2021-06-01 23:43:28 +08:00
|
|
|
astcenc_averages_and_directions.cpp
|
|
|
|
astcenc_block_sizes.cpp
|
|
|
|
astcenc_color_quantize.cpp
|
|
|
|
astcenc_color_unquantize.cpp
|
|
|
|
astcenc_compress_symbolic.cpp
|
|
|
|
astcenc_compute_variance.cpp
|
|
|
|
astcenc_decompress_symbolic.cpp
|
|
|
|
astcenc_diagnostic_trace.cpp
|
|
|
|
astcenc_entry.cpp
|
|
|
|
astcenc_find_best_partitioning.cpp
|
|
|
|
astcenc_ideal_endpoints_and_weights.cpp
|
|
|
|
astcenc_image.cpp
|
|
|
|
astcenc_integer_sequence.cpp
|
|
|
|
astcenc_mathlib.cpp
|
|
|
|
astcenc_mathlib_softfloat.cpp
|
|
|
|
astcenc_partition_tables.cpp
|
|
|
|
astcenc_percentile_tables.cpp
|
|
|
|
astcenc_pick_best_endpoint_format.cpp
|
|
|
|
astcenc_platform_isa_detection.cpp
|
|
|
|
astcenc_quantization.cpp
|
|
|
|
astcenc_symbolic_physical.cpp
|
|
|
|
astcenc_weight_align.cpp
|
|
|
|
astcenc_weight_quant_xfer_tables.cpp
|
2020-11-16 14:47:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
add_library(${target_name} STATIC
|
|
|
|
${${target_name}_src}
|
|
|
|
)
|
|
|
|
|
2021-07-02 00:18:02 +08:00
|
|
|
# target_compile_definitions(${target_name}
|
|
|
|
# PUBLIC ASTCENC_DECOMPRESS_ONLY)
|
2022-12-17 11:56:48 +08:00
|
|
|
if (NOT DEFINED ASTC_ISA_SIMD)
|
2022-09-05 14:13:52 +08:00
|
|
|
if (NOT (ARCH_ALIAS STREQUAL "x86") AND NOT TVOS)
|
2022-12-17 11:56:48 +08:00
|
|
|
set(ASTC_HAVE_AVX2_INTRINSICS ${AX_HAVE_AVX2_INTRINSICS})
|
|
|
|
set(ASTC_HAVE_SSE42_INTRINSICS ${AX_HAVE_SSE42_INTRINSICS})
|
|
|
|
set(ASTC_HAVE_SSE41_INTRINSICS ${AX_HAVE_SSE41_INTRINSICS})
|
2022-12-17 14:31:23 +08:00
|
|
|
if (AX_HAVE_NEON_INTRINSICS)
|
|
|
|
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
|
|
|
|
check_cxx_source_compiles("#include <arm_neon.h>
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int32x4_t ret4 = vdupq_n_s32(0);
|
|
|
|
uint32x4_t v{};
|
|
|
|
float16x4_t f16 = vcvt_f16_f32(v);
|
|
|
|
return vgetq_lane_s32(ret4, 0);
|
|
|
|
}" ASTC_HAVE_NEON_INTRINSICS)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
|
|
|
|
unset(OLD_REQUIRED_FLAGS)
|
|
|
|
endif()
|
2022-06-16 12:22:39 +08:00
|
|
|
else()
|
2022-12-17 11:56:48 +08:00
|
|
|
set(ASTC_HAVE_SSE2_INTRINSICS ${AX_HAVE_SSE2_INTRINSICS})
|
|
|
|
message(AUTHOR_WARNING "Skipping AVX2/SSE4/NEON detection for astc-encoder when build target 'x86' and 'tvos'")
|
2022-06-16 12:22:39 +08:00
|
|
|
endif()
|
2021-06-06 16:15:26 +08:00
|
|
|
|
2022-12-17 11:56:48 +08:00
|
|
|
### set ASTC_ISA_SIMD
|
2022-06-15 21:16:51 +08:00
|
|
|
if(ASTC_HAVE_AVX2_INTRINSICS)
|
2022-12-17 11:56:48 +08:00
|
|
|
set(ASTC_ISA_SIMD "avx2")
|
2022-06-15 21:16:51 +08:00
|
|
|
elseif(ASTC_HAVE_SSE42_INTRINSICS)
|
2022-12-17 11:56:48 +08:00
|
|
|
set(ASTC_ISA_SIMD "sse4.2")
|
2022-06-15 21:16:51 +08:00
|
|
|
elseif(ASTC_HAVE_SSE41_INTRINSICS)
|
2022-12-17 11:56:48 +08:00
|
|
|
set(ASTC_ISA_SIMD "sse4.1")
|
2022-06-15 21:16:51 +08:00
|
|
|
elseif(ASTC_HAVE_SSE2_INTRINSICS)
|
2022-12-17 11:56:48 +08:00
|
|
|
set(ASTC_ISA_SIMD "sse2")
|
2021-06-05 12:18:15 +08:00
|
|
|
elseif(ASTC_HAVE_NEON_INTRINSICS)
|
2022-12-17 11:56:48 +08:00
|
|
|
set(ASTC_ISA_SIMD "neon")
|
2021-06-05 12:18:15 +08:00
|
|
|
else()
|
2022-12-17 11:56:48 +08:00
|
|
|
set(ASTC_ISA_SIMD "none")
|
2022-09-05 14:13:52 +08:00
|
|
|
endif()
|
2021-06-05 12:18:15 +08:00
|
|
|
|
2022-12-17 11:56:48 +08:00
|
|
|
message(AUTHOR_WARNING "ASTC_ISA_SIMD=${ASTC_ISA_SIMD}")
|
2021-06-01 23:43:28 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Set up configuration for SIMD ISA builds
|
2022-12-17 11:56:48 +08:00
|
|
|
if(${ASTC_ISA_SIMD} MATCHES "none")
|
2021-06-01 23:43:28 +08:00
|
|
|
target_compile_definitions(${target_name}
|
2021-06-05 12:18:15 +08:00
|
|
|
PUBLIC
|
2021-06-01 23:43:28 +08:00
|
|
|
ASTCENC_NEON=0
|
|
|
|
ASTCENC_SSE=0
|
|
|
|
ASTCENC_AVX=0
|
|
|
|
ASTCENC_POPCNT=0
|
|
|
|
ASTCENC_F16C=0)
|
2022-12-17 11:56:48 +08:00
|
|
|
elseif(${ASTC_ISA_SIMD} MATCHES "neon")
|
2021-06-01 23:43:28 +08:00
|
|
|
target_compile_definitions(${target_name}
|
2021-06-05 12:18:15 +08:00
|
|
|
PUBLIC
|
2021-06-01 23:43:28 +08:00
|
|
|
ASTCENC_NEON=1
|
|
|
|
ASTCENC_SSE=0
|
|
|
|
ASTCENC_AVX=0
|
|
|
|
ASTCENC_POPCNT=0
|
|
|
|
ASTCENC_F16C=0)
|
2022-12-17 11:56:48 +08:00
|
|
|
elseif(${ASTC_ISA_SIMD} MATCHES "avx2")
|
2022-06-15 21:16:51 +08:00
|
|
|
target_compile_definitions(${target_name}
|
|
|
|
PUBLIC
|
|
|
|
ASTCENC_NEON=0
|
|
|
|
ASTCENC_SSE=42
|
|
|
|
ASTCENC_AVX=2
|
|
|
|
ASTCENC_POPCNT=1
|
|
|
|
ASTCENC_F16C=1)
|
2021-06-01 23:43:28 +08:00
|
|
|
|
2022-06-15 21:16:51 +08:00
|
|
|
target_compile_options(${target_name}
|
|
|
|
PRIVATE
|
|
|
|
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-mavx2 -mpopcnt -mf16c>
|
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/arch:AVX2>)
|
2022-12-17 11:56:48 +08:00
|
|
|
elseif(${ASTC_ISA_SIMD} MATCHES "sse4.2")
|
2021-06-01 23:43:28 +08:00
|
|
|
target_compile_definitions(${target_name}
|
2021-06-05 12:18:15 +08:00
|
|
|
PUBLIC
|
2021-06-01 23:43:28 +08:00
|
|
|
ASTCENC_NEON=0
|
2022-06-15 21:16:51 +08:00
|
|
|
ASTCENC_SSE=42
|
2021-06-01 23:43:28 +08:00
|
|
|
ASTCENC_AVX=0
|
2022-06-15 21:16:51 +08:00
|
|
|
ASTCENC_POPCNT=1
|
2021-06-01 23:43:28 +08:00
|
|
|
ASTCENC_F16C=0)
|
|
|
|
|
2022-06-15 21:16:51 +08:00
|
|
|
target_compile_options(${target_name}
|
|
|
|
PRIVATE
|
|
|
|
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse4.2 -mpopcnt>)
|
2022-12-17 11:56:48 +08:00
|
|
|
elseif(${ASTC_ISA_SIMD} MATCHES "sse4.1")
|
2021-06-01 23:43:28 +08:00
|
|
|
target_compile_definitions(${target_name}
|
2021-06-05 12:18:15 +08:00
|
|
|
PUBLIC
|
2021-06-01 23:43:28 +08:00
|
|
|
ASTCENC_NEON=0
|
|
|
|
ASTCENC_SSE=41
|
|
|
|
ASTCENC_AVX=0
|
|
|
|
ASTCENC_POPCNT=1
|
|
|
|
ASTCENC_F16C=0)
|
|
|
|
|
|
|
|
target_compile_options(${target_name}
|
|
|
|
PRIVATE
|
|
|
|
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse4.1 -mpopcnt>)
|
2022-12-17 11:56:48 +08:00
|
|
|
elseif(${ASTC_ISA_SIMD} MATCHES "sse2")
|
2021-06-01 23:43:28 +08:00
|
|
|
target_compile_definitions(${target_name}
|
2021-06-05 12:18:15 +08:00
|
|
|
PUBLIC
|
2021-06-01 23:43:28 +08:00
|
|
|
ASTCENC_NEON=0
|
2022-06-15 21:16:51 +08:00
|
|
|
ASTCENC_SSE=20
|
|
|
|
ASTCENC_AVX=0
|
|
|
|
ASTCENC_POPCNT=0
|
|
|
|
ASTCENC_F16C=0)
|
2021-06-01 23:43:28 +08:00
|
|
|
endif()
|
|
|
|
|
2020-11-16 14:47:43 +08:00
|
|
|
target_include_directories(${target_name} PUBLIC ..)
|