xref: /aosp_15_r20/external/libopus/celt/x86/pitch_sse.h (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1 /* Copyright (c) 2013 Jean-Marc Valin and John Ridges
2    Copyright (c) 2014, Cisco Systems, INC MingXiang WeiZhou MinPeng YanWang*/
3 /**
4    @file pitch_sse.h
5    @brief Pitch analysis
6  */
7 
8 /*
9    Redistribution and use in source and binary forms, with or without
10    modification, are permitted provided that the following conditions
11    are met:
12 
13    - Redistributions of source code must retain the above copyright
14    notice, this list of conditions and the following disclaimer.
15 
16    - Redistributions in binary form must reproduce the above copyright
17    notice, this list of conditions and the following disclaimer in the
18    documentation and/or other materials provided with the distribution.
19 
20    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
24    OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 
33 #ifndef PITCH_SSE_H
34 #define PITCH_SSE_H
35 
36 #if defined(HAVE_CONFIG_H)
37 #include "config.h"
38 #endif
39 
40 #if defined(OPUS_X86_MAY_HAVE_SSE4_1) && defined(FIXED_POINT)
41 void xcorr_kernel_sse4_1(
42                     const opus_int16 *x,
43                     const opus_int16 *y,
44                     opus_val32       sum[4],
45                     int              len);
46 #endif
47 
48 #if defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT)
49 void xcorr_kernel_sse(
50                     const opus_val16 *x,
51                     const opus_val16 *y,
52                     opus_val32       sum[4],
53                     int              len);
54 #endif
55 
56 #if defined(OPUS_X86_PRESUME_SSE4_1) && defined(FIXED_POINT)
57 #define OVERRIDE_XCORR_KERNEL
58 #define xcorr_kernel(x, y, sum, len, arch) \
59     ((void)arch, xcorr_kernel_sse4_1(x, y, sum, len))
60 
61 #elif defined(OPUS_X86_PRESUME_SSE) && !defined(FIXED_POINT)
62 #define OVERRIDE_XCORR_KERNEL
63 #define xcorr_kernel(x, y, sum, len, arch) \
64     ((void)arch, xcorr_kernel_sse(x, y, sum, len))
65 
66 #elif defined(OPUS_HAVE_RTCD) &&  ((defined(OPUS_X86_MAY_HAVE_SSE4_1) && defined(FIXED_POINT)) || (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT)))
67 
68 extern void (*const XCORR_KERNEL_IMPL[OPUS_ARCHMASK + 1])(
69                     const opus_val16 *x,
70                     const opus_val16 *y,
71                     opus_val32       sum[4],
72                     int              len);
73 
74 #define OVERRIDE_XCORR_KERNEL
75 #define xcorr_kernel(x, y, sum, len, arch) \
76     ((*XCORR_KERNEL_IMPL[(arch) & OPUS_ARCHMASK])(x, y, sum, len))
77 
78 #endif
79 
80 #if defined(OPUS_X86_MAY_HAVE_SSE4_1) && defined(FIXED_POINT)
81 opus_val32 celt_inner_prod_sse4_1(
82     const opus_int16 *x,
83     const opus_int16 *y,
84     int               N);
85 #endif
86 
87 #if defined(OPUS_X86_MAY_HAVE_SSE2) && defined(FIXED_POINT)
88 opus_val32 celt_inner_prod_sse2(
89     const opus_int16 *x,
90     const opus_int16 *y,
91     int               N);
92 #endif
93 
94 #if defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT)
95 opus_val32 celt_inner_prod_sse(
96     const opus_val16 *x,
97     const opus_val16 *y,
98     int               N);
99 #endif
100 
101 
102 #if defined(OPUS_X86_PRESUME_SSE4_1) && defined(FIXED_POINT)
103 #define OVERRIDE_CELT_INNER_PROD
104 #define celt_inner_prod(x, y, N, arch) \
105     ((void)arch, celt_inner_prod_sse4_1(x, y, N))
106 
107 #elif defined(OPUS_X86_PRESUME_SSE2) && defined(FIXED_POINT) && !defined(OPUS_X86_MAY_HAVE_SSE4_1)
108 #define OVERRIDE_CELT_INNER_PROD
109 #define celt_inner_prod(x, y, N, arch) \
110     ((void)arch, celt_inner_prod_sse2(x, y, N))
111 
112 #elif defined(OPUS_X86_PRESUME_SSE) && !defined(FIXED_POINT)
113 #define OVERRIDE_CELT_INNER_PROD
114 #define celt_inner_prod(x, y, N, arch) \
115     ((void)arch, celt_inner_prod_sse(x, y, N))
116 
117 
118 #elif defined(OPUS_HAVE_RTCD) && (((defined(OPUS_X86_MAY_HAVE_SSE4_1) || defined(OPUS_X86_MAY_HAVE_SSE2)) && defined(FIXED_POINT)) || \
119     (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT)))
120 
121 extern opus_val32 (*const CELT_INNER_PROD_IMPL[OPUS_ARCHMASK + 1])(
122                     const opus_val16 *x,
123                     const opus_val16 *y,
124                     int               N);
125 
126 #define OVERRIDE_CELT_INNER_PROD
127 #define celt_inner_prod(x, y, N, arch) \
128     ((*CELT_INNER_PROD_IMPL[(arch) & OPUS_ARCHMASK])(x, y, N))
129 
130 #endif
131 
132 #if defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT)
133 
134 void dual_inner_prod_sse(const opus_val16 *x,
135     const opus_val16 *y01,
136     const opus_val16 *y02,
137     int               N,
138     opus_val32       *xy1,
139     opus_val32       *xy2);
140 
141 void comb_filter_const_sse(opus_val32 *y,
142     opus_val32 *x,
143     int         T,
144     int         N,
145     opus_val16  g10,
146     opus_val16  g11,
147     opus_val16  g12);
148 
149 
150 #if defined(OPUS_X86_PRESUME_SSE)
151 #define OVERRIDE_DUAL_INNER_PROD
152 #define OVERRIDE_COMB_FILTER_CONST
153 # define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) \
154     ((void)(arch),dual_inner_prod_sse(x, y01, y02, N, xy1, xy2))
155 
156 # define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
157     ((void)(arch),comb_filter_const_sse(y, x, T, N, g10, g11, g12))
158 #elif defined(OPUS_HAVE_RTCD)
159 
160 #define OVERRIDE_DUAL_INNER_PROD
161 #define OVERRIDE_COMB_FILTER_CONST
162 extern void (*const DUAL_INNER_PROD_IMPL[OPUS_ARCHMASK + 1])(
163               const opus_val16 *x,
164               const opus_val16 *y01,
165               const opus_val16 *y02,
166               int               N,
167               opus_val32       *xy1,
168               opus_val32       *xy2);
169 
170 #define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) \
171     ((*DUAL_INNER_PROD_IMPL[(arch) & OPUS_ARCHMASK])(x, y01, y02, N, xy1, xy2))
172 
173 extern void (*const COMB_FILTER_CONST_IMPL[OPUS_ARCHMASK + 1])(
174               opus_val32 *y,
175               opus_val32 *x,
176               int         T,
177               int         N,
178               opus_val16  g10,
179               opus_val16  g11,
180               opus_val16  g12);
181 
182 #define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
183     ((*COMB_FILTER_CONST_IMPL[(arch) & OPUS_ARCHMASK])(y, x, T, N, g10, g11, g12))
184 
185 #define NON_STATIC_COMB_FILTER_CONST_C
186 
187 #endif
188 
189 void celt_pitch_xcorr_avx2(const float *_x, const float *_y, float *xcorr, int len, int max_pitch, int arch);
190 
191 #if defined(OPUS_X86_PRESUME_AVX2)
192 
193 #define OVERRIDE_PITCH_XCORR
194 # define celt_pitch_xcorr celt_pitch_xcorr_avx2
195 
196 #elif defined(OPUS_HAVE_RTCD) && defined(OPUS_X86_MAY_HAVE_AVX2)
197 
198 #define OVERRIDE_PITCH_XCORR
199 extern void (*const PITCH_XCORR_IMPL[OPUS_ARCHMASK + 1])(
200               const float *_x,
201               const float *_y,
202               float *xcorr,
203               int len,
204               int max_pitch,
205               int arch
206               );
207 
208 #define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \
209     ((*PITCH_XCORR_IMPL[(arch) & OPUS_ARCHMASK])(_x, _y, xcorr, len, max_pitch, arch))
210 
211 
212 #endif /* OPUS_X86_PRESUME_AVX2 && !OPUS_HAVE_RTCD */
213 
214 #endif /* OPUS_X86_MAY_HAVE_SSE && !FIXED_POINT */
215 
216 #endif
217