From 0df01bcf8d112e953422ede2149462f0260d380c Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 2 Oct 2024 15:13:06 +0200 Subject: [PATCH] [cmake] Allow disabling AVX2 extensions --- cmake/ConfigOptions.cmake | 2 ++ include/config/config.h.in | 1 + libfreerdp/primitives/CMakeLists.txt | 9 +++++++-- libfreerdp/primitives/prim_copy.c | 2 ++ libfreerdp/primitives/prim_copy.h | 3 +++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 396c1da39..c4b4e4dd9 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -23,6 +23,8 @@ option(WITH_PROFILER "Compile profiler." OFF) option(WITH_GPROF "Compile with GProf profiler." OFF) option(WITH_SSE2 "Enable SSE2 optimization." OFF) +cmake_dependent_option(WITH_AVX2 "Compile AVX2 optimizations" ON "WITH_SSE2" OFF) + option(WITH_NEON "Enable NEON optimization." OFF) option(WITH_JPEG "Use JPEG decoding." OFF) diff --git a/include/config/config.h.in b/include/config/config.h.in index a0a73f32d..5da29b8e8 100644 --- a/include/config/config.h.in +++ b/include/config/config.h.in @@ -22,6 +22,7 @@ #cmakedefine WITH_PROFILER #cmakedefine WITH_GPROF #cmakedefine WITH_SSE2 +#cmakedefine WITH_AVX2 #cmakedefine WITH_NEON #cmakedefine WITH_CUPS #cmakedefine WITH_JPEG diff --git a/libfreerdp/primitives/CMakeLists.txt b/libfreerdp/primitives/CMakeLists.txt index f85974858..38a8dcc15 100644 --- a/libfreerdp/primitives/CMakeLists.txt +++ b/libfreerdp/primitives/CMakeLists.txt @@ -87,9 +87,14 @@ set(PRIMITIVES_OPT_SRCS ${PRIMITIVES_SSSE3_SRCS} ${PRIMITIVES_SSE4_1_SRCS} ${PRIMITIVES_SSE4_2_SRCS} - ${PRIMITIVES_AVX2_SRCS} ${PRIMITIVES_OPENCL_SRCS}) +if (WITH_AVX2) + list(APPEND PRIMITIVES_OPT_SRCS + ${PRIMITIVES_AVX2_SRCS} + ) +endif() + set(PRIMITIVES_SRCS ${PRIMITIVES_SRCS} ${PRIMITIVES_OPT_SRCS}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -117,7 +122,7 @@ if(WITH_SSE2) if (PRIMITIVES_SSE4_2_SRCS) set_source_files_properties(${PRIMITIVES_SSE4_2_SRCS} PROPERTIES COMPILE_FLAGS "-msse4.2" ) endif() - if (PRIMITIVES_AVX2_SRCS) + if (PRIMITIVES_AVX2_SRCS AND WITH_AVX2) set_source_files_properties(${PRIMITIVES_AVX2_SRCS} PROPERTIES COMPILE_FLAGS "-mavx2" ) endif() endif() diff --git a/libfreerdp/primitives/prim_copy.c b/libfreerdp/primitives/prim_copy.c index 4c33615e2..99b40b5b8 100644 --- a/libfreerdp/primitives/prim_copy.c +++ b/libfreerdp/primitives/prim_copy.c @@ -382,5 +382,7 @@ void primitives_init_copy(primitives_t* WINPR_RESTRICT prims) void primitives_init_copy_opt(primitives_t* prims) { primitives_init_copy_sse41(prims); +#if defined(WITH_AVX2) primitives_init_copy_avx2(prims); +#endif } diff --git a/libfreerdp/primitives/prim_copy.h b/libfreerdp/primitives/prim_copy.h index ace7f925f..8275adc9d 100644 --- a/libfreerdp/primitives/prim_copy.h +++ b/libfreerdp/primitives/prim_copy.h @@ -39,6 +39,9 @@ pstatus_t generic_image_copy_no_overlap_memcpy( UINT32 flags); void primitives_init_copy_sse41(primitives_t* prims); + +#if defined(WITH_AVX2) void primitives_init_copy_avx2(primitives_t* prims); +#endif #endif