Skip to content

Commit e7d4e82

Browse files
Timothy B. Terriberryjmvalin
authored andcommitted
Fix _mm_loadu_si32 detection for vendored Clang.
Apple uses different __clang_major__ version numbers than upstream, so our test did not work. This caused compilation failures with, e.g., XCode 10.1, which reports __clang_major__ as 10 despite being forked from upstream's 7.0 branch. Fixes #2369 Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>
1 parent 556c2d4 commit e7d4e82

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

celt/x86/x86cpu.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,22 @@ int opus_select_arch(void);
6868
Use this to work around those restrictions (which should hopefully all get
6969
optimized to a single MOVD instruction).
7070
GCC implemented _mm_loadu_si32() since GCC 11; HOWEVER, there is a bug!
71-
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99754 */
72-
# if !defined(_MSC_VER) && !OPUS_GNUC_PREREQ(11,3) && !(defined(__clang__) && (__clang_major__ >= 8))
71+
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99754
72+
LLVM implemented _mm_loadu_si32() since Clang 8.0, however the
73+
__clang_major__ version number macro is unreliable, as vendors
74+
(specifically, Apple) will use different numbering schemes than upstream.
75+
Clang's advice is "use feature detection", but they do not provide feature
76+
detection support for specific SIMD functions.
77+
We follow the approach from the SIMDe project and instead detect unrelated
78+
features that should be available in the version we want (see
79+
<https://github.com/simd-everywhere/simde/blob/master/simde/simde-detect-clang.h>).*/
80+
# if defined(__clang__)
81+
# if __has_warning("-Wextra-semi-stmt") || \
82+
__has_builtin(__builtin_rotateleft32)
83+
# define OPUS_CLANG_8 (1)
84+
# endif
85+
# endif
86+
# if !defined(_MSC_VER) && !OPUS_GNUC_PREREQ(11,3) && !defined(OPUS_CLANG_8)
7387
# include <string.h>
7488
# include <emmintrin.h>
7589

0 commit comments

Comments
 (0)