mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The LibYuv project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "row.h" |
| 12 | |
frkoenig@google.com | c82af4a | 2011-11-11 00:54:34 +0000 | [diff] [blame] | 13 | #include "libyuv/basic_types.h" |
| 14 | |
fbarchard@google.com | fe5ff7e | 2011-12-10 07:45:58 +0000 | [diff] [blame] | 15 | #ifdef __cplusplus |
| 16 | namespace libyuv { |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 17 | extern "C" { |
fbarchard@google.com | fe5ff7e | 2011-12-10 07:45:58 +0000 | [diff] [blame] | 18 | #endif |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 19 | |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 20 | #ifdef __APPLE__ |
| 21 | #define CONST |
| 22 | #else |
| 23 | #define CONST static const |
| 24 | #endif |
| 25 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 26 | #ifdef HAS_ARGBTOUVROW_SSSE3 |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 27 | CONST vec8 kARGBToU = { |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 28 | 112, -74, -38, 0, 112, -74, -38, 0, 112, -74, -38, 0, 112, -74, -38, 0 |
| 29 | }; |
| 30 | |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 31 | CONST uvec8 kARGBToV = { |
fbarchard@google.com | 2430e04 | 2011-11-11 21:57:06 +0000 | [diff] [blame] | 32 | -18, -94, 112, 0, -18, -94, 112, 0, -18, -94, 112, 0, -18, -94, 112, 0 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 33 | }; |
fbarchard@google.com | 2430e04 | 2011-11-11 21:57:06 +0000 | [diff] [blame] | 34 | |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 35 | CONST uvec8 kAddUV128 = { |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 36 | 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, |
| 37 | 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u |
| 38 | }; |
| 39 | #endif |
| 40 | |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 41 | #ifdef HAS_ARGBTOYROW_SSSE3 |
| 42 | |
| 43 | // Constant multiplication table for converting ARGB to I400. |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 44 | CONST vec8 kARGBToY = { |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 45 | 13, 65, 33, 0, 13, 65, 33, 0, 13, 65, 33, 0, 13, 65, 33, 0 |
| 46 | }; |
| 47 | |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 48 | CONST uvec8 kAddY16 = { |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 49 | 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u |
| 50 | }; |
| 51 | |
fbarchard@google.com | ba1f526 | 2012-01-12 19:22:41 +0000 | [diff] [blame^] | 52 | // Shuffle table for converting RGB24 to ARGB. |
| 53 | CONST uvec8 kShuffleMaskRGB24ToARGB = { |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 54 | 0u, 1u, 2u, 12u, 3u, 4u, 5u, 13u, 6u, 7u, 8u, 14u, 9u, 10u, 11u, 15u |
| 55 | }; |
| 56 | |
| 57 | // Shuffle table for converting RAW to ARGB. |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 58 | CONST uvec8 kShuffleMaskRAWToARGB = { |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 59 | 2u, 1u, 0u, 12u, 5u, 4u, 3u, 13u, 8u, 7u, 6u, 14u, 11u, 10u, 9u, 15u |
| 60 | }; |
| 61 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 62 | // Shuffle table for converting ABGR to ARGB. |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 63 | CONST uvec8 kShuffleMaskABGRToARGB = { |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 64 | 2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u |
| 65 | }; |
| 66 | |
| 67 | // Shuffle table for converting BGRA to ARGB. |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 68 | CONST uvec8 kShuffleMaskBGRAToARGB = { |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 69 | 3u, 2u, 1u, 0u, 7u, 6u, 5u, 4u, 11u, 10u, 9u, 8u, 15u, 14u, 13u, 12u |
| 70 | }; |
| 71 | |
| 72 | void I400ToARGBRow_SSE2(const uint8* src_y, uint8* dst_argb, int pix) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 73 | asm volatile ( |
| 74 | "pcmpeqb %%xmm5,%%xmm5 \n" |
| 75 | "pslld $0x18,%%xmm5 \n" |
| 76 | "1: \n" |
| 77 | "movq (%0),%%xmm0 \n" |
| 78 | "lea 0x8(%0),%0 \n" |
| 79 | "punpcklbw %%xmm0,%%xmm0 \n" |
| 80 | "movdqa %%xmm0,%%xmm1 \n" |
| 81 | "punpcklwd %%xmm0,%%xmm0 \n" |
| 82 | "punpckhwd %%xmm1,%%xmm1 \n" |
| 83 | "por %%xmm5,%%xmm0 \n" |
| 84 | "por %%xmm5,%%xmm1 \n" |
| 85 | "movdqa %%xmm0,(%1) \n" |
| 86 | "movdqa %%xmm1,0x10(%1) \n" |
| 87 | "lea 0x20(%1),%1 \n" |
| 88 | "sub $0x8,%2 \n" |
| 89 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 90 | : "+r"(src_y), // %0 |
| 91 | "+r"(dst_argb), // %1 |
| 92 | "+r"(pix) // %2 |
| 93 | : |
| 94 | : "memory", "cc" |
| 95 | #if defined(__SSE2__) |
| 96 | , "xmm0", "xmm1", "xmm5" |
| 97 | #endif |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 98 | ); |
| 99 | } |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 100 | |
| 101 | void ABGRToARGBRow_SSSE3(const uint8* src_abgr, uint8* dst_argb, int pix) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 102 | asm volatile ( |
| 103 | "movdqa %3,%%xmm5 \n" |
| 104 | "1: \n" |
| 105 | "movdqa (%0),%%xmm0 \n" |
| 106 | "lea 0x10(%0),%0 \n" |
| 107 | "pshufb %%xmm5,%%xmm0 \n" |
| 108 | "movdqa %%xmm0,(%1) \n" |
| 109 | "lea 0x10(%1),%1 \n" |
| 110 | "sub $0x4,%2 \n" |
| 111 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 112 | : "+r"(src_abgr), // %0 |
| 113 | "+r"(dst_argb), // %1 |
| 114 | "+r"(pix) // %2 |
| 115 | : "m"(kShuffleMaskABGRToARGB) // %3 |
| 116 | : "memory", "cc" |
| 117 | #if defined(__SSE2__) |
| 118 | , "xmm0", "xmm5" |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 119 | #endif |
| 120 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 121 | ); |
| 122 | } |
| 123 | |
| 124 | void BGRAToARGBRow_SSSE3(const uint8* src_bgra, uint8* dst_argb, int pix) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 125 | asm volatile ( |
| 126 | "movdqa %3,%%xmm5 \n" |
| 127 | "1: \n" |
| 128 | "movdqa (%0),%%xmm0 \n" |
| 129 | "lea 0x10(%0),%0 \n" |
| 130 | "pshufb %%xmm5,%%xmm0 \n" |
| 131 | "movdqa %%xmm0,(%1) \n" |
| 132 | "lea 0x10(%1),%1 \n" |
| 133 | "sub $0x4,%2 \n" |
| 134 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 135 | : "+r"(src_bgra), // %0 |
| 136 | "+r"(dst_argb), // %1 |
| 137 | "+r"(pix) // %2 |
| 138 | : "m"(kShuffleMaskBGRAToARGB) // %3 |
| 139 | : "memory", "cc" |
| 140 | #if defined(__SSE2__) |
| 141 | , "xmm0", "xmm5" |
| 142 | #endif |
| 143 | ); |
| 144 | } |
| 145 | |
fbarchard@google.com | ba1f526 | 2012-01-12 19:22:41 +0000 | [diff] [blame^] | 146 | void RGB24ToARGBRow_SSSE3(const uint8* src_rgb24, uint8* dst_argb, int pix) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 147 | asm volatile ( |
| 148 | "pcmpeqb %%xmm5,%%xmm5 \n" // generate mask 0xff000000 |
| 149 | "pslld $0x18,%%xmm5 \n" |
| 150 | "movdqa %3,%%xmm4 \n" |
| 151 | "1: \n" |
| 152 | "movdqa (%0),%%xmm0 \n" |
| 153 | "movdqa 0x10(%0),%%xmm1 \n" |
| 154 | "movdqa 0x20(%0),%%xmm3 \n" |
| 155 | "lea 0x30(%0),%0 \n" |
| 156 | "movdqa %%xmm3,%%xmm2 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 157 | "palignr $0x8,%%xmm1,%%xmm2 \n" |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 158 | "pshufb %%xmm4,%%xmm2 \n" |
| 159 | "por %%xmm5,%%xmm2 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 160 | "palignr $0xc,%%xmm0,%%xmm1 \n" |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 161 | "pshufb %%xmm4,%%xmm0 \n" |
| 162 | "movdqa %%xmm2,0x20(%1) \n" |
| 163 | "por %%xmm5,%%xmm0 \n" |
| 164 | "pshufb %%xmm4,%%xmm1 \n" |
| 165 | "movdqa %%xmm0,(%1) \n" |
| 166 | "por %%xmm5,%%xmm1 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 167 | "palignr $0x4,%%xmm3,%%xmm3 \n" |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 168 | "pshufb %%xmm4,%%xmm3 \n" |
| 169 | "movdqa %%xmm1,0x10(%1) \n" |
| 170 | "por %%xmm5,%%xmm3 \n" |
| 171 | "movdqa %%xmm3,0x30(%1) \n" |
| 172 | "lea 0x40(%1),%1 \n" |
| 173 | "sub $0x10,%2 \n" |
| 174 | "ja 1b \n" |
fbarchard@google.com | ba1f526 | 2012-01-12 19:22:41 +0000 | [diff] [blame^] | 175 | : "+r"(src_rgb24), // %0 |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 176 | "+r"(dst_argb), // %1 |
| 177 | "+r"(pix) // %2 |
fbarchard@google.com | ba1f526 | 2012-01-12 19:22:41 +0000 | [diff] [blame^] | 178 | : "m"(kShuffleMaskRGB24ToARGB) // %3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 179 | : "memory", "cc" |
| 180 | #if defined(__SSE2__) |
| 181 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
| 182 | #endif |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 183 | ); |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 184 | } |
| 185 | |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 186 | void RAWToARGBRow_SSSE3(const uint8* src_raw, uint8* dst_argb, int pix) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 187 | asm volatile ( |
| 188 | "pcmpeqb %%xmm5,%%xmm5 \n" // generate mask 0xff000000 |
| 189 | "pslld $0x18,%%xmm5 \n" |
| 190 | "movdqa %3,%%xmm4 \n" |
| 191 | "1: \n" |
| 192 | "movdqa (%0),%%xmm0 \n" |
| 193 | "movdqa 0x10(%0),%%xmm1 \n" |
| 194 | "movdqa 0x20(%0),%%xmm3 \n" |
| 195 | "lea 0x30(%0),%0 \n" |
| 196 | "movdqa %%xmm3,%%xmm2 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 197 | "palignr $0x8,%%xmm1,%%xmm2 \n" |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 198 | "pshufb %%xmm4,%%xmm2 \n" |
| 199 | "por %%xmm5,%%xmm2 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 200 | "palignr $0xc,%%xmm0,%%xmm1 \n" |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 201 | "pshufb %%xmm4,%%xmm0 \n" |
| 202 | "movdqa %%xmm2,0x20(%1) \n" |
| 203 | "por %%xmm5,%%xmm0 \n" |
| 204 | "pshufb %%xmm4,%%xmm1 \n" |
| 205 | "movdqa %%xmm0,(%1) \n" |
| 206 | "por %%xmm5,%%xmm1 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 207 | "palignr $0x4,%%xmm3,%%xmm3 \n" |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 208 | "pshufb %%xmm4,%%xmm3 \n" |
| 209 | "movdqa %%xmm1,0x10(%1) \n" |
| 210 | "por %%xmm5,%%xmm3 \n" |
| 211 | "movdqa %%xmm3,0x30(%1) \n" |
| 212 | "lea 0x40(%1),%1 \n" |
| 213 | "sub $0x10,%2 \n" |
| 214 | "ja 1b \n" |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 215 | : "+r"(src_raw), // %0 |
| 216 | "+r"(dst_argb), // %1 |
| 217 | "+r"(pix) // %2 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 218 | : "m"(kShuffleMaskRAWToARGB) // %3 |
| 219 | : "memory", "cc" |
| 220 | #if defined(__SSE2__) |
| 221 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
| 222 | #endif |
| 223 | ); |
| 224 | } |
| 225 | |
| 226 | void ARGBToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 227 | asm volatile ( |
| 228 | "movdqa %4,%%xmm5 \n" |
| 229 | "movdqa %3,%%xmm4 \n" |
| 230 | "1: \n" |
| 231 | "movdqa (%0),%%xmm0 \n" |
| 232 | "movdqa 0x10(%0),%%xmm1 \n" |
| 233 | "movdqa 0x20(%0),%%xmm2 \n" |
| 234 | "movdqa 0x30(%0),%%xmm3 \n" |
| 235 | "pmaddubsw %%xmm4,%%xmm0 \n" |
| 236 | "pmaddubsw %%xmm4,%%xmm1 \n" |
| 237 | "pmaddubsw %%xmm4,%%xmm2 \n" |
| 238 | "pmaddubsw %%xmm4,%%xmm3 \n" |
| 239 | "lea 0x40(%0),%0 \n" |
| 240 | "phaddw %%xmm1,%%xmm0 \n" |
| 241 | "phaddw %%xmm3,%%xmm2 \n" |
| 242 | "psrlw $0x7,%%xmm0 \n" |
| 243 | "psrlw $0x7,%%xmm2 \n" |
| 244 | "packuswb %%xmm2,%%xmm0 \n" |
| 245 | "paddb %%xmm5,%%xmm0 \n" |
| 246 | "movdqa %%xmm0,(%1) \n" |
| 247 | "lea 0x10(%1),%1 \n" |
| 248 | "sub $0x10,%2 \n" |
| 249 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 250 | : "+r"(src_argb), // %0 |
| 251 | "+r"(dst_y), // %1 |
| 252 | "+r"(pix) // %2 |
| 253 | : "m"(kARGBToY), // %3 |
| 254 | "m"(kAddY16) // %4 |
| 255 | : "memory", "cc" |
| 256 | #if defined(__SSE2__) |
| 257 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
| 258 | #endif |
| 259 | |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 260 | ); |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 261 | } |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 262 | #endif |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 263 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 264 | #ifdef HAS_ARGBTOUVROW_SSSE3 |
| 265 | void ARGBToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb, |
| 266 | uint8* dst_u, uint8* dst_v, int width) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 267 | asm volatile ( |
| 268 | "movdqa %0,%%xmm4 \n" |
| 269 | "movdqa %1,%%xmm3 \n" |
| 270 | "movdqa %2,%%xmm5 \n" |
fbarchard@google.com | d93d448 | 2011-11-10 18:26:20 +0000 | [diff] [blame] | 271 | : |
| 272 | : "m"(kARGBToU), // %0 |
| 273 | "m"(kARGBToV), // %1 |
| 274 | "m"(kAddUV128) // %2 |
| 275 | : |
| 276 | #if defined(__SSE2__) |
| 277 | "xmm3", "xmm4", "xmm5" |
| 278 | #endif |
| 279 | ); |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 280 | asm volatile ( |
| 281 | "sub %1,%2 \n" |
| 282 | "1: \n" |
| 283 | "movdqa (%0),%%xmm0 \n" |
| 284 | "movdqa 0x10(%0),%%xmm1 \n" |
| 285 | "movdqa 0x20(%0),%%xmm2 \n" |
| 286 | "movdqa 0x30(%0),%%xmm6 \n" |
| 287 | "pavgb (%0,%4,1),%%xmm0 \n" |
| 288 | "pavgb 0x10(%0,%4,1),%%xmm1 \n" |
| 289 | "pavgb 0x20(%0,%4,1),%%xmm2 \n" |
| 290 | "pavgb 0x30(%0,%4,1),%%xmm6 \n" |
| 291 | "lea 0x40(%0),%0 \n" |
| 292 | "movdqa %%xmm0,%%xmm7 \n" |
| 293 | "shufps $0x88,%%xmm1,%%xmm0 \n" |
| 294 | "shufps $0xdd,%%xmm1,%%xmm7 \n" |
| 295 | "pavgb %%xmm7,%%xmm0 \n" |
| 296 | "movdqa %%xmm2,%%xmm7 \n" |
| 297 | "shufps $0x88,%%xmm6,%%xmm2 \n" |
| 298 | "shufps $0xdd,%%xmm6,%%xmm7 \n" |
| 299 | "pavgb %%xmm7,%%xmm2 \n" |
| 300 | "movdqa %%xmm0,%%xmm1 \n" |
| 301 | "movdqa %%xmm2,%%xmm6 \n" |
| 302 | "pmaddubsw %%xmm4,%%xmm0 \n" |
| 303 | "pmaddubsw %%xmm4,%%xmm2 \n" |
| 304 | "pmaddubsw %%xmm3,%%xmm1 \n" |
| 305 | "pmaddubsw %%xmm3,%%xmm6 \n" |
| 306 | "phaddw %%xmm2,%%xmm0 \n" |
| 307 | "phaddw %%xmm6,%%xmm1 \n" |
| 308 | "psraw $0x8,%%xmm0 \n" |
| 309 | "psraw $0x8,%%xmm1 \n" |
| 310 | "packsswb %%xmm1,%%xmm0 \n" |
| 311 | "paddb %%xmm5,%%xmm0 \n" |
| 312 | "movlps %%xmm0,(%1) \n" |
| 313 | "movhps %%xmm0,(%1,%2,1) \n" |
| 314 | "lea 0x8(%1),%1 \n" |
| 315 | "sub $0x10,%3 \n" |
| 316 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 317 | : "+r"(src_argb0), // %0 |
| 318 | "+r"(dst_u), // %1 |
| 319 | "+r"(dst_v), // %2 |
| 320 | "+rm"(width) // %3 |
fbarchard@google.com | d93d448 | 2011-11-10 18:26:20 +0000 | [diff] [blame] | 321 | : "r"(static_cast<intptr_t>(src_stride_argb)) |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 322 | : "memory", "cc" |
| 323 | #if defined(__SSE2__) |
fbarchard@google.com | d93d448 | 2011-11-10 18:26:20 +0000 | [diff] [blame] | 324 | , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 325 | #endif |
| 326 | ); |
| 327 | } |
| 328 | #endif |
| 329 | |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 330 | #ifdef HAS_FASTCONVERTYUVTOARGBROW_SSSE3 |
| 331 | #define UB 127 /* min(63,static_cast<int8>(2.018 * 64)) */ |
| 332 | #define UG -25 /* static_cast<int8>(-0.391 * 64 - 0.5) */ |
| 333 | #define UR 0 |
| 334 | |
| 335 | #define VB 0 |
| 336 | #define VG -52 /* static_cast<int8>(-0.813 * 64 - 0.5) */ |
| 337 | #define VR 102 /* static_cast<int8>(1.596 * 64 + 0.5) */ |
| 338 | |
| 339 | // Bias |
| 340 | #define BB UB * 128 + VB * 128 |
| 341 | #define BG UG * 128 + VG * 128 |
| 342 | #define BR UR * 128 + VR * 128 |
| 343 | |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 344 | #define YG 74 /* static_cast<int8>(1.164 * 64 + 0.5) */ |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 345 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 346 | #if defined(__APPLE__) || defined(__x86_64__) |
| 347 | #define OMITFP |
| 348 | #else |
| 349 | #define OMITFP __attribute__((optimize("omit-frame-pointer"))) |
| 350 | #endif |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 351 | |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 352 | struct { |
| 353 | vec8 kUVToB; |
| 354 | vec8 kUVToG; |
| 355 | vec8 kUVToR; |
| 356 | vec16 kUVBiasB; |
| 357 | vec16 kUVBiasG; |
| 358 | vec16 kUVBiasR; |
| 359 | vec16 kYSub16; |
| 360 | vec16 kYToRgb; |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 361 | } CONST SIMD_ALIGNED(kYuvConstants) = { |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 362 | { UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB }, |
| 363 | { UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG }, |
| 364 | { UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR }, |
| 365 | { BB, BB, BB, BB, BB, BB, BB, BB }, |
| 366 | { BG, BG, BG, BG, BG, BG, BG, BG }, |
| 367 | { BR, BR, BR, BR, BR, BR, BR, BR }, |
| 368 | { 16, 16, 16, 16, 16, 16, 16, 16 }, |
| 369 | { YG, YG, YG, YG, YG, YG, YG, YG } |
| 370 | }; |
| 371 | |
| 372 | // Convert 8 pixels |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 373 | #define YUVTORGB \ |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 374 | "movd (%1),%%xmm0 \n" \ |
| 375 | "movd (%1,%2,1),%%xmm1 \n" \ |
| 376 | "lea 0x4(%1),%1 \n" \ |
| 377 | "punpcklbw %%xmm1,%%xmm0 \n" \ |
| 378 | "punpcklwd %%xmm0,%%xmm0 \n" \ |
| 379 | "movdqa %%xmm0,%%xmm1 \n" \ |
| 380 | "movdqa %%xmm0,%%xmm2 \n" \ |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 381 | "pmaddubsw (%5),%%xmm0 \n" \ |
| 382 | "pmaddubsw 16(%5),%%xmm1 \n" \ |
| 383 | "pmaddubsw 32(%5),%%xmm2 \n" \ |
| 384 | "psubw 48(%5),%%xmm0 \n" \ |
| 385 | "psubw 64(%5),%%xmm1 \n" \ |
| 386 | "psubw 80(%5),%%xmm2 \n" \ |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 387 | "movq (%0),%%xmm3 \n" \ |
| 388 | "lea 0x8(%0),%0 \n" \ |
| 389 | "punpcklbw %%xmm4,%%xmm3 \n" \ |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 390 | "psubsw 96(%5),%%xmm3 \n" \ |
| 391 | "pmullw 112(%5),%%xmm3 \n" \ |
fbarchard@google.com | bc8f28e | 2011-11-18 21:03:54 +0000 | [diff] [blame] | 392 | "paddsw %%xmm3,%%xmm0 \n" \ |
| 393 | "paddsw %%xmm3,%%xmm1 \n" \ |
| 394 | "paddsw %%xmm3,%%xmm2 \n" \ |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 395 | "psraw $0x6,%%xmm0 \n" \ |
| 396 | "psraw $0x6,%%xmm1 \n" \ |
| 397 | "psraw $0x6,%%xmm2 \n" \ |
| 398 | "packuswb %%xmm0,%%xmm0 \n" \ |
| 399 | "packuswb %%xmm1,%%xmm1 \n" \ |
| 400 | "packuswb %%xmm2,%%xmm2 \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 401 | |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 402 | void OMITFP FastConvertYUVToARGBRow_SSSE3(const uint8* y_buf, // rdi |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 403 | const uint8* u_buf, // rsi |
| 404 | const uint8* v_buf, // rdx |
| 405 | uint8* rgb_buf, // rcx |
| 406 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 407 | asm volatile ( |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 408 | "sub %1,%2 \n" |
| 409 | "pcmpeqb %%xmm5,%%xmm5 \n" |
| 410 | "pxor %%xmm4,%%xmm4 \n" |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 411 | |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 412 | "1: \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 413 | YUVTORGB |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 414 | "punpcklbw %%xmm1,%%xmm0 \n" |
| 415 | "punpcklbw %%xmm5,%%xmm2 \n" |
| 416 | "movdqa %%xmm0,%%xmm1 \n" |
| 417 | "punpcklwd %%xmm2,%%xmm0 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 418 | "punpckhwd %%xmm2,%%xmm1 \n" |
fbarchard@google.com | 3fe3696 | 2011-12-13 02:49:22 +0000 | [diff] [blame] | 419 | "movdqa %%xmm0,(%3) \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 420 | "movdqa %%xmm1,0x10(%3) \n" |
| 421 | "lea 0x20(%3),%3 \n" |
| 422 | "sub $0x8,%4 \n" |
| 423 | "ja 1b \n" |
fbarchard@google.com | 3faa0f1 | 2011-10-20 06:04:16 +0000 | [diff] [blame] | 424 | : "+r"(y_buf), // %0 |
| 425 | "+r"(u_buf), // %1 |
| 426 | "+r"(v_buf), // %2 |
| 427 | "+r"(rgb_buf), // %3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 428 | "+rm"(width) // %4 |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 429 | : "r"(&kYuvConstants.kUVToB) // %5 |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 430 | : "memory", "cc" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 431 | #if defined(__SSE2__) |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 432 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 433 | #endif |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 434 | ); |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 435 | } |
| 436 | |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 437 | void OMITFP FastConvertYUVToBGRARow_SSSE3(const uint8* y_buf, // rdi |
| 438 | const uint8* u_buf, // rsi |
| 439 | const uint8* v_buf, // rdx |
| 440 | uint8* rgb_buf, // rcx |
| 441 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 442 | asm volatile ( |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 443 | "sub %1,%2 \n" |
| 444 | "pcmpeqb %%xmm5,%%xmm5 \n" |
| 445 | "pxor %%xmm4,%%xmm4 \n" |
| 446 | |
| 447 | "1: \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 448 | YUVTORGB |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 449 | "pcmpeqb %%xmm5,%%xmm5 \n" |
| 450 | "punpcklbw %%xmm0,%%xmm1 \n" |
| 451 | "punpcklbw %%xmm2,%%xmm5 \n" |
| 452 | "movdqa %%xmm5,%%xmm0 \n" |
| 453 | "punpcklwd %%xmm1,%%xmm5 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 454 | "punpckhwd %%xmm1,%%xmm0 \n" |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 455 | "movdqa %%xmm5,(%3) \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 456 | "movdqa %%xmm0,0x10(%3) \n" |
| 457 | "lea 0x20(%3),%3 \n" |
| 458 | "sub $0x8,%4 \n" |
| 459 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 460 | : "+r"(y_buf), // %0 |
| 461 | "+r"(u_buf), // %1 |
| 462 | "+r"(v_buf), // %2 |
| 463 | "+r"(rgb_buf), // %3 |
| 464 | "+rm"(width) // %4 |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 465 | : "r"(&kYuvConstants.kUVToB) // %5 |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 466 | : "memory", "cc" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 467 | #if defined(__SSE2__) |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 468 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 469 | #endif |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 470 | ); |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 471 | } |
| 472 | |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 473 | void OMITFP FastConvertYUVToABGRRow_SSSE3(const uint8* y_buf, // rdi |
| 474 | const uint8* u_buf, // rsi |
| 475 | const uint8* v_buf, // rdx |
| 476 | uint8* rgb_buf, // rcx |
| 477 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 478 | asm volatile ( |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 479 | "sub %1,%2 \n" |
| 480 | "pcmpeqb %%xmm5,%%xmm5 \n" |
| 481 | "pxor %%xmm4,%%xmm4 \n" |
| 482 | |
| 483 | "1: \n" |
| 484 | YUVTORGB |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 485 | "punpcklbw %%xmm1,%%xmm2 \n" |
| 486 | "punpcklbw %%xmm5,%%xmm0 \n" |
| 487 | "movdqa %%xmm2,%%xmm1 \n" |
| 488 | "punpcklwd %%xmm0,%%xmm2 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 489 | "punpckhwd %%xmm0,%%xmm1 \n" |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 490 | "movdqa %%xmm2,(%3) \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 491 | "movdqa %%xmm1,0x10(%3) \n" |
| 492 | "lea 0x20(%3),%3 \n" |
| 493 | "sub $0x8,%4 \n" |
| 494 | "ja 1b \n" |
fbarchard@google.com | 3faa0f1 | 2011-10-20 06:04:16 +0000 | [diff] [blame] | 495 | : "+r"(y_buf), // %0 |
| 496 | "+r"(u_buf), // %1 |
| 497 | "+r"(v_buf), // %2 |
| 498 | "+r"(rgb_buf), // %3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 499 | "+rm"(width) // %4 |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 500 | : "r"(&kYuvConstants.kUVToB) // %5 |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 501 | : "memory", "cc" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 502 | #if defined(__SSE2__) |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 503 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 504 | #endif |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 505 | ); |
mikhal@webrtc.org | 120d5e7 | 2011-10-07 17:57:17 +0000 | [diff] [blame] | 506 | } |
| 507 | |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 508 | void OMITFP FastConvertYUV444ToARGBRow_SSSE3(const uint8* y_buf, // rdi |
| 509 | const uint8* u_buf, // rsi |
| 510 | const uint8* v_buf, // rdx |
| 511 | uint8* rgb_buf, // rcx |
| 512 | int width) { // r8 |
| 513 | asm volatile ( |
| 514 | "sub %1,%2 \n" |
| 515 | "pcmpeqb %%xmm5,%%xmm5 \n" |
| 516 | "pxor %%xmm4,%%xmm4 \n" |
| 517 | |
| 518 | "1: \n" |
| 519 | "movd (%1),%%xmm0 \n" |
| 520 | "movd (%1,%2,1),%%xmm1 \n" |
| 521 | "lea 0x4(%1),%1 \n" |
| 522 | "punpcklbw %%xmm1,%%xmm0 \n" |
| 523 | "movdqa %%xmm0,%%xmm1 \n" |
| 524 | "movdqa %%xmm0,%%xmm2 \n" |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 525 | "pmaddubsw (%5),%%xmm0 \n" |
| 526 | "pmaddubsw 16(%5),%%xmm1 \n" |
| 527 | "pmaddubsw 32(%5),%%xmm2 \n" |
| 528 | "psubw 48(%5),%%xmm0 \n" |
| 529 | "psubw 64(%5),%%xmm1 \n" |
| 530 | "psubw 80(%5),%%xmm2 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 531 | "movd (%0),%%xmm3 \n" |
| 532 | "lea 0x4(%0),%0 \n" |
| 533 | "punpcklbw %%xmm4,%%xmm3 \n" |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 534 | "psubsw 96(%5),%%xmm3 \n" |
| 535 | "pmullw 112(%5),%%xmm3 \n" |
fbarchard@google.com | bc8f28e | 2011-11-18 21:03:54 +0000 | [diff] [blame] | 536 | "paddsw %%xmm3,%%xmm0 \n" |
| 537 | "paddsw %%xmm3,%%xmm1 \n" |
| 538 | "paddsw %%xmm3,%%xmm2 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 539 | "psraw $0x6,%%xmm0 \n" |
| 540 | "psraw $0x6,%%xmm1 \n" |
| 541 | "psraw $0x6,%%xmm2 \n" |
| 542 | "packuswb %%xmm0,%%xmm0 \n" |
| 543 | "packuswb %%xmm1,%%xmm1 \n" |
| 544 | "packuswb %%xmm2,%%xmm2 \n" |
| 545 | "punpcklbw %%xmm1,%%xmm0 \n" |
| 546 | "punpcklbw %%xmm5,%%xmm2 \n" |
| 547 | "punpcklwd %%xmm2,%%xmm0 \n" |
| 548 | "movdqa %%xmm0,(%3) \n" |
| 549 | "lea 0x10(%3),%3 \n" |
| 550 | "sub $0x4,%4 \n" |
| 551 | "ja 1b \n" |
| 552 | : "+r"(y_buf), // %0 |
| 553 | "+r"(u_buf), // %1 |
| 554 | "+r"(v_buf), // %2 |
| 555 | "+r"(rgb_buf), // %3 |
| 556 | "+rm"(width) // %4 |
fbarchard@google.com | 1c2d8be | 2011-11-17 21:57:54 +0000 | [diff] [blame] | 557 | : "r"(&kYuvConstants.kUVToB) // %5 |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 558 | : "memory", "cc" |
| 559 | #if defined(__SSE2__) |
| 560 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
| 561 | #endif |
| 562 | ); |
| 563 | } |
| 564 | #endif |
| 565 | |
| 566 | #ifdef HAS_FASTCONVERTYTOARGBROW_SSE2 |
fbarchard@google.com | 8b9759c | 2011-12-14 04:17:39 +0000 | [diff] [blame] | 567 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 568 | void FastConvertYToARGBRow_SSE2(const uint8* y_buf, // rdi |
| 569 | uint8* rgb_buf, // rcx |
| 570 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 571 | asm volatile ( |
fbarchard@google.com | 8b9759c | 2011-12-14 04:17:39 +0000 | [diff] [blame] | 572 | "pcmpeqb %%xmm4,%%xmm4 \n" |
| 573 | "pslld $0x18,%%xmm4 \n" |
| 574 | "mov $0x10001000,%%eax \n" |
| 575 | "movd %%eax,%%xmm3 \n" |
| 576 | "pshufd $0x0,%%xmm3,%%xmm3 \n" |
| 577 | "mov $0x012a012a,%%eax \n" |
| 578 | "movd %%eax,%%xmm2 \n" |
| 579 | "pshufd $0x0,%%xmm2,%%xmm2 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 580 | |
| 581 | "1: \n" |
fbarchard@google.com | 8b9759c | 2011-12-14 04:17:39 +0000 | [diff] [blame] | 582 | // Step 1: Scale Y contribution to 8 G values. G = (y - 16) * 1.164 |
| 583 | "movq (%0),%%xmm0 \n" |
| 584 | "lea 0x8(%0),%0 \n" |
| 585 | "punpcklbw %%xmm0,%%xmm0 \n" |
| 586 | "psubusw %%xmm3,%%xmm0 \n" |
| 587 | "pmulhuw %%xmm2,%%xmm0 \n" |
| 588 | "packuswb %%xmm0,%%xmm0 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 589 | |
fbarchard@google.com | 8b9759c | 2011-12-14 04:17:39 +0000 | [diff] [blame] | 590 | // Step 2: Weave into ARGB |
| 591 | "punpcklbw %%xmm0,%%xmm0 \n" |
| 592 | "movdqa %%xmm0,%%xmm1 \n" |
| 593 | "punpcklwd %%xmm0,%%xmm0 \n" |
| 594 | "punpckhwd %%xmm1,%%xmm1 \n" |
| 595 | "por %%xmm4,%%xmm0 \n" |
| 596 | "por %%xmm4,%%xmm1 \n" |
| 597 | "movdqa %%xmm0,(%1) \n" |
| 598 | "movdqa %%xmm1,16(%1) \n" |
| 599 | "lea 32(%1),%1 \n" |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 600 | |
fbarchard@google.com | 8b9759c | 2011-12-14 04:17:39 +0000 | [diff] [blame] | 601 | "sub $0x8,%2 \n" |
| 602 | "ja 1b \n" |
fbarchard@google.com | 3faa0f1 | 2011-10-20 06:04:16 +0000 | [diff] [blame] | 603 | : "+r"(y_buf), // %0 |
| 604 | "+r"(rgb_buf), // %1 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 605 | "+rm"(width) // %2 |
fbarchard@google.com | 8b9759c | 2011-12-14 04:17:39 +0000 | [diff] [blame] | 606 | : |
| 607 | : "memory", "cc", "eax" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 608 | #if defined(__SSE2__) |
fbarchard@google.com | 8b9759c | 2011-12-14 04:17:39 +0000 | [diff] [blame] | 609 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 610 | #endif |
fbarchard@google.com | 228bdc2 | 2011-11-15 21:58:26 +0000 | [diff] [blame] | 611 | ); |
mikhal@webrtc.org | 120d5e7 | 2011-10-07 17:57:17 +0000 | [diff] [blame] | 612 | } |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 613 | #endif |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 614 | |
frkoenig@google.com | e518542 | 2011-11-07 23:07:57 +0000 | [diff] [blame] | 615 | #ifdef HAS_ARGBTOYROW_SSSE3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 616 | void ABGRToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) { |
| 617 | SIMD_ALIGNED(uint8 row[kMaxStride]); |
| 618 | ABGRToARGBRow_SSSE3(src_argb, row, pix); |
| 619 | ARGBToYRow_SSSE3(row, dst_y, pix); |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 620 | } |
| 621 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 622 | void BGRAToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) { |
| 623 | SIMD_ALIGNED(uint8 row[kMaxStride]); |
| 624 | BGRAToARGBRow_SSSE3(src_argb, row, pix); |
| 625 | ARGBToYRow_SSSE3(row, dst_y, pix); |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 626 | } |
frkoenig@google.com | e518542 | 2011-11-07 23:07:57 +0000 | [diff] [blame] | 627 | #endif |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 628 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 629 | #ifdef HAS_ARGBTOUVROW_SSSE3 |
| 630 | void ABGRToUVRow_SSSE3(const uint8* src_argb, int src_stride_argb, |
| 631 | uint8* dst_u, uint8* dst_v, int pix) { |
| 632 | SIMD_ALIGNED(uint8 row[kMaxStride * 2]); |
| 633 | ABGRToARGBRow_SSSE3(src_argb, row, pix); |
| 634 | ABGRToARGBRow_SSSE3(src_argb + src_stride_argb, row + kMaxStride, pix); |
| 635 | ARGBToUVRow_SSSE3(row, kMaxStride, dst_u, dst_v, pix); |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 636 | } |
| 637 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 638 | void BGRAToUVRow_SSSE3(const uint8* src_argb, int src_stride_argb, |
| 639 | uint8* dst_u, uint8* dst_v, int pix) { |
| 640 | SIMD_ALIGNED(uint8 row[kMaxStride * 2]); |
| 641 | BGRAToARGBRow_SSSE3(src_argb, row, pix); |
| 642 | BGRAToARGBRow_SSSE3(src_argb + src_stride_argb, row + kMaxStride, pix); |
| 643 | ARGBToUVRow_SSSE3(row, kMaxStride, dst_u, dst_v, pix); |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 644 | } |
mikhal@webrtc.org | 120d5e7 | 2011-10-07 17:57:17 +0000 | [diff] [blame] | 645 | #endif |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 646 | |
fbarchard@google.com | 12d0483 | 2011-11-21 23:54:38 +0000 | [diff] [blame] | 647 | #ifdef HAS_REVERSE_ROW_SSSE3 |
| 648 | |
| 649 | // Shuffle table for reversing the bytes. |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 650 | CONST uvec8 kShuffleReverse = { |
fbarchard@google.com | 12d0483 | 2011-11-21 23:54:38 +0000 | [diff] [blame] | 651 | 15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u, 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u |
| 652 | }; |
| 653 | |
| 654 | void ReverseRow_SSSE3(const uint8* src, uint8* dst, int width) { |
| 655 | intptr_t temp_width = static_cast<intptr_t>(width); |
| 656 | asm volatile ( |
| 657 | "movdqa %3,%%xmm5 \n" |
| 658 | "lea -0x10(%0,%2,1),%0 \n" |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 659 | "1: \n" |
| 660 | "movdqa (%0),%%xmm0 \n" |
| 661 | "lea -0x10(%0),%0 \n" |
| 662 | "pshufb %%xmm5,%%xmm0 \n" |
| 663 | "movdqa %%xmm0,(%1) \n" |
| 664 | "lea 0x10(%1),%1 \n" |
| 665 | "sub $0x10,%2 \n" |
| 666 | "ja 1b \n" |
fbarchard@google.com | 12d0483 | 2011-11-21 23:54:38 +0000 | [diff] [blame] | 667 | : "+r"(src), // %0 |
| 668 | "+r"(dst), // %1 |
| 669 | "+r"(temp_width) // %2 |
| 670 | : "m"(kShuffleReverse) // %3 |
| 671 | : "memory", "cc" |
| 672 | #if defined(__SSE2__) |
| 673 | , "xmm0", "xmm5" |
| 674 | #endif |
| 675 | ); |
| 676 | } |
| 677 | #endif |
| 678 | |
fbarchard@google.com | 373cdbd | 2011-12-14 21:10:07 +0000 | [diff] [blame] | 679 | #ifdef HAS_REVERSE_ROW_SSE2 |
| 680 | |
| 681 | void ReverseRow_SSE2(const uint8* src, uint8* dst, int width) { |
| 682 | intptr_t temp_width = static_cast<intptr_t>(width); |
| 683 | asm volatile ( |
| 684 | "lea -0x10(%0,%2,1),%0 \n" |
| 685 | "1: \n" |
| 686 | "movdqa (%0),%%xmm0 \n" |
| 687 | "lea -0x10(%0),%0 \n" |
| 688 | "movdqa %%xmm0,%%xmm1 \n" |
| 689 | "psllw $0x8,%%xmm0 \n" |
| 690 | "psrlw $0x8,%%xmm1 \n" |
| 691 | "por %%xmm1,%%xmm0 \n" |
| 692 | "pshuflw $0x1b,%%xmm0,%%xmm0 \n" |
| 693 | "pshufhw $0x1b,%%xmm0,%%xmm0 \n" |
| 694 | "pshufd $0x4e,%%xmm0,%%xmm0 \n" |
| 695 | "movdqa %%xmm0,(%1) \n" |
| 696 | "lea 0x10(%1),%1 \n" |
| 697 | "sub $0x10,%2 \n" |
| 698 | "ja 1b \n" |
| 699 | : "+r"(src), // %0 |
| 700 | "+r"(dst), // %1 |
| 701 | "+r"(temp_width) // %2 |
| 702 | : |
| 703 | : "memory", "cc" |
| 704 | #if defined(__SSE2__) |
| 705 | , "xmm0", "xmm1" |
| 706 | #endif |
| 707 | ); |
| 708 | } |
| 709 | #endif |
| 710 | |
fbarchard@google.com | fe5ff7e | 2011-12-10 07:45:58 +0000 | [diff] [blame] | 711 | #ifdef __cplusplus |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 712 | } // extern "C" |
fbarchard@google.com | fe5ff7e | 2011-12-10 07:45:58 +0000 | [diff] [blame] | 713 | } // namespace libyuv |
| 714 | #endif |