blob: 2eb5fc3afc3fd6bf495c8f215d194b19c877aafe [file] [log] [blame]
mikhal@webrtc.orgaed1cc92011-09-28 00:06:25 +00001/*
2 * Copyright (c) 2011 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 "row.h"
12
frkoenig@google.comc82af4a2011-11-11 00:54:34 +000013#include "libyuv/basic_types.h"
14
mikhal@webrtc.orgaed1cc92011-09-28 00:06:25 +000015extern "C" {
16
fbarchard@google.comb6149762011-11-07 21:58:52 +000017#ifdef HAS_ARGBTOUVROW_SSSE3
fbarchard@google.com228bdc22011-11-15 21:58:26 +000018vec8 kARGBToU = {
fbarchard@google.comb6149762011-11-07 21:58:52 +000019 112, -74, -38, 0, 112, -74, -38, 0, 112, -74, -38, 0, 112, -74, -38, 0
20};
21
fbarchard@google.com228bdc22011-11-15 21:58:26 +000022uvec8 kARGBToV = {
fbarchard@google.com2430e042011-11-11 21:57:06 +000023 -18, -94, 112, 0, -18, -94, 112, 0, -18, -94, 112, 0, -18, -94, 112, 0
fbarchard@google.comb6149762011-11-07 21:58:52 +000024};
fbarchard@google.com2430e042011-11-11 21:57:06 +000025
fbarchard@google.com228bdc22011-11-15 21:58:26 +000026uvec8 kAddUV128 = {
fbarchard@google.comb6149762011-11-07 21:58:52 +000027 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u,
28 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u
29};
30#endif
31
fbarchard@google.com228bdc22011-11-15 21:58:26 +000032#ifdef HAS_ARGBTOYROW_SSSE3
33
34// Constant multiplication table for converting ARGB to I400.
35vec8 kARGBToY = {
36 13, 65, 33, 0, 13, 65, 33, 0, 13, 65, 33, 0, 13, 65, 33, 0
37};
38
39uvec8 kAddY16 = {
40 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u
41};
42
fbarchard@google.com9394ed92011-10-31 21:36:47 +000043// Shuffle table for converting BG24 to ARGB.
fbarchard@google.com228bdc22011-11-15 21:58:26 +000044uvec8 kShuffleMaskBG24ToARGB = {
fbarchard@google.com9394ed92011-10-31 21:36:47 +000045 0u, 1u, 2u, 12u, 3u, 4u, 5u, 13u, 6u, 7u, 8u, 14u, 9u, 10u, 11u, 15u
46};
47
48// Shuffle table for converting RAW to ARGB.
fbarchard@google.com228bdc22011-11-15 21:58:26 +000049uvec8 kShuffleMaskRAWToARGB = {
fbarchard@google.com9394ed92011-10-31 21:36:47 +000050 2u, 1u, 0u, 12u, 5u, 4u, 3u, 13u, 8u, 7u, 6u, 14u, 11u, 10u, 9u, 15u
51};
52
fbarchard@google.comb6149762011-11-07 21:58:52 +000053// Shuffle table for converting ABGR to ARGB.
fbarchard@google.com228bdc22011-11-15 21:58:26 +000054uvec8 kShuffleMaskABGRToARGB = {
fbarchard@google.comb6149762011-11-07 21:58:52 +000055 2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u
56};
57
58// Shuffle table for converting BGRA to ARGB.
fbarchard@google.com228bdc22011-11-15 21:58:26 +000059uvec8 kShuffleMaskBGRAToARGB = {
fbarchard@google.comb6149762011-11-07 21:58:52 +000060 3u, 2u, 1u, 0u, 7u, 6u, 5u, 4u, 11u, 10u, 9u, 8u, 15u, 14u, 13u, 12u
61};
62
63void I400ToARGBRow_SSE2(const uint8* src_y, uint8* dst_argb, int pix) {
fbarchard@google.comf7a50482011-11-10 22:41:20 +000064 asm volatile (
65 "pcmpeqb %%xmm5,%%xmm5 \n"
66 "pslld $0x18,%%xmm5 \n"
67"1: \n"
68 "movq (%0),%%xmm0 \n"
69 "lea 0x8(%0),%0 \n"
70 "punpcklbw %%xmm0,%%xmm0 \n"
71 "movdqa %%xmm0,%%xmm1 \n"
72 "punpcklwd %%xmm0,%%xmm0 \n"
73 "punpckhwd %%xmm1,%%xmm1 \n"
74 "por %%xmm5,%%xmm0 \n"
75 "por %%xmm5,%%xmm1 \n"
76 "movdqa %%xmm0,(%1) \n"
77 "movdqa %%xmm1,0x10(%1) \n"
78 "lea 0x20(%1),%1 \n"
79 "sub $0x8,%2 \n"
80 "ja 1b \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +000081 : "+r"(src_y), // %0
82 "+r"(dst_argb), // %1
83 "+r"(pix) // %2
84 :
85 : "memory", "cc"
86#if defined(__SSE2__)
87 , "xmm0", "xmm1", "xmm5"
88#endif
fbarchard@google.com585a1262011-10-28 23:51:08 +000089);
90}
fbarchard@google.comb6149762011-11-07 21:58:52 +000091
92void ABGRToARGBRow_SSSE3(const uint8* src_abgr, uint8* dst_argb, int pix) {
fbarchard@google.comf7a50482011-11-10 22:41:20 +000093 asm volatile (
94 "movdqa %3,%%xmm5 \n"
95"1: \n"
96 "movdqa (%0),%%xmm0 \n"
97 "lea 0x10(%0),%0 \n"
98 "pshufb %%xmm5,%%xmm0 \n"
99 "movdqa %%xmm0,(%1) \n"
100 "lea 0x10(%1),%1 \n"
101 "sub $0x4,%2 \n"
102 "ja 1b \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000103 : "+r"(src_abgr), // %0
104 "+r"(dst_argb), // %1
105 "+r"(pix) // %2
106 : "m"(kShuffleMaskABGRToARGB) // %3
107 : "memory", "cc"
108#if defined(__SSE2__)
109 , "xmm0", "xmm5"
fbarchard@google.com585a1262011-10-28 23:51:08 +0000110#endif
111
fbarchard@google.comb6149762011-11-07 21:58:52 +0000112);
113}
114
115void BGRAToARGBRow_SSSE3(const uint8* src_bgra, uint8* dst_argb, int pix) {
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000116 asm volatile (
117 "movdqa %3,%%xmm5 \n"
118"1: \n"
119 "movdqa (%0),%%xmm0 \n"
120 "lea 0x10(%0),%0 \n"
121 "pshufb %%xmm5,%%xmm0 \n"
122 "movdqa %%xmm0,(%1) \n"
123 "lea 0x10(%1),%1 \n"
124 "sub $0x4,%2 \n"
125 "ja 1b \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000126 : "+r"(src_bgra), // %0
127 "+r"(dst_argb), // %1
128 "+r"(pix) // %2
129 : "m"(kShuffleMaskBGRAToARGB) // %3
130 : "memory", "cc"
131#if defined(__SSE2__)
132 , "xmm0", "xmm5"
133#endif
134);
135}
136
fbarchard@google.com9394ed92011-10-31 21:36:47 +0000137void BG24ToARGBRow_SSSE3(const uint8* src_bg24, uint8* dst_argb, int pix) {
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000138 asm volatile (
139 "pcmpeqb %%xmm5,%%xmm5 \n" // generate mask 0xff000000
140 "pslld $0x18,%%xmm5 \n"
141 "movdqa %3,%%xmm4 \n"
142"1: \n"
143 "movdqa (%0),%%xmm0 \n"
144 "movdqa 0x10(%0),%%xmm1 \n"
145 "movdqa 0x20(%0),%%xmm3 \n"
146 "lea 0x30(%0),%0 \n"
147 "movdqa %%xmm3,%%xmm2 \n"
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000148 "palignr $0x8,%%xmm1,%%xmm2 \n"
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000149 "pshufb %%xmm4,%%xmm2 \n"
150 "por %%xmm5,%%xmm2 \n"
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000151 "palignr $0xc,%%xmm0,%%xmm1 \n"
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000152 "pshufb %%xmm4,%%xmm0 \n"
153 "movdqa %%xmm2,0x20(%1) \n"
154 "por %%xmm5,%%xmm0 \n"
155 "pshufb %%xmm4,%%xmm1 \n"
156 "movdqa %%xmm0,(%1) \n"
157 "por %%xmm5,%%xmm1 \n"
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000158 "palignr $0x4,%%xmm3,%%xmm3 \n"
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000159 "pshufb %%xmm4,%%xmm3 \n"
160 "movdqa %%xmm1,0x10(%1) \n"
161 "por %%xmm5,%%xmm3 \n"
162 "movdqa %%xmm3,0x30(%1) \n"
163 "lea 0x40(%1),%1 \n"
164 "sub $0x10,%2 \n"
165 "ja 1b \n"
fbarchard@google.com9394ed92011-10-31 21:36:47 +0000166 : "+r"(src_bg24), // %0
167 "+r"(dst_argb), // %1
168 "+r"(pix) // %2
fbarchard@google.comb6149762011-11-07 21:58:52 +0000169 : "m"(kShuffleMaskBG24ToARGB) // %3
170 : "memory", "cc"
171#if defined(__SSE2__)
172 , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
173#endif
fbarchard@google.com9394ed92011-10-31 21:36:47 +0000174);
fbarchard@google.com585a1262011-10-28 23:51:08 +0000175}
176
fbarchard@google.com9394ed92011-10-31 21:36:47 +0000177void RAWToARGBRow_SSSE3(const uint8* src_raw, uint8* dst_argb, int pix) {
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000178 asm volatile (
179 "pcmpeqb %%xmm5,%%xmm5 \n" // generate mask 0xff000000
180 "pslld $0x18,%%xmm5 \n"
181 "movdqa %3,%%xmm4 \n"
182"1: \n"
183 "movdqa (%0),%%xmm0 \n"
184 "movdqa 0x10(%0),%%xmm1 \n"
185 "movdqa 0x20(%0),%%xmm3 \n"
186 "lea 0x30(%0),%0 \n"
187 "movdqa %%xmm3,%%xmm2 \n"
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000188 "palignr $0x8,%%xmm1,%%xmm2 \n"
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000189 "pshufb %%xmm4,%%xmm2 \n"
190 "por %%xmm5,%%xmm2 \n"
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000191 "palignr $0xc,%%xmm0,%%xmm1 \n"
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000192 "pshufb %%xmm4,%%xmm0 \n"
193 "movdqa %%xmm2,0x20(%1) \n"
194 "por %%xmm5,%%xmm0 \n"
195 "pshufb %%xmm4,%%xmm1 \n"
196 "movdqa %%xmm0,(%1) \n"
197 "por %%xmm5,%%xmm1 \n"
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000198 "palignr $0x4,%%xmm3,%%xmm3 \n"
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000199 "pshufb %%xmm4,%%xmm3 \n"
200 "movdqa %%xmm1,0x10(%1) \n"
201 "por %%xmm5,%%xmm3 \n"
202 "movdqa %%xmm3,0x30(%1) \n"
203 "lea 0x40(%1),%1 \n"
204 "sub $0x10,%2 \n"
205 "ja 1b \n"
fbarchard@google.com9394ed92011-10-31 21:36:47 +0000206 : "+r"(src_raw), // %0
207 "+r"(dst_argb), // %1
208 "+r"(pix) // %2
fbarchard@google.comb6149762011-11-07 21:58:52 +0000209 : "m"(kShuffleMaskRAWToARGB) // %3
210 : "memory", "cc"
211#if defined(__SSE2__)
212 , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
213#endif
214);
215}
216
217void ARGBToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) {
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000218 asm volatile (
219 "movdqa %4,%%xmm5 \n"
220 "movdqa %3,%%xmm4 \n"
221"1: \n"
222 "movdqa (%0),%%xmm0 \n"
223 "movdqa 0x10(%0),%%xmm1 \n"
224 "movdqa 0x20(%0),%%xmm2 \n"
225 "movdqa 0x30(%0),%%xmm3 \n"
226 "pmaddubsw %%xmm4,%%xmm0 \n"
227 "pmaddubsw %%xmm4,%%xmm1 \n"
228 "pmaddubsw %%xmm4,%%xmm2 \n"
229 "pmaddubsw %%xmm4,%%xmm3 \n"
230 "lea 0x40(%0),%0 \n"
231 "phaddw %%xmm1,%%xmm0 \n"
232 "phaddw %%xmm3,%%xmm2 \n"
233 "psrlw $0x7,%%xmm0 \n"
234 "psrlw $0x7,%%xmm2 \n"
235 "packuswb %%xmm2,%%xmm0 \n"
236 "paddb %%xmm5,%%xmm0 \n"
237 "movdqa %%xmm0,(%1) \n"
238 "lea 0x10(%1),%1 \n"
239 "sub $0x10,%2 \n"
240 "ja 1b \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000241 : "+r"(src_argb), // %0
242 "+r"(dst_y), // %1
243 "+r"(pix) // %2
244 : "m"(kARGBToY), // %3
245 "m"(kAddY16) // %4
246 : "memory", "cc"
247#if defined(__SSE2__)
248 , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
249#endif
250
fbarchard@google.com9394ed92011-10-31 21:36:47 +0000251);
fbarchard@google.com585a1262011-10-28 23:51:08 +0000252}
fbarchard@google.com9394ed92011-10-31 21:36:47 +0000253#endif
fbarchard@google.com585a1262011-10-28 23:51:08 +0000254
fbarchard@google.comb6149762011-11-07 21:58:52 +0000255#ifdef HAS_ARGBTOUVROW_SSSE3
256void ARGBToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
257 uint8* dst_u, uint8* dst_v, int width) {
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000258 asm volatile (
259 "movdqa %0,%%xmm4 \n"
260 "movdqa %1,%%xmm3 \n"
261 "movdqa %2,%%xmm5 \n"
fbarchard@google.comd93d4482011-11-10 18:26:20 +0000262 :
263 : "m"(kARGBToU), // %0
264 "m"(kARGBToV), // %1
265 "m"(kAddUV128) // %2
266 :
267#if defined(__SSE2__)
268 "xmm3", "xmm4", "xmm5"
269#endif
270 );
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000271 asm volatile (
272 "sub %1,%2 \n"
273"1: \n"
274 "movdqa (%0),%%xmm0 \n"
275 "movdqa 0x10(%0),%%xmm1 \n"
276 "movdqa 0x20(%0),%%xmm2 \n"
277 "movdqa 0x30(%0),%%xmm6 \n"
278 "pavgb (%0,%4,1),%%xmm0 \n"
279 "pavgb 0x10(%0,%4,1),%%xmm1 \n"
280 "pavgb 0x20(%0,%4,1),%%xmm2 \n"
281 "pavgb 0x30(%0,%4,1),%%xmm6 \n"
282 "lea 0x40(%0),%0 \n"
283 "movdqa %%xmm0,%%xmm7 \n"
284 "shufps $0x88,%%xmm1,%%xmm0 \n"
285 "shufps $0xdd,%%xmm1,%%xmm7 \n"
286 "pavgb %%xmm7,%%xmm0 \n"
287 "movdqa %%xmm2,%%xmm7 \n"
288 "shufps $0x88,%%xmm6,%%xmm2 \n"
289 "shufps $0xdd,%%xmm6,%%xmm7 \n"
290 "pavgb %%xmm7,%%xmm2 \n"
291 "movdqa %%xmm0,%%xmm1 \n"
292 "movdqa %%xmm2,%%xmm6 \n"
293 "pmaddubsw %%xmm4,%%xmm0 \n"
294 "pmaddubsw %%xmm4,%%xmm2 \n"
295 "pmaddubsw %%xmm3,%%xmm1 \n"
296 "pmaddubsw %%xmm3,%%xmm6 \n"
297 "phaddw %%xmm2,%%xmm0 \n"
298 "phaddw %%xmm6,%%xmm1 \n"
299 "psraw $0x8,%%xmm0 \n"
300 "psraw $0x8,%%xmm1 \n"
301 "packsswb %%xmm1,%%xmm0 \n"
302 "paddb %%xmm5,%%xmm0 \n"
303 "movlps %%xmm0,(%1) \n"
304 "movhps %%xmm0,(%1,%2,1) \n"
305 "lea 0x8(%1),%1 \n"
306 "sub $0x10,%3 \n"
307 "ja 1b \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000308 : "+r"(src_argb0), // %0
309 "+r"(dst_u), // %1
310 "+r"(dst_v), // %2
311 "+rm"(width) // %3
fbarchard@google.comd93d4482011-11-10 18:26:20 +0000312 : "r"(static_cast<intptr_t>(src_stride_argb))
fbarchard@google.comb6149762011-11-07 21:58:52 +0000313 : "memory", "cc"
314#if defined(__SSE2__)
fbarchard@google.comd93d4482011-11-10 18:26:20 +0000315 , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000316#endif
317);
318}
319#endif
320
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000321
322#ifdef HAS_FASTCONVERTYTOARGBROW_SSE2
323#define YG 74 /* static_cast<int8>(1.164 * 64 + 0.5) */
324
325vec16 kYToRgb = { YG, YG, YG, YG, YG, YG, YG, YG };
326vec16 kYSub16 = { 16, 16, 16, 16, 16, 16, 16, 16 };
fbarchard@google.comb6149762011-11-07 21:58:52 +0000327#endif
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000328
329#ifdef HAS_FASTCONVERTYUVTOARGBROW_SSSE3
330#define UB 127 /* min(63,static_cast<int8>(2.018 * 64)) */
331#define UG -25 /* static_cast<int8>(-0.391 * 64 - 0.5) */
332#define UR 0
333
334#define VB 0
335#define VG -52 /* static_cast<int8>(-0.813 * 64 - 0.5) */
336#define VR 102 /* static_cast<int8>(1.596 * 64 + 0.5) */
337
338// Bias
339#define BB UB * 128 + VB * 128
340#define BG UG * 128 + VG * 128
341#define BR UR * 128 + VR * 128
342
343vec8 kUVToB = {
344 UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB
345};
346
347vec8 kUVToR = {
348 UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR
349};
350
351vec8 kUVToG = {
352 UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG
353};
354
355
356vec16 kUVBiasB = { BB, BB, BB, BB, BB, BB, BB, BB };
357vec16 kUVBiasG = { BG, BG, BG, BG, BG, BG, BG, BG };
358vec16 kUVBiasR = { BR, BR, BR, BR, BR, BR, BR, BR };
359
fbarchard@google.comb6149762011-11-07 21:58:52 +0000360#if defined(__APPLE__) || defined(__x86_64__)
361#define OMITFP
362#else
363#define OMITFP __attribute__((optimize("omit-frame-pointer")))
364#endif
mikhal@webrtc.orgaed1cc92011-09-28 00:06:25 +0000365
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000366// This version produces 8 pixels
fbarchard@google.comb6149762011-11-07 21:58:52 +0000367#define YUVTORGB \
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000368 "movd (%1),%%xmm0 \n" \
369 "movd (%1,%2,1),%%xmm1 \n" \
370 "lea 0x4(%1),%1 \n" \
371 "punpcklbw %%xmm1,%%xmm0 \n" \
372 "punpcklwd %%xmm0,%%xmm0 \n" \
373 "movdqa %%xmm0,%%xmm1 \n" \
374 "movdqa %%xmm0,%%xmm2 \n" \
375 "pmaddubsw %5,%%xmm0 \n" \
376 "pmaddubsw %6,%%xmm1 \n" \
377 "pmaddubsw %7,%%xmm2 \n" \
378 "psubw %8,%%xmm0 \n" \
379 "psubw %9,%%xmm1 \n" \
380 "psubw %10,%%xmm2 \n" \
381 "movq (%0),%%xmm3 \n" \
382 "lea 0x8(%0),%0 \n" \
383 "punpcklbw %%xmm4,%%xmm3 \n" \
384 "psubsw %11,%%xmm3 \n" \
385 "pmullw %12,%%xmm3 \n" \
386 "paddw %%xmm3,%%xmm0 \n" \
387 "paddw %%xmm3,%%xmm1 \n" \
388 "paddw %%xmm3,%%xmm2 \n" \
389 "psraw $0x6,%%xmm0 \n" \
390 "psraw $0x6,%%xmm1 \n" \
391 "psraw $0x6,%%xmm2 \n" \
392 "packuswb %%xmm0,%%xmm0 \n" \
393 "packuswb %%xmm1,%%xmm1 \n" \
394 "packuswb %%xmm2,%%xmm2 \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000395
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000396void OMITFP FastConvertYUVToARGBRow_SSSE3(const uint8* y_buf, // rdi
fbarchard@google.comb6149762011-11-07 21:58:52 +0000397 const uint8* u_buf, // rsi
398 const uint8* v_buf, // rdx
399 uint8* rgb_buf, // rcx
400 int width) { // r8
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000401 asm volatile (
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000402 "sub %1,%2 \n"
403 "pcmpeqb %%xmm5,%%xmm5 \n"
404 "pxor %%xmm4,%%xmm4 \n"
mikhal@webrtc.org43575c82011-10-12 18:49:21 +0000405
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000406 "1: \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000407 YUVTORGB
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000408 "punpcklbw %%xmm1,%%xmm0 \n"
409 "punpcklbw %%xmm5,%%xmm2 \n"
410 "movdqa %%xmm0,%%xmm1 \n"
411 "punpcklwd %%xmm2,%%xmm0 \n"
412 "movdqa %%xmm0,(%3) \n"
413 "punpckhwd %%xmm2,%%xmm1 \n"
414 "movdqa %%xmm1,0x10(%3) \n"
415 "lea 0x20(%3),%3 \n"
416 "sub $0x8,%4 \n"
417 "ja 1b \n"
fbarchard@google.com3faa0f12011-10-20 06:04:16 +0000418 : "+r"(y_buf), // %0
419 "+r"(u_buf), // %1
420 "+r"(v_buf), // %2
421 "+r"(rgb_buf), // %3
fbarchard@google.comb6149762011-11-07 21:58:52 +0000422 "+rm"(width) // %4
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000423 : "m" (kUVToB), // %5
424 "m" (kUVToG), // %6
425 "m" (kUVToR), // %7
426 "m" (kUVBiasB), // %8
427 "m" (kUVBiasG), // %9
428 "m" (kUVBiasR), // %10
429 "m" (kYSub16), // %11
430 "m" (kYToRgb) // %12
431 : "memory", "cc"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000432#if defined(__SSE2__)
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000433 , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000434#endif
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000435 );
mikhal@webrtc.org43575c82011-10-12 18:49:21 +0000436}
437
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000438void OMITFP FastConvertYUVToBGRARow_SSSE3(const uint8* y_buf, // rdi
439 const uint8* u_buf, // rsi
440 const uint8* v_buf, // rdx
441 uint8* rgb_buf, // rcx
442 int width) { // r8
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000443 asm volatile (
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000444 "sub %1,%2 \n"
445 "pcmpeqb %%xmm5,%%xmm5 \n"
446 "pxor %%xmm4,%%xmm4 \n"
447
448 "1: \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000449 YUVTORGB
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000450 "pcmpeqb %%xmm5,%%xmm5 \n"
451 "punpcklbw %%xmm0,%%xmm1 \n"
452 "punpcklbw %%xmm2,%%xmm5 \n"
453 "movdqa %%xmm5,%%xmm0 \n"
454 "punpcklwd %%xmm1,%%xmm5 \n"
455 "movdqa %%xmm5,(%3) \n"
456 "punpckhwd %%xmm1,%%xmm0 \n"
457 "movdqa %%xmm0,0x10(%3) \n"
458 "lea 0x20(%3),%3 \n"
459 "sub $0x8,%4 \n"
460 "ja 1b \n"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000461 : "+r"(y_buf), // %0
462 "+r"(u_buf), // %1
463 "+r"(v_buf), // %2
464 "+r"(rgb_buf), // %3
465 "+rm"(width) // %4
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000466 : "m" (kUVToB), // %5
467 "m" (kUVToG), // %6
468 "m" (kUVToR), // %7
469 "m" (kUVBiasB), // %8
470 "m" (kUVBiasG), // %9
471 "m" (kUVBiasR), // %10
472 "m" (kYSub16), // %11
473 "m" (kYToRgb) // %12
474 : "memory", "cc"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000475#if defined(__SSE2__)
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000476 , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000477#endif
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000478 );
fbarchard@google.comb6149762011-11-07 21:58:52 +0000479}
480
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000481void OMITFP FastConvertYUVToABGRRow_SSSE3(const uint8* y_buf, // rdi
482 const uint8* u_buf, // rsi
483 const uint8* v_buf, // rdx
484 uint8* rgb_buf, // rcx
485 int width) { // r8
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000486 asm volatile (
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000487 "sub %1,%2 \n"
488 "pcmpeqb %%xmm5,%%xmm5 \n"
489 "pxor %%xmm4,%%xmm4 \n"
490
491 "1: \n"
492 YUVTORGB
493 "packuswb %%xmm0,%%xmm0 \n"
494 "packuswb %%xmm1,%%xmm1 \n"
495 "packuswb %%xmm2,%%xmm2 \n"
496 "punpcklbw %%xmm1,%%xmm2 \n"
497 "punpcklbw %%xmm5,%%xmm0 \n"
498 "movdqa %%xmm2,%%xmm1 \n"
499 "punpcklwd %%xmm0,%%xmm2 \n"
500 "movdqa %%xmm2,(%3) \n"
501 "punpckhwd %%xmm0,%%xmm1 \n"
502 "movdqa %%xmm1,0x10(%3) \n"
503 "lea 0x20(%3),%3 \n"
504 "sub $0x8,%4 \n"
505 "ja 1b \n"
fbarchard@google.com3faa0f12011-10-20 06:04:16 +0000506 : "+r"(y_buf), // %0
507 "+r"(u_buf), // %1
508 "+r"(v_buf), // %2
509 "+r"(rgb_buf), // %3
fbarchard@google.comb6149762011-11-07 21:58:52 +0000510 "+rm"(width) // %4
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000511 : "m" (kUVToB), // %5
512 "m" (kUVToG), // %6
513 "m" (kUVToR), // %7
514 "m" (kUVBiasB), // %8
515 "m" (kUVBiasG), // %9
516 "m" (kUVBiasR), // %10
517 "m" (kYSub16), // %11
518 "m" (kYToRgb) // %12
519 : "memory", "cc"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000520#if defined(__SSE2__)
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000521 , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000522#endif
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000523 );
mikhal@webrtc.org120d5e72011-10-07 17:57:17 +0000524}
525
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000526void OMITFP FastConvertYUV444ToARGBRow_SSSE3(const uint8* y_buf, // rdi
527 const uint8* u_buf, // rsi
528 const uint8* v_buf, // rdx
529 uint8* rgb_buf, // rcx
530 int width) { // r8
531 asm volatile (
532 "sub %1,%2 \n"
533 "pcmpeqb %%xmm5,%%xmm5 \n"
534 "pxor %%xmm4,%%xmm4 \n"
535
536 "1: \n"
537 "movd (%1),%%xmm0 \n"
538 "movd (%1,%2,1),%%xmm1 \n"
539 "lea 0x4(%1),%1 \n"
540 "punpcklbw %%xmm1,%%xmm0 \n"
541 "movdqa %%xmm0,%%xmm1 \n"
542 "movdqa %%xmm0,%%xmm2 \n"
543 "pmaddubsw %5,%%xmm0 \n"
544 "pmaddubsw %6,%%xmm1 \n"
545 "pmaddubsw %7,%%xmm2 \n"
546 "psubw %8,%%xmm0 \n"
547 "psubw %9,%%xmm1 \n"
548 "psubw %10,%%xmm2 \n"
549 "movd (%0),%%xmm3 \n"
550 "lea 0x4(%0),%0 \n"
551 "punpcklbw %%xmm4,%%xmm3 \n"
552 "psubsw %11,%%xmm3 \n"
553 "pmullw %12,%%xmm3 \n"
554 "paddw %%xmm3,%%xmm0 \n"
555 "paddw %%xmm3,%%xmm1 \n"
556 "paddw %%xmm3,%%xmm2 \n"
557 "psraw $0x6,%%xmm0 \n"
558 "psraw $0x6,%%xmm1 \n"
559 "psraw $0x6,%%xmm2 \n"
560 "packuswb %%xmm0,%%xmm0 \n"
561 "packuswb %%xmm1,%%xmm1 \n"
562 "packuswb %%xmm2,%%xmm2 \n"
563 "punpcklbw %%xmm1,%%xmm0 \n"
564 "punpcklbw %%xmm5,%%xmm2 \n"
565 "punpcklwd %%xmm2,%%xmm0 \n"
566 "movdqa %%xmm0,(%3) \n"
567 "lea 0x10(%3),%3 \n"
568 "sub $0x4,%4 \n"
569 "ja 1b \n"
570 : "+r"(y_buf), // %0
571 "+r"(u_buf), // %1
572 "+r"(v_buf), // %2
573 "+r"(rgb_buf), // %3
574 "+rm"(width) // %4
575 : "m" (kUVToB), // %5
576 "m" (kUVToG), // %6
577 "m" (kUVToR), // %7
578 "m" (kUVBiasB), // %8
579 "m" (kUVBiasG), // %9
580 "m" (kUVBiasR), // %10
581 "m" (kYSub16), // %11
582 "m" (kYToRgb) // %12
583 : "memory", "cc"
584#if defined(__SSE2__)
585 , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
586#endif
587 );
588}
589#endif
590
591#ifdef HAS_FASTCONVERTYTOARGBROW_SSE2
fbarchard@google.comb6149762011-11-07 21:58:52 +0000592void FastConvertYToARGBRow_SSE2(const uint8* y_buf, // rdi
593 uint8* rgb_buf, // rcx
594 int width) { // r8
fbarchard@google.comf7a50482011-11-10 22:41:20 +0000595 asm volatile (
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000596 "pcmpeqb %%xmm5,%%xmm5 \n"
597 "pslld $0x18,%%xmm5 \n"
598 "pxor %%xmm4,%%xmm4 \n"
599 "movdqa %3,%%xmm3 \n"
600 "movdqa %4,%%xmm2 \n"
601
602 "1: \n"
603 // Step 1: Scale Y contribution to 8 G values. G = (y - 16) * 1.164
604 "movq (%0),%%xmm0 \n"
605 "lea 0x8(%0),%0 \n"
606 "punpcklbw %%xmm4,%%xmm0 \n"
607 "psubsw %%xmm3,%%xmm0 \n"
608 "pmullw %%xmm2,%%xmm0 \n"
609 "psraw $0x6,%%xmm0 \n"
610 "packuswb %%xmm0,%%xmm0 \n"
611
612 // Step 2: Weave into ARGB
613 "punpcklbw %%xmm0,%%xmm0 \n"
614 "movdqa %%xmm0,%%xmm1 \n"
615 "punpcklwd %%xmm0,%%xmm0 \n"
616 "por %%xmm5,%%xmm0 \n"
617 "movdqa %%xmm0,(%1) \n"
618 "punpckhwd %%xmm1,%%xmm1 \n"
619 "por %%xmm5,%%xmm1 \n"
620 "movdqa %%xmm1,16(%1) \n"
621 "lea 32(%1),%1 \n"
622
623 "sub $0x8,%2 \n"
624 "ja 1b \n"
fbarchard@google.com3faa0f12011-10-20 06:04:16 +0000625 : "+r"(y_buf), // %0
626 "+r"(rgb_buf), // %1
fbarchard@google.comb6149762011-11-07 21:58:52 +0000627 "+rm"(width) // %2
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000628 : "m" (kYSub16), // %3
629 "m" (kYToRgb) // %4
630 : "memory", "cc"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000631#if defined(__SSE2__)
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000632 , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
fbarchard@google.comb6149762011-11-07 21:58:52 +0000633#endif
fbarchard@google.com228bdc22011-11-15 21:58:26 +0000634 );
mikhal@webrtc.org120d5e72011-10-07 17:57:17 +0000635}
fbarchard@google.comb6149762011-11-07 21:58:52 +0000636#endif
mikhal@webrtc.orgaed1cc92011-09-28 00:06:25 +0000637
frkoenig@google.come5185422011-11-07 23:07:57 +0000638#ifdef HAS_ARGBTOYROW_SSSE3
fbarchard@google.comb6149762011-11-07 21:58:52 +0000639void ABGRToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) {
640 SIMD_ALIGNED(uint8 row[kMaxStride]);
641 ABGRToARGBRow_SSSE3(src_argb, row, pix);
642 ARGBToYRow_SSSE3(row, dst_y, pix);
mikhal@webrtc.orgaed1cc92011-09-28 00:06:25 +0000643}
644
fbarchard@google.comb6149762011-11-07 21:58:52 +0000645void BGRAToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) {
646 SIMD_ALIGNED(uint8 row[kMaxStride]);
647 BGRAToARGBRow_SSSE3(src_argb, row, pix);
648 ARGBToYRow_SSSE3(row, dst_y, pix);
mikhal@webrtc.org43575c82011-10-12 18:49:21 +0000649}
frkoenig@google.come5185422011-11-07 23:07:57 +0000650#endif
mikhal@webrtc.org43575c82011-10-12 18:49:21 +0000651
fbarchard@google.comb6149762011-11-07 21:58:52 +0000652#ifdef HAS_ARGBTOUVROW_SSSE3
653void ABGRToUVRow_SSSE3(const uint8* src_argb, int src_stride_argb,
654 uint8* dst_u, uint8* dst_v, int pix) {
655 SIMD_ALIGNED(uint8 row[kMaxStride * 2]);
656 ABGRToARGBRow_SSSE3(src_argb, row, pix);
657 ABGRToARGBRow_SSSE3(src_argb + src_stride_argb, row + kMaxStride, pix);
658 ARGBToUVRow_SSSE3(row, kMaxStride, dst_u, dst_v, pix);
mikhal@webrtc.org43575c82011-10-12 18:49:21 +0000659}
660
fbarchard@google.comb6149762011-11-07 21:58:52 +0000661void BGRAToUVRow_SSSE3(const uint8* src_argb, int src_stride_argb,
662 uint8* dst_u, uint8* dst_v, int pix) {
663 SIMD_ALIGNED(uint8 row[kMaxStride * 2]);
664 BGRAToARGBRow_SSSE3(src_argb, row, pix);
665 BGRAToARGBRow_SSSE3(src_argb + src_stride_argb, row + kMaxStride, pix);
666 ARGBToUVRow_SSSE3(row, kMaxStride, dst_u, dst_v, pix);
mikhal@webrtc.orgaed1cc92011-09-28 00:06:25 +0000667}
mikhal@webrtc.org120d5e72011-10-07 17:57:17 +0000668#endif
fbarchard@google.com9394ed92011-10-31 21:36:47 +0000669
mikhal@webrtc.orgaed1cc92011-09-28 00:06:25 +0000670} // extern "C"