Skip to content

Commit 21d57a4

Browse files
committed
Check for __builtin_cpu_supports("ssse3") in make-only builds
Prevents failures on older compilers that don't have this builtin, or don't support using it to test for ssse3.
1 parent 64defab commit 21d57a4

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,12 @@ config.h:
334334
echo '#if defined __x86_64__ || defined __arm__ || defined __aarch64__' >> $@
335335
echo '#define HAVE_ATTRIBUTE_CONSTRUCTOR 1' >> $@
336336
echo '#endif' >> $@
337-
echo '#if (defined(__x86_64__) || defined(_M_X64))' >> $@
338-
echo '#define HAVE_ATTRIBUTE_TARGET_SSSE3 1' >> $@
339-
echo '#define HAVE_BUILTIN_CPU_SUPPORT_SSSE3 1' >> $@
340-
echo '#endif' >> $@
337+
if [ "x$(HTS_HAVE_SSSE3_BUILTINS)" != "x" ]; then \
338+
echo '#if (defined(__x86_64__) || defined(_M_X64))' >> $@ ; \
339+
echo '#define HAVE_ATTRIBUTE_TARGET_SSSE3 1' >> $@ ; \
340+
echo '#define HAVE_BUILTIN_CPU_SUPPORT_SSSE3 1' >> $@ ; \
341+
echo '#endif' >> $@ ; \
342+
fi
341343
echo '#if defined __linux__' >> $@
342344
echo '#define HAVE_GETAUXVAL' >> $@
343345
echo '#elif defined __FreeBSD__' >> $@

hts_probe_cc.sh

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ run_test ()
6060
rm -f conftest conftest.err conftest.c
6161
cat - > conftest.c
6262
if run_compiler ; then
63-
echo "$2 ="
63+
if test "x$2" != x ; then
64+
echo "$2 ="
65+
fi
6466
echo "$3 = 1"
65-
elif run_compiler "$1" ; then
67+
elif test "x$1" != x && run_compiler "$1" ; then
6668
echo "$2 = $1"
6769
echo "$3 = 1"
6870
else
@@ -140,4 +142,29 @@ int main(int argc, char **argv) { return 0; }
140142
#endif
141143
EOF
142144

145+
# Check for __builtin_cpu_supports("ssse3") and __attribute__((target("ssse3")))
146+
147+
run_test '' '' HTS_HAVE_SSSE3_BUILTINS <<'EOF'
148+
#ifdef __x86_64__
149+
#include "x86intrin.h"
150+
__attribute__((target("ssse3")))
151+
static void shuffle(char *aptr, char *bptr) {
152+
if (__builtin_cpu_supports("ssse3")) {
153+
__m128i a = _mm_lddqu_si128((__m128i *)aptr);
154+
__m128i b = _mm_shuffle_epi8(a, a);
155+
_mm_storeu_si128((__m128i *)bptr, b);
156+
}
157+
}
158+
159+
int main(int argc, char **argv) {
160+
char in[sizeof(__m128i)] = { 0 }, out[sizeof(__m128i)] = { 0 };
161+
in[0] = argv[0][0];
162+
shuffle(in, out);
163+
return out[0];
164+
}
165+
#else
166+
int main(int argc, char **argv) { return 0; }
167+
#endif
168+
EOF
169+
143170
rm -f conftest.c

0 commit comments

Comments
 (0)