1 /* Copyright (c) 2014, Cisco Systems, INC
2 Written by XiangMingZhu WeiZhou MinPeng YanWang
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #if !defined(X86CPU_H)
29 # define X86CPU_H
30
31 # if defined(OPUS_X86_MAY_HAVE_SSE)
32 # define MAY_HAVE_SSE(name) name ## _sse
33 # else
34 # define MAY_HAVE_SSE(name) name ## _c
35 # endif
36
37 # if defined(OPUS_X86_MAY_HAVE_SSE2)
38 # define MAY_HAVE_SSE2(name) name ## _sse2
39 # else
40 # define MAY_HAVE_SSE2(name) name ## _c
41 # endif
42
43 # if defined(OPUS_X86_MAY_HAVE_SSE4_1)
44 # define MAY_HAVE_SSE4_1(name) name ## _sse4_1
45 # else
46 # define MAY_HAVE_SSE4_1(name) name ## _c
47 # endif
48
49 # if defined(OPUS_X86_MAY_HAVE_AVX2)
50 # define MAY_HAVE_AVX2(name) name ## _avx2
51 # else
52 # define MAY_HAVE_AVX2(name) name ## _c
53 # endif
54
55 # if defined(OPUS_HAVE_RTCD) && \
56 ((defined(OPUS_X86_MAY_HAVE_SSE) && !defined(OPUS_X86_PRESUME_SSE)) || \
57 (defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(OPUS_X86_PRESUME_SSE2)) || \
58 (defined(OPUS_X86_MAY_HAVE_SSE4_1) && !defined(OPUS_X86_PRESUME_SSE4_1)) || \
59 (defined(OPUS_X86_MAY_HAVE_AVX2) && !defined(OPUS_X86_PRESUME_AVX2)))
60 int opus_select_arch(void);
61 # endif
62
63 # if defined(OPUS_X86_MAY_HAVE_SSE2)
64 # include "opus_defines.h"
65
66 /*MOVD should not impose any alignment restrictions, but the C standard does,
67 and UBSan will report errors if we actually make unaligned accesses.
68 Use this to work around those restrictions (which should hopefully all get
69 optimized to a single MOVD instruction).
70 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))
73 # include <string.h>
74 # include <emmintrin.h>
75
76 # ifdef _mm_loadu_si32
77 # undef _mm_loadu_si32
78 # endif
79 # define _mm_loadu_si32 WORKAROUND_mm_loadu_si32
WORKAROUND_mm_loadu_si32(void const * mem_addr)80 static inline __m128i WORKAROUND_mm_loadu_si32(void const* mem_addr) {
81 int val;
82 memcpy(&val, mem_addr, sizeof(val));
83 return _mm_cvtsi32_si128(val);
84 }
85 # elif defined(_MSC_VER)
86 /* MSVC needs this for _mm_loadu_si32 */
87 # include <immintrin.h>
88 # endif
89
90 # define OP_CVTEPI8_EPI32_M32(x) \
91 (_mm_cvtepi8_epi32(_mm_loadu_si32(x)))
92
93 # define OP_CVTEPI16_EPI32_M64(x) \
94 (_mm_cvtepi16_epi32(_mm_loadl_epi64((__m128i *)(void*)(x))))
95
96 # endif
97
98 #endif
99