Skip to content

Commit 4f5c1f0

Browse files
committed
CMake: check _mm256_setr_m128i is supported
Some older AVX2 compilers don't have it, but it's possible to use a macro instead [^1]. [^1]: https://stackoverflow.com/a/32630658/1266123 Signed-off-by: Steve Lhomme <robux4@ycbcr.xyz>
1 parent 2cc3d6e commit 4f5c1f0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ elseif(UNIX OR MINGW)
120120
endif()
121121
if(HAS_AVX2)
122122
set_property(SOURCE ${AVX} APPEND PROPERTY COMPILE_FLAGS "-mavx2")
123+
# check _mm256_setr_m128i is supported
124+
include(CheckCSourceCompiles)
125+
include(CMakePushCheckState)
126+
127+
cmake_push_check_state(RESET)
128+
set(CMAKE_REQUIRED_FLAGS "-mavx2")
129+
check_c_source_compiles("
130+
#include <immintrin.h>
131+
int main(void)
132+
{
133+
__m128i a, b;
134+
_mm256_setr_m128i(a, b);
135+
return 0;
136+
}
137+
" HAVE_MM256_SETR)
138+
cmake_pop_check_state()
139+
if(HAVE_MM256_SETR)
140+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_MM256_SETR")
141+
endif(HAVE_MM256_SETR)
123142
endif()
124143
endif()
125144

src/avx/oapv_tq_avx.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
#include "oapv_def.h"
3333
#include "oapv_tq_avx.h"
3434

35+
#ifndef HAVE_MM256_SETR
36+
#define _mm256_set_m128i(v0, v1) _mm256_insertf128_si256(_mm256_castsi128_si256(v1), (v0), 1)
37+
#define _mm256_setr_m128i(v0, v1) _mm256_set_m128i((v1), (v0))
38+
#endif
39+
40+
3541
#if X86_SSE
3642
#ifndef _mm256_set_m128i
3743
#define _mm256_set_m128i(/* __m128i */ hi, /* __m128i */ lo) \

0 commit comments

Comments
 (0)