row_posix.cc 141 KB
Newer Older
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1
/*
2
 *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
3 4 5 6 7 8 9 10
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

fbarchard@google.com's avatar
fbarchard@google.com committed
11
#include "source/row.h"
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
12

frkoenig@google.com's avatar
frkoenig@google.com committed
13 14
#include "libyuv/basic_types.h"

15 16
#ifdef __cplusplus
namespace libyuv {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
17
extern "C" {
18
#endif
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
19

20
// This module is for GCC x86 and x64
21
#if !defined(YUV_DISABLE_ASM) && (defined(__x86_64__) || defined(__i386__))
22

23 24
// GCC 4.2 on OSX has link error when passing static or const to inline.
// TODO(fbarchard): Use static const when gcc 4.2 support is dropped.
25 26 27 28 29 30
#ifdef __APPLE__
#define CONST
#else
#define CONST static const
#endif

31 32 33 34 35 36 37
#ifdef HAS_ARGBTOYROW_SSSE3

// Constants for ARGB
CONST vec8 kARGBToY = {
  13, 65, 33, 0, 13, 65, 33, 0, 13, 65, 33, 0, 13, 65, 33, 0
};

38
CONST vec8 kARGBToU = {
39 40 41
  112, -74, -38, 0, 112, -74, -38, 0, 112, -74, -38, 0, 112, -74, -38, 0
};

42 43
CONST vec8 kARGBToV = {
  -18, -94, 112, 0, -18, -94, 112, 0, -18, -94, 112, 0, -18, -94, 112, 0,
44
};
45

46 47 48
// Constants for BGRA
CONST vec8 kBGRAToY = {
  0, 33, 65, 13, 0, 33, 65, 13, 0, 33, 65, 13, 0, 33, 65, 13
49 50
};

51 52 53
CONST vec8 kBGRAToU = {
  0, -38, -74, 112, 0, -38, -74, 112, 0, -38, -74, 112, 0, -38, -74, 112
};
54

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
CONST vec8 kBGRAToV = {
  0, 112, -94, -18, 0, 112, -94, -18, 0, 112, -94, -18, 0, 112, -94, -18
};

// Constants for ABGR
CONST vec8 kABGRToY = {
  33, 65, 13, 0, 33, 65, 13, 0, 33, 65, 13, 0, 33, 65, 13, 0
};

CONST vec8 kABGRToU = {
  -38, -74, 112, 0, -38, -74, 112, 0, -38, -74, 112, 0, -38, -74, 112, 0
};

CONST vec8 kABGRToV = {
  112, -94, -18, 0, 112, -94, -18, 0, 112, -94, -18, 0, 112, -94, -18, 0
70 71
};

72
CONST uvec8 kAddY16 = {
73 74 75
  16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u
};

76 77 78 79 80
CONST uvec8 kAddUV128 = {
  128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u,
  128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u
};

81 82
// Shuffle table for converting RGB24 to ARGB.
CONST uvec8 kShuffleMaskRGB24ToARGB = {
83 84 85 86
  0u, 1u, 2u, 12u, 3u, 4u, 5u, 13u, 6u, 7u, 8u, 14u, 9u, 10u, 11u, 15u
};

// Shuffle table for converting RAW to ARGB.
87
CONST uvec8 kShuffleMaskRAWToARGB = {
88 89 90
  2u, 1u, 0u, 12u, 5u, 4u, 3u, 13u, 8u, 7u, 6u, 14u, 11u, 10u, 9u, 15u
};

91
// Shuffle table for converting ABGR to ARGB.
92
CONST uvec8 kShuffleMaskABGRToARGB = {
93 94 95 96
  2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u
};

// Shuffle table for converting BGRA to ARGB.
97
CONST uvec8 kShuffleMaskBGRAToARGB = {
98 99 100
  3u, 2u, 1u, 0u, 7u, 6u, 5u, 4u, 11u, 10u, 9u, 8u, 15u, 14u, 13u, 12u
};

fbarchard@google.com's avatar
fbarchard@google.com committed
101 102 103 104 105 106 107
// Shuffle table for converting ARGB to RGB24.
CONST uvec8 kShuffleMaskARGBToRGB24 = {
  0u, 1u, 2u, 4u, 5u, 6u, 8u, 9u, 10u, 12u, 13u, 14u, 128u, 128u, 128u, 128u
};

// Shuffle table for converting ARGB to RAW.
CONST uvec8 kShuffleMaskARGBToRAW = {
108
  2u, 1u, 0u, 6u, 5u, 4u, 10u, 9u, 8u, 14u, 13u, 12u, 128u, 128u, 128u, 128u
fbarchard@google.com's avatar
fbarchard@google.com committed
109 110
};

111
void I400ToARGBRow_SSE2(const uint8* src_y, uint8* dst_argb, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
112
  asm volatile (
113 114
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pslld     $0x18,%%xmm5                    \n"
115
    ".p2align  4                               \n"
116 117 118 119 120 121 122 123 124 125 126 127 128
  "1:                                          \n"
    "movq      (%0),%%xmm0                     \n"
    "lea       0x8(%0),%0                      \n"
    "punpcklbw %%xmm0,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm0,%%xmm0                   \n"
    "punpckhwd %%xmm1,%%xmm1                   \n"
    "por       %%xmm5,%%xmm0                   \n"
    "por       %%xmm5,%%xmm1                   \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "movdqa    %%xmm1,0x10(%1)                 \n"
    "lea       0x20(%1),%1                     \n"
    "sub       $0x8,%2                         \n"
129
    "jg        1b                              \n"
130 131 132 133 134 135 136 137
  : "+r"(src_y),     // %0
    "+r"(dst_argb),  // %1
    "+r"(pix)        // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm5"
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
138
  );
139
}
140 141

void ABGRToARGBRow_SSSE3(const uint8* src_abgr, uint8* dst_argb, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
142
  asm volatile (
143
    "movdqa    %3,%%xmm5                       \n"
144
    "sub       %0,%1                           \n"
145
    ".p2align  4                               \n"
146 147 148 149
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "pshufb    %%xmm5,%%xmm0                   \n"
    "sub       $0x4,%2                         \n"
150 151 152 153
    "movdqa    %%xmm0,(%0,%1,1)                \n"
    "lea       0x10(%0),%0                     \n"
    "jg        1b                              \n"

154 155 156 157 158 159 160
  : "+r"(src_abgr),  // %0
    "+r"(dst_argb),  // %1
    "+r"(pix)        // %2
  : "m"(kShuffleMaskABGRToARGB)  // %3
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm5"
161
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
162
  );
163 164 165
}

void BGRAToARGBRow_SSSE3(const uint8* src_bgra, uint8* dst_argb, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
166
  asm volatile (
167
    "movdqa    %3,%%xmm5                       \n"
168
    "sub       %0,%1                           \n"
169
    ".p2align  4                               \n"
170 171 172 173
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "pshufb    %%xmm5,%%xmm0                   \n"
    "sub       $0x4,%2                         \n"
174 175 176
    "movdqa    %%xmm0,(%0,%1,1)                \n"
    "lea       0x10(%0),%0                     \n"
    "jg        1b                              \n"
177 178 179 180 181 182 183 184
  : "+r"(src_bgra),  // %0
    "+r"(dst_argb),  // %1
    "+r"(pix)        // %2
  : "m"(kShuffleMaskBGRAToARGB)  // %3
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm5"
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
185
  );
186 187
}

188
void RGB24ToARGBRow_SSSE3(const uint8* src_rgb24, uint8* dst_argb, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
189
  asm volatile (
190 191 192
    "pcmpeqb   %%xmm5,%%xmm5                   \n"  // generate mask 0xff000000
    "pslld     $0x18,%%xmm5                    \n"
    "movdqa    %3,%%xmm4                       \n"
193
    ".p2align  4                               \n"
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    0x20(%0),%%xmm3                 \n"
    "lea       0x30(%0),%0                     \n"
    "movdqa    %%xmm3,%%xmm2                   \n"
    "palignr   $0x8,%%xmm1,%%xmm2              \n"
    "pshufb    %%xmm4,%%xmm2                   \n"
    "por       %%xmm5,%%xmm2                   \n"
    "palignr   $0xc,%%xmm0,%%xmm1              \n"
    "pshufb    %%xmm4,%%xmm0                   \n"
    "movdqa    %%xmm2,0x20(%1)                 \n"
    "por       %%xmm5,%%xmm0                   \n"
    "pshufb    %%xmm4,%%xmm1                   \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "por       %%xmm5,%%xmm1                   \n"
    "palignr   $0x4,%%xmm3,%%xmm3              \n"
    "pshufb    %%xmm4,%%xmm3                   \n"
    "movdqa    %%xmm1,0x10(%1)                 \n"
    "por       %%xmm5,%%xmm3                   \n"
214
    "sub       $0x10,%2                        \n"
215 216
    "movdqa    %%xmm3,0x30(%1)                 \n"
    "lea       0x40(%1),%1                     \n"
217
    "jg        1b                              \n"
218
  : "+r"(src_rgb24),  // %0
219 220
    "+r"(dst_argb),  // %1
    "+r"(pix)        // %2
221
  : "m"(kShuffleMaskRGB24ToARGB)  // %3
222 223 224 225
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
226
  );
227 228
}

229
void RAWToARGBRow_SSSE3(const uint8* src_raw, uint8* dst_argb, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
230
  asm volatile (
231 232 233
    "pcmpeqb   %%xmm5,%%xmm5                   \n"  // generate mask 0xff000000
    "pslld     $0x18,%%xmm5                    \n"
    "movdqa    %3,%%xmm4                       \n"
234
    ".p2align  4                               \n"
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    0x20(%0),%%xmm3                 \n"
    "lea       0x30(%0),%0                     \n"
    "movdqa    %%xmm3,%%xmm2                   \n"
    "palignr   $0x8,%%xmm1,%%xmm2              \n"
    "pshufb    %%xmm4,%%xmm2                   \n"
    "por       %%xmm5,%%xmm2                   \n"
    "palignr   $0xc,%%xmm0,%%xmm1              \n"
    "pshufb    %%xmm4,%%xmm0                   \n"
    "movdqa    %%xmm2,0x20(%1)                 \n"
    "por       %%xmm5,%%xmm0                   \n"
    "pshufb    %%xmm4,%%xmm1                   \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "por       %%xmm5,%%xmm1                   \n"
    "palignr   $0x4,%%xmm3,%%xmm3              \n"
    "pshufb    %%xmm4,%%xmm3                   \n"
    "movdqa    %%xmm1,0x10(%1)                 \n"
    "por       %%xmm5,%%xmm3                   \n"
255
    "sub       $0x10,%2                        \n"
256 257
    "movdqa    %%xmm3,0x30(%1)                 \n"
    "lea       0x40(%1),%1                     \n"
258
    "jg        1b                              \n"
259 260 261
  : "+r"(src_raw),   // %0
    "+r"(dst_argb),  // %1
    "+r"(pix)        // %2
262 263 264 265 266
  : "m"(kShuffleMaskRAWToARGB)  // %3
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
267 268 269 270
  );
}

void RGB565ToARGBRow_SSE2(const uint8* src, uint8* dst, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
271
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
272 273 274
    "mov       $0x1080108,%%eax                \n"
    "movd      %%eax,%%xmm5                    \n"
    "pshufd    $0x0,%%xmm5,%%xmm5              \n"
275
    "mov       $0x20802080,%%eax               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
276 277 278 279 280 281 282 283 284 285 286
    "movd      %%eax,%%xmm6                    \n"
    "pshufd    $0x0,%%xmm6,%%xmm6              \n"
    "pcmpeqb   %%xmm3,%%xmm3                   \n"
    "psllw     $0xb,%%xmm3                     \n"
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "psllw     $0xa,%%xmm4                     \n"
    "psrlw     $0x5,%%xmm4                     \n"
    "pcmpeqb   %%xmm7,%%xmm7                   \n"
    "psllw     $0x8,%%xmm7                     \n"
    "sub       %0,%1                           \n"
    "sub       %0,%1                           \n"
287
    ".p2align  4                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm0,%%xmm2                   \n"
    "pand      %%xmm3,%%xmm1                   \n"
    "psllw     $0xb,%%xmm2                     \n"
    "pmulhuw   %%xmm5,%%xmm1                   \n"
    "pmulhuw   %%xmm5,%%xmm2                   \n"
    "psllw     $0x8,%%xmm1                     \n"
    "por       %%xmm2,%%xmm1                   \n"
    "pand      %%xmm4,%%xmm0                   \n"
    "pmulhuw   %%xmm6,%%xmm0                   \n"
    "por       %%xmm7,%%xmm0                   \n"
    "movdqa    %%xmm1,%%xmm2                   \n"
    "punpcklbw %%xmm0,%%xmm1                   \n"
    "punpckhbw %%xmm0,%%xmm2                   \n"
    "movdqa    %%xmm1,(%1,%0,2)                \n"
    "movdqa    %%xmm2,0x10(%1,%0,2)            \n"
    "lea       0x10(%0),%0                     \n"
    "sub       $0x8,%2                         \n"
308
    "jg        1b                              \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
309 310 311 312 313 314 315 316 317 318 319 320
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(pix)   // %2
  :
  : "memory", "cc", "eax"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
#endif
  );
}

void ARGB1555ToARGBRow_SSE2(const uint8* src, uint8* dst, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
321
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335
    "mov       $0x1080108,%%eax                \n"
    "movd      %%eax,%%xmm5                    \n"
    "pshufd    $0x0,%%xmm5,%%xmm5              \n"
    "mov       $0x42004200,%%eax               \n"
    "movd      %%eax,%%xmm6                    \n"
    "pshufd    $0x0,%%xmm6,%%xmm6              \n"
    "pcmpeqb   %%xmm3,%%xmm3                   \n"
    "psllw     $0xb,%%xmm3                     \n"
    "movdqa    %%xmm3,%%xmm4                   \n"
    "psrlw     $0x6,%%xmm4                     \n"
    "pcmpeqb   %%xmm7,%%xmm7                   \n"
    "psllw     $0x8,%%xmm7                     \n"
    "sub       %0,%1                           \n"
    "sub       %0,%1                           \n"
336
    ".p2align  4                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm0,%%xmm2                   \n"
    "psllw     $0x1,%%xmm1                     \n"
    "psllw     $0xb,%%xmm2                     \n"
    "pand      %%xmm3,%%xmm1                   \n"
    "pmulhuw   %%xmm5,%%xmm2                   \n"
    "pmulhuw   %%xmm5,%%xmm1                   \n"
    "psllw     $0x8,%%xmm1                     \n"
    "por       %%xmm2,%%xmm1                   \n"
    "movdqa    %%xmm0,%%xmm2                   \n"
    "pand      %%xmm4,%%xmm0                   \n"
    "psraw     $0x8,%%xmm2                     \n"
    "pmulhuw   %%xmm6,%%xmm0                   \n"
    "pand      %%xmm7,%%xmm2                   \n"
    "por       %%xmm2,%%xmm0                   \n"
    "movdqa    %%xmm1,%%xmm2                   \n"
    "punpcklbw %%xmm0,%%xmm1                   \n"
    "punpckhbw %%xmm0,%%xmm2                   \n"
    "movdqa    %%xmm1,(%1,%0,2)                \n"
    "movdqa    %%xmm2,0x10(%1,%0,2)            \n"
    "lea       0x10(%0),%0                     \n"
    "sub       $0x8,%2                         \n"
361
    "jg        1b                              \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
362 363 364 365 366 367 368 369 370 371 372 373
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(pix)   // %2
  :
  : "memory", "cc", "eax"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
#endif
  );
}

void ARGB4444ToARGBRow_SSE2(const uint8* src, uint8* dst, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
374
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
375 376 377 378 379 380 381
    "mov       $0xf0f0f0f,%%eax                \n"
    "movd      %%eax,%%xmm4                    \n"
    "pshufd    $0x0,%%xmm4,%%xmm4              \n"
    "movdqa    %%xmm4,%%xmm5                   \n"
    "pslld     $0x4,%%xmm5                     \n"
    "sub       %0,%1                           \n"
    "sub       %0,%1                           \n"
382
    ".p2align  4                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqa    %%xmm0,%%xmm2                   \n"
    "pand      %%xmm4,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm2,%%xmm3                   \n"
    "psllw     $0x4,%%xmm1                     \n"
    "psrlw     $0x4,%%xmm3                     \n"
    "por       %%xmm1,%%xmm0                   \n"
    "por       %%xmm3,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklbw %%xmm2,%%xmm0                   \n"
    "punpckhbw %%xmm2,%%xmm1                   \n"
    "movdqa    %%xmm0,(%1,%0,2)                \n"
    "movdqa    %%xmm1,0x10(%1,%0,2)            \n"
    "lea       0x10(%0),%0                     \n"
    "sub       $0x8,%2                         \n"
401
    "jg        1b                              \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
402 403 404 405 406 407 408 409 410
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(pix)   // %2
  :
  : "memory", "cc", "eax"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
411 412
}

fbarchard@google.com's avatar
fbarchard@google.com committed
413
void ARGBToRGB24Row_SSSE3(const uint8* src, uint8* dst, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
414
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
415
    "movdqa    %3,%%xmm6                       \n"
416
    ".p2align  4                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm3                 \n"
    "lea       0x40(%0),%0                     \n"
    "pshufb    %%xmm6,%%xmm0                   \n"
    "pshufb    %%xmm6,%%xmm1                   \n"
    "pshufb    %%xmm6,%%xmm2                   \n"
    "pshufb    %%xmm6,%%xmm3                   \n"
    "movdqa    %%xmm1,%%xmm4                   \n"
    "psrldq    $0x4,%%xmm1                     \n"
    "pslldq    $0xc,%%xmm4                     \n"
    "movdqa    %%xmm2,%%xmm5                   \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pslldq    $0x8,%%xmm5                     \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "por       %%xmm5,%%xmm1                   \n"
    "psrldq    $0x8,%%xmm2                     \n"
    "pslldq    $0x4,%%xmm3                     \n"
    "por       %%xmm3,%%xmm2                   \n"
    "movdqa    %%xmm1,0x10(%1)                 \n"
    "movdqa    %%xmm2,0x20(%1)                 \n"
    "lea       0x30(%1),%1                     \n"
    "sub       $0x10,%2                        \n"
442
    "jg        1b                              \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
443 444 445 446 447 448 449 450 451 452 453 454
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(pix)   // %2
  : "m"(kShuffleMaskARGBToRGB24)  // %3
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"
#endif
  );
}

void ARGBToRAWRow_SSSE3(const uint8* src, uint8* dst, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
455
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
456
    "movdqa    %3,%%xmm6                       \n"
457
    ".p2align  4                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm3                 \n"
    "lea       0x40(%0),%0                     \n"
    "pshufb    %%xmm6,%%xmm0                   \n"
    "pshufb    %%xmm6,%%xmm1                   \n"
    "pshufb    %%xmm6,%%xmm2                   \n"
    "pshufb    %%xmm6,%%xmm3                   \n"
    "movdqa    %%xmm1,%%xmm4                   \n"
    "psrldq    $0x4,%%xmm1                     \n"
    "pslldq    $0xc,%%xmm4                     \n"
    "movdqa    %%xmm2,%%xmm5                   \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pslldq    $0x8,%%xmm5                     \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "por       %%xmm5,%%xmm1                   \n"
    "psrldq    $0x8,%%xmm2                     \n"
    "pslldq    $0x4,%%xmm3                     \n"
    "por       %%xmm3,%%xmm2                   \n"
    "movdqa    %%xmm1,0x10(%1)                 \n"
    "movdqa    %%xmm2,0x20(%1)                 \n"
    "lea       0x30(%1),%1                     \n"
    "sub       $0x10,%2                        \n"
483
    "jg        1b                              \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
484 485 486 487 488 489 490 491 492 493 494 495
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(pix)   // %2
  : "m"(kShuffleMaskARGBToRAW)  // %3
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"
#endif
  );
}

void ARGBToRGB565Row_SSE2(const uint8* src, uint8* dst, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
496
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
497 498 499 500 501 502 503
    "pcmpeqb   %%xmm3,%%xmm3                   \n"
    "psrld     $0x1b,%%xmm3                    \n"
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "psrld     $0x1a,%%xmm4                    \n"
    "pslld     $0x5,%%xmm4                     \n"
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pslld     $0xb,%%xmm5                     \n"
504
    ".p2align  4                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm0,%%xmm2                   \n"
    "pslld     $0x8,%%xmm0                     \n"
    "psrld     $0x3,%%xmm1                     \n"
    "psrld     $0x5,%%xmm2                     \n"
    "psrad     $0x10,%%xmm0                    \n"
    "pand      %%xmm3,%%xmm1                   \n"
    "pand      %%xmm4,%%xmm2                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "por       %%xmm2,%%xmm1                   \n"
    "por       %%xmm1,%%xmm0                   \n"
    "packssdw  %%xmm0,%%xmm0                   \n"
    "lea       0x10(%0),%0                     \n"
    "movq      %%xmm0,(%1)                     \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x4,%2                         \n"
523
    "jg        1b                              \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
524 525 526 527 528 529 530 531 532 533 534 535
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(pix)   // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void ARGBToARGB1555Row_SSE2(const uint8* src, uint8* dst, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
536
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
537 538 539 540 541 542 543 544
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "psrld     $0x1b,%%xmm4                    \n"
    "movdqa    %%xmm4,%%xmm5                   \n"
    "pslld     $0x5,%%xmm5                     \n"
    "movdqa    %%xmm4,%%xmm6                   \n"
    "pslld     $0xa,%%xmm6                     \n"
    "pcmpeqb   %%xmm7,%%xmm7                   \n"
    "pslld     $0xf,%%xmm7                     \n"
545
    ".p2align  4                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm0,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm3                   \n"
    "psrad     $0x10,%%xmm0                    \n"
    "psrld     $0x3,%%xmm1                     \n"
    "psrld     $0x6,%%xmm2                     \n"
    "psrld     $0x9,%%xmm3                     \n"
    "pand      %%xmm7,%%xmm0                   \n"
    "pand      %%xmm4,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm2                   \n"
    "pand      %%xmm6,%%xmm3                   \n"
    "por       %%xmm1,%%xmm0                   \n"
    "por       %%xmm3,%%xmm2                   \n"
    "por       %%xmm2,%%xmm0                   \n"
    "packssdw  %%xmm0,%%xmm0                   \n"
    "lea       0x10(%0),%0                     \n"
    "movq      %%xmm0,(%1)                     \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x4,%2                         \n"
567
    "jg        1b                              \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
568 569 570 571 572 573 574 575 576 577 578 579
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(pix)   // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
#endif
  );
}

void ARGBToARGB4444Row_SSE2(const uint8* src, uint8* dst, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
580
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
581 582 583 584
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "psllw     $0xc,%%xmm4                     \n"
    "movdqa    %%xmm4,%%xmm3                   \n"
    "psrlw     $0x8,%%xmm3                     \n"
585
    ".p2align  4                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
586 587 588 589 590 591 592 593 594 595 596 597 598
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm3,%%xmm0                   \n"
    "pand      %%xmm4,%%xmm1                   \n"
    "psrlq     $0x4,%%xmm0                     \n"
    "psrlq     $0x8,%%xmm1                     \n"
    "por       %%xmm1,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "lea       0x10(%0),%0                     \n"
    "movq      %%xmm0,(%1)                     \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x4,%2                         \n"
599
    "jg        1b                              \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
600 601 602 603 604 605 606 607 608 609 610
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(pix)   // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"
#endif
  );
}

611
void ARGBToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
612
  asm volatile (
613 614
    "movdqa    %4,%%xmm5                       \n"
    "movdqa    %3,%%xmm4                       \n"
615
    ".p2align  4                               \n"
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm3                 \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm4,%%xmm3                   \n"
    "lea       0x40(%0),%0                     \n"
    "phaddw    %%xmm1,%%xmm0                   \n"
    "phaddw    %%xmm3,%%xmm2                   \n"
    "psrlw     $0x7,%%xmm0                     \n"
    "psrlw     $0x7,%%xmm2                     \n"
    "packuswb  %%xmm2,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
632
    "sub       $0x10,%2                        \n"
633 634
    "movdqa    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
635
    "jg        1b                              \n"
636 637 638 639 640 641 642 643 644
  : "+r"(src_argb),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  : "m"(kARGBToY),   // %3
    "m"(kAddY16)     // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
645
  );
646 647 648
}

void ARGBToYRow_Unaligned_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
649
  asm volatile (
650 651
    "movdqa    %4,%%xmm5                       \n"
    "movdqa    %3,%%xmm4                       \n"
652
    ".p2align  4                               \n"
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    0x20(%0),%%xmm2                 \n"
    "movdqu    0x30(%0),%%xmm3                 \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm4,%%xmm3                   \n"
    "lea       0x40(%0),%0                     \n"
    "phaddw    %%xmm1,%%xmm0                   \n"
    "phaddw    %%xmm3,%%xmm2                   \n"
    "psrlw     $0x7,%%xmm0                     \n"
    "psrlw     $0x7,%%xmm2                     \n"
    "packuswb  %%xmm2,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
669
    "sub       $0x10,%2                        \n"
670 671
    "movdqu    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
672
    "jg        1b                              \n"
673 674 675 676 677 678 679 680 681
  : "+r"(src_argb),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  : "m"(kARGBToY),   // %3
    "m"(kAddY16)     // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
682
  );
683
}
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
684

685 686 687 688 689
// TODO(fbarchard): pass xmm constants to single block of assembly.
// fpic on GCC 4.2 for OSX runs out of GPR registers.  "m" effectively takes
// 3 registers - ebx, ebp and eax.  "m" can be passed with 3 normal registers,
// or 4 if stack frame is disabled.  Doing 2 assembly blocks is a work around
// and considered unsafe.
690 691
void ARGBToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
                       uint8* dst_u, uint8* dst_v, int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
692
  asm volatile (
693 694 695
    "movdqa    %0,%%xmm4                       \n"
    "movdqa    %1,%%xmm3                       \n"
    "movdqa    %2,%%xmm5                       \n"
696
  :
697 698 699
  : "m"(kARGBToU),  // %0
    "m"(kARGBToV),  // %1
    "m"(kAddUV128)  // %2
fbarchard@google.com's avatar
fbarchard@google.com committed
700
  );
fbarchard@google.com's avatar
fbarchard@google.com committed
701
  asm volatile (
702
    "sub       %1,%2                           \n"
703
    ".p2align  4                               \n"
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm6                 \n"
    "pavgb     (%0,%4,1),%%xmm0                \n"
    "pavgb     0x10(%0,%4,1),%%xmm1            \n"
    "pavgb     0x20(%0,%4,1),%%xmm2            \n"
    "pavgb     0x30(%0,%4,1),%%xmm6            \n"
    "lea       0x40(%0),%0                     \n"
    "movdqa    %%xmm0,%%xmm7                   \n"
    "shufps    $0x88,%%xmm1,%%xmm0             \n"
    "shufps    $0xdd,%%xmm1,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqa    %%xmm2,%%xmm7                   \n"
    "shufps    $0x88,%%xmm6,%%xmm2             \n"
    "shufps    $0xdd,%%xmm6,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm2,%%xmm6                   \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm3,%%xmm1                   \n"
    "pmaddubsw %%xmm3,%%xmm6                   \n"
    "phaddw    %%xmm2,%%xmm0                   \n"
    "phaddw    %%xmm6,%%xmm1                   \n"
    "psraw     $0x8,%%xmm0                     \n"
    "psraw     $0x8,%%xmm1                     \n"
    "packsswb  %%xmm1,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
734
    "sub       $0x10,%3                        \n"
735 736 737
    "movlps    %%xmm0,(%1)                     \n"
    "movhps    %%xmm0,(%1,%2,1)                \n"
    "lea       0x8(%1),%1                      \n"
738
    "jg        1b                              \n"
739 740 741 742
  : "+r"(src_argb0),       // %0
    "+r"(dst_u),           // %1
    "+r"(dst_v),           // %2
    "+rm"(width)           // %3
743
  : "r"(static_cast<intptr_t>(src_stride_argb))
744 745
  : "memory", "cc"
#if defined(__SSE2__)
746
    , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"
747
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
748
  );
749
}
750 751 752

void ARGBToUVRow_Unaligned_SSSE3(const uint8* src_argb0, int src_stride_argb,
                                 uint8* dst_u, uint8* dst_v, int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
753
  asm volatile (
754 755 756
    "movdqa    %0,%%xmm4                       \n"
    "movdqa    %1,%%xmm3                       \n"
    "movdqa    %2,%%xmm5                       \n"
757 758 759 760
  :
  : "m"(kARGBToU),         // %0
    "m"(kARGBToV),         // %1
    "m"(kAddUV128)         // %2
fbarchard@google.com's avatar
fbarchard@google.com committed
761
  );
fbarchard@google.com's avatar
fbarchard@google.com committed
762
  asm volatile (
763
    "sub       %1,%2                           \n"
764
    ".p2align  4                               \n"
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    0x20(%0),%%xmm2                 \n"
    "movdqu    0x30(%0),%%xmm6                 \n"
    "movdqu    (%0,%4,1),%%xmm7                \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqu    0x10(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm1                   \n"
    "movdqu    0x20(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqu    0x30(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm6                   \n"
    "lea       0x40(%0),%0                     \n"
    "movdqa    %%xmm0,%%xmm7                   \n"
    "shufps    $0x88,%%xmm1,%%xmm0             \n"
    "shufps    $0xdd,%%xmm1,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqa    %%xmm2,%%xmm7                   \n"
    "shufps    $0x88,%%xmm6,%%xmm2             \n"
    "shufps    $0xdd,%%xmm6,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm2,%%xmm6                   \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm3,%%xmm1                   \n"
    "pmaddubsw %%xmm3,%%xmm6                   \n"
    "phaddw    %%xmm2,%%xmm0                   \n"
    "phaddw    %%xmm6,%%xmm1                   \n"
    "psraw     $0x8,%%xmm0                     \n"
    "psraw     $0x8,%%xmm1                     \n"
    "packsswb  %%xmm1,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
799
    "sub       $0x10,%3                        \n"
800 801 802
    "movlps    %%xmm0,(%1)                     \n"
    "movhps    %%xmm0,(%1,%2,1)                \n"
    "lea       0x8(%1),%1                      \n"
803
    "jg        1b                              \n"
804 805 806 807 808 809 810 811 812
  : "+r"(src_argb0),       // %0
    "+r"(dst_u),           // %1
    "+r"(dst_v),           // %2
    "+rm"(width)           // %3
  : "r"(static_cast<intptr_t>(src_stride_argb))
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
813
  );
814
}
815 816

void BGRAToYRow_SSSE3(const uint8* src_bgra, uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
817
  asm volatile (
818 819
    "movdqa    %4,%%xmm5                       \n"
    "movdqa    %3,%%xmm4                       \n"
820
    ".p2align  4                               \n"
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm3                 \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm4,%%xmm3                   \n"
    "lea       0x40(%0),%0                     \n"
    "phaddw    %%xmm1,%%xmm0                   \n"
    "phaddw    %%xmm3,%%xmm2                   \n"
    "psrlw     $0x7,%%xmm0                     \n"
    "psrlw     $0x7,%%xmm2                     \n"
    "packuswb  %%xmm2,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
837
    "sub       $0x10,%2                        \n"
838 839
    "movdqa    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
840
    "jg        1b                              \n"
841 842 843 844 845 846 847 848 849 850 851 852 853
  : "+r"(src_bgra),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  : "m"(kBGRAToY),   // %3
    "m"(kAddY16)     // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void BGRAToYRow_Unaligned_SSSE3(const uint8* src_bgra, uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
854
  asm volatile (
855 856
    "movdqa    %4,%%xmm5                       \n"
    "movdqa    %3,%%xmm4                       \n"
857
    ".p2align  4                               \n"
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    0x20(%0),%%xmm2                 \n"
    "movdqu    0x30(%0),%%xmm3                 \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm4,%%xmm3                   \n"
    "lea       0x40(%0),%0                     \n"
    "phaddw    %%xmm1,%%xmm0                   \n"
    "phaddw    %%xmm3,%%xmm2                   \n"
    "psrlw     $0x7,%%xmm0                     \n"
    "psrlw     $0x7,%%xmm2                     \n"
    "packuswb  %%xmm2,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
874
    "sub       $0x10,%2                        \n"
875 876
    "movdqu    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
877
    "jg        1b                              \n"
878 879 880 881 882 883 884 885 886 887 888 889 890 891
  : "+r"(src_bgra),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  : "m"(kBGRAToY),   // %3
    "m"(kAddY16)     // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void BGRAToUVRow_SSSE3(const uint8* src_bgra0, int src_stride_bgra,
                       uint8* dst_u, uint8* dst_v, int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
892
  asm volatile (
893 894 895 896 897 898 899 900
    "movdqa    %0,%%xmm4                       \n"
    "movdqa    %1,%%xmm3                       \n"
    "movdqa    %2,%%xmm5                       \n"
  :
  : "m"(kBGRAToU),         // %0
    "m"(kBGRAToV),         // %1
    "m"(kAddUV128)         // %2
  );
fbarchard@google.com's avatar
fbarchard@google.com committed
901
  asm volatile (
902
    "sub       %1,%2                           \n"
903
    ".p2align  4                               \n"
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm6                 \n"
    "pavgb     (%0,%4,1),%%xmm0                \n"
    "pavgb     0x10(%0,%4,1),%%xmm1            \n"
    "pavgb     0x20(%0,%4,1),%%xmm2            \n"
    "pavgb     0x30(%0,%4,1),%%xmm6            \n"
    "lea       0x40(%0),%0                     \n"
    "movdqa    %%xmm0,%%xmm7                   \n"
    "shufps    $0x88,%%xmm1,%%xmm0             \n"
    "shufps    $0xdd,%%xmm1,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqa    %%xmm2,%%xmm7                   \n"
    "shufps    $0x88,%%xmm6,%%xmm2             \n"
    "shufps    $0xdd,%%xmm6,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm2,%%xmm6                   \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm3,%%xmm1                   \n"
    "pmaddubsw %%xmm3,%%xmm6                   \n"
    "phaddw    %%xmm2,%%xmm0                   \n"
    "phaddw    %%xmm6,%%xmm1                   \n"
    "psraw     $0x8,%%xmm0                     \n"
    "psraw     $0x8,%%xmm1                     \n"
    "packsswb  %%xmm1,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
934
    "sub       $0x10,%3                        \n"
935 936 937
    "movlps    %%xmm0,(%1)                     \n"
    "movhps    %%xmm0,(%1,%2,1)                \n"
    "lea       0x8(%1),%1                      \n"
938
    "jg        1b                              \n"
939 940 941 942 943 944 945 946 947 948 949 950 951 952
  : "+r"(src_bgra0),       // %0
    "+r"(dst_u),           // %1
    "+r"(dst_v),           // %2
    "+rm"(width)           // %3
  : "r"(static_cast<intptr_t>(src_stride_bgra))
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"
#endif
  );
}

void BGRAToUVRow_Unaligned_SSSE3(const uint8* src_bgra0, int src_stride_bgra,
                                 uint8* dst_u, uint8* dst_v, int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
953
  asm volatile (
954 955 956 957 958 959 960 961
    "movdqa    %0,%%xmm4                       \n"
    "movdqa    %1,%%xmm3                       \n"
    "movdqa    %2,%%xmm5                       \n"
  :
  : "m"(kBGRAToU),         // %0
    "m"(kBGRAToV),         // %1
    "m"(kAddUV128)         // %2
  );
fbarchard@google.com's avatar
fbarchard@google.com committed
962
  asm volatile (
963
    "sub       %1,%2                           \n"
964
    ".p2align  4                               \n"
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    0x20(%0),%%xmm2                 \n"
    "movdqu    0x30(%0),%%xmm6                 \n"
    "movdqu    (%0,%4,1),%%xmm7                \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqu    0x10(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm1                   \n"
    "movdqu    0x20(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqu    0x30(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm6                   \n"
    "lea       0x40(%0),%0                     \n"
    "movdqa    %%xmm0,%%xmm7                   \n"
    "shufps    $0x88,%%xmm1,%%xmm0             \n"
    "shufps    $0xdd,%%xmm1,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqa    %%xmm2,%%xmm7                   \n"
    "shufps    $0x88,%%xmm6,%%xmm2             \n"
    "shufps    $0xdd,%%xmm6,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm2,%%xmm6                   \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm3,%%xmm1                   \n"
    "pmaddubsw %%xmm3,%%xmm6                   \n"
    "phaddw    %%xmm2,%%xmm0                   \n"
    "phaddw    %%xmm6,%%xmm1                   \n"
    "psraw     $0x8,%%xmm0                     \n"
    "psraw     $0x8,%%xmm1                     \n"
    "packsswb  %%xmm1,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
999
    "sub       $0x10,%3                        \n"
1000 1001 1002
    "movlps    %%xmm0,(%1)                     \n"
    "movhps    %%xmm0,(%1,%2,1)                \n"
    "lea       0x8(%1),%1                      \n"
1003
    "jg        1b                              \n"
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
  : "+r"(src_bgra0),       // %0
    "+r"(dst_u),           // %1
    "+r"(dst_v),           // %2
    "+rm"(width)           // %3
  : "r"(static_cast<intptr_t>(src_stride_bgra))
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"
#endif
  );
}

void ABGRToYRow_SSSE3(const uint8* src_abgr, uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1017
  asm volatile (
1018 1019
    "movdqa    %4,%%xmm5                       \n"
    "movdqa    %3,%%xmm4                       \n"
1020
    ".p2align  4                               \n"
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm3                 \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm4,%%xmm3                   \n"
    "lea       0x40(%0),%0                     \n"
    "phaddw    %%xmm1,%%xmm0                   \n"
    "phaddw    %%xmm3,%%xmm2                   \n"
    "psrlw     $0x7,%%xmm0                     \n"
    "psrlw     $0x7,%%xmm2                     \n"
    "packuswb  %%xmm2,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
1037
    "sub       $0x10,%2                        \n"
1038 1039
    "movdqa    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
1040
    "jg        1b                              \n"
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
  : "+r"(src_abgr),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  : "m"(kABGRToY),   // %3
    "m"(kAddY16)     // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void ABGRToYRow_Unaligned_SSSE3(const uint8* src_abgr, uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1054
  asm volatile (
1055 1056
    "movdqa    %4,%%xmm5                       \n"
    "movdqa    %3,%%xmm4                       \n"
1057
    ".p2align  4                               \n"
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    0x20(%0),%%xmm2                 \n"
    "movdqu    0x30(%0),%%xmm3                 \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm4,%%xmm3                   \n"
    "lea       0x40(%0),%0                     \n"
    "phaddw    %%xmm1,%%xmm0                   \n"
    "phaddw    %%xmm3,%%xmm2                   \n"
    "psrlw     $0x7,%%xmm0                     \n"
    "psrlw     $0x7,%%xmm2                     \n"
    "packuswb  %%xmm2,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
1074
    "sub       $0x10,%2                        \n"
1075 1076
    "movdqu    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
1077
    "jg        1b                              \n"
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
  : "+r"(src_abgr),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  : "m"(kABGRToY),   // %3
    "m"(kAddY16)     // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void ABGRToUVRow_SSSE3(const uint8* src_abgr0, int src_stride_abgr,
                       uint8* dst_u, uint8* dst_v, int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1092
  asm volatile (
1093 1094 1095 1096 1097 1098 1099 1100
    "movdqa    %0,%%xmm4                       \n"
    "movdqa    %1,%%xmm3                       \n"
    "movdqa    %2,%%xmm5                       \n"
  :
  : "m"(kABGRToU),         // %0
    "m"(kABGRToV),         // %1
    "m"(kAddUV128)         // %2
  );
fbarchard@google.com's avatar
fbarchard@google.com committed
1101
  asm volatile (
1102
    "sub       %1,%2                           \n"
1103
    ".p2align  4                               \n"
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm6                 \n"
    "pavgb     (%0,%4,1),%%xmm0                \n"
    "pavgb     0x10(%0,%4,1),%%xmm1            \n"
    "pavgb     0x20(%0,%4,1),%%xmm2            \n"
    "pavgb     0x30(%0,%4,1),%%xmm6            \n"
    "lea       0x40(%0),%0                     \n"
    "movdqa    %%xmm0,%%xmm7                   \n"
    "shufps    $0x88,%%xmm1,%%xmm0             \n"
    "shufps    $0xdd,%%xmm1,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqa    %%xmm2,%%xmm7                   \n"
    "shufps    $0x88,%%xmm6,%%xmm2             \n"
    "shufps    $0xdd,%%xmm6,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm2,%%xmm6                   \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm3,%%xmm1                   \n"
    "pmaddubsw %%xmm3,%%xmm6                   \n"
    "phaddw    %%xmm2,%%xmm0                   \n"
    "phaddw    %%xmm6,%%xmm1                   \n"
    "psraw     $0x8,%%xmm0                     \n"
    "psraw     $0x8,%%xmm1                     \n"
    "packsswb  %%xmm1,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
1134
    "sub       $0x10,%3                        \n"
1135 1136 1137
    "movlps    %%xmm0,(%1)                     \n"
    "movhps    %%xmm0,(%1,%2,1)                \n"
    "lea       0x8(%1),%1                      \n"
1138
    "jg        1b                              \n"
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
  : "+r"(src_abgr0),       // %0
    "+r"(dst_u),           // %1
    "+r"(dst_v),           // %2
    "+rm"(width)           // %3
  : "r"(static_cast<intptr_t>(src_stride_abgr))
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"
#endif
  );
}

void ABGRToUVRow_Unaligned_SSSE3(const uint8* src_abgr0, int src_stride_abgr,
                                 uint8* dst_u, uint8* dst_v, int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1153
  asm volatile (
1154 1155 1156 1157 1158 1159 1160 1161
    "movdqa    %0,%%xmm4                       \n"
    "movdqa    %1,%%xmm3                       \n"
    "movdqa    %2,%%xmm5                       \n"
  :
  : "m"(kABGRToU),         // %0
    "m"(kABGRToV),         // %1
    "m"(kAddUV128)         // %2
  );
fbarchard@google.com's avatar
fbarchard@google.com committed
1162
  asm volatile (
1163
    "sub       %1,%2                           \n"
1164
    ".p2align  4                               \n"
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    0x20(%0),%%xmm2                 \n"
    "movdqu    0x30(%0),%%xmm6                 \n"
    "movdqu    (%0,%4,1),%%xmm7                \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqu    0x10(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm1                   \n"
    "movdqu    0x20(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqu    0x30(%0,%4,1),%%xmm7            \n"
    "pavgb     %%xmm7,%%xmm6                   \n"
    "lea       0x40(%0),%0                     \n"
    "movdqa    %%xmm0,%%xmm7                   \n"
    "shufps    $0x88,%%xmm1,%%xmm0             \n"
    "shufps    $0xdd,%%xmm1,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm0                   \n"
    "movdqa    %%xmm2,%%xmm7                   \n"
    "shufps    $0x88,%%xmm6,%%xmm2             \n"
    "shufps    $0xdd,%%xmm6,%%xmm7             \n"
    "pavgb     %%xmm7,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "movdqa    %%xmm2,%%xmm6                   \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm2                   \n"
    "pmaddubsw %%xmm3,%%xmm1                   \n"
    "pmaddubsw %%xmm3,%%xmm6                   \n"
    "phaddw    %%xmm2,%%xmm0                   \n"
    "phaddw    %%xmm6,%%xmm1                   \n"
    "psraw     $0x8,%%xmm0                     \n"
    "psraw     $0x8,%%xmm1                     \n"
    "packsswb  %%xmm1,%%xmm0                   \n"
    "paddb     %%xmm5,%%xmm0                   \n"
1199
    "sub       $0x10,%3                        \n"
1200 1201 1202
    "movlps    %%xmm0,(%1)                     \n"
    "movhps    %%xmm0,(%1,%2,1)                \n"
    "lea       0x8(%1),%1                      \n"
1203
    "jg        1b                              \n"
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
  : "+r"(src_abgr0),       // %0
    "+r"(dst_u),           // %1
    "+r"(dst_v),           // %2
    "+rm"(width)           // %3
  : "r"(static_cast<intptr_t>(src_stride_abgr))
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7"
#endif
  );
}
#endif  // HAS_ARGBTOYROW_SSSE3
1216

1217
#ifdef HAS_I422TOARGBROW_SSSE3
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
#define UB 127 /* min(63,static_cast<int8>(2.018 * 64)) */
#define UG -25 /* static_cast<int8>(-0.391 * 64 - 0.5) */
#define UR 0

#define VB 0
#define VG -52 /* static_cast<int8>(-0.813 * 64 - 0.5) */
#define VR 102 /* static_cast<int8>(1.596 * 64 + 0.5) */

// Bias
#define BB UB * 128 + VB * 128
#define BG UG * 128 + VG * 128
#define BR UR * 128 + VR * 128

1231
#define YG 74 /* static_cast<int8>(1.164 * 64 + 0.5) */
1232

1233
struct {
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
  vec8 kUVToB;  // 0
  vec8 kUVToG;  // 16
  vec8 kUVToR;  // 32
  vec16 kUVBiasB;  // 48
  vec16 kUVBiasG;  // 64
  vec16 kUVBiasR;  // 80
  vec16 kYSub16;  // 96
  vec16 kYToRgb;  // 112
  vec8 kVUToB;  // 128
  vec8 kVUToG;  // 144
  vec8 kVUToR;  // 160
1245
} CONST SIMD_ALIGNED(kYuvConstants) = {
1246 1247 1248 1249 1250 1251 1252
  { UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB },
  { UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG },
  { UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR },
  { BB, BB, BB, BB, BB, BB, BB, BB },
  { BG, BG, BG, BG, BG, BG, BG, BG },
  { BR, BR, BR, BR, BR, BR, BR, BR },
  { 16, 16, 16, 16, 16, 16, 16, 16 },
1253 1254 1255 1256
  { YG, YG, YG, YG, YG, YG, YG, YG },
  { VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB },
  { VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG },
  { VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR }
1257 1258
};

1259

1260 1261
// Read 8 UV from 411
#define READYUV444                                                             \
1262 1263 1264
    "movq       (%[u_buf]),%%xmm0              \n"                             \
    "movq       (%[u_buf],%[v_buf],1),%%xmm1   \n"                             \
    "lea        0x8(%[u_buf]),%[u_buf]         \n"                             \
1265 1266
    "punpcklbw  %%xmm1,%%xmm0                  \n"                             \

1267 1268
// Read 4 UV from 422, upsample to 8 UV
#define READYUV422                                                             \
1269 1270 1271
    "movd       (%[u_buf]),%%xmm0              \n"                             \
    "movd       (%[u_buf],%[v_buf],1),%%xmm1   \n"                             \
    "lea        0x4(%[u_buf]),%[u_buf]         \n"                             \
1272 1273 1274
    "punpcklbw  %%xmm1,%%xmm0                  \n"                             \
    "punpcklwd  %%xmm0,%%xmm0                  \n"                             \

1275 1276
// Read 2 UV from 411, upsample to 8 UV
#define READYUV411                                                             \
1277 1278 1279
    "movd       (%[u_buf]),%%xmm0              \n"                             \
    "movd       (%[u_buf],%[v_buf],1),%%xmm1   \n"                             \
    "lea        0x2(%[u_buf]),%[u_buf]         \n"                             \
1280 1281 1282
    "punpcklbw  %%xmm1,%%xmm0                  \n"                             \
    "punpcklwd  %%xmm0,%%xmm0                  \n"                             \
    "punpckldq  %%xmm0,%%xmm0                  \n"                             \
1283

1284 1285 1286 1287 1288 1289
// Read 4 UV from NV12, upsample to 8 UV
#define READNV12                                                               \
    "movq       (%[uv_buf]),%%xmm0             \n"                             \
    "lea        0x8(%[uv_buf]),%[uv_buf]       \n"                             \
    "punpcklbw  %%xmm1,%%xmm0                  \n"                             \

1290 1291
// Convert 8 pixels: 8 UV and 8 Y
#define YUVTORGB                                                               \
1292 1293
    "movdqa     %%xmm0,%%xmm1                  \n"                             \
    "movdqa     %%xmm0,%%xmm2                  \n"                             \
1294 1295 1296 1297 1298 1299 1300 1301
    "pmaddubsw  (%[kYuvConstants]),%%xmm0      \n"                             \
    "pmaddubsw  16(%[kYuvConstants]),%%xmm1    \n"                             \
    "pmaddubsw  32(%[kYuvConstants]),%%xmm2    \n"                             \
    "psubw      48(%[kYuvConstants]),%%xmm0    \n"                             \
    "psubw      64(%[kYuvConstants]),%%xmm1    \n"                             \
    "psubw      80(%[kYuvConstants]),%%xmm2    \n"                             \
    "movq       (%[y_buf]),%%xmm3              \n"                             \
    "lea        0x8(%[y_buf]),%[y_buf]         \n"                             \
1302
    "punpcklbw  %%xmm4,%%xmm3                  \n"                             \
1303 1304
    "psubsw     96(%[kYuvConstants]),%%xmm3    \n"                             \
    "pmullw     112(%[kYuvConstants]),%%xmm3   \n"                             \
1305 1306 1307 1308 1309 1310 1311 1312
    "paddsw     %%xmm3,%%xmm0                  \n"                             \
    "paddsw     %%xmm3,%%xmm1                  \n"                             \
    "paddsw     %%xmm3,%%xmm2                  \n"                             \
    "psraw      $0x6,%%xmm0                    \n"                             \
    "psraw      $0x6,%%xmm1                    \n"                             \
    "psraw      $0x6,%%xmm2                    \n"                             \
    "packuswb   %%xmm0,%%xmm0                  \n"                             \
    "packuswb   %%xmm1,%%xmm1                  \n"                             \
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338
    "packuswb   %%xmm2,%%xmm2                  \n"                             \

// Convert 8 pixels: 8 VU and 8 Y
#define YVUTORGB                                                               \
    "movdqa     %%xmm0,%%xmm1                  \n"                             \
    "movdqa     %%xmm0,%%xmm2                  \n"                             \
    "pmaddubsw  128(%[kYuvConstants]),%%xmm0   \n"                             \
    "pmaddubsw  144(%[kYuvConstants]),%%xmm1   \n"                             \
    "pmaddubsw  160(%[kYuvConstants]),%%xmm2   \n"                             \
    "psubw      48(%[kYuvConstants]),%%xmm0    \n"                             \
    "psubw      64(%[kYuvConstants]),%%xmm1    \n"                             \
    "psubw      80(%[kYuvConstants]),%%xmm2    \n"                             \
    "movq       (%[y_buf]),%%xmm3              \n"                             \
    "lea        0x8(%[y_buf]),%[y_buf]         \n"                             \
    "punpcklbw  %%xmm4,%%xmm3                  \n"                             \
    "psubsw     96(%[kYuvConstants]),%%xmm3    \n"                             \
    "pmullw     112(%[kYuvConstants]),%%xmm3   \n"                             \
    "paddsw     %%xmm3,%%xmm0                  \n"                             \
    "paddsw     %%xmm3,%%xmm1                  \n"                             \
    "paddsw     %%xmm3,%%xmm2                  \n"                             \
    "psraw      $0x6,%%xmm0                    \n"                             \
    "psraw      $0x6,%%xmm1                    \n"                             \
    "psraw      $0x6,%%xmm2                    \n"                             \
    "packuswb   %%xmm0,%%xmm0                  \n"                             \
    "packuswb   %%xmm1,%%xmm1                  \n"                             \
    "packuswb   %%xmm2,%%xmm2                  \n"                             \
1339 1340

void OMITFP I444ToARGBRow_SSSE3(const uint8* y_buf,
fbarchard@google.com's avatar
fbarchard@google.com committed
1341 1342
                                const uint8* u_buf,
                                const uint8* v_buf,
1343
                                uint8* argb_buf,
fbarchard@google.com's avatar
fbarchard@google.com committed
1344
                                int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1345
  asm volatile (
1346
    "sub       %[u_buf],%[v_buf]               \n"
1347 1348
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
1349
    ".p2align  4                               \n"
1350
  "1:                                          \n"
1351 1352
    READYUV444
    YUVTORGB
1353 1354 1355 1356 1357
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
1358 1359 1360 1361
    "movdqa    %%xmm0,(%[argb_buf])            \n"
    "movdqa    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1362
    "jg        1b                              \n"
1363 1364 1365 1366 1367 1368
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1369
  : "memory", "cc"
1370
#if defined(__SSE2__)
1371
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
1372
#endif
1373
  );
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1374 1375
}

1376
void OMITFP I422ToARGBRow_SSSE3(const uint8* y_buf,
fbarchard@google.com's avatar
fbarchard@google.com committed
1377 1378
                                const uint8* u_buf,
                                const uint8* v_buf,
1379
                                uint8* argb_buf,
fbarchard@google.com's avatar
fbarchard@google.com committed
1380
                                int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1381
  asm volatile (
1382
    "sub       %[u_buf],%[v_buf]               \n"
1383 1384
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
1385
    ".p2align  4                               \n"
1386
  "1:                                          \n"
1387 1388
    READYUV422
    YUVTORGB
1389 1390 1391 1392 1393
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
1394 1395 1396 1397
    "movdqa    %%xmm0,(%[argb_buf])            \n"
    "movdqa    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1398
    "jg        1b                              \n"
1399 1400 1401 1402 1403 1404
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1405
  : "memory", "cc"
1406
#if defined(__SSE2__)
1407
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
1408
#endif
1409
  );
1410 1411
}

1412
void OMITFP I411ToARGBRow_SSSE3(const uint8* y_buf,
fbarchard@google.com's avatar
fbarchard@google.com committed
1413 1414
                                const uint8* u_buf,
                                const uint8* v_buf,
1415
                                uint8* argb_buf,
fbarchard@google.com's avatar
fbarchard@google.com committed
1416
                                int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1417
  asm volatile (
1418
    "sub       %[u_buf],%[v_buf]               \n"
1419 1420
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
1421
    ".p2align  4                               \n"
1422
  "1:                                          \n"
1423 1424
    READYUV411
    YUVTORGB
1425 1426 1427 1428 1429
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
    "movdqa    %%xmm0,(%[argb_buf])            \n"
    "movdqa    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
    "jg        1b                              \n"
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void OMITFP NV12ToARGBRow_SSSE3(const uint8* y_buf,
                                const uint8* uv_buf,
                                uint8* argb_buf,
                                int width) {
  asm volatile (
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    READNV12
    YUVTORGB
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
    "movdqa    %%xmm0,(%[argb_buf])            \n"
    "movdqa    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
    "jg        1b                              \n"
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [uv_buf]"+r"(uv_buf),    // %[uv_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void OMITFP NV21ToARGBRow_SSSE3(const uint8* y_buf,
                                const uint8* vu_buf,
                                uint8* argb_buf,
                                int width) {
  asm volatile (
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    READNV12
    YVUTORGB
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
    "movdqa    %%xmm0,(%[argb_buf])            \n"
    "movdqa    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1501
    "jg        1b                              \n"
1502 1503 1504 1505 1506
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [uv_buf]"+r"(vu_buf),    // %[uv_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1507 1508 1509 1510 1511 1512 1513
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

1514
void OMITFP I444ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
1515 1516
                                          const uint8* u_buf,
                                          const uint8* v_buf,
1517
                                          uint8* argb_buf,
1518 1519
                                          int width) {
  asm volatile (
1520
    "sub       %[u_buf],%[v_buf]               \n"
1521 1522
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
1523
    ".p2align  4                               \n"
1524
  "1:                                          \n"
1525 1526
    READYUV444
    YUVTORGB
1527 1528 1529 1530 1531
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
1532 1533 1534 1535
    "movdqu    %%xmm0,(%[argb_buf])            \n"
    "movdqu    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1536
    "jg        1b                              \n"
1537 1538 1539 1540 1541 1542
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1543 1544 1545 1546 1547 1548 1549
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

1550
void OMITFP I422ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
1551 1552
                                          const uint8* u_buf,
                                          const uint8* v_buf,
1553
                                          uint8* argb_buf,
1554 1555
                                          int width) {
  asm volatile (
1556
    "sub       %[u_buf],%[v_buf]               \n"
1557 1558
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
1559
    ".p2align  4                               \n"
1560
  "1:                                          \n"
1561 1562
    READYUV422
    YUVTORGB
1563 1564 1565 1566 1567
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
1568 1569 1570 1571
    "movdqu    %%xmm0,(%[argb_buf])            \n"
    "movdqu    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1572
    "jg        1b                              \n"
1573 1574 1575 1576 1577 1578
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void OMITFP I411ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
                                          const uint8* u_buf,
                                          const uint8* v_buf,
                                          uint8* argb_buf,
                                          int width) {
  asm volatile (
1592
    "sub       %[u_buf],%[v_buf]               \n"
1593 1594 1595 1596
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
    ".p2align  4                               \n"
  "1:                                          \n"
1597 1598
    READYUV411
    YUVTORGB
1599 1600 1601 1602 1603
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
    "movdqu    %%xmm0,(%[argb_buf])            \n"
    "movdqu    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
    "jg        1b                              \n"
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void OMITFP NV12ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
                                          const uint8* uv_buf,
                                          uint8* argb_buf,
                                          int width) {
  asm volatile (
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    READNV12
    YUVTORGB
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
    "movdqu    %%xmm0,(%[argb_buf])            \n"
    "movdqu    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1642
    "jg        1b                              \n"
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [uv_buf]"+r"(uv_buf),    // %[uv_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void OMITFP NV21ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
                                          const uint8* vu_buf,
                                          uint8* argb_buf,
                                          int width) {
  asm volatile (
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    READNV12
    YVUTORGB
    "punpcklbw %%xmm1,%%xmm0                   \n"
    "punpcklbw %%xmm5,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm2,%%xmm0                   \n"
    "punpckhwd %%xmm2,%%xmm1                   \n"
    "movdqu    %%xmm0,(%[argb_buf])            \n"
    "movdqu    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
    "jg        1b                              \n"
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [uv_buf]"+r"(vu_buf),    // %[uv_buf]
    [argb_buf]"+r"(argb_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

void OMITFP I422ToBGRARow_SSSE3(const uint8* y_buf,
                                const uint8* u_buf,
                                const uint8* v_buf,
                                uint8* bgra_buf,
                                int width) {
  asm volatile (
1694
    "sub       %[u_buf],%[v_buf]               \n"
1695 1696 1697 1698
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
    ".p2align  4                               \n"
  "1:                                          \n"
1699 1700
    READYUV422
    YUVTORGB
1701 1702 1703 1704 1705 1706
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "punpcklbw %%xmm0,%%xmm1                   \n"
    "punpcklbw %%xmm2,%%xmm5                   \n"
    "movdqa    %%xmm5,%%xmm0                   \n"
    "punpcklwd %%xmm1,%%xmm5                   \n"
    "punpckhwd %%xmm1,%%xmm0                   \n"
1707 1708 1709 1710
    "movdqa    %%xmm5,(%[argb_buf])            \n"
    "movdqa    %%xmm0,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1711
    "jg        1b                              \n"
1712 1713 1714 1715 1716 1717
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(bgra_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1718 1719 1720 1721 1722 1723 1724
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}

1725 1726 1727 1728 1729
void OMITFP I422ToABGRRow_SSSE3(const uint8* y_buf,
                                const uint8* u_buf,
                                const uint8* v_buf,
                                uint8* abgr_buf,
                                int width) {
1730
  asm volatile (
1731
    "sub       %[u_buf],%[v_buf]               \n"
1732 1733
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
1734
    ".p2align  4                               \n"
1735
  "1:                                          \n"
1736 1737
    READYUV422
    YUVTORGB
1738 1739 1740 1741 1742
    "punpcklbw %%xmm1,%%xmm2                   \n"
    "punpcklbw %%xmm5,%%xmm0                   \n"
    "movdqa    %%xmm2,%%xmm1                   \n"
    "punpcklwd %%xmm0,%%xmm2                   \n"
    "punpckhwd %%xmm0,%%xmm1                   \n"
1743 1744 1745 1746
    "movdqa    %%xmm2,(%[argb_buf])            \n"
    "movdqa    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1747
    "jg        1b                              \n"
1748 1749 1750 1751 1752 1753
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(abgr_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1754
  : "memory", "cc"
1755
#if defined(__SSE2__)
1756
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
1757
#endif
1758
  );
1759 1760
}

1761 1762 1763 1764 1765
void OMITFP I422ToBGRARow_Unaligned_SSSE3(const uint8* y_buf,
                                          const uint8* u_buf,
                                          const uint8* v_buf,
                                          uint8* bgra_buf,
                                          int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1766
  asm volatile (
1767
    "sub       %[u_buf],%[v_buf]               \n"
1768 1769
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
1770
    ".p2align  4                               \n"
1771
  "1:                                          \n"
1772 1773
    READYUV422
    YUVTORGB
1774 1775 1776 1777 1778 1779
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "punpcklbw %%xmm0,%%xmm1                   \n"
    "punpcklbw %%xmm2,%%xmm5                   \n"
    "movdqa    %%xmm5,%%xmm0                   \n"
    "punpcklwd %%xmm1,%%xmm5                   \n"
    "punpckhwd %%xmm1,%%xmm0                   \n"
1780 1781 1782 1783
    "movdqu    %%xmm5,(%[argb_buf])            \n"
    "movdqu    %%xmm0,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1784
    "jg        1b                              \n"
1785 1786 1787 1788 1789 1790
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(bgra_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1791
  : "memory", "cc"
1792
#if defined(__SSE2__)
1793
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
1794
#endif
1795
  );
1796
}
1797 1798 1799 1800 1801 1802 1803

void OMITFP I422ToABGRRow_Unaligned_SSSE3(const uint8* y_buf,
                                          const uint8* u_buf,
                                          const uint8* v_buf,
                                          uint8* abgr_buf,
                                          int width) {
  asm volatile (
1804
    "sub       %[u_buf],%[v_buf]               \n"
1805 1806 1807 1808
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "pxor      %%xmm4,%%xmm4                   \n"
    ".p2align  4                               \n"
  "1:                                          \n"
1809 1810
    READYUV422
    YUVTORGB
1811 1812 1813 1814 1815
    "punpcklbw %%xmm1,%%xmm2                   \n"
    "punpcklbw %%xmm5,%%xmm0                   \n"
    "movdqa    %%xmm2,%%xmm1                   \n"
    "punpcklwd %%xmm0,%%xmm2                   \n"
    "punpckhwd %%xmm0,%%xmm1                   \n"
1816 1817 1818 1819
    "movdqu    %%xmm2,(%[argb_buf])            \n"
    "movdqu    %%xmm1,0x10(%[argb_buf])        \n"
    "lea       0x20(%[argb_buf]),%[argb_buf]   \n"
    "sub       $0x8,%[width]                   \n"
1820
    "jg        1b                              \n"
1821 1822 1823 1824 1825 1826
  : [y_buf]"+r"(y_buf),    // %[y_buf]
    [u_buf]"+r"(u_buf),    // %[u_buf]
    [v_buf]"+r"(v_buf),    // %[v_buf]
    [argb_buf]"+r"(abgr_buf),  // %[argb_buf]
    [width]"+rm"(width)    // %[width]
  : [kYuvConstants]"r"(&kYuvConstants.kUVToB) // %[kYuvConstants]
1827 1828 1829
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
1830
#endif
1831 1832 1833
  );
}
#endif  // HAS_I422TOARGBROW_SSSE3
1834

1835
#ifdef HAS_YTOARGBROW_SSE2
fbarchard@google.com's avatar
fbarchard@google.com committed
1836 1837 1838
void YToARGBRow_SSE2(const uint8* y_buf,
                     uint8* rgb_buf,
                     int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
1839
  asm volatile (
1840 1841 1842 1843 1844 1845 1846 1847
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "pslld     $0x18,%%xmm4                    \n"
    "mov       $0x10001000,%%eax               \n"
    "movd      %%eax,%%xmm3                    \n"
    "pshufd    $0x0,%%xmm3,%%xmm3              \n"
    "mov       $0x012a012a,%%eax               \n"
    "movd      %%eax,%%xmm2                    \n"
    "pshufd    $0x0,%%xmm2,%%xmm2              \n"
1848
    ".p2align  4                               \n"
1849
  "1:                                          \n"
1850
    // Step 1: Scale Y contribution to 8 G values. G = (y - 16) * 1.164
1851 1852 1853 1854 1855 1856
    "movq      (%0),%%xmm0                     \n"
    "lea       0x8(%0),%0                      \n"
    "punpcklbw %%xmm0,%%xmm0                   \n"
    "psubusw   %%xmm3,%%xmm0                   \n"
    "pmulhuw   %%xmm2,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
1857 1858

    // Step 2: Weave into ARGB
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869
    "punpcklbw %%xmm0,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm0,%%xmm0                   \n"
    "punpckhwd %%xmm1,%%xmm1                   \n"
    "por       %%xmm4,%%xmm0                   \n"
    "por       %%xmm4,%%xmm1                   \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "movdqa    %%xmm1,16(%1)                   \n"
    "lea       32(%1),%1                       \n"

    "sub       $0x8,%2                         \n"
1870
    "jg        1b                              \n"
1871 1872
  : "+r"(y_buf),    // %0
    "+r"(rgb_buf),  // %1
1873
    "+rm"(width)    // %2
1874 1875
  :
  : "memory", "cc", "eax"
1876
#if defined(__SSE2__)
1877
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"
1878
#endif
1879
  );
1880
}
1881
#endif  // HAS_YTOARGBROW_SSE2
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
1882

1883
#ifdef HAS_MIRRORROW_SSSE3
1884
// Shuffle table for reversing the bytes.
1885
CONST uvec8 kShuffleMirror = {
1886 1887 1888
  15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u
};

1889
void MirrorRow_SSSE3(const uint8* src, uint8* dst, int width) {
1890
  intptr_t temp_width = static_cast<intptr_t>(width);
fbarchard@google.com's avatar
fbarchard@google.com committed
1891
  asm volatile (
1892 1893
    "movdqa    %3,%%xmm5                       \n"
    "lea       -0x10(%0),%0                    \n"
1894
    ".p2align  4                               \n"
1895
  "1:                                          \n"
1896 1897 1898 1899 1900
    "movdqa    (%0,%2),%%xmm0                  \n"
    "pshufb    %%xmm5,%%xmm0                   \n"
    "sub       $0x10,%2                        \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
1901
    "jg        1b                              \n"
1902 1903 1904
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(temp_width)  // %2
1905
  : "m"(kShuffleMirror) // %3
1906 1907 1908 1909 1910 1911
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm5"
#endif
  );
}
1912
#endif  // HAS_MIRRORROW_SSSE3
1913

1914 1915
#ifdef HAS_MIRRORROW_SSE2
void MirrorRow_SSE2(const uint8* src, uint8* dst, int width) {
1916
  intptr_t temp_width = static_cast<intptr_t>(width);
fbarchard@google.com's avatar
fbarchard@google.com committed
1917
  asm volatile (
1918
    "lea       -0x10(%0),%0                    \n"
1919
    ".p2align  4                               \n"
1920
  "1:                                          \n"
1921
    "movdqu    (%0,%2),%%xmm0                  \n"
1922
    "movdqa    %%xmm0,%%xmm1                   \n"
1923 1924 1925 1926 1927 1928 1929 1930 1931
    "psllw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "por       %%xmm1,%%xmm0                   \n"
    "pshuflw   $0x1b,%%xmm0,%%xmm0             \n"
    "pshufhw   $0x1b,%%xmm0,%%xmm0             \n"
    "pshufd    $0x4e,%%xmm0,%%xmm0             \n"
    "sub       $0x10,%2                        \n"
    "movdqu    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
1932
    "jg        1b                              \n"
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(temp_width)  // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1"
#endif
  );
}
1943
#endif  // HAS_MIRRORROW_SSE2
1944

1945 1946 1947 1948 1949 1950 1951 1952
#ifdef HAS_MIRRORROW_UV_SSSE3
// Shuffle table for reversing the bytes of UV channels.
CONST uvec8 kShuffleMirrorUV = {
  14u, 12u, 10u, 8u, 6u, 4u, 2u, 0u, 15u, 13u, 11u, 9u, 7u, 5u, 3u, 1u
};
void MirrorRowUV_SSSE3(const uint8* src, uint8* dst_u, uint8* dst_v,
                       int width) {
  intptr_t temp_width = static_cast<intptr_t>(width);
fbarchard@google.com's avatar
fbarchard@google.com committed
1953
  asm volatile (
1954 1955 1956
    "movdqa    %4,%%xmm1                       \n"
    "lea       -16(%0,%3,2),%0                 \n"
    "sub       %1,%2                           \n"
1957
    ".p2align  4                               \n"
1958 1959 1960 1961 1962 1963 1964 1965
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "lea       -16(%0),%0                      \n"
    "pshufb    %%xmm1,%%xmm0                   \n"
    "sub       $8,%3                           \n"
    "movlpd    %%xmm0,(%1)                     \n"
    "movhpd    %%xmm0,(%1,%2)                  \n"
    "lea       8(%1),%1                        \n"
1966
    "jg        1b                              \n"
1967 1968 1969 1970
  : "+r"(src),      // %0
    "+r"(dst_u),    // %1
    "+r"(dst_v),    // %2
    "+r"(temp_width)  // %3
1971
  : "m"(kShuffleMirrorUV)  // %4
1972 1973 1974 1975 1976 1977
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1"
#endif
  );
}
1978
#endif  // HAS_MIRRORROW_UV_SSSE3
1979

1980 1981
#ifdef HAS_ARGBMIRRORROW_SSSE3
// Shuffle table for reversing the bytes.
1982
CONST uvec8 kARGBShuffleMirror = {
1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001
  12u, 13u, 14u, 15u, 8u, 9u, 10u, 11u, 4u, 5u, 6u, 7u, 0u, 1u, 2u, 3u
};

void ARGBMirrorRow_SSSE3(const uint8* src, uint8* dst, int width) {
  intptr_t temp_width = static_cast<intptr_t>(width);
  asm volatile (
    "movdqa    %3,%%xmm5                       \n"
    "lea       -0x10(%0),%0                    \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    "movdqa    (%0,%2,4),%%xmm0                \n"
    "pshufb    %%xmm5,%%xmm0                   \n"
    "sub       $0x4,%2                         \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
    "jg        1b                              \n"
  : "+r"(src),  // %0
    "+r"(dst),  // %1
    "+r"(temp_width)  // %2
2002
  : "m"(kARGBShuffleMirror)  // %3
2003 2004 2005 2006 2007 2008 2009 2010
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm5"
#endif
  );
}
#endif  // HAS_ARGBMIRRORROW_SSSE3

2011 2012
#ifdef HAS_SPLITUV_SSE2
void SplitUV_SSE2(const uint8* src_uv, uint8* dst_u, uint8* dst_v, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2013
  asm volatile (
2014 2015 2016
    "pcmpeqb    %%xmm5,%%xmm5                    \n"
    "psrlw      $0x8,%%xmm5                      \n"
    "sub        %1,%2                            \n"
2017
    ".p2align  4                               \n"
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033
  "1:                                            \n"
    "movdqa     (%0),%%xmm0                      \n"
    "movdqa     0x10(%0),%%xmm1                  \n"
    "lea        0x20(%0),%0                      \n"
    "movdqa     %%xmm0,%%xmm2                    \n"
    "movdqa     %%xmm1,%%xmm3                    \n"
    "pand       %%xmm5,%%xmm0                    \n"
    "pand       %%xmm5,%%xmm1                    \n"
    "packuswb   %%xmm1,%%xmm0                    \n"
    "psrlw      $0x8,%%xmm2                      \n"
    "psrlw      $0x8,%%xmm3                      \n"
    "packuswb   %%xmm3,%%xmm2                    \n"
    "movdqa     %%xmm0,(%1)                      \n"
    "movdqa     %%xmm2,(%1,%2)                   \n"
    "lea        0x10(%1),%1                      \n"
    "sub        $0x10,%3                         \n"
2034
    "jg         1b                               \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
2035 2036 2037 2038 2039 2040
  : "+r"(src_uv),     // %0
    "+r"(dst_u),      // %1
    "+r"(dst_v),      // %2
    "+r"(pix)         // %3
  :
  : "memory", "cc"
2041
#if defined(__SSE2__)
fbarchard@google.com's avatar
fbarchard@google.com committed
2042
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"
2043 2044 2045
#endif
  );
}
2046
#endif  // HAS_SPLITUV_SSE2
2047

2048 2049
#ifdef HAS_COPYROW_SSE2
void CopyRow_SSE2(const uint8* src, uint8* dst, int count) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2050
  asm volatile (
fbarchard@google.com's avatar
fbarchard@google.com committed
2051
    "sub        %0,%1                          \n"
2052
    ".p2align  4                               \n"
2053 2054 2055 2056 2057 2058 2059
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    %%xmm0,(%0,%1)                  \n"
    "movdqa    %%xmm1,0x10(%0,%1)              \n"
    "lea       0x20(%0),%0                     \n"
    "sub       $0x20,%2                        \n"
2060
    "jg        1b                              \n"
2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075
  : "+r"(src),   // %0
    "+r"(dst),   // %1
    "+r"(count)  // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1"
#endif
  );
}
#endif  // HAS_COPYROW_SSE2

#ifdef HAS_COPYROW_X86
void CopyRow_X86(const uint8* src, uint8* dst, int width) {
  size_t width_tmp = static_cast<size_t>(width);
fbarchard@google.com's avatar
fbarchard@google.com committed
2076
  asm volatile (
2077 2078 2079 2080 2081 2082 2083 2084 2085
    "shr       $0x2,%2                         \n"
    "rep movsl                                 \n"
  : "+S"(src),  // %0
    "+D"(dst),  // %1
    "+c"(width_tmp) // %2
  :
  : "memory", "cc"
  );
}
2086
#endif  // HAS_COPYROW_X86
2087

2088
#ifdef HAS_YUY2TOYROW_SSE2
2089
void YUY2ToYRow_SSE2(const uint8* src_yuy2, uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2090
  asm volatile (
2091 2092
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
2093
    ".p2align  4                               \n"
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "lea       0x20(%0),%0                     \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
    "sub       $0x10,%2                        \n"
2104
    "jg        1b                              \n"
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116
  : "+r"(src_yuy2),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm5"
#endif
  );
}

void YUY2ToUVRow_SSE2(const uint8* src_yuy2, int stride_yuy2,
2117
                      uint8* dst_u, uint8* dst_v, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2118
  asm volatile (
2119 2120 2121
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
    "sub       %1,%2                           \n"
2122
    ".p2align  4                               \n"
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    (%0,%4,1),%%xmm2                \n"
    "movdqa    0x10(%0,%4,1),%%xmm3            \n"
    "lea       0x20(%0),%0                     \n"
    "pavgb     %%xmm2,%%xmm0                   \n"
    "pavgb     %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm1                   \n"
    "movq      %%xmm0,(%1)                     \n"
    "movq      %%xmm1,(%1,%2)                  \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x10,%3                        \n"
2143
    "jg        1b                              \n"
2144 2145
  : "+r"(src_yuy2),    // %0
    "+r"(dst_u),       // %1
2146
    "+r"(dst_v),       // %2
2147 2148 2149 2150 2151 2152 2153 2154 2155
    "+r"(pix)          // %3
  : "r"(static_cast<intptr_t>(stride_yuy2))  // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"
#endif
  );
}

2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190
void YUY2ToUV422Row_SSE2(const uint8* src_yuy2,
                         uint8* dst_u, uint8* dst_v, int pix) {
  asm volatile (
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
    "sub       %1,%2                           \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "lea       0x20(%0),%0                     \n"
    "psrlw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm1                   \n"
    "movq      %%xmm0,(%1)                     \n"
    "movq      %%xmm1,(%1,%2)                  \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x10,%3                        \n"
    "jg        1b                              \n"
  : "+r"(src_yuy2),    // %0
    "+r"(dst_u),       // %1
    "+r"(dst_v),       // %2
    "+r"(pix)          // %3
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm5"
#endif
  );
}
2191

2192 2193
void YUY2ToYRow_Unaligned_SSE2(const uint8* src_yuy2,
                               uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2194
  asm volatile (
2195 2196
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
2197
    ".p2align  4                               \n"
2198 2199 2200 2201 2202 2203 2204
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "lea       0x20(%0),%0                     \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
2205
    "sub       $0x10,%2                        \n"
2206 2207
    "movdqu    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
2208
    "jg        1b                              \n"
2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221
  : "+r"(src_yuy2),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm5"
#endif
  );
}

void YUY2ToUVRow_Unaligned_SSE2(const uint8* src_yuy2,
                                int stride_yuy2,
2222
                                uint8* dst_u, uint8* dst_v, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2223
  asm volatile (
2224 2225 2226
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
    "sub       %1,%2                           \n"
2227
    ".p2align  4                               \n"
2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    (%0,%4,1),%%xmm2                \n"
    "movdqu    0x10(%0,%4,1),%%xmm3            \n"
    "lea       0x20(%0),%0                     \n"
    "pavgb     %%xmm2,%%xmm0                   \n"
    "pavgb     %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm1                   \n"
    "movq      %%xmm0,(%1)                     \n"
    "movq      %%xmm1,(%1,%2)                  \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x10,%3                        \n"
2248
    "jg        1b                              \n"
2249 2250
  : "+r"(src_yuy2),    // %0
    "+r"(dst_u),       // %1
2251
    "+r"(dst_v),       // %2
2252 2253 2254 2255 2256 2257
    "+r"(pix)          // %3
  : "r"(static_cast<intptr_t>(stride_yuy2))  // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"
#endif
fbarchard@google.com's avatar
fbarchard@google.com committed
2258
  );
2259 2260
}

2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296
void YUY2ToUV422Row_Unaligned_SSE2(const uint8* src_yuy2,
                                   uint8* dst_u, uint8* dst_v, int pix) {
  asm volatile (
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
    "sub       %1,%2                           \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "lea       0x20(%0),%0                     \n"
    "psrlw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm1                   \n"
    "movq      %%xmm0,(%1)                     \n"
    "movq      %%xmm1,(%1,%2)                  \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x10,%3                        \n"
    "jg        1b                              \n"
  : "+r"(src_yuy2),    // %0
    "+r"(dst_u),       // %1
    "+r"(dst_v),       // %2
    "+r"(pix)          // %3
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm5"
#endif
  );
}

2297
void UYVYToYRow_SSE2(const uint8* src_uyvy, uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2298
  asm volatile (
2299
    ".p2align  4                               \n"
2300 2301 2302 2303 2304 2305 2306
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "lea       0x20(%0),%0                     \n"
    "psrlw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
2307
    "sub       $0x10,%2                        \n"
2308 2309
    "movdqa    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
2310
    "jg        1b                              \n"
2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322
  : "+r"(src_uyvy),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1"
#endif
  );
}

void UYVYToUVRow_SSE2(const uint8* src_uyvy, int stride_uyvy,
2323
                      uint8* dst_u, uint8* dst_v, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2324
  asm volatile (
2325 2326 2327
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
    "sub       %1,%2                           \n"
2328
    ".p2align  4                               \n"
2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    (%0,%4,1),%%xmm2                \n"
    "movdqa    0x10(%0,%4,1),%%xmm3            \n"
    "lea       0x20(%0),%0                     \n"
    "pavgb     %%xmm2,%%xmm0                   \n"
    "pavgb     %%xmm3,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm1                   \n"
    "movq      %%xmm0,(%1)                     \n"
    "movq      %%xmm1,(%1,%2)                  \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x10,%3                        \n"
2349
    "jg        1b                              \n"
2350 2351
  : "+r"(src_uyvy),    // %0
    "+r"(dst_u),       // %1
2352
    "+r"(dst_v),       // %2
2353 2354 2355 2356 2357 2358 2359 2360 2361
    "+r"(pix)          // %3
  : "r"(static_cast<intptr_t>(stride_uyvy))  // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"
#endif
  );
}

2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397
void UYVYToUV422Row_SSE2(const uint8* src_uyvy,
                         uint8* dst_u, uint8* dst_v, int pix) {
  asm volatile (
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
    "sub       %1,%2                           \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "lea       0x20(%0),%0                     \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm1                   \n"
    "movq      %%xmm0,(%1)                     \n"
    "movq      %%xmm1,(%1,%2)                  \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x10,%3                        \n"
    "jg        1b                              \n"
  : "+r"(src_uyvy),    // %0
    "+r"(dst_u),       // %1
    "+r"(dst_v),       // %2
    "+r"(pix)          // %3
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm5"
#endif
  );
}

2398 2399
void UYVYToYRow_Unaligned_SSE2(const uint8* src_uyvy,
                               uint8* dst_y, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2400
  asm volatile (
2401
    ".p2align  4                               \n"
2402 2403 2404 2405 2406 2407 2408
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "lea       0x20(%0),%0                     \n"
    "psrlw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
2409
    "sub       $0x10,%2                        \n"
2410 2411
    "movdqu    %%xmm0,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
2412
    "jg        1b                              \n"
2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424
  : "+r"(src_uyvy),  // %0
    "+r"(dst_y),     // %1
    "+r"(pix)        // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1"
#endif
  );
}

void UYVYToUVRow_Unaligned_SSE2(const uint8* src_uyvy, int stride_uyvy,
2425
                                uint8* dst_u, uint8* dst_v, int pix) {
fbarchard@google.com's avatar
fbarchard@google.com committed
2426
  asm volatile (
2427 2428 2429
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
    "sub       %1,%2                           \n"
2430
    ".p2align  4                               \n"
2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "movdqu    (%0,%4,1),%%xmm2                \n"
    "movdqu    0x10(%0,%4,1),%%xmm3            \n"
    "lea       0x20(%0),%0                     \n"
    "pavgb     %%xmm2,%%xmm0                   \n"
    "pavgb     %%xmm3,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm1                   \n"
    "movq      %%xmm0,(%1)                     \n"
    "movq      %%xmm1,(%1,%2)                  \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x10,%3                        \n"
2451
    "jg        1b                              \n"
2452 2453
  : "+r"(src_uyvy),    // %0
    "+r"(dst_u),       // %1
2454
    "+r"(dst_v),       // %2
2455 2456 2457 2458 2459 2460 2461 2462
    "+r"(pix)          // %3
  : "r"(static_cast<intptr_t>(stride_uyvy))  // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm5"
#endif
  );
}
2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498

void UYVYToUV422Row_Unaligned_SSE2(const uint8* src_uyvy,
                                   uint8* dst_u, uint8* dst_v, int pix) {
  asm volatile (
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrlw     $0x8,%%xmm5                     \n"
    "sub       %1,%2                           \n"
    ".p2align  4                               \n"
  "1:                                          \n"
    "movdqu    (%0),%%xmm0                     \n"
    "movdqu    0x10(%0),%%xmm1                 \n"
    "lea       0x20(%0),%0                     \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm1                   \n"
    "movq      %%xmm0,(%1)                     \n"
    "movq      %%xmm1,(%1,%2)                  \n"
    "lea       0x8(%1),%1                      \n"
    "sub       $0x10,%3                        \n"
    "jg        1b                              \n"
  : "+r"(src_uyvy),    // %0
    "+r"(dst_u),       // %1
    "+r"(dst_v),       // %2
    "+r"(pix)          // %3
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm5"
#endif
  );
}
2499
#endif  // HAS_YUY2TOYROW_SSE2
2500

2501
#ifdef HAS_ARGBBLENDROW_SSE2
2502
// Blend 8 pixels at a time.
2503 2504
void ARGBBlendRow_SSE2(const uint8* src_argb0, const uint8* src_argb1,
                       uint8* dst_argb, int width) {
2505 2506 2507 2508 2509 2510 2511 2512 2513
  asm volatile (
    "pcmpeqb   %%xmm7,%%xmm7                   \n"
    "psrlw     $0xf,%%xmm7                     \n"
    "pcmpeqb   %%xmm6,%%xmm6                   \n"
    "psrlw     $0x8,%%xmm6                     \n"
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psllw     $0x8,%%xmm5                     \n"
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "pslld     $0x18,%%xmm4                    \n"
2514 2515 2516
    "sub       $0x1,%3                         \n"
    "je        91f                             \n"
    "jl        99f                             \n"
2517

2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547
    // 1 pixel loop until destination pointer is aligned.
  "10:                                         \n"
    "test      $0xf,%2                         \n"
    "je        19f                             \n"
    "movd      (%0),%%xmm3                     \n"
    "lea       0x4(%0),%0                      \n"
    "movdqa    %%xmm3,%%xmm0                   \n"
    "pxor      %%xmm4,%%xmm3                   \n"
    "movd      (%1),%%xmm2                     \n"
    "psrlw     $0x8,%%xmm3                     \n"
    "pshufhw   $0xf5,%%xmm3,%%xmm3             \n"
    "pshuflw   $0xf5,%%xmm3,%%xmm3             \n"
    "pand      %%xmm6,%%xmm2                   \n"
    "paddw     %%xmm7,%%xmm3                   \n"
    "pmullw    %%xmm3,%%xmm2                   \n"
    "movd      (%1),%%xmm1                     \n"
    "lea       0x4(%1),%1                      \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pmullw    %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm2                     \n"
    "paddusb   %%xmm2,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "paddusb   %%xmm1,%%xmm0                   \n"
    "sub       $0x1,%3                         \n"
    "movd      %%xmm0,(%2)                     \n"
    "lea       0x4(%2),%2                      \n"
    "jge       10b                             \n"

  "19:                                         \n"
2548
    "add       $1-4,%3                         \n"
2549 2550
    "jl        49f                             \n"

2551
    // 4 pixel loop.
2552 2553
    ".p2align  2                               \n"
  "41:                                         \n"
2554
    "movdqu    (%0),%%xmm3                     \n"
2555
    "lea       0x10(%0),%0                     \n"
2556 2557
    "movdqa    %%xmm3,%%xmm0                   \n"
    "pxor      %%xmm4,%%xmm3                   \n"
2558
    "movdqu    (%1),%%xmm2                     \n"
2559 2560 2561 2562 2563 2564
    "psrlw     $0x8,%%xmm3                     \n"
    "pshufhw   $0xf5,%%xmm3,%%xmm3             \n"
    "pshuflw   $0xf5,%%xmm3,%%xmm3             \n"
    "pand      %%xmm6,%%xmm2                   \n"
    "paddw     %%xmm7,%%xmm3                   \n"
    "pmullw    %%xmm3,%%xmm2                   \n"
2565
    "movdqu    (%1),%%xmm1                     \n"
2566
    "lea       0x10(%1),%1                     \n"
2567 2568 2569 2570 2571 2572 2573 2574 2575
    "psrlw     $0x8,%%xmm1                     \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pmullw    %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm2                     \n"
    "paddusb   %%xmm2,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "paddusb   %%xmm1,%%xmm0                   \n"
    "sub       $0x4,%3                         \n"
    "movdqa    %%xmm0,(%2)                     \n"
2576
    "lea       0x10(%2),%2                     \n"
2577
    "jge       41b                             \n"
2578

2579 2580 2581
  "49:                                         \n"
    "add       $0x3,%3                         \n"
    "jl        99f                             \n"
2582

2583
    // 1 pixel loop.
2584
  "91:                                         \n"
2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596
    "movd      (%0),%%xmm3                     \n"
    "lea       0x4(%0),%0                      \n"
    "movdqa    %%xmm3,%%xmm0                   \n"
    "pxor      %%xmm4,%%xmm3                   \n"
    "movd      (%1),%%xmm2                     \n"
    "psrlw     $0x8,%%xmm3                     \n"
    "pshufhw   $0xf5,%%xmm3,%%xmm3             \n"
    "pshuflw   $0xf5,%%xmm3,%%xmm3             \n"
    "pand      %%xmm6,%%xmm2                   \n"
    "paddw     %%xmm7,%%xmm3                   \n"
    "pmullw    %%xmm3,%%xmm2                   \n"
    "movd      (%1),%%xmm1                     \n"
2597
    "lea       0x4(%1),%1                      \n"
2598 2599 2600 2601 2602 2603 2604 2605 2606 2607
    "psrlw     $0x8,%%xmm1                     \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pmullw    %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm2                     \n"
    "paddusb   %%xmm2,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "paddusb   %%xmm1,%%xmm0                   \n"
    "sub       $0x1,%3                         \n"
    "movd      %%xmm0,(%2)                     \n"
    "lea       0x4(%2),%2                      \n"
2608 2609 2610 2611 2612 2613
    "jge       91b                             \n"
  "99:                                         \n"
  : "+r"(src_argb0),    // %0
    "+r"(src_argb1),    // %1
    "+r"(dst_argb),     // %2
    "+r"(width)         // %3
2614 2615 2616 2617 2618 2619 2620
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
#endif
  );
}
2621
#endif  // HAS_ARGBBLENDROW_SSE2
2622 2623

#ifdef HAS_ARGBBLENDROW_SSSE3
2624
// Shuffle table for isolating alpha.
2625 2626 2627 2628
CONST uvec8 kShuffleAlpha = {
  3u, 0x80, 3u, 0x80, 7u, 0x80, 7u, 0x80,
  11u, 0x80, 11u, 0x80, 15u, 0x80, 15u, 0x80
};
2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641

// Blend 8 pixels at a time
// Shuffle table for reversing the bytes.

// Same as SSE2, but replaces
//    psrlw      xmm3, 8          // alpha
//    pshufhw    xmm3, xmm3,0F5h  // 8 alpha words
//    pshuflw    xmm3, xmm3,0F5h
// with..
//    pshufb     xmm3, kShuffleAlpha // alpha

void ARGBBlendRow_SSSE3(const uint8* src_argb0, const uint8* src_argb1,
                        uint8* dst_argb, int width) {
2642 2643 2644 2645 2646 2647 2648 2649 2650
  asm volatile (
    "pcmpeqb   %%xmm7,%%xmm7                   \n"
    "psrlw     $0xf,%%xmm7                     \n"
    "pcmpeqb   %%xmm6,%%xmm6                   \n"
    "psrlw     $0x8,%%xmm6                     \n"
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psllw     $0x8,%%xmm5                     \n"
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "pslld     $0x18,%%xmm4                    \n"
2651 2652 2653
    "sub       $0x1,%3                         \n"
    "je        91f                             \n"
    "jl        99f                             \n"
2654

2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682
    // 1 pixel loop until destination pointer is aligned.
  "10:                                         \n"
    "test      $0xf,%2                         \n"
    "je        19f                             \n"
    "movd      (%0),%%xmm3                     \n"
    "lea       0x4(%0),%0                      \n"
    "movdqa    %%xmm3,%%xmm0                   \n"
    "pxor      %%xmm4,%%xmm3                   \n"
    "movd      (%1),%%xmm2                     \n"
    "pshufb    %4,%%xmm3                       \n"
    "pand      %%xmm6,%%xmm2                   \n"
    "paddw     %%xmm7,%%xmm3                   \n"
    "pmullw    %%xmm3,%%xmm2                   \n"
    "movd      (%1),%%xmm1                     \n"
    "lea       0x4(%1),%1                      \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pmullw    %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm2                     \n"
    "paddusb   %%xmm2,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "paddusb   %%xmm1,%%xmm0                   \n"
    "sub       $0x1,%3                         \n"
    "movd      %%xmm0,(%2)                     \n"
    "lea       0x4(%2),%2                      \n"
    "jge       10b                             \n"

  "19:                                         \n"
2683
    "add       $1-4,%3                         \n"
2684
    "jl        49f                             \n"
2685 2686 2687 2688
    "test      $0xf,%0                         \n"
    "jne       41f                             \n"
    "test      $0xf,%1                         \n"
    "jne       41f                             \n"
2689

2690
    // 4 pixel loop.
2691
    ".p2align  2                               \n"
2692
  "40:                                         \n"
2693
    "movdqa    (%0),%%xmm3                     \n"
2694 2695 2696
    "lea       0x10(%0),%0                     \n"
    "movdqa    %%xmm3,%%xmm0                   \n"
    "pxor      %%xmm4,%%xmm3                   \n"
2697
    "movdqa    (%1),%%xmm2                     \n"
2698 2699 2700 2701
    "pshufb    %4,%%xmm3                       \n"
    "pand      %%xmm6,%%xmm2                   \n"
    "paddw     %%xmm7,%%xmm3                   \n"
    "pmullw    %%xmm3,%%xmm2                   \n"
2702
    "movdqa    (%1),%%xmm1                     \n"
2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718
    "lea       0x10(%1),%1                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pmullw    %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm2                     \n"
    "paddusb   %%xmm2,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "paddusb   %%xmm1,%%xmm0                   \n"
    "sub       $0x4,%3                         \n"
    "movdqa    %%xmm0,(%2)                     \n"
    "lea       0x10(%2),%2                     \n"
    "jge       40b                             \n"
    "jmp       49f                             \n"

    // 4 pixel unaligned loop.
    ".p2align  2                               \n"
2719
  "41:                                         \n"
2720
    "movdqu    (%0),%%xmm3                     \n"
2721
    "lea       0x10(%0),%0                     \n"
2722 2723 2724
    "movdqa    %%xmm3,%%xmm0                   \n"
    "pxor      %%xmm4,%%xmm3                   \n"
    "movdqu    (%1),%%xmm2                     \n"
2725
    "pshufb    %4,%%xmm3                       \n"
2726 2727 2728 2729
    "pand      %%xmm6,%%xmm2                   \n"
    "paddw     %%xmm7,%%xmm3                   \n"
    "pmullw    %%xmm3,%%xmm2                   \n"
    "movdqu    (%1),%%xmm1                     \n"
2730
    "lea       0x10(%1),%1                     \n"
2731 2732 2733 2734
    "psrlw     $0x8,%%xmm1                     \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pmullw    %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm2                     \n"
2735
    "paddusb   %%xmm2,%%xmm0                   \n"
2736
    "pand      %%xmm5,%%xmm1                   \n"
2737
    "paddusb   %%xmm1,%%xmm0                   \n"
2738 2739
    "sub       $0x4,%3                         \n"
    "movdqa    %%xmm0,(%2)                     \n"
2740
    "lea       0x10(%2),%2                     \n"
2741
    "jge       41b                             \n"
2742

2743 2744 2745
  "49:                                         \n"
    "add       $0x3,%3                         \n"
    "jl        99f                             \n"
2746

2747
    // 1 pixel loop.
2748
  "91:                                         \n"
2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769
    "movd      (%0),%%xmm3                     \n"
    "lea       0x4(%0),%0                      \n"
    "movdqa    %%xmm3,%%xmm0                   \n"
    "pxor      %%xmm4,%%xmm3                   \n"
    "movd      (%1),%%xmm2                     \n"
    "pshufb    %4,%%xmm3                       \n"
    "pand      %%xmm6,%%xmm2                   \n"
    "paddw     %%xmm7,%%xmm3                   \n"
    "pmullw    %%xmm3,%%xmm2                   \n"
    "movd      (%1),%%xmm1                     \n"
    "lea       0x4(%1),%1                      \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "por       %%xmm4,%%xmm0                   \n"
    "pmullw    %%xmm3,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm2                     \n"
    "paddusb   %%xmm2,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm1                   \n"
    "paddusb   %%xmm1,%%xmm0                   \n"
    "sub       $0x1,%3                         \n"
    "movd      %%xmm0,(%2)                     \n"
    "lea       0x4(%2),%2                      \n"
2770 2771
    "jge       91b                             \n"
  "99:                                         \n"
2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782
  : "+r"(src_argb0),    // %0
    "+r"(src_argb1),    // %1
    "+r"(dst_argb),     // %2
    "+r"(width)         // %3
  : "m"(kShuffleAlpha)  // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
#endif
  );
}
2783
#endif  // HAS_ARGBBLENDROW_SSSE3
2784

2785 2786 2787 2788 2789 2790 2791 2792 2793 2794
#ifdef HAS_ARGBATTENUATE_SSE2
// Attenuate 4 pixels at a time.
// aligned to 16 bytes
void ARGBAttenuateRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width) {
  asm volatile (
    "sub       %0,%1                           \n"
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "pslld     $0x18,%%xmm4                    \n"
    "pcmpeqb   %%xmm5,%%xmm5                   \n"
    "psrld     $0x8,%%xmm5                     \n"
2795

2796
    // 4 pixel loop.
2797
    ".p2align  4                               \n"
2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "punpcklbw %%xmm0,%%xmm0                   \n"
    "pshufhw   $0xff,%%xmm0,%%xmm2             \n"
    "pshuflw   $0xff,%%xmm2,%%xmm2             \n"
    "pmulhuw   %%xmm2,%%xmm0                   \n"
    "movdqa    (%0),%%xmm1                     \n"
    "punpckhbw %%xmm1,%%xmm1                   \n"
    "pshufhw   $0xff,%%xmm1,%%xmm2             \n"
    "pshuflw   $0xff,%%xmm2,%%xmm2             \n"
    "pmulhuw   %%xmm2,%%xmm1                   \n"
2809
    "movdqa    (%0),%%xmm2                     \n"
2810
    "psrlw     $0x8,%%xmm0                     \n"
2811
    "pand      %%xmm4,%%xmm2                   \n"
2812 2813 2814
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "pand      %%xmm5,%%xmm0                   \n"
2815
    "por       %%xmm2,%%xmm0                   \n"
2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831
    "sub       $0x4,%2                         \n"
    "movdqa    %%xmm0,(%0,%1,1)                \n"
    "lea       0x10(%0),%0                     \n"
    "jg        1b                              \n"
  : "+r"(src_argb),    // %0
    "+r"(dst_argb),    // %1
    "+r"(width)        // %2
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}
#endif  // HAS_ARGBATTENUATE_SSE2

2832
#ifdef HAS_ARGBATTENUATEROW_SSSE3
2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850
// Shuffle table duplicating alpha
CONST uvec8 kShuffleAlpha0 = {
  3u, 3u, 3u, 3u, 3u, 3u, 128u, 128u, 7u, 7u, 7u, 7u, 7u, 7u, 128u, 128u,
};
CONST uvec8 kShuffleAlpha1 = {
  11u, 11u, 11u, 11u, 11u, 11u, 128u, 128u,
  15u, 15u, 15u, 15u, 15u, 15u, 128u, 128u,
};
// Attenuate 4 pixels at a time.
// aligned to 16 bytes
void ARGBAttenuateRow_SSSE3(const uint8* src_argb, uint8* dst_argb, int width) {
  asm volatile (
    "sub       %0,%1                           \n"
    "pcmpeqb   %%xmm3,%%xmm3                   \n"
    "pslld     $0x18,%%xmm3                    \n"
    "movdqa    %3,%%xmm4                       \n"
    "movdqa    %4,%%xmm5                       \n"

2851
    // 4 pixel loop.
2852
    ".p2align  4                               \n"
2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "pshufb    %%xmm4,%%xmm0                   \n"
    "movdqa    (%0),%%xmm1                     \n"
    "punpcklbw %%xmm1,%%xmm1                   \n"
    "pmulhuw   %%xmm1,%%xmm0                   \n"
    "movdqa    (%0),%%xmm1                     \n"
    "pshufb    %%xmm5,%%xmm1                   \n"
    "movdqa    (%0),%%xmm2                     \n"
    "punpckhbw %%xmm2,%%xmm2                   \n"
    "pmulhuw   %%xmm2,%%xmm1                   \n"
    "movdqa    (%0),%%xmm2                     \n"
    "pand      %%xmm3,%%xmm2                   \n"
    "psrlw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "por       %%xmm2,%%xmm0                   \n"
    "sub       $0x4,%2                         \n"
    "movdqa    %%xmm0,(%0,%1,1)                \n"
    "lea       0x10(%0),%0                     \n"
    "jg        1b                              \n"
  : "+r"(src_argb),    // %0
    "+r"(dst_argb),    // %1
    "+r"(width)        // %2
  : "m"(kShuffleAlpha0),  // %3
    "m"(kShuffleAlpha1)  // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}
2885
#endif  // HAS_ARGBATTENUATEROW_SSSE3
2886

2887
#ifdef HAS_ARGBUNATTENUATEROW_SSE2
2888 2889 2890 2891 2892 2893 2894 2895 2896 2897
// Unattenuate 4 pixels at a time.
// aligned to 16 bytes
void ARGBUnattenuateRow_SSE2(const uint8* src_argb, uint8* dst_argb,
                             int width) {
  uintptr_t alpha = 0;
  asm volatile (
    "sub       %0,%1                           \n"
    "pcmpeqb   %%xmm4,%%xmm4                   \n"
    "pslld     $0x18,%%xmm4                    \n"

2898
    // 4 pixel loop.
2899
    ".p2align  4                               \n"
2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movzb     0x3(%0),%3                      \n"
    "punpcklbw %%xmm0,%%xmm0                   \n"
    "movd      0x0(%4,%3,4),%%xmm2             \n"
    "movzb     0x7(%0),%3                      \n"
    "movd      0x0(%4,%3,4),%%xmm3             \n"
    "pshuflw   $0xc0,%%xmm2,%%xmm2             \n"
    "pshuflw   $0xc0,%%xmm3,%%xmm3             \n"
    "movlhps   %%xmm3,%%xmm2                   \n"
    "pmulhuw   %%xmm2,%%xmm0                   \n"
    "movdqa    (%0),%%xmm1                     \n"
    "movzb     0xb(%0),%3                      \n"
    "punpckhbw %%xmm1,%%xmm1                   \n"
    "movd      0x0(%4,%3,4),%%xmm2             \n"
    "movzb     0xf(%0),%3                      \n"
    "movd      0x0(%4,%3,4),%%xmm3             \n"
    "pshuflw   $0xc0,%%xmm2,%%xmm2             \n"
    "pshuflw   $0xc0,%%xmm3,%%xmm3             \n"
    "movlhps   %%xmm3,%%xmm2                   \n"
    "pmulhuw   %%xmm2,%%xmm1                   \n"
    "movdqa    (%0),%%xmm2                     \n"
    "pand      %%xmm4,%%xmm2                   \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "por       %%xmm2,%%xmm0                   \n"
    "sub       $0x4,%2                         \n"
    "movdqa    %%xmm0,(%0,%1,1)                \n"
    "lea       0x10(%0),%0                     \n"
    "jg        1b                              \n"
  : "+r"(src_argb),    // %0
    "+r"(dst_argb),    // %1
    "+r"(width),       // %2
    "+r"(alpha)        // %3
  : "r"(fixed_invtbl8)  // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}
2940
#endif  // HAS_ARGBUNATTENUATEROW_SSE2
2941

2942
#ifdef HAS_ARGBGRAYROW_SSSE3
2943 2944 2945 2946 2947
// Constant for ARGB color to gray scale.  0.11 * B + 0.59 * G + 0.30 * R
CONST vec8 kARGBToGray = {
  14, 76, 38, 0, 14, 76, 38, 0, 14, 76, 38, 0, 14, 76, 38, 0
};

2948
// Convert 8 ARGB pixels (64 bytes) to 8 Gray ARGB pixels
2949
void ARGBGrayRow_SSSE3(const uint8* src_argb, uint8* dst_argb, int width) {
2950
  asm volatile (
2951 2952
    "movdqa    %3,%%xmm4                       \n"
    "sub       %0,%1                           \n"
2953 2954

    // 8 pixel loop.
2955 2956 2957 2958 2959 2960 2961 2962 2963
    ".p2align  4                               \n"
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "pmaddubsw %%xmm4,%%xmm0                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
    "phaddw    %%xmm1,%%xmm0                   \n"
    "psrlw     $0x7,%%xmm0                     \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
2964 2965 2966 2967 2968 2969 2970
    "movdqa    (%0),%%xmm2                     \n"
    "movdqa    0x10(%0),%%xmm3                 \n"
    "psrld     $0x18,%%xmm2                    \n"
    "psrld     $0x18,%%xmm3                    \n"
    "packuswb  %%xmm3,%%xmm2                   \n"
    "packuswb  %%xmm2,%%xmm2                   \n"
    "movdqa    %%xmm0,%%xmm3                   \n"
2971
    "punpcklbw %%xmm0,%%xmm0                   \n"
2972
    "punpcklbw %%xmm2,%%xmm3                   \n"
2973
    "movdqa    %%xmm0,%%xmm1                   \n"
2974 2975
    "punpcklwd %%xmm3,%%xmm0                   \n"
    "punpckhwd %%xmm3,%%xmm1                   \n"
2976 2977 2978
    "sub       $0x8,%2                         \n"
    "movdqa    %%xmm0,(%0,%1,1)                \n"
    "movdqa    %%xmm1,0x10(%0,%1,1)            \n"
2979 2980
    "lea       0x20(%0),%0                     \n"
    "jg        1b                              \n"
2981 2982 2983 2984
  : "+r"(src_argb),   // %0
    "+r"(dst_argb),   // %1
    "+r"(width)       // %2
  : "m"(kARGBToGray)  // %3
2985 2986
  : "memory", "cc"
#if defined(__SSE2__)
2987
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"
2988 2989 2990 2991
#endif
  );
}
#endif  // HAS_ARGBGRAYROW_SSSE3
2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009

#ifdef HAS_ARGBSEPIAROW_SSSE3
//    b = (r * 35 + g * 68 + b * 17) >> 7
//    g = (r * 45 + g * 88 + b * 22) >> 7
//    r = (r * 50 + g * 98 + b * 24) >> 7
// Constant for ARGB color to sepia tone
CONST vec8 kARGBToSepiaB = {
  17, 68, 35, 0, 17, 68, 35, 0, 17, 68, 35, 0, 17, 68, 35, 0
};

CONST vec8 kARGBToSepiaG = {
  22, 88, 45, 0, 22, 88, 45, 0, 22, 88, 45, 0, 22, 88, 45, 0
};

CONST vec8 kARGBToSepiaR = {
  24, 98, 50, 0, 24, 98, 50, 0, 24, 98, 50, 0, 24, 98, 50, 0
};

3010
// Convert 8 ARGB pixels (32 bytes) to 8 Sepia ARGB pixels.
3011 3012 3013 3014 3015
void ARGBSepiaRow_SSSE3(uint8* dst_argb, int width) {
  asm volatile (
    "movdqa    %2,%%xmm2                       \n"
    "movdqa    %3,%%xmm3                       \n"
    "movdqa    %4,%%xmm4                       \n"
3016 3017

    // 8 pixel loop.
3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069
    ".p2align  4                               \n"
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm6                 \n"
    "pmaddubsw %%xmm2,%%xmm0                   \n"
    "pmaddubsw %%xmm2,%%xmm6                   \n"
    "phaddw    %%xmm6,%%xmm0                   \n"
    "psrlw     $0x7,%%xmm0                     \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "movdqa    (%0),%%xmm5                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "pmaddubsw %%xmm3,%%xmm5                   \n"
    "pmaddubsw %%xmm3,%%xmm1                   \n"
    "phaddw    %%xmm1,%%xmm5                   \n"
    "psrlw     $0x7,%%xmm5                     \n"
    "packuswb  %%xmm5,%%xmm5                   \n"
    "punpcklbw %%xmm5,%%xmm0                   \n"
    "movdqa    (%0),%%xmm5                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "pmaddubsw %%xmm4,%%xmm5                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
    "phaddw    %%xmm1,%%xmm5                   \n"
    "psrlw     $0x7,%%xmm5                     \n"
    "packuswb  %%xmm5,%%xmm5                   \n"
    "movdqa    (%0),%%xmm6                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "psrld     $0x18,%%xmm6                    \n"
    "psrld     $0x18,%%xmm1                    \n"
    "packuswb  %%xmm1,%%xmm6                   \n"
    "packuswb  %%xmm6,%%xmm6                   \n"
    "punpcklbw %%xmm6,%%xmm5                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklwd %%xmm5,%%xmm0                   \n"
    "punpckhwd %%xmm5,%%xmm1                   \n"
    "sub       $0x8,%1                         \n"
    "movdqa    %%xmm0,(%0)                     \n"
    "movdqa    %%xmm1,0x10(%0)                 \n"
    "lea       0x20(%0),%0                     \n"
    "jg        1b                              \n"
  : "+r"(dst_argb),      // %0
    "+r"(width)          // %1
  : "m"(kARGBToSepiaB),  // %2
    "m"(kARGBToSepiaG),  // %3
    "m"(kARGBToSepiaR)   // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"
#endif
  );
}
#endif  // HAS_ARGBSEPIAROW_SSSE3

3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081
#ifdef HAS_ARGBCOLORMATRIXROW_SSSE3
// Tranform 8 ARGB pixels (32 bytes) with color matrix.
// Same as Sepia except matrix is provided.
void ARGBColorMatrixRow_SSSE3(uint8* dst_argb, const int8* matrix_argb,
                              int width) {
  asm volatile (
    "movd      (%2),%%xmm2                     \n"
    "movd      0x4(%2),%%xmm3                  \n"
    "movd      0x8(%2),%%xmm4                  \n"
    "pshufd    $0x0,%%xmm2,%%xmm2              \n"
    "pshufd    $0x0,%%xmm3,%%xmm3              \n"
    "pshufd    $0x0,%%xmm4,%%xmm4              \n"
3082 3083

    // 8 pixel loop.
3084 3085 3086 3087 3088 3089 3090 3091 3092 3093
    ".p2align  4                               \n"
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm6                 \n"
    "pmaddubsw %%xmm2,%%xmm0                   \n"
    "pmaddubsw %%xmm2,%%xmm6                   \n"
    "movdqa    (%0),%%xmm5                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "pmaddubsw %%xmm3,%%xmm5                   \n"
    "pmaddubsw %%xmm3,%%xmm1                   \n"
3094 3095 3096 3097 3098
    "phaddsw   %%xmm6,%%xmm0                   \n"
    "phaddsw   %%xmm1,%%xmm5                   \n"
    "psraw     $0x7,%%xmm0                     \n"
    "psraw     $0x7,%%xmm5                     \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
3099 3100 3101 3102 3103 3104
    "packuswb  %%xmm5,%%xmm5                   \n"
    "punpcklbw %%xmm5,%%xmm0                   \n"
    "movdqa    (%0),%%xmm5                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "pmaddubsw %%xmm4,%%xmm5                   \n"
    "pmaddubsw %%xmm4,%%xmm1                   \n"
3105 3106
    "phaddsw   %%xmm1,%%xmm5                   \n"
    "psraw     $0x7,%%xmm5                     \n"
3107 3108 3109 3110 3111 3112 3113 3114
    "packuswb  %%xmm5,%%xmm5                   \n"
    "movdqa    (%0),%%xmm6                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "psrld     $0x18,%%xmm6                    \n"
    "psrld     $0x18,%%xmm1                    \n"
    "packuswb  %%xmm1,%%xmm6                   \n"
    "packuswb  %%xmm6,%%xmm6                   \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
3115
    "punpcklbw %%xmm6,%%xmm5                   \n"
3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133
    "punpcklwd %%xmm5,%%xmm0                   \n"
    "punpckhwd %%xmm5,%%xmm1                   \n"
    "sub       $0x8,%1                         \n"
    "movdqa    %%xmm0,(%0)                     \n"
    "movdqa    %%xmm1,0x10(%0)                 \n"
    "lea       0x20(%0),%0                     \n"
    "jg        1b                              \n"
  : "+r"(dst_argb),      // %0
    "+r"(width)          // %1
  : "r"(matrix_argb)     // %2
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6"
#endif
  );
}
#endif  // HAS_ARGBCOLORMATRIXROW_SSSE3

3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186
#ifdef HAS_ARGBQUANTIZEROW_SSE2
// Quantize 4 ARGB pixels (16 bytes).
// aligned to 16 bytes
void ARGBQuantizeRow_SSE2(uint8* dst_argb, int scale, int interval_size,
                          int interval_offset, int width) {
  asm volatile (
    "movd      %2,%%xmm2                       \n"
    "movd      %3,%%xmm3                       \n"
    "movd      %4,%%xmm4                       \n"
    "pshuflw   $0x40,%%xmm2,%%xmm2             \n"
    "pshufd    $0x44,%%xmm2,%%xmm2             \n"
    "pshuflw   $0x40,%%xmm3,%%xmm3             \n"
    "pshufd    $0x44,%%xmm3,%%xmm3             \n"
    "pshuflw   $0x40,%%xmm4,%%xmm4             \n"
    "pshufd    $0x44,%%xmm4,%%xmm4             \n"
    "pxor      %%xmm5,%%xmm5                   \n"
    "pcmpeqb   %%xmm6,%%xmm6                   \n"
    "pslld     $0x18,%%xmm6                    \n"

    // 4 pixel loop.
    ".p2align  2                               \n"
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "punpcklbw %%xmm5,%%xmm0                   \n"
    "pmulhuw   %%xmm2,%%xmm0                   \n"
    "movdqa    (%0),%%xmm1                     \n"
    "punpckhbw %%xmm5,%%xmm1                   \n"
    "pmulhuw   %%xmm2,%%xmm1                   \n"
    "pmullw    %%xmm3,%%xmm0                   \n"
    "movdqa    (%0),%%xmm7                     \n"
    "pmullw    %%xmm3,%%xmm1                   \n"
    "pand      %%xmm6,%%xmm7                   \n"
    "paddw     %%xmm4,%%xmm0                   \n"
    "paddw     %%xmm4,%%xmm1                   \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "por       %%xmm7,%%xmm0                   \n"
    "sub       $0x4,%1                         \n"
    "movdqa    %%xmm0,(%0)                     \n"
    "lea       0x10(%0),%0                     \n"
    "jg        1b                              \n"
  : "+r"(dst_argb),       // %0
    "+r"(width)           // %1
  : "r"(scale),           // %2
    "r"(interval_size),   // %3
    "r"(interval_offset)  // %4
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
#endif
  );
}
#endif  // HAS_ARGBQUANTIZEROW_SSE2

fbarchard@google.com's avatar
fbarchard@google.com committed
3187 3188 3189 3190
#ifdef HAS_COMPUTECUMULATIVESUMROW_SSE2
// Creates a table of cumulative sums where each value is a sum of all values
// above and to the left of the value, inclusive of the value.
void ComputeCumulativeSumRow_SSE2(const uint8* row, int32* cumsum,
3191
                                  const int32* previous_cumsum, int width) {
fbarchard@google.com's avatar
fbarchard@google.com committed
3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243
  asm volatile (
    "sub       %1,%2                           \n"
    "pxor      %%xmm0,%%xmm0                   \n"
    "pxor      %%xmm1,%%xmm1                   \n"
    "sub       $0x4,%3                         \n"
    "jl        49f                             \n"
    "test      $0xf,%1                         \n"
    "jne       49f                             \n"

  // 4 pixel loop                              \n"
    ".p2align  2                               \n"
  "40:                                         \n"
    "movdqu    (%0),%%xmm2                     \n"
    "lea       0x10(%0),%0                     \n"
    "movdqa    %%xmm2,%%xmm4                   \n"
    "punpcklbw %%xmm1,%%xmm2                   \n"
    "movdqa    %%xmm2,%%xmm3                   \n"
    "punpcklwd %%xmm1,%%xmm2                   \n"
    "punpckhwd %%xmm1,%%xmm3                   \n"
    "punpckhbw %%xmm1,%%xmm4                   \n"
    "movdqa    %%xmm4,%%xmm5                   \n"
    "punpcklwd %%xmm1,%%xmm4                   \n"
    "punpckhwd %%xmm1,%%xmm5                   \n"
    "paddd     %%xmm2,%%xmm0                   \n"
    "movdqa    (%1,%2,1),%%xmm2                \n"
    "paddd     %%xmm0,%%xmm2                   \n"
    "paddd     %%xmm3,%%xmm0                   \n"
    "movdqa    0x10(%1,%2,1),%%xmm3            \n"
    "paddd     %%xmm0,%%xmm3                   \n"
    "paddd     %%xmm4,%%xmm0                   \n"
    "movdqa    0x20(%1,%2,1),%%xmm4            \n"
    "paddd     %%xmm0,%%xmm4                   \n"
    "paddd     %%xmm5,%%xmm0                   \n"
    "movdqa    0x30(%1,%2,1),%%xmm5            \n"
    "paddd     %%xmm0,%%xmm5                   \n"
    "movdqa    %%xmm2,(%1)                     \n"
    "movdqa    %%xmm3,0x10(%1)                 \n"
    "movdqa    %%xmm4,0x20(%1)                 \n"
    "movdqa    %%xmm5,0x30(%1)                 \n"
    "lea       0x40(%1),%1                     \n"
    "sub       $0x4,%3                         \n"
    "jge       40b                             \n"

  "49:                                         \n"
    "add       $0x3,%3                         \n"
    "jl        19f                             \n"

  // 1 pixel loop                              \n"
    ".p2align  2                               \n"
  "10:                                         \n"
    "movd      (%0),%%xmm2                     \n"
    "lea       0x4(%0),%0                      \n"
3244 3245
    "punpcklbw %%xmm1,%%xmm2                   \n"
    "punpcklwd %%xmm1,%%xmm2                   \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355
    "paddd     %%xmm2,%%xmm0                   \n"
    "movdqu    (%1,%2,1),%%xmm2                \n"
    "paddd     %%xmm0,%%xmm2                   \n"
    "movdqu    %%xmm2,(%1)                     \n"
    "lea       0x10(%1),%1                     \n"
    "sub       $0x1,%3                         \n"
    "jge       10b                             \n"

  "19:                                         \n"
  : "+r"(row),  // %0
    "+r"(cumsum),  // %1
    "+r"(previous_cumsum),  // %2
    "+r"(width)  // %3
  :
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5"
#endif
  );
}
#endif  // HAS_COMPUTECUMULATIVESUMROW_SSE2

#ifdef HAS_CUMULATIVESUMTOAVERAGE_SSE2
void CumulativeSumToAverage_SSE2(const int32* topleft, const int32* botleft,
                                 int width, int area, uint8* dst, int count) {
  asm volatile (
    "movd      %5,%%xmm4                       \n"
    "cvtdq2ps  %%xmm4,%%xmm4                   \n"
    "rcpss     %%xmm4,%%xmm4                   \n"
    "pshufd    $0x0,%%xmm4,%%xmm4              \n"
    "sub       $0x4,%3                         \n"
    "jl        49f                             \n"

  // 4 pixel loop                              \n"
    ".p2align  2                               \n"
  "40:                                         \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    0x10(%0),%%xmm1                 \n"
    "movdqa    0x20(%0),%%xmm2                 \n"
    "movdqa    0x30(%0),%%xmm3                 \n"
    "psubd     (%0,%4,4),%%xmm0                \n"
    "psubd     0x10(%0,%4,4),%%xmm1            \n"
    "psubd     0x20(%0,%4,4),%%xmm2            \n"
    "psubd     0x30(%0,%4,4),%%xmm3            \n"
    "lea       0x40(%0),%0                     \n"
    "psubd     (%1),%%xmm0                     \n"
    "psubd     0x10(%1),%%xmm1                 \n"
    "psubd     0x20(%1),%%xmm2                 \n"
    "psubd     0x30(%1),%%xmm3                 \n"
    "paddd     (%1,%4,4),%%xmm0                \n"
    "paddd     0x10(%1,%4,4),%%xmm1            \n"
    "paddd     0x20(%1,%4,4),%%xmm2            \n"
    "paddd     0x30(%1,%4,4),%%xmm3            \n"
    "lea       0x40(%1),%1                     \n"
    "cvtdq2ps  %%xmm0,%%xmm0                   \n"
    "cvtdq2ps  %%xmm1,%%xmm1                   \n"
    "mulps     %%xmm4,%%xmm0                   \n"
    "mulps     %%xmm4,%%xmm1                   \n"
    "cvtdq2ps  %%xmm2,%%xmm2                   \n"
    "cvtdq2ps  %%xmm3,%%xmm3                   \n"
    "mulps     %%xmm4,%%xmm2                   \n"
    "mulps     %%xmm4,%%xmm3                   \n"
    "cvtps2dq  %%xmm0,%%xmm0                   \n"
    "cvtps2dq  %%xmm1,%%xmm1                   \n"
    "cvtps2dq  %%xmm2,%%xmm2                   \n"
    "cvtps2dq  %%xmm3,%%xmm3                   \n"
    "packssdw  %%xmm1,%%xmm0                   \n"
    "packssdw  %%xmm3,%%xmm2                   \n"
    "packuswb  %%xmm2,%%xmm0                   \n"
    "movdqu    %%xmm0,(%2)                     \n"
    "lea       0x10(%2),%2                     \n"
    "sub       $0x4,%3                         \n"
    "jge       40b                             \n"

  "49:                                         \n"
    "add       $0x3,%3                         \n"
    "jl        19f                             \n"

  // 1 pixel loop                              \n"
    ".p2align  2                               \n"
  "10:                                         \n"
    "movdqa    (%0),%%xmm0                     \n"
    "psubd     (%0,%4,4),%%xmm0                \n"
    "lea       0x10(%0),%0                     \n"
    "psubd     (%1),%%xmm0                     \n"
    "paddd     (%1,%4,4),%%xmm0                \n"
    "lea       0x10(%1),%1                     \n"
    "cvtdq2ps  %%xmm0,%%xmm0                   \n"
    "mulps     %%xmm4,%%xmm0                   \n"
    "cvtps2dq  %%xmm0,%%xmm0                   \n"
    "packssdw  %%xmm0,%%xmm0                   \n"
    "packuswb  %%xmm0,%%xmm0                   \n"
    "movd      %%xmm0,(%2)                     \n"
    "lea       0x4(%2),%2                      \n"
    "sub       $0x1,%3                         \n"
    "jge       10b                             \n"
  "19:                                         \n"
  : "+r"(topleft),  // %0
    "+r"(botleft),  // %1
    "+r"(dst),      // %2
    "+rm"(count)    // %3
  : "r"(static_cast<intptr_t>(width)),  // %4
    "rm"(area)     // %5
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"
#endif
  );
}
#endif  // HAS_CUMULATIVESUMTOAVERAGE_SSE2
3356 3357 3358 3359 3360 3361 3362 3363 3364 3365
#ifdef HAS_ARGBSHADE_SSE2
// Shade 4 pixels at a time by specified value.
// Aligned to 16 bytes.
void ARGBShadeRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width,
                       uint32 value) {
  asm volatile (
    "movd      %3,%%xmm2                       \n"
    "sub       %0,%1                           \n"
    "punpcklbw %%xmm2,%%xmm2                   \n"
    "punpcklqdq %%xmm2,%%xmm2                  \n"
fbarchard@google.com's avatar
fbarchard@google.com committed
3366

3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393
    // 4 pixel loop.
    ".p2align  2                               \n"
  "1:                                          \n"
    "movdqa    (%0),%%xmm0                     \n"
    "movdqa    %%xmm0,%%xmm1                   \n"
    "punpcklbw %%xmm0,%%xmm0                   \n"
    "punpckhbw %%xmm1,%%xmm1                   \n"
    "pmulhuw   %%xmm2,%%xmm0                   \n"
    "pmulhuw   %%xmm2,%%xmm1                   \n"
    "psrlw     $0x8,%%xmm0                     \n"
    "psrlw     $0x8,%%xmm1                     \n"
    "packuswb  %%xmm1,%%xmm0                   \n"
    "sub       $0x4,%2                         \n"
    "movdqa    %%xmm0,(%0,%1,1)                \n"
    "lea       0x10(%0),%0                     \n"
    "jg        1b                              \n"
  : "+r"(src_argb),       // %0
    "+r"(dst_argb),       // %1
    "+r"(width)           // %2
  : "r"(value)            // %3
  : "memory", "cc"
#if defined(__SSE2__)
    , "xmm0", "xmm1", "xmm2"
#endif
  );
}
#endif  // HAS_ARGBSHADE_SSE2
fbarchard@google.com's avatar
fbarchard@google.com committed
3394

3395
#ifdef HAS_ARGBAFFINEROW_SSE2
3396 3397
// TODO(fbarchard): Find 64 bit way to avoid masking.
// TODO(fbarchard): Investigate why 4 pixels is slower than 2 on Core2.
3398
// Copy ARGB pixels from source image with slope to a row of destination.
3399 3400 3401
// Caveat - in 64 bit, movd is used with 64 bit gpr due to Mac gcc producing
// an error if movq is used.  movd  %%xmm0,%1

3402 3403 3404
void ARGBAffineRow_SSE2(const uint8* src_argb, int src_argb_stride,
                        uint8* dst_argb, const float* uv_dudv, int width) {
  intptr_t src_argb_stride_temp = src_argb_stride;
3405
  intptr_t temp = 0;
3406 3407
  asm volatile (
    "movq      (%3),%%xmm2                     \n"
3408
    "movq      0x8(%3),%%xmm7                  \n"
3409 3410
    "shl       $0x10,%1                        \n"
    "add       $0x4,%1                         \n"
3411 3412 3413 3414 3415 3416
    "movd      %1,%%xmm5                       \n"
    "sub       $0x4,%4                         \n"
    "jl        49f                             \n"

    "pshufd    $0x44,%%xmm7,%%xmm7             \n"
    "pshufd    $0x0,%%xmm5,%%xmm5              \n"
3417
    "movdqa    %%xmm2,%%xmm0                   \n"
3418
    "addps     %%xmm7,%%xmm0                   \n"
3419
    "movlhps   %%xmm0,%%xmm2                   \n"
3420 3421 3422 3423 3424
    "movdqa    %%xmm7,%%xmm4                   \n"
    "addps     %%xmm4,%%xmm4                   \n"
    "movdqa    %%xmm2,%%xmm3                   \n"
    "addps     %%xmm4,%%xmm3                   \n"
    "addps     %%xmm4,%%xmm4                   \n"
3425

3426 3427 3428 3429 3430 3431 3432 3433
  // 4 pixel loop                              \n"
    ".p2align  4                               \n"
  "40:                                         \n"
    "cvttps2dq %%xmm2,%%xmm0                   \n"
    "cvttps2dq %%xmm3,%%xmm1                   \n"
    "packssdw  %%xmm1,%%xmm0                   \n"
    "pmaddwd   %%xmm5,%%xmm0                   \n"
#if defined(__x86_64__)
3434
    "movd      %%xmm0,%1                       \n"
3435
    "mov       %1,%5                           \n"
3436
    "and       $0x0fffffff,%1                  \n"
3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450
    "shr       $32,%5                          \n"
    "pshufd    $0xEE,%%xmm0,%%xmm0             \n"
#else
    "movd      %%xmm0,%1                       \n"
    "pshufd    $0x39,%%xmm0,%%xmm0             \n"
    "movd      %%xmm0,%5                       \n"
    "pshufd    $0x39,%%xmm0,%%xmm0             \n"
#endif
    "movd      (%0,%1,1),%%xmm1                \n"
    "movd      (%0,%5,1),%%xmm6                \n"
    "punpckldq %%xmm6,%%xmm1                   \n"
    "addps     %%xmm4,%%xmm2                   \n"
    "movq      %%xmm1,(%2)                     \n"
#if defined(__x86_64__)
3451
    "movd      %%xmm0,%1                       \n"
3452
    "mov       %1,%5                           \n"
3453
    "and       $0x0fffffff,%1                  \n"
3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470
    "shr       $32,%5                          \n"
#else
    "movd      %%xmm0,%1                       \n"
    "pshufd    $0x39,%%xmm0,%%xmm0             \n"
    "movd      %%xmm0,%5                       \n"
#endif
    "movd      (%0,%1,1),%%xmm0                \n"
    "movd      (%0,%5,1),%%xmm6                \n"
    "punpckldq %%xmm6,%%xmm0                   \n"
    "addps     %%xmm4,%%xmm3                   \n"
    "sub       $0x4,%4                         \n"
    "movq      %%xmm0,0x08(%2)                 \n"
    "lea       0x10(%2),%2                     \n"
    "jge       40b                             \n"

  "49:                                         \n"
    "add       $0x3,%4                         \n"
3471 3472 3473
    "jl        19f                             \n"

  // 1 pixel loop                              \n"
3474
    ".p2align  4                               \n"
3475
  "10:                                         \n"
3476 3477 3478 3479 3480 3481
    "cvttps2dq %%xmm2,%%xmm0                   \n"
    "packssdw  %%xmm0,%%xmm0                   \n"
    "pmaddwd   %%xmm5,%%xmm0                   \n"
    "addps     %%xmm7,%%xmm2                   \n"
    "movd      %%xmm0,%1                       \n"
#if defined(__x86_64__)
3482
    "and       $0x0fffffff,%1                  \n"
3483
#endif
3484 3485 3486 3487 3488 3489 3490 3491 3492 3493
    "movd      (%0,%1,1),%%xmm0                \n"
    "sub       $0x1,%4                         \n"
    "movd      %%xmm0,(%2)                     \n"
    "lea       0x4(%2),%2                      \n"
    "jge       10b                             \n"
  "19:                                         \n"
  : "+r"(src_argb),  // %0
    "+r"(src_argb_stride_temp),  // %1
    "+r"(dst_argb),  // %2
    "+r"(uv_dudv),   // %3
3494 3495
    "+rm"(width),    // %4
    "+r"(temp)   // %5
3496 3497 3498
  :
  : "memory", "cc"
#if defined(__SSE2__)
3499
    , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
3500 3501 3502 3503 3504
#endif
  );
}
#endif  // HAS_ARGBAFFINEROW_SSE2

3505 3506
#endif  // defined(__x86_64__) || defined(__i386__)

3507
#ifdef __cplusplus
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
3508
}  // extern "C"
3509 3510
}  // namespace libyuv
#endif