1/*
2 *  Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS. All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "libyuv/row.h"
12
13#include <string.h>  // For memset.
14
15#include "libyuv/basic_types.h"
16
17#ifdef __cplusplus
18namespace libyuv {
19extern "C" {
20#endif
21
22// memset for temp is meant to clear the source buffer (not dest) so that
23// SIMD that reads full multiple of 16 bytes will not trigger msan errors.
24// memset is not needed for production, as the garbage values are processed but
25// not used, although there may be edge cases for subsampling.
26// The size of the buffer is based on the largest read, which can be inferred
27// by the source type (e.g. ARGB) and the mask (last parameter), or by examining
28// the source code for how much the source pointers are advanced.
29
30// Subsampled source needs to be increase by 1 of not even.
31#define SS(width, shift) (((width) + (1 << (shift)) - 1) >> (shift))
32
33// Any 4 planes to 1 with yuvconstants
34#define ANY41C(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK)            \
35  void NAMEANY(const uint8* y_buf, const uint8* u_buf, const uint8* v_buf, \
36               const uint8* a_buf, uint8* dst_ptr,                         \
37               const struct YuvConstants* yuvconstants, int width) {       \
38    SIMD_ALIGNED(uint8 temp[64 * 5]);                                      \
39    memset(temp, 0, 64 * 4); /* for msan */                                \
40    int r = width & MASK;                                                  \
41    int n = width & ~MASK;                                                 \
42    if (n > 0) {                                                           \
43      ANY_SIMD(y_buf, u_buf, v_buf, a_buf, dst_ptr, yuvconstants, n);      \
44    }                                                                      \
45    memcpy(temp, y_buf + n, r);                                            \
46    memcpy(temp + 64, u_buf + (n >> UVSHIFT), SS(r, UVSHIFT));             \
47    memcpy(temp + 128, v_buf + (n >> UVSHIFT), SS(r, UVSHIFT));            \
48    memcpy(temp + 192, a_buf + n, r);                                      \
49    ANY_SIMD(temp, temp + 64, temp + 128, temp + 192, temp + 256,          \
50             yuvconstants, MASK + 1);                                      \
51    memcpy(dst_ptr + (n >> DUVSHIFT) * BPP, temp + 256,                    \
52           SS(r, DUVSHIFT) * BPP);                                         \
53  }
54
55#ifdef HAS_I422ALPHATOARGBROW_SSSE3
56ANY41C(I422AlphaToARGBRow_Any_SSSE3, I422AlphaToARGBRow_SSSE3, 1, 0, 4, 7)
57#endif
58#ifdef HAS_I422ALPHATOARGBROW_AVX2
59ANY41C(I422AlphaToARGBRow_Any_AVX2, I422AlphaToARGBRow_AVX2, 1, 0, 4, 15)
60#endif
61#ifdef HAS_I422ALPHATOARGBROW_NEON
62ANY41C(I422AlphaToARGBRow_Any_NEON, I422AlphaToARGBRow_NEON, 1, 0, 4, 7)
63#endif
64#ifdef HAS_I422ALPHATOARGBROW_MSA
65ANY41C(I422AlphaToARGBRow_Any_MSA, I422AlphaToARGBRow_MSA, 1, 0, 4, 7)
66#endif
67#undef ANY41C
68
69// Any 3 planes to 1.
70#define ANY31(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK)             \
71  void NAMEANY(const uint8* y_buf, const uint8* u_buf, const uint8* v_buf, \
72               uint8* dst_ptr, int width) {                                \
73    SIMD_ALIGNED(uint8 temp[64 * 4]);                                      \
74    memset(temp, 0, 64 * 3); /* for YUY2 and msan */                       \
75    int r = width & MASK;                                                  \
76    int n = width & ~MASK;                                                 \
77    if (n > 0) {                                                           \
78      ANY_SIMD(y_buf, u_buf, v_buf, dst_ptr, n);                           \
79    }                                                                      \
80    memcpy(temp, y_buf + n, r);                                            \
81    memcpy(temp + 64, u_buf + (n >> UVSHIFT), SS(r, UVSHIFT));             \
82    memcpy(temp + 128, v_buf + (n >> UVSHIFT), SS(r, UVSHIFT));            \
83    ANY_SIMD(temp, temp + 64, temp + 128, temp + 192, MASK + 1);           \
84    memcpy(dst_ptr + (n >> DUVSHIFT) * BPP, temp + 192,                    \
85           SS(r, DUVSHIFT) * BPP);                                         \
86  }
87#ifdef HAS_I422TOYUY2ROW_SSE2
88ANY31(I422ToYUY2Row_Any_SSE2, I422ToYUY2Row_SSE2, 1, 1, 4, 15)
89ANY31(I422ToUYVYRow_Any_SSE2, I422ToUYVYRow_SSE2, 1, 1, 4, 15)
90#endif
91#ifdef HAS_I422TOYUY2ROW_NEON
92ANY31(I422ToYUY2Row_Any_NEON, I422ToYUY2Row_NEON, 1, 1, 4, 15)
93#endif
94#ifdef HAS_I422TOYUY2ROW_MSA
95ANY31(I422ToYUY2Row_Any_MSA, I422ToYUY2Row_MSA, 1, 1, 4, 31)
96#endif
97#ifdef HAS_I422TOUYVYROW_NEON
98ANY31(I422ToUYVYRow_Any_NEON, I422ToUYVYRow_NEON, 1, 1, 4, 15)
99#endif
100#ifdef HAS_I422TOUYVYROW_MSA
101ANY31(I422ToUYVYRow_Any_MSA, I422ToUYVYRow_MSA, 1, 1, 4, 31)
102#endif
103#ifdef HAS_BLENDPLANEROW_AVX2
104ANY31(BlendPlaneRow_Any_AVX2, BlendPlaneRow_AVX2, 0, 0, 1, 31)
105#endif
106#ifdef HAS_BLENDPLANEROW_SSSE3
107ANY31(BlendPlaneRow_Any_SSSE3, BlendPlaneRow_SSSE3, 0, 0, 1, 7)
108#endif
109#undef ANY31
110
111// Note that odd width replication includes 444 due to implementation
112// on arm that subsamples 444 to 422 internally.
113// Any 3 planes to 1 with yuvconstants
114#define ANY31C(NAMEANY, ANY_SIMD, UVSHIFT, DUVSHIFT, BPP, MASK)                \
115  void NAMEANY(const uint8* y_buf, const uint8* u_buf, const uint8* v_buf,     \
116               uint8* dst_ptr, const struct YuvConstants* yuvconstants,        \
117               int width) {                                                    \
118    SIMD_ALIGNED(uint8 temp[64 * 4]);                                          \
119    memset(temp, 0, 64 * 3); /* for YUY2 and msan */                           \
120    int r = width & MASK;                                                      \
121    int n = width & ~MASK;                                                     \
122    if (n > 0) {                                                               \
123      ANY_SIMD(y_buf, u_buf, v_buf, dst_ptr, yuvconstants, n);                 \
124    }                                                                          \
125    memcpy(temp, y_buf + n, r);                                                \
126    memcpy(temp + 64, u_buf + (n >> UVSHIFT), SS(r, UVSHIFT));                 \
127    memcpy(temp + 128, v_buf + (n >> UVSHIFT), SS(r, UVSHIFT));                \
128    if (width & 1) {                                                           \
129      temp[64 + SS(r, UVSHIFT)] = temp[64 + SS(r, UVSHIFT) - 1];               \
130      temp[128 + SS(r, UVSHIFT)] = temp[128 + SS(r, UVSHIFT) - 1];             \
131    }                                                                          \
132    ANY_SIMD(temp, temp + 64, temp + 128, temp + 192, yuvconstants, MASK + 1); \
133    memcpy(dst_ptr + (n >> DUVSHIFT) * BPP, temp + 192,                        \
134           SS(r, DUVSHIFT) * BPP);                                             \
135  }
136
137#ifdef HAS_I422TOARGBROW_SSSE3
138ANY31C(I422ToARGBRow_Any_SSSE3, I422ToARGBRow_SSSE3, 1, 0, 4, 7)
139#endif
140#ifdef HAS_I444TOARGBROW_SSSE3
141ANY31C(I444ToARGBRow_Any_SSSE3, I444ToARGBRow_SSSE3, 0, 0, 4, 7)
142ANY31C(I422ToRGBARow_Any_SSSE3, I422ToRGBARow_SSSE3, 1, 0, 4, 7)
143ANY31C(I422ToARGB4444Row_Any_SSSE3, I422ToARGB4444Row_SSSE3, 1, 0, 2, 7)
144ANY31C(I422ToARGB1555Row_Any_SSSE3, I422ToARGB1555Row_SSSE3, 1, 0, 2, 7)
145ANY31C(I422ToRGB565Row_Any_SSSE3, I422ToRGB565Row_SSSE3, 1, 0, 2, 7)
146ANY31C(I422ToRGB24Row_Any_SSSE3, I422ToRGB24Row_SSSE3, 1, 0, 3, 7)
147#endif  // HAS_I444TOARGBROW_SSSE3
148#ifdef HAS_I422TORGB24ROW_AVX2
149ANY31C(I422ToRGB24Row_Any_AVX2, I422ToRGB24Row_AVX2, 1, 0, 3, 15)
150#endif
151#ifdef HAS_I422TOARGBROW_AVX2
152ANY31C(I422ToARGBRow_Any_AVX2, I422ToARGBRow_AVX2, 1, 0, 4, 15)
153#endif
154#ifdef HAS_I422TORGBAROW_AVX2
155ANY31C(I422ToRGBARow_Any_AVX2, I422ToRGBARow_AVX2, 1, 0, 4, 15)
156#endif
157#ifdef HAS_I444TOARGBROW_AVX2
158ANY31C(I444ToARGBRow_Any_AVX2, I444ToARGBRow_AVX2, 0, 0, 4, 15)
159#endif
160#ifdef HAS_I422TOARGB4444ROW_AVX2
161ANY31C(I422ToARGB4444Row_Any_AVX2, I422ToARGB4444Row_AVX2, 1, 0, 2, 15)
162#endif
163#ifdef HAS_I422TOARGB1555ROW_AVX2
164ANY31C(I422ToARGB1555Row_Any_AVX2, I422ToARGB1555Row_AVX2, 1, 0, 2, 15)
165#endif
166#ifdef HAS_I422TORGB565ROW_AVX2
167ANY31C(I422ToRGB565Row_Any_AVX2, I422ToRGB565Row_AVX2, 1, 0, 2, 15)
168#endif
169#ifdef HAS_I422TOARGBROW_NEON
170ANY31C(I444ToARGBRow_Any_NEON, I444ToARGBRow_NEON, 0, 0, 4, 7)
171ANY31C(I422ToARGBRow_Any_NEON, I422ToARGBRow_NEON, 1, 0, 4, 7)
172ANY31C(I422ToRGBARow_Any_NEON, I422ToRGBARow_NEON, 1, 0, 4, 7)
173ANY31C(I422ToRGB24Row_Any_NEON, I422ToRGB24Row_NEON, 1, 0, 3, 7)
174ANY31C(I422ToARGB4444Row_Any_NEON, I422ToARGB4444Row_NEON, 1, 0, 2, 7)
175ANY31C(I422ToARGB1555Row_Any_NEON, I422ToARGB1555Row_NEON, 1, 0, 2, 7)
176ANY31C(I422ToRGB565Row_Any_NEON, I422ToRGB565Row_NEON, 1, 0, 2, 7)
177#endif
178#ifdef HAS_I422TOARGBROW_DSPR2
179ANY31C(I444ToARGBRow_Any_DSPR2, I444ToARGBRow_DSPR2, 0, 0, 4, 7)
180ANY31C(I422ToARGBRow_Any_DSPR2, I422ToARGBRow_DSPR2, 1, 0, 4, 7)
181ANY31C(I422ToARGB4444Row_Any_DSPR2, I422ToARGB4444Row_DSPR2, 1, 0, 2, 7)
182ANY31C(I422ToARGB1555Row_Any_DSPR2, I422ToARGB1555Row_DSPR2, 1, 0, 2, 7)
183#endif
184#ifdef HAS_I422TOARGBROW_MSA
185ANY31C(I444ToARGBRow_Any_MSA, I444ToARGBRow_MSA, 0, 0, 4, 7)
186ANY31C(I422ToARGBRow_Any_MSA, I422ToARGBRow_MSA, 1, 0, 4, 7)
187ANY31C(I422ToRGBARow_Any_MSA, I422ToRGBARow_MSA, 1, 0, 4, 7)
188ANY31C(I422ToRGB24Row_Any_MSA, I422ToRGB24Row_MSA, 1, 0, 3, 15)
189ANY31C(I422ToARGB4444Row_Any_MSA, I422ToARGB4444Row_MSA, 1, 0, 2, 7)
190ANY31C(I422ToARGB1555Row_Any_MSA, I422ToARGB1555Row_MSA, 1, 0, 2, 7)
191ANY31C(I422ToRGB565Row_Any_MSA, I422ToRGB565Row_MSA, 1, 0, 2, 7)
192#endif
193#undef ANY31C
194
195// Any 2 planes to 1.
196#define ANY21(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, SBPP2, BPP, MASK)       \
197  void NAMEANY(const uint8* y_buf, const uint8* uv_buf, uint8* dst_ptr, \
198               int width) {                                             \
199    SIMD_ALIGNED(uint8 temp[64 * 3]);                                   \
200    memset(temp, 0, 64 * 2); /* for msan */                             \
201    int r = width & MASK;                                               \
202    int n = width & ~MASK;                                              \
203    if (n > 0) {                                                        \
204      ANY_SIMD(y_buf, uv_buf, dst_ptr, n);                              \
205    }                                                                   \
206    memcpy(temp, y_buf + n * SBPP, r * SBPP);                           \
207    memcpy(temp + 64, uv_buf + (n >> UVSHIFT) * SBPP2,                  \
208           SS(r, UVSHIFT) * SBPP2);                                     \
209    ANY_SIMD(temp, temp + 64, temp + 128, MASK + 1);                    \
210    memcpy(dst_ptr + n * BPP, temp + 128, r * BPP);                     \
211  }
212
213// Merge functions.
214#ifdef HAS_MERGEUVROW_SSE2
215ANY21(MergeUVRow_Any_SSE2, MergeUVRow_SSE2, 0, 1, 1, 2, 15)
216#endif
217#ifdef HAS_MERGEUVROW_AVX2
218ANY21(MergeUVRow_Any_AVX2, MergeUVRow_AVX2, 0, 1, 1, 2, 31)
219#endif
220#ifdef HAS_MERGEUVROW_NEON
221ANY21(MergeUVRow_Any_NEON, MergeUVRow_NEON, 0, 1, 1, 2, 15)
222#endif
223#ifdef HAS_MERGEUVROW_MSA
224ANY21(MergeUVRow_Any_MSA, MergeUVRow_MSA, 0, 1, 1, 2, 15)
225#endif
226
227// Math functions.
228#ifdef HAS_ARGBMULTIPLYROW_SSE2
229ANY21(ARGBMultiplyRow_Any_SSE2, ARGBMultiplyRow_SSE2, 0, 4, 4, 4, 3)
230#endif
231#ifdef HAS_ARGBADDROW_SSE2
232ANY21(ARGBAddRow_Any_SSE2, ARGBAddRow_SSE2, 0, 4, 4, 4, 3)
233#endif
234#ifdef HAS_ARGBSUBTRACTROW_SSE2
235ANY21(ARGBSubtractRow_Any_SSE2, ARGBSubtractRow_SSE2, 0, 4, 4, 4, 3)
236#endif
237#ifdef HAS_ARGBMULTIPLYROW_AVX2
238ANY21(ARGBMultiplyRow_Any_AVX2, ARGBMultiplyRow_AVX2, 0, 4, 4, 4, 7)
239#endif
240#ifdef HAS_ARGBADDROW_AVX2
241ANY21(ARGBAddRow_Any_AVX2, ARGBAddRow_AVX2, 0, 4, 4, 4, 7)
242#endif
243#ifdef HAS_ARGBSUBTRACTROW_AVX2
244ANY21(ARGBSubtractRow_Any_AVX2, ARGBSubtractRow_AVX2, 0, 4, 4, 4, 7)
245#endif
246#ifdef HAS_ARGBMULTIPLYROW_NEON
247ANY21(ARGBMultiplyRow_Any_NEON, ARGBMultiplyRow_NEON, 0, 4, 4, 4, 7)
248#endif
249#ifdef HAS_ARGBADDROW_NEON
250ANY21(ARGBAddRow_Any_NEON, ARGBAddRow_NEON, 0, 4, 4, 4, 7)
251#endif
252#ifdef HAS_ARGBSUBTRACTROW_NEON
253ANY21(ARGBSubtractRow_Any_NEON, ARGBSubtractRow_NEON, 0, 4, 4, 4, 7)
254#endif
255#ifdef HAS_ARGBMULTIPLYROW_MSA
256ANY21(ARGBMultiplyRow_Any_MSA, ARGBMultiplyRow_MSA, 0, 4, 4, 4, 3)
257#endif
258#ifdef HAS_ARGBADDROW_MSA
259ANY21(ARGBAddRow_Any_MSA, ARGBAddRow_MSA, 0, 4, 4, 4, 7)
260#endif
261#ifdef HAS_ARGBSUBTRACTROW_MSA
262ANY21(ARGBSubtractRow_Any_MSA, ARGBSubtractRow_MSA, 0, 4, 4, 4, 7)
263#endif
264#ifdef HAS_SOBELROW_SSE2
265ANY21(SobelRow_Any_SSE2, SobelRow_SSE2, 0, 1, 1, 4, 15)
266#endif
267#ifdef HAS_SOBELROW_NEON
268ANY21(SobelRow_Any_NEON, SobelRow_NEON, 0, 1, 1, 4, 7)
269#endif
270#ifdef HAS_SOBELROW_MSA
271ANY21(SobelRow_Any_MSA, SobelRow_MSA, 0, 1, 1, 4, 15)
272#endif
273#ifdef HAS_SOBELTOPLANEROW_SSE2
274ANY21(SobelToPlaneRow_Any_SSE2, SobelToPlaneRow_SSE2, 0, 1, 1, 1, 15)
275#endif
276#ifdef HAS_SOBELTOPLANEROW_NEON
277ANY21(SobelToPlaneRow_Any_NEON, SobelToPlaneRow_NEON, 0, 1, 1, 1, 15)
278#endif
279#ifdef HAS_SOBELTOPLANEROW_MSA
280ANY21(SobelToPlaneRow_Any_MSA, SobelToPlaneRow_MSA, 0, 1, 1, 1, 31)
281#endif
282#ifdef HAS_SOBELXYROW_SSE2
283ANY21(SobelXYRow_Any_SSE2, SobelXYRow_SSE2, 0, 1, 1, 4, 15)
284#endif
285#ifdef HAS_SOBELXYROW_NEON
286ANY21(SobelXYRow_Any_NEON, SobelXYRow_NEON, 0, 1, 1, 4, 7)
287#endif
288#ifdef HAS_SOBELXYROW_MSA
289ANY21(SobelXYRow_Any_MSA, SobelXYRow_MSA, 0, 1, 1, 4, 15)
290#endif
291#undef ANY21
292
293// Any 2 planes to 1 with yuvconstants
294#define ANY21C(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, SBPP2, BPP, MASK)      \
295  void NAMEANY(const uint8* y_buf, const uint8* uv_buf, uint8* dst_ptr, \
296               const struct YuvConstants* yuvconstants, int width) {    \
297    SIMD_ALIGNED(uint8 temp[64 * 3]);                                   \
298    memset(temp, 0, 64 * 2); /* for msan */                             \
299    int r = width & MASK;                                               \
300    int n = width & ~MASK;                                              \
301    if (n > 0) {                                                        \
302      ANY_SIMD(y_buf, uv_buf, dst_ptr, yuvconstants, n);                \
303    }                                                                   \
304    memcpy(temp, y_buf + n * SBPP, r * SBPP);                           \
305    memcpy(temp + 64, uv_buf + (n >> UVSHIFT) * SBPP2,                  \
306           SS(r, UVSHIFT) * SBPP2);                                     \
307    ANY_SIMD(temp, temp + 64, temp + 128, yuvconstants, MASK + 1);      \
308    memcpy(dst_ptr + n * BPP, temp + 128, r * BPP);                     \
309  }
310
311// Biplanar to RGB.
312#ifdef HAS_NV12TOARGBROW_SSSE3
313ANY21C(NV12ToARGBRow_Any_SSSE3, NV12ToARGBRow_SSSE3, 1, 1, 2, 4, 7)
314#endif
315#ifdef HAS_NV12TOARGBROW_AVX2
316ANY21C(NV12ToARGBRow_Any_AVX2, NV12ToARGBRow_AVX2, 1, 1, 2, 4, 15)
317#endif
318#ifdef HAS_NV12TOARGBROW_NEON
319ANY21C(NV12ToARGBRow_Any_NEON, NV12ToARGBRow_NEON, 1, 1, 2, 4, 7)
320#endif
321#ifdef HAS_NV12TOARGBROW_DSPR2
322ANY21C(NV12ToARGBRow_Any_DSPR2, NV12ToARGBRow_DSPR2, 1, 1, 2, 4, 7)
323#endif
324#ifdef HAS_NV12TOARGBROW_MSA
325ANY21C(NV12ToARGBRow_Any_MSA, NV12ToARGBRow_MSA, 1, 1, 2, 4, 7)
326#endif
327#ifdef HAS_NV21TOARGBROW_SSSE3
328ANY21C(NV21ToARGBRow_Any_SSSE3, NV21ToARGBRow_SSSE3, 1, 1, 2, 4, 7)
329#endif
330#ifdef HAS_NV21TOARGBROW_AVX2
331ANY21C(NV21ToARGBRow_Any_AVX2, NV21ToARGBRow_AVX2, 1, 1, 2, 4, 15)
332#endif
333#ifdef HAS_NV21TOARGBROW_NEON
334ANY21C(NV21ToARGBRow_Any_NEON, NV21ToARGBRow_NEON, 1, 1, 2, 4, 7)
335#endif
336#ifdef HAS_NV21TOARGBROW_MSA
337ANY21C(NV21ToARGBRow_Any_MSA, NV21ToARGBRow_MSA, 1, 1, 2, 4, 7)
338#endif
339#ifdef HAS_NV12TORGB565ROW_SSSE3
340ANY21C(NV12ToRGB565Row_Any_SSSE3, NV12ToRGB565Row_SSSE3, 1, 1, 2, 2, 7)
341#endif
342#ifdef HAS_NV12TORGB565ROW_AVX2
343ANY21C(NV12ToRGB565Row_Any_AVX2, NV12ToRGB565Row_AVX2, 1, 1, 2, 2, 15)
344#endif
345#ifdef HAS_NV12TORGB565ROW_NEON
346ANY21C(NV12ToRGB565Row_Any_NEON, NV12ToRGB565Row_NEON, 1, 1, 2, 2, 7)
347#endif
348#ifdef HAS_NV12TORGB565ROW_MSA
349ANY21C(NV12ToRGB565Row_Any_MSA, NV12ToRGB565Row_MSA, 1, 1, 2, 2, 7)
350#endif
351#undef ANY21C
352
353// Any 1 to 1.
354#define ANY11(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK)                \
355  void NAMEANY(const uint8* src_ptr, uint8* dst_ptr, int width) {         \
356    SIMD_ALIGNED(uint8 temp[128 * 2]);                                    \
357    memset(temp, 0, 128); /* for YUY2 and msan */                         \
358    int r = width & MASK;                                                 \
359    int n = width & ~MASK;                                                \
360    if (n > 0) {                                                          \
361      ANY_SIMD(src_ptr, dst_ptr, n);                                      \
362    }                                                                     \
363    memcpy(temp, src_ptr + (n >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \
364    ANY_SIMD(temp, temp + 128, MASK + 1);                                 \
365    memcpy(dst_ptr + n * BPP, temp + 128, r * BPP);                       \
366  }
367
368#ifdef HAS_COPYROW_AVX
369ANY11(CopyRow_Any_AVX, CopyRow_AVX, 0, 1, 1, 63)
370#endif
371#ifdef HAS_COPYROW_SSE2
372ANY11(CopyRow_Any_SSE2, CopyRow_SSE2, 0, 1, 1, 31)
373#endif
374#ifdef HAS_COPYROW_NEON
375ANY11(CopyRow_Any_NEON, CopyRow_NEON, 0, 1, 1, 31)
376#endif
377#if defined(HAS_ARGBTORGB24ROW_SSSE3)
378ANY11(ARGBToRGB24Row_Any_SSSE3, ARGBToRGB24Row_SSSE3, 0, 4, 3, 15)
379ANY11(ARGBToRAWRow_Any_SSSE3, ARGBToRAWRow_SSSE3, 0, 4, 3, 15)
380ANY11(ARGBToRGB565Row_Any_SSE2, ARGBToRGB565Row_SSE2, 0, 4, 2, 3)
381ANY11(ARGBToARGB1555Row_Any_SSE2, ARGBToARGB1555Row_SSE2, 0, 4, 2, 3)
382ANY11(ARGBToARGB4444Row_Any_SSE2, ARGBToARGB4444Row_SSE2, 0, 4, 2, 3)
383#endif
384#if defined(HAS_ARGBTORGB565ROW_AVX2)
385ANY11(ARGBToRGB565Row_Any_AVX2, ARGBToRGB565Row_AVX2, 0, 4, 2, 7)
386#endif
387#if defined(HAS_ARGBTOARGB4444ROW_AVX2)
388ANY11(ARGBToARGB1555Row_Any_AVX2, ARGBToARGB1555Row_AVX2, 0, 4, 2, 7)
389ANY11(ARGBToARGB4444Row_Any_AVX2, ARGBToARGB4444Row_AVX2, 0, 4, 2, 7)
390#endif
391#if defined(HAS_J400TOARGBROW_SSE2)
392ANY11(J400ToARGBRow_Any_SSE2, J400ToARGBRow_SSE2, 0, 1, 4, 7)
393#endif
394#if defined(HAS_J400TOARGBROW_AVX2)
395ANY11(J400ToARGBRow_Any_AVX2, J400ToARGBRow_AVX2, 0, 1, 4, 15)
396#endif
397#if defined(HAS_I400TOARGBROW_SSE2)
398ANY11(I400ToARGBRow_Any_SSE2, I400ToARGBRow_SSE2, 0, 1, 4, 7)
399#endif
400#if defined(HAS_I400TOARGBROW_AVX2)
401ANY11(I400ToARGBRow_Any_AVX2, I400ToARGBRow_AVX2, 0, 1, 4, 15)
402#endif
403#if defined(HAS_RGB24TOARGBROW_SSSE3)
404ANY11(RGB24ToARGBRow_Any_SSSE3, RGB24ToARGBRow_SSSE3, 0, 3, 4, 15)
405ANY11(RAWToARGBRow_Any_SSSE3, RAWToARGBRow_SSSE3, 0, 3, 4, 15)
406ANY11(RGB565ToARGBRow_Any_SSE2, RGB565ToARGBRow_SSE2, 0, 2, 4, 7)
407ANY11(ARGB1555ToARGBRow_Any_SSE2, ARGB1555ToARGBRow_SSE2, 0, 2, 4, 7)
408ANY11(ARGB4444ToARGBRow_Any_SSE2, ARGB4444ToARGBRow_SSE2, 0, 2, 4, 7)
409#endif
410#if defined(HAS_RAWTORGB24ROW_SSSE3)
411ANY11(RAWToRGB24Row_Any_SSSE3, RAWToRGB24Row_SSSE3, 0, 3, 3, 7)
412#endif
413#if defined(HAS_RGB565TOARGBROW_AVX2)
414ANY11(RGB565ToARGBRow_Any_AVX2, RGB565ToARGBRow_AVX2, 0, 2, 4, 15)
415#endif
416#if defined(HAS_ARGB1555TOARGBROW_AVX2)
417ANY11(ARGB1555ToARGBRow_Any_AVX2, ARGB1555ToARGBRow_AVX2, 0, 2, 4, 15)
418#endif
419#if defined(HAS_ARGB4444TOARGBROW_AVX2)
420ANY11(ARGB4444ToARGBRow_Any_AVX2, ARGB4444ToARGBRow_AVX2, 0, 2, 4, 15)
421#endif
422#if defined(HAS_ARGBTORGB24ROW_NEON)
423ANY11(ARGBToRGB24Row_Any_NEON, ARGBToRGB24Row_NEON, 0, 4, 3, 7)
424ANY11(ARGBToRAWRow_Any_NEON, ARGBToRAWRow_NEON, 0, 4, 3, 7)
425ANY11(ARGBToRGB565Row_Any_NEON, ARGBToRGB565Row_NEON, 0, 4, 2, 7)
426ANY11(ARGBToARGB1555Row_Any_NEON, ARGBToARGB1555Row_NEON, 0, 4, 2, 7)
427ANY11(ARGBToARGB4444Row_Any_NEON, ARGBToARGB4444Row_NEON, 0, 4, 2, 7)
428ANY11(J400ToARGBRow_Any_NEON, J400ToARGBRow_NEON, 0, 1, 4, 7)
429ANY11(I400ToARGBRow_Any_NEON, I400ToARGBRow_NEON, 0, 1, 4, 7)
430#endif
431#if defined(HAS_ARGBTORGB24ROW_MSA)
432ANY11(ARGBToRGB24Row_Any_MSA, ARGBToRGB24Row_MSA, 0, 4, 3, 15)
433ANY11(ARGBToRAWRow_Any_MSA, ARGBToRAWRow_MSA, 0, 4, 3, 15)
434ANY11(ARGBToRGB565Row_Any_MSA, ARGBToRGB565Row_MSA, 0, 4, 2, 7)
435ANY11(ARGBToARGB1555Row_Any_MSA, ARGBToARGB1555Row_MSA, 0, 4, 2, 7)
436ANY11(ARGBToARGB4444Row_Any_MSA, ARGBToARGB4444Row_MSA, 0, 4, 2, 7)
437ANY11(J400ToARGBRow_Any_MSA, J400ToARGBRow_MSA, 0, 1, 4, 15)
438ANY11(I400ToARGBRow_Any_MSA, I400ToARGBRow_MSA, 0, 1, 4, 15)
439#endif
440#if defined(HAS_RAWTORGB24ROW_NEON)
441ANY11(RAWToRGB24Row_Any_NEON, RAWToRGB24Row_NEON, 0, 3, 3, 7)
442#endif
443#if defined(HAS_RAWTORGB24ROW_MSA)
444ANY11(RAWToRGB24Row_Any_MSA, RAWToRGB24Row_MSA, 0, 3, 3, 15)
445#endif
446#ifdef HAS_ARGBTOYROW_AVX2
447ANY11(ARGBToYRow_Any_AVX2, ARGBToYRow_AVX2, 0, 4, 1, 31)
448#endif
449#ifdef HAS_ARGBTOYJROW_AVX2
450ANY11(ARGBToYJRow_Any_AVX2, ARGBToYJRow_AVX2, 0, 4, 1, 31)
451#endif
452#ifdef HAS_UYVYTOYROW_AVX2
453ANY11(UYVYToYRow_Any_AVX2, UYVYToYRow_AVX2, 0, 2, 1, 31)
454#endif
455#ifdef HAS_YUY2TOYROW_AVX2
456ANY11(YUY2ToYRow_Any_AVX2, YUY2ToYRow_AVX2, 1, 4, 1, 31)
457#endif
458#ifdef HAS_ARGBTOYROW_SSSE3
459ANY11(ARGBToYRow_Any_SSSE3, ARGBToYRow_SSSE3, 0, 4, 1, 15)
460#endif
461#ifdef HAS_BGRATOYROW_SSSE3
462ANY11(BGRAToYRow_Any_SSSE3, BGRAToYRow_SSSE3, 0, 4, 1, 15)
463ANY11(ABGRToYRow_Any_SSSE3, ABGRToYRow_SSSE3, 0, 4, 1, 15)
464ANY11(RGBAToYRow_Any_SSSE3, RGBAToYRow_SSSE3, 0, 4, 1, 15)
465ANY11(YUY2ToYRow_Any_SSE2, YUY2ToYRow_SSE2, 1, 4, 1, 15)
466ANY11(UYVYToYRow_Any_SSE2, UYVYToYRow_SSE2, 1, 4, 1, 15)
467#endif
468#ifdef HAS_ARGBTOYJROW_SSSE3
469ANY11(ARGBToYJRow_Any_SSSE3, ARGBToYJRow_SSSE3, 0, 4, 1, 15)
470#endif
471#ifdef HAS_ARGBTOYROW_NEON
472ANY11(ARGBToYRow_Any_NEON, ARGBToYRow_NEON, 0, 4, 1, 7)
473#endif
474#ifdef HAS_ARGBTOYROW_MSA
475ANY11(ARGBToYRow_Any_MSA, ARGBToYRow_MSA, 0, 4, 1, 15)
476#endif
477#ifdef HAS_ARGBTOYJROW_NEON
478ANY11(ARGBToYJRow_Any_NEON, ARGBToYJRow_NEON, 0, 4, 1, 7)
479#endif
480#ifdef HAS_ARGBTOYJROW_MSA
481ANY11(ARGBToYJRow_Any_MSA, ARGBToYJRow_MSA, 0, 4, 1, 15)
482#endif
483#ifdef HAS_BGRATOYROW_NEON
484ANY11(BGRAToYRow_Any_NEON, BGRAToYRow_NEON, 0, 4, 1, 7)
485#endif
486#ifdef HAS_BGRATOYROW_MSA
487ANY11(BGRAToYRow_Any_MSA, BGRAToYRow_MSA, 0, 4, 1, 15)
488#endif
489#ifdef HAS_ABGRTOYROW_NEON
490ANY11(ABGRToYRow_Any_NEON, ABGRToYRow_NEON, 0, 4, 1, 7)
491#endif
492#ifdef HAS_ABGRTOYROW_MSA
493ANY11(ABGRToYRow_Any_MSA, ABGRToYRow_MSA, 0, 4, 1, 7)
494#endif
495#ifdef HAS_RGBATOYROW_NEON
496ANY11(RGBAToYRow_Any_NEON, RGBAToYRow_NEON, 0, 4, 1, 7)
497#endif
498#ifdef HAS_RGBATOYROW_MSA
499ANY11(RGBAToYRow_Any_MSA, RGBAToYRow_MSA, 0, 4, 1, 15)
500#endif
501#ifdef HAS_RGB24TOYROW_NEON
502ANY11(RGB24ToYRow_Any_NEON, RGB24ToYRow_NEON, 0, 3, 1, 7)
503#endif
504#ifdef HAS_RGB24TOYROW_MSA
505ANY11(RGB24ToYRow_Any_MSA, RGB24ToYRow_MSA, 0, 3, 1, 15)
506#endif
507#ifdef HAS_RAWTOYROW_NEON
508ANY11(RAWToYRow_Any_NEON, RAWToYRow_NEON, 0, 3, 1, 7)
509#endif
510#ifdef HAS_RAWTOYROW_MSA
511ANY11(RAWToYRow_Any_MSA, RAWToYRow_MSA, 0, 3, 1, 15)
512#endif
513#ifdef HAS_RGB565TOYROW_NEON
514ANY11(RGB565ToYRow_Any_NEON, RGB565ToYRow_NEON, 0, 2, 1, 7)
515#endif
516#ifdef HAS_RGB565TOYROW_MSA
517ANY11(RGB565ToYRow_Any_MSA, RGB565ToYRow_MSA, 0, 2, 1, 15)
518#endif
519#ifdef HAS_ARGB1555TOYROW_NEON
520ANY11(ARGB1555ToYRow_Any_NEON, ARGB1555ToYRow_NEON, 0, 2, 1, 7)
521#endif
522#ifdef HAS_ARGB1555TOYROW_MSA
523ANY11(ARGB1555ToYRow_Any_MSA, ARGB1555ToYRow_MSA, 0, 2, 1, 15)
524#endif
525#ifdef HAS_ARGB4444TOYROW_NEON
526ANY11(ARGB4444ToYRow_Any_NEON, ARGB4444ToYRow_NEON, 0, 2, 1, 7)
527#endif
528#ifdef HAS_YUY2TOYROW_NEON
529ANY11(YUY2ToYRow_Any_NEON, YUY2ToYRow_NEON, 1, 4, 1, 15)
530#endif
531#ifdef HAS_UYVYTOYROW_NEON
532ANY11(UYVYToYRow_Any_NEON, UYVYToYRow_NEON, 1, 4, 1, 15)
533#endif
534#ifdef HAS_YUY2TOYROW_MSA
535ANY11(YUY2ToYRow_Any_MSA, YUY2ToYRow_MSA, 1, 4, 1, 31)
536#endif
537#ifdef HAS_UYVYTOYROW_MSA
538ANY11(UYVYToYRow_Any_MSA, UYVYToYRow_MSA, 1, 4, 1, 31)
539#endif
540#ifdef HAS_RGB24TOARGBROW_NEON
541ANY11(RGB24ToARGBRow_Any_NEON, RGB24ToARGBRow_NEON, 0, 3, 4, 7)
542#endif
543#ifdef HAS_RGB24TOARGBROW_MSA
544ANY11(RGB24ToARGBRow_Any_MSA, RGB24ToARGBRow_MSA, 0, 3, 4, 15)
545#endif
546#ifdef HAS_RAWTOARGBROW_NEON
547ANY11(RAWToARGBRow_Any_NEON, RAWToARGBRow_NEON, 0, 3, 4, 7)
548#endif
549#ifdef HAS_RAWTOARGBROW_MSA
550ANY11(RAWToARGBRow_Any_MSA, RAWToARGBRow_MSA, 0, 3, 4, 15)
551#endif
552#ifdef HAS_RGB565TOARGBROW_NEON
553ANY11(RGB565ToARGBRow_Any_NEON, RGB565ToARGBRow_NEON, 0, 2, 4, 7)
554#endif
555#ifdef HAS_RGB565TOARGBROW_MSA
556ANY11(RGB565ToARGBRow_Any_MSA, RGB565ToARGBRow_MSA, 0, 2, 4, 15)
557#endif
558#ifdef HAS_ARGB1555TOARGBROW_NEON
559ANY11(ARGB1555ToARGBRow_Any_NEON, ARGB1555ToARGBRow_NEON, 0, 2, 4, 7)
560#endif
561#ifdef HAS_ARGB1555TOARGBROW_MSA
562ANY11(ARGB1555ToARGBRow_Any_MSA, ARGB1555ToARGBRow_MSA, 0, 2, 4, 15)
563#endif
564#ifdef HAS_ARGB4444TOARGBROW_NEON
565ANY11(ARGB4444ToARGBRow_Any_NEON, ARGB4444ToARGBRow_NEON, 0, 2, 4, 7)
566#endif
567#ifdef HAS_RGB24TOARGBROW_DSPR2
568ANY11(RGB24ToARGBRow_Any_DSPR2, RGB24ToARGBRow_DSPR2, 0, 3, 4, 7)
569#endif
570#ifdef HAS_RAWTOARGBROW_DSPR2
571ANY11(RAWToARGBRow_Any_DSPR2, RAWToARGBRow_DSPR2, 0, 3, 4, 7)
572#endif
573#ifdef HAS_RGB565TOARGBROW_DSPR2
574ANY11(RGB565ToARGBRow_Any_DSPR2, RGB565ToARGBRow_DSPR2, 0, 2, 4, 7)
575#endif
576#ifdef HAS_ARGB1555TOARGBROW_DSPR2
577ANY11(ARGB1555ToARGBRow_Any_DSPR2, ARGB1555ToARGBRow_DSPR2, 0, 2, 4, 7)
578#endif
579#ifdef HAS_ARGB4444TOARGBROW_DSPR2
580ANY11(ARGB4444ToARGBRow_Any_DSPR2, ARGB4444ToARGBRow_DSPR2, 0, 2, 4, 7)
581#endif
582#ifdef HAS_BGRATOYROW_DSPR2
583ANY11(BGRAToYRow_Any_DSPR2, BGRAToYRow_DSPR2, 0, 4, 1, 7)
584#endif
585#ifdef HAS_ARGBTOYROW_DSPR2
586ANY11(ARGBToYRow_Any_DSPR2, ARGBToYRow_DSPR2, 0, 4, 1, 7)
587#endif
588#ifdef HAS_ABGRTOYROW_DSPR2
589ANY11(ABGRToYRow_Any_DSPR2, ABGRToYRow_DSPR2, 0, 4, 1, 7)
590#endif
591#ifdef HAS_RGBATOYROW_DSPR2
592ANY11(RGBAToYRow_Any_DSPR2, RGBAToYRow_DSPR2, 0, 4, 1, 7)
593#endif
594#ifdef HAS_ARGB4444TOARGBROW_MSA
595ANY11(ARGB4444ToARGBRow_Any_MSA, ARGB4444ToARGBRow_MSA, 0, 2, 4, 15)
596#endif
597#ifdef HAS_ARGBATTENUATEROW_SSSE3
598ANY11(ARGBAttenuateRow_Any_SSSE3, ARGBAttenuateRow_SSSE3, 0, 4, 4, 3)
599#endif
600#ifdef HAS_ARGBUNATTENUATEROW_SSE2
601ANY11(ARGBUnattenuateRow_Any_SSE2, ARGBUnattenuateRow_SSE2, 0, 4, 4, 3)
602#endif
603#ifdef HAS_ARGBATTENUATEROW_AVX2
604ANY11(ARGBAttenuateRow_Any_AVX2, ARGBAttenuateRow_AVX2, 0, 4, 4, 7)
605#endif
606#ifdef HAS_ARGBUNATTENUATEROW_AVX2
607ANY11(ARGBUnattenuateRow_Any_AVX2, ARGBUnattenuateRow_AVX2, 0, 4, 4, 7)
608#endif
609#ifdef HAS_ARGBATTENUATEROW_NEON
610ANY11(ARGBAttenuateRow_Any_NEON, ARGBAttenuateRow_NEON, 0, 4, 4, 7)
611#endif
612#ifdef HAS_ARGBATTENUATEROW_MSA
613ANY11(ARGBAttenuateRow_Any_MSA, ARGBAttenuateRow_MSA, 0, 4, 4, 7)
614#endif
615#ifdef HAS_ARGBEXTRACTALPHAROW_SSE2
616ANY11(ARGBExtractAlphaRow_Any_SSE2, ARGBExtractAlphaRow_SSE2, 0, 4, 1, 7)
617#endif
618#ifdef HAS_ARGBEXTRACTALPHAROW_AVX2
619ANY11(ARGBExtractAlphaRow_Any_AVX2, ARGBExtractAlphaRow_AVX2, 0, 4, 1, 32)
620#endif
621#ifdef HAS_ARGBEXTRACTALPHAROW_NEON
622ANY11(ARGBExtractAlphaRow_Any_NEON, ARGBExtractAlphaRow_NEON, 0, 4, 1, 15)
623#endif
624#undef ANY11
625
626// Any 1 to 1 blended.  Destination is read, modify, write.
627#define ANY11B(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK)               \
628  void NAMEANY(const uint8* src_ptr, uint8* dst_ptr, int width) {         \
629    SIMD_ALIGNED(uint8 temp[64 * 2]);                                     \
630    memset(temp, 0, 64 * 2); /* for msan */                               \
631    int r = width & MASK;                                                 \
632    int n = width & ~MASK;                                                \
633    if (n > 0) {                                                          \
634      ANY_SIMD(src_ptr, dst_ptr, n);                                      \
635    }                                                                     \
636    memcpy(temp, src_ptr + (n >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \
637    memcpy(temp + 64, dst_ptr + n * BPP, r * BPP);                        \
638    ANY_SIMD(temp, temp + 64, MASK + 1);                                  \
639    memcpy(dst_ptr + n * BPP, temp + 64, r * BPP);                        \
640  }
641
642#ifdef HAS_ARGBCOPYALPHAROW_AVX2
643ANY11B(ARGBCopyAlphaRow_Any_AVX2, ARGBCopyAlphaRow_AVX2, 0, 4, 4, 15)
644#endif
645#ifdef HAS_ARGBCOPYALPHAROW_SSE2
646ANY11B(ARGBCopyAlphaRow_Any_SSE2, ARGBCopyAlphaRow_SSE2, 0, 4, 4, 7)
647#endif
648#ifdef HAS_ARGBCOPYYTOALPHAROW_AVX2
649ANY11B(ARGBCopyYToAlphaRow_Any_AVX2, ARGBCopyYToAlphaRow_AVX2, 0, 1, 4, 15)
650#endif
651#ifdef HAS_ARGBCOPYYTOALPHAROW_SSE2
652ANY11B(ARGBCopyYToAlphaRow_Any_SSE2, ARGBCopyYToAlphaRow_SSE2, 0, 1, 4, 7)
653#endif
654#undef ANY11B
655
656// Any 1 to 1 with parameter.
657#define ANY11P(NAMEANY, ANY_SIMD, T, SBPP, BPP, MASK)                         \
658  void NAMEANY(const uint8* src_ptr, uint8* dst_ptr, T shuffler, int width) { \
659    SIMD_ALIGNED(uint8 temp[64 * 2]);                                         \
660    memset(temp, 0, 64); /* for msan */                                       \
661    int r = width & MASK;                                                     \
662    int n = width & ~MASK;                                                    \
663    if (n > 0) {                                                              \
664      ANY_SIMD(src_ptr, dst_ptr, shuffler, n);                                \
665    }                                                                         \
666    memcpy(temp, src_ptr + n * SBPP, r * SBPP);                               \
667    ANY_SIMD(temp, temp + 64, shuffler, MASK + 1);                            \
668    memcpy(dst_ptr + n * BPP, temp + 64, r * BPP);                            \
669  }
670
671#if defined(HAS_ARGBTORGB565DITHERROW_SSE2)
672ANY11P(ARGBToRGB565DitherRow_Any_SSE2,
673       ARGBToRGB565DitherRow_SSE2,
674       const uint32,
675       4,
676       2,
677       3)
678#endif
679#if defined(HAS_ARGBTORGB565DITHERROW_AVX2)
680ANY11P(ARGBToRGB565DitherRow_Any_AVX2,
681       ARGBToRGB565DitherRow_AVX2,
682       const uint32,
683       4,
684       2,
685       7)
686#endif
687#if defined(HAS_ARGBTORGB565DITHERROW_NEON)
688ANY11P(ARGBToRGB565DitherRow_Any_NEON,
689       ARGBToRGB565DitherRow_NEON,
690       const uint32,
691       4,
692       2,
693       7)
694#endif
695#if defined(HAS_ARGBTORGB565DITHERROW_MSA)
696ANY11P(ARGBToRGB565DitherRow_Any_MSA,
697       ARGBToRGB565DitherRow_MSA,
698       const uint32,
699       4,
700       2,
701       7)
702#endif
703#ifdef HAS_ARGBSHUFFLEROW_SSE2
704ANY11P(ARGBShuffleRow_Any_SSE2, ARGBShuffleRow_SSE2, const uint8*, 4, 4, 3)
705#endif
706#ifdef HAS_ARGBSHUFFLEROW_SSSE3
707ANY11P(ARGBShuffleRow_Any_SSSE3, ARGBShuffleRow_SSSE3, const uint8*, 4, 4, 7)
708#endif
709#ifdef HAS_ARGBSHUFFLEROW_AVX2
710ANY11P(ARGBShuffleRow_Any_AVX2, ARGBShuffleRow_AVX2, const uint8*, 4, 4, 15)
711#endif
712#ifdef HAS_ARGBSHUFFLEROW_NEON
713ANY11P(ARGBShuffleRow_Any_NEON, ARGBShuffleRow_NEON, const uint8*, 4, 4, 3)
714#endif
715#ifdef HAS_ARGBSHUFFLEROW_MSA
716ANY11P(ARGBShuffleRow_Any_MSA, ARGBShuffleRow_MSA, const uint8*, 4, 4, 7)
717#endif
718#undef ANY11P
719
720// Any 1 to 1 with parameter and shorts.  BPP measures in shorts.
721#define ANY11P16(NAMEANY, ANY_SIMD, T, SBPP, BPP, MASK)            \
722  void NAMEANY(const uint16* src_ptr, uint16* dst_ptr, T shuffler, \
723               int width) {                                        \
724    SIMD_ALIGNED(uint16 temp[16 * 2]);                             \
725    memset(temp, 0, 32); /* for msan */                            \
726    int r = width & MASK;                                          \
727    int n = width & ~MASK;                                         \
728    if (n > 0) {                                                   \
729      ANY_SIMD(src_ptr, dst_ptr, shuffler, n);                     \
730    }                                                              \
731    memcpy(temp, src_ptr + n, r * SBPP);                           \
732    ANY_SIMD(temp, temp + 16, shuffler, MASK + 1);                 \
733    memcpy(dst_ptr + n, temp + 16, r * BPP);                       \
734  }
735
736#ifdef HAS_HALFFLOATROW_SSE2
737ANY11P16(HalfFloatRow_Any_SSE2, HalfFloatRow_SSE2, float, 2, 2, 7)
738#endif
739#ifdef HAS_HALFFLOATROW_AVX2
740ANY11P16(HalfFloatRow_Any_AVX2, HalfFloatRow_AVX2, float, 2, 2, 15)
741#endif
742#ifdef HAS_HALFFLOATROW_F16C
743ANY11P16(HalfFloatRow_Any_F16C, HalfFloatRow_F16C, float, 2, 2, 15)
744ANY11P16(HalfFloat1Row_Any_F16C, HalfFloat1Row_F16C, float, 2, 2, 15)
745#endif
746#ifdef HAS_HALFFLOATROW_NEON
747ANY11P16(HalfFloatRow_Any_NEON, HalfFloatRow_NEON, float, 2, 2, 7)
748ANY11P16(HalfFloat1Row_Any_NEON, HalfFloat1Row_NEON, float, 2, 2, 7)
749#endif
750#undef ANY11P16
751
752// Any 1 to 1 with yuvconstants
753#define ANY11C(NAMEANY, ANY_SIMD, UVSHIFT, SBPP, BPP, MASK)               \
754  void NAMEANY(const uint8* src_ptr, uint8* dst_ptr,                      \
755               const struct YuvConstants* yuvconstants, int width) {      \
756    SIMD_ALIGNED(uint8 temp[128 * 2]);                                    \
757    memset(temp, 0, 128); /* for YUY2 and msan */                         \
758    int r = width & MASK;                                                 \
759    int n = width & ~MASK;                                                \
760    if (n > 0) {                                                          \
761      ANY_SIMD(src_ptr, dst_ptr, yuvconstants, n);                        \
762    }                                                                     \
763    memcpy(temp, src_ptr + (n >> UVSHIFT) * SBPP, SS(r, UVSHIFT) * SBPP); \
764    ANY_SIMD(temp, temp + 128, yuvconstants, MASK + 1);                   \
765    memcpy(dst_ptr + n * BPP, temp + 128, r * BPP);                       \
766  }
767#if defined(HAS_YUY2TOARGBROW_SSSE3)
768ANY11C(YUY2ToARGBRow_Any_SSSE3, YUY2ToARGBRow_SSSE3, 1, 4, 4, 15)
769ANY11C(UYVYToARGBRow_Any_SSSE3, UYVYToARGBRow_SSSE3, 1, 4, 4, 15)
770#endif
771#if defined(HAS_YUY2TOARGBROW_AVX2)
772ANY11C(YUY2ToARGBRow_Any_AVX2, YUY2ToARGBRow_AVX2, 1, 4, 4, 31)
773ANY11C(UYVYToARGBRow_Any_AVX2, UYVYToARGBRow_AVX2, 1, 4, 4, 31)
774#endif
775#if defined(HAS_YUY2TOARGBROW_NEON)
776ANY11C(YUY2ToARGBRow_Any_NEON, YUY2ToARGBRow_NEON, 1, 4, 4, 7)
777ANY11C(UYVYToARGBRow_Any_NEON, UYVYToARGBRow_NEON, 1, 4, 4, 7)
778#endif
779#if defined(HAS_YUY2TOARGBROW_MSA)
780ANY11C(YUY2ToARGBRow_Any_MSA, YUY2ToARGBRow_MSA, 1, 4, 4, 7)
781ANY11C(UYVYToARGBRow_Any_MSA, UYVYToARGBRow_MSA, 1, 4, 4, 7)
782#endif
783#undef ANY11C
784
785// Any 1 to 1 interpolate.  Takes 2 rows of source via stride.
786#define ANY11T(NAMEANY, ANY_SIMD, SBPP, BPP, MASK)                             \
787  void NAMEANY(uint8* dst_ptr, const uint8* src_ptr, ptrdiff_t src_stride_ptr, \
788               int width, int source_y_fraction) {                             \
789    SIMD_ALIGNED(uint8 temp[64 * 3]);                                          \
790    memset(temp, 0, 64 * 2); /* for msan */                                    \
791    int r = width & MASK;                                                      \
792    int n = width & ~MASK;                                                     \
793    if (n > 0) {                                                               \
794      ANY_SIMD(dst_ptr, src_ptr, src_stride_ptr, n, source_y_fraction);        \
795    }                                                                          \
796    memcpy(temp, src_ptr + n * SBPP, r * SBPP);                                \
797    memcpy(temp + 64, src_ptr + src_stride_ptr + n * SBPP, r * SBPP);          \
798    ANY_SIMD(temp + 128, temp, 64, MASK + 1, source_y_fraction);               \
799    memcpy(dst_ptr + n * BPP, temp + 128, r * BPP);                            \
800  }
801
802#ifdef HAS_INTERPOLATEROW_AVX2
803ANY11T(InterpolateRow_Any_AVX2, InterpolateRow_AVX2, 1, 1, 31)
804#endif
805#ifdef HAS_INTERPOLATEROW_SSSE3
806ANY11T(InterpolateRow_Any_SSSE3, InterpolateRow_SSSE3, 1, 1, 15)
807#endif
808#ifdef HAS_INTERPOLATEROW_NEON
809ANY11T(InterpolateRow_Any_NEON, InterpolateRow_NEON, 1, 1, 15)
810#endif
811#ifdef HAS_INTERPOLATEROW_DSPR2
812ANY11T(InterpolateRow_Any_DSPR2, InterpolateRow_DSPR2, 1, 1, 3)
813#endif
814#ifdef HAS_INTERPOLATEROW_MSA
815ANY11T(InterpolateRow_Any_MSA, InterpolateRow_MSA, 1, 1, 31)
816#endif
817#undef ANY11T
818
819// Any 1 to 1 mirror.
820#define ANY11M(NAMEANY, ANY_SIMD, BPP, MASK)                              \
821  void NAMEANY(const uint8* src_ptr, uint8* dst_ptr, int width) {         \
822    SIMD_ALIGNED(uint8 temp[64 * 2]);                                     \
823    memset(temp, 0, 64); /* for msan */                                   \
824    int r = width & MASK;                                                 \
825    int n = width & ~MASK;                                                \
826    if (n > 0) {                                                          \
827      ANY_SIMD(src_ptr + r * BPP, dst_ptr, n);                            \
828    }                                                                     \
829    memcpy(temp, src_ptr, r* BPP);                                        \
830    ANY_SIMD(temp, temp + 64, MASK + 1);                                  \
831    memcpy(dst_ptr + n * BPP, temp + 64 + (MASK + 1 - r) * BPP, r * BPP); \
832  }
833
834#ifdef HAS_MIRRORROW_AVX2
835ANY11M(MirrorRow_Any_AVX2, MirrorRow_AVX2, 1, 31)
836#endif
837#ifdef HAS_MIRRORROW_SSSE3
838ANY11M(MirrorRow_Any_SSSE3, MirrorRow_SSSE3, 1, 15)
839#endif
840#ifdef HAS_MIRRORROW_NEON
841ANY11M(MirrorRow_Any_NEON, MirrorRow_NEON, 1, 15)
842#endif
843#ifdef HAS_MIRRORROW_MSA
844ANY11M(MirrorRow_Any_MSA, MirrorRow_MSA, 1, 63)
845#endif
846#ifdef HAS_ARGBMIRRORROW_AVX2
847ANY11M(ARGBMirrorRow_Any_AVX2, ARGBMirrorRow_AVX2, 4, 7)
848#endif
849#ifdef HAS_ARGBMIRRORROW_SSE2
850ANY11M(ARGBMirrorRow_Any_SSE2, ARGBMirrorRow_SSE2, 4, 3)
851#endif
852#ifdef HAS_ARGBMIRRORROW_NEON
853ANY11M(ARGBMirrorRow_Any_NEON, ARGBMirrorRow_NEON, 4, 3)
854#endif
855#ifdef HAS_ARGBMIRRORROW_MSA
856ANY11M(ARGBMirrorRow_Any_MSA, ARGBMirrorRow_MSA, 4, 15)
857#endif
858#undef ANY11M
859
860// Any 1 plane. (memset)
861#define ANY1(NAMEANY, ANY_SIMD, T, BPP, MASK)      \
862  void NAMEANY(uint8* dst_ptr, T v32, int width) { \
863    SIMD_ALIGNED(uint8 temp[64]);                  \
864    int r = width & MASK;                          \
865    int n = width & ~MASK;                         \
866    if (n > 0) {                                   \
867      ANY_SIMD(dst_ptr, v32, n);                   \
868    }                                              \
869    ANY_SIMD(temp, v32, MASK + 1);                 \
870    memcpy(dst_ptr + n * BPP, temp, r * BPP);      \
871  }
872
873#ifdef HAS_SETROW_X86
874ANY1(SetRow_Any_X86, SetRow_X86, uint8, 1, 3)
875#endif
876#ifdef HAS_SETROW_NEON
877ANY1(SetRow_Any_NEON, SetRow_NEON, uint8, 1, 15)
878#endif
879#ifdef HAS_ARGBSETROW_NEON
880ANY1(ARGBSetRow_Any_NEON, ARGBSetRow_NEON, uint32, 4, 3)
881#endif
882#ifdef HAS_ARGBSETROW_MSA
883ANY1(ARGBSetRow_Any_MSA, ARGBSetRow_MSA, uint32, 4, 3)
884#endif
885#undef ANY1
886
887// Any 1 to 2.  Outputs UV planes.
888#define ANY12(NAMEANY, ANY_SIMD, UVSHIFT, BPP, DUVSHIFT, MASK)                \
889  void NAMEANY(const uint8* src_ptr, uint8* dst_u, uint8* dst_v, int width) { \
890    SIMD_ALIGNED(uint8 temp[128 * 3]);                                        \
891    memset(temp, 0, 128); /* for msan */                                      \
892    int r = width & MASK;                                                     \
893    int n = width & ~MASK;                                                    \
894    if (n > 0) {                                                              \
895      ANY_SIMD(src_ptr, dst_u, dst_v, n);                                     \
896    }                                                                         \
897    memcpy(temp, src_ptr + (n >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP);       \
898    ANY_SIMD(temp, temp + 128, temp + 256, MASK + 1);                         \
899    memcpy(dst_u + (n >> DUVSHIFT), temp + 128, SS(r, DUVSHIFT));             \
900    memcpy(dst_v + (n >> DUVSHIFT), temp + 256, SS(r, DUVSHIFT));             \
901  }
902
903#ifdef HAS_SPLITUVROW_SSE2
904ANY12(SplitUVRow_Any_SSE2, SplitUVRow_SSE2, 0, 2, 0, 15)
905#endif
906#ifdef HAS_SPLITUVROW_AVX2
907ANY12(SplitUVRow_Any_AVX2, SplitUVRow_AVX2, 0, 2, 0, 31)
908#endif
909#ifdef HAS_SPLITUVROW_NEON
910ANY12(SplitUVRow_Any_NEON, SplitUVRow_NEON, 0, 2, 0, 15)
911#endif
912#ifdef HAS_SPLITUVROW_DSPR2
913ANY12(SplitUVRow_Any_DSPR2, SplitUVRow_DSPR2, 0, 2, 0, 15)
914#endif
915#ifdef HAS_ARGBTOUV444ROW_SSSE3
916ANY12(ARGBToUV444Row_Any_SSSE3, ARGBToUV444Row_SSSE3, 0, 4, 0, 15)
917#endif
918#ifdef HAS_YUY2TOUV422ROW_AVX2
919ANY12(YUY2ToUV422Row_Any_AVX2, YUY2ToUV422Row_AVX2, 1, 4, 1, 31)
920ANY12(UYVYToUV422Row_Any_AVX2, UYVYToUV422Row_AVX2, 1, 4, 1, 31)
921#endif
922#ifdef HAS_YUY2TOUV422ROW_SSE2
923ANY12(YUY2ToUV422Row_Any_SSE2, YUY2ToUV422Row_SSE2, 1, 4, 1, 15)
924ANY12(UYVYToUV422Row_Any_SSE2, UYVYToUV422Row_SSE2, 1, 4, 1, 15)
925#endif
926#ifdef HAS_YUY2TOUV422ROW_NEON
927ANY12(ARGBToUV444Row_Any_NEON, ARGBToUV444Row_NEON, 0, 4, 0, 7)
928ANY12(YUY2ToUV422Row_Any_NEON, YUY2ToUV422Row_NEON, 1, 4, 1, 15)
929ANY12(UYVYToUV422Row_Any_NEON, UYVYToUV422Row_NEON, 1, 4, 1, 15)
930#endif
931#ifdef HAS_YUY2TOUV422ROW_MSA
932ANY12(ARGBToUV444Row_Any_MSA, ARGBToUV444Row_MSA, 0, 4, 0, 15)
933ANY12(YUY2ToUV422Row_Any_MSA, YUY2ToUV422Row_MSA, 1, 4, 1, 31)
934ANY12(UYVYToUV422Row_Any_MSA, UYVYToUV422Row_MSA, 1, 4, 1, 31)
935#endif
936#undef ANY12
937
938// Any 1 to 2 with source stride (2 rows of source).  Outputs UV planes.
939// 128 byte row allows for 32 avx ARGB pixels.
940#define ANY12S(NAMEANY, ANY_SIMD, UVSHIFT, BPP, MASK)                        \
941  void NAMEANY(const uint8* src_ptr, int src_stride_ptr, uint8* dst_u,       \
942               uint8* dst_v, int width) {                                    \
943    SIMD_ALIGNED(uint8 temp[128 * 4]);                                       \
944    memset(temp, 0, 128 * 2); /* for msan */                                 \
945    int r = width & MASK;                                                    \
946    int n = width & ~MASK;                                                   \
947    if (n > 0) {                                                             \
948      ANY_SIMD(src_ptr, src_stride_ptr, dst_u, dst_v, n);                    \
949    }                                                                        \
950    memcpy(temp, src_ptr + (n >> UVSHIFT) * BPP, SS(r, UVSHIFT) * BPP);      \
951    memcpy(temp + 128, src_ptr + src_stride_ptr + (n >> UVSHIFT) * BPP,      \
952           SS(r, UVSHIFT) * BPP);                                            \
953    if ((width & 1) && UVSHIFT == 0) { /* repeat last pixel for subsample */ \
954      memcpy(temp + SS(r, UVSHIFT) * BPP, temp + SS(r, UVSHIFT) * BPP - BPP, \
955             BPP);                                                           \
956      memcpy(temp + 128 + SS(r, UVSHIFT) * BPP,                              \
957             temp + 128 + SS(r, UVSHIFT) * BPP - BPP, BPP);                  \
958    }                                                                        \
959    ANY_SIMD(temp, 128, temp + 256, temp + 384, MASK + 1);                   \
960    memcpy(dst_u + (n >> 1), temp + 256, SS(r, 1));                          \
961    memcpy(dst_v + (n >> 1), temp + 384, SS(r, 1));                          \
962  }
963
964#ifdef HAS_ARGBTOUVROW_AVX2
965ANY12S(ARGBToUVRow_Any_AVX2, ARGBToUVRow_AVX2, 0, 4, 31)
966#endif
967#ifdef HAS_ARGBTOUVJROW_AVX2
968ANY12S(ARGBToUVJRow_Any_AVX2, ARGBToUVJRow_AVX2, 0, 4, 31)
969#endif
970#ifdef HAS_ARGBTOUVROW_SSSE3
971ANY12S(ARGBToUVRow_Any_SSSE3, ARGBToUVRow_SSSE3, 0, 4, 15)
972ANY12S(ARGBToUVJRow_Any_SSSE3, ARGBToUVJRow_SSSE3, 0, 4, 15)
973ANY12S(BGRAToUVRow_Any_SSSE3, BGRAToUVRow_SSSE3, 0, 4, 15)
974ANY12S(ABGRToUVRow_Any_SSSE3, ABGRToUVRow_SSSE3, 0, 4, 15)
975ANY12S(RGBAToUVRow_Any_SSSE3, RGBAToUVRow_SSSE3, 0, 4, 15)
976#endif
977#ifdef HAS_YUY2TOUVROW_AVX2
978ANY12S(YUY2ToUVRow_Any_AVX2, YUY2ToUVRow_AVX2, 1, 4, 31)
979ANY12S(UYVYToUVRow_Any_AVX2, UYVYToUVRow_AVX2, 1, 4, 31)
980#endif
981#ifdef HAS_YUY2TOUVROW_SSE2
982ANY12S(YUY2ToUVRow_Any_SSE2, YUY2ToUVRow_SSE2, 1, 4, 15)
983ANY12S(UYVYToUVRow_Any_SSE2, UYVYToUVRow_SSE2, 1, 4, 15)
984#endif
985#ifdef HAS_ARGBTOUVROW_NEON
986ANY12S(ARGBToUVRow_Any_NEON, ARGBToUVRow_NEON, 0, 4, 15)
987#endif
988#ifdef HAS_ARGBTOUVROW_MSA
989ANY12S(ARGBToUVRow_Any_MSA, ARGBToUVRow_MSA, 0, 4, 31)
990#endif
991#ifdef HAS_ARGBTOUVJROW_NEON
992ANY12S(ARGBToUVJRow_Any_NEON, ARGBToUVJRow_NEON, 0, 4, 15)
993#endif
994#ifdef HAS_ARGBTOUVJROW_MSA
995ANY12S(ARGBToUVJRow_Any_MSA, ARGBToUVJRow_MSA, 0, 4, 31)
996#endif
997#ifdef HAS_BGRATOUVROW_NEON
998ANY12S(BGRAToUVRow_Any_NEON, BGRAToUVRow_NEON, 0, 4, 15)
999#endif
1000#ifdef HAS_BGRATOUVROW_MSA
1001ANY12S(BGRAToUVRow_Any_MSA, BGRAToUVRow_MSA, 0, 4, 31)
1002#endif
1003#ifdef HAS_ABGRTOUVROW_NEON
1004ANY12S(ABGRToUVRow_Any_NEON, ABGRToUVRow_NEON, 0, 4, 15)
1005#endif
1006#ifdef HAS_ABGRTOUVROW_MSA
1007ANY12S(ABGRToUVRow_Any_MSA, ABGRToUVRow_MSA, 0, 4, 31)
1008#endif
1009#ifdef HAS_RGBATOUVROW_NEON
1010ANY12S(RGBAToUVRow_Any_NEON, RGBAToUVRow_NEON, 0, 4, 15)
1011#endif
1012#ifdef HAS_RGBATOUVROW_MSA
1013ANY12S(RGBAToUVRow_Any_MSA, RGBAToUVRow_MSA, 0, 4, 31)
1014#endif
1015#ifdef HAS_RGB24TOUVROW_NEON
1016ANY12S(RGB24ToUVRow_Any_NEON, RGB24ToUVRow_NEON, 0, 3, 15)
1017#endif
1018#ifdef HAS_RGB24TOUVROW_MSA
1019ANY12S(RGB24ToUVRow_Any_MSA, RGB24ToUVRow_MSA, 0, 3, 15)
1020#endif
1021#ifdef HAS_RAWTOUVROW_NEON
1022ANY12S(RAWToUVRow_Any_NEON, RAWToUVRow_NEON, 0, 3, 15)
1023#endif
1024#ifdef HAS_RAWTOUVROW_MSA
1025ANY12S(RAWToUVRow_Any_MSA, RAWToUVRow_MSA, 0, 3, 15)
1026#endif
1027#ifdef HAS_RGB565TOUVROW_NEON
1028ANY12S(RGB565ToUVRow_Any_NEON, RGB565ToUVRow_NEON, 0, 2, 15)
1029#endif
1030#ifdef HAS_RGB565TOUVROW_MSA
1031ANY12S(RGB565ToUVRow_Any_MSA, RGB565ToUVRow_MSA, 0, 2, 15)
1032#endif
1033#ifdef HAS_ARGB1555TOUVROW_NEON
1034ANY12S(ARGB1555ToUVRow_Any_NEON, ARGB1555ToUVRow_NEON, 0, 2, 15)
1035#endif
1036#ifdef HAS_ARGB1555TOUVROW_MSA
1037ANY12S(ARGB1555ToUVRow_Any_MSA, ARGB1555ToUVRow_MSA, 0, 2, 15)
1038#endif
1039#ifdef HAS_ARGB4444TOUVROW_NEON
1040ANY12S(ARGB4444ToUVRow_Any_NEON, ARGB4444ToUVRow_NEON, 0, 2, 15)
1041#endif
1042#ifdef HAS_YUY2TOUVROW_NEON
1043ANY12S(YUY2ToUVRow_Any_NEON, YUY2ToUVRow_NEON, 1, 4, 15)
1044#endif
1045#ifdef HAS_UYVYTOUVROW_NEON
1046ANY12S(UYVYToUVRow_Any_NEON, UYVYToUVRow_NEON, 1, 4, 15)
1047#endif
1048#ifdef HAS_BGRATOUVROW_DSPR2
1049ANY12S(BGRAToUVRow_Any_DSPR2, BGRAToUVRow_DSPR2, 0, 4, 15)
1050#endif
1051#ifdef HAS_ABGRTOUVROW_DSPR2
1052ANY12S(ABGRToUVRow_Any_DSPR2, ABGRToUVRow_DSPR2, 0, 4, 15)
1053#endif
1054#ifdef HAS_RGBATOUVROW_DSPR2
1055ANY12S(RGBAToUVRow_Any_DSPR2, RGBAToUVRow_DSPR2, 0, 4, 15)
1056#endif
1057#ifdef HAS_ARGBTOUVROW_DSPR2
1058ANY12S(ARGBToUVRow_Any_DSPR2, ARGBToUVRow_DSPR2, 0, 4, 15)
1059#endif
1060#ifdef HAS_YUY2TOUVROW_MSA
1061ANY12S(YUY2ToUVRow_Any_MSA, YUY2ToUVRow_MSA, 1, 4, 31)
1062#endif
1063#ifdef HAS_UYVYTOUVROW_MSA
1064ANY12S(UYVYToUVRow_Any_MSA, UYVYToUVRow_MSA, 1, 4, 31)
1065#endif
1066#undef ANY12S
1067
1068#ifdef __cplusplus
1069}  // extern "C"
1070}  // namespace libyuv
1071#endif
1072