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 | |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 15 | extern "C" { |
| 16 | |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 17 | #ifdef HAS_ARGBTOYROW_SSSE3 |
| 18 | |
| 19 | // Constant multiplication table for converting ARGB to I400. |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 20 | static const vec8 kARGBToY = { |
| 21 | 13, 65, 33, 0, 13, 65, 33, 0, 13, 65, 33, 0, 13, 65, 33, 0 |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 24 | static const uvec8 kAddY16 = { |
fbarchard@google.com | 2430e04 | 2011-11-11 21:57:06 +0000 | [diff] [blame^] | 25 | 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u, 16u |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 26 | }; |
| 27 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 28 | #ifdef HAS_ARGBTOUVROW_SSSE3 |
| 29 | static const vec8 kARGBToU = { |
| 30 | 112, -74, -38, 0, 112, -74, -38, 0, 112, -74, -38, 0, 112, -74, -38, 0 |
| 31 | }; |
| 32 | |
| 33 | static const uvec8 kARGBToV = { |
fbarchard@google.com | 2430e04 | 2011-11-11 21:57:06 +0000 | [diff] [blame^] | 34 | -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] | 35 | }; |
fbarchard@google.com | 2430e04 | 2011-11-11 21:57:06 +0000 | [diff] [blame^] | 36 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 37 | static const uvec8 kAddUV128 = { |
| 38 | 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u, |
| 39 | 128u, 128u, 128u, 128u, 128u, 128u, 128u, 128u |
| 40 | }; |
| 41 | #endif |
| 42 | |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 43 | // Shuffle table for converting BG24 to ARGB. |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 44 | static const uvec8 kShuffleMaskBG24ToARGB = { |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 45 | 0u, 1u, 2u, 12u, 3u, 4u, 5u, 13u, 6u, 7u, 8u, 14u, 9u, 10u, 11u, 15u |
| 46 | }; |
| 47 | |
| 48 | // Shuffle table for converting RAW to ARGB. |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 49 | static const uvec8 kShuffleMaskRAWToARGB = { |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 50 | 2u, 1u, 0u, 12u, 5u, 4u, 3u, 13u, 8u, 7u, 6u, 14u, 11u, 10u, 9u, 15u |
| 51 | }; |
| 52 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 53 | // Shuffle table for converting ABGR to ARGB. |
| 54 | static const uvec8 kShuffleMaskABGRToARGB = { |
| 55 | 2u, 1u, 0u, 3u, 6u, 5u, 4u, 7u, 10u, 9u, 8u, 11u, 14u, 13u, 12u, 15u |
| 56 | }; |
| 57 | |
| 58 | // Shuffle table for converting BGRA to ARGB. |
| 59 | static const uvec8 kShuffleMaskBGRAToARGB = { |
| 60 | 3u, 2u, 1u, 0u, 7u, 6u, 5u, 4u, 11u, 10u, 9u, 8u, 15u, 14u, 13u, 12u |
| 61 | }; |
| 62 | |
| 63 | 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] | 64 | asm volatile ( |
| 65 | "pcmpeqb %%xmm5,%%xmm5 \n" |
| 66 | "pslld $0x18,%%xmm5 \n" |
| 67 | "1: \n" |
| 68 | "movq (%0),%%xmm0 \n" |
| 69 | "lea 0x8(%0),%0 \n" |
| 70 | "punpcklbw %%xmm0,%%xmm0 \n" |
| 71 | "movdqa %%xmm0,%%xmm1 \n" |
| 72 | "punpcklwd %%xmm0,%%xmm0 \n" |
| 73 | "punpckhwd %%xmm1,%%xmm1 \n" |
| 74 | "por %%xmm5,%%xmm0 \n" |
| 75 | "por %%xmm5,%%xmm1 \n" |
| 76 | "movdqa %%xmm0,(%1) \n" |
| 77 | "movdqa %%xmm1,0x10(%1) \n" |
| 78 | "lea 0x20(%1),%1 \n" |
| 79 | "sub $0x8,%2 \n" |
| 80 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 81 | : "+r"(src_y), // %0 |
| 82 | "+r"(dst_argb), // %1 |
| 83 | "+r"(pix) // %2 |
| 84 | : |
| 85 | : "memory", "cc" |
| 86 | #if defined(__SSE2__) |
| 87 | , "xmm0", "xmm1", "xmm5" |
| 88 | #endif |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 89 | ); |
| 90 | } |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 91 | |
| 92 | 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] | 93 | asm volatile ( |
| 94 | "movdqa %3,%%xmm5 \n" |
| 95 | "1: \n" |
| 96 | "movdqa (%0),%%xmm0 \n" |
| 97 | "lea 0x10(%0),%0 \n" |
| 98 | "pshufb %%xmm5,%%xmm0 \n" |
| 99 | "movdqa %%xmm0,(%1) \n" |
| 100 | "lea 0x10(%1),%1 \n" |
| 101 | "sub $0x4,%2 \n" |
| 102 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 103 | : "+r"(src_abgr), // %0 |
| 104 | "+r"(dst_argb), // %1 |
| 105 | "+r"(pix) // %2 |
| 106 | : "m"(kShuffleMaskABGRToARGB) // %3 |
| 107 | : "memory", "cc" |
| 108 | #if defined(__SSE2__) |
| 109 | , "xmm0", "xmm5" |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 110 | #endif |
| 111 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 112 | ); |
| 113 | } |
| 114 | |
| 115 | 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] | 116 | asm volatile ( |
| 117 | "movdqa %3,%%xmm5 \n" |
| 118 | "1: \n" |
| 119 | "movdqa (%0),%%xmm0 \n" |
| 120 | "lea 0x10(%0),%0 \n" |
| 121 | "pshufb %%xmm5,%%xmm0 \n" |
| 122 | "movdqa %%xmm0,(%1) \n" |
| 123 | "lea 0x10(%1),%1 \n" |
| 124 | "sub $0x4,%2 \n" |
| 125 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 126 | : "+r"(src_bgra), // %0 |
| 127 | "+r"(dst_argb), // %1 |
| 128 | "+r"(pix) // %2 |
| 129 | : "m"(kShuffleMaskBGRAToARGB) // %3 |
| 130 | : "memory", "cc" |
| 131 | #if defined(__SSE2__) |
| 132 | , "xmm0", "xmm5" |
| 133 | #endif |
| 134 | ); |
| 135 | } |
| 136 | |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 137 | void BG24ToARGBRow_SSSE3(const uint8* src_bg24, uint8* dst_argb, int pix) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 138 | asm volatile ( |
| 139 | "pcmpeqb %%xmm5,%%xmm5 \n" // generate mask 0xff000000 |
| 140 | "pslld $0x18,%%xmm5 \n" |
| 141 | "movdqa %3,%%xmm4 \n" |
| 142 | "1: \n" |
| 143 | "movdqa (%0),%%xmm0 \n" |
| 144 | "movdqa 0x10(%0),%%xmm1 \n" |
| 145 | "movdqa 0x20(%0),%%xmm3 \n" |
| 146 | "lea 0x30(%0),%0 \n" |
| 147 | "movdqa %%xmm3,%%xmm2 \n" |
| 148 | "palignr $0x8,%%xmm1,%%xmm2 \n" // xmm2 = { xmm3[0:3] xmm1[8:15] } |
| 149 | "pshufb %%xmm4,%%xmm2 \n" |
| 150 | "por %%xmm5,%%xmm2 \n" |
| 151 | "palignr $0xc,%%xmm0,%%xmm1 \n" // xmm1 = { xmm3[0:7] xmm0[12:15] } |
| 152 | "pshufb %%xmm4,%%xmm0 \n" |
| 153 | "movdqa %%xmm2,0x20(%1) \n" |
| 154 | "por %%xmm5,%%xmm0 \n" |
| 155 | "pshufb %%xmm4,%%xmm1 \n" |
| 156 | "movdqa %%xmm0,(%1) \n" |
| 157 | "por %%xmm5,%%xmm1 \n" |
| 158 | "palignr $0x4,%%xmm3,%%xmm3 \n" // xmm3 = { xmm3[4:15] } |
| 159 | "pshufb %%xmm4,%%xmm3 \n" |
| 160 | "movdqa %%xmm1,0x10(%1) \n" |
| 161 | "por %%xmm5,%%xmm3 \n" |
| 162 | "movdqa %%xmm3,0x30(%1) \n" |
| 163 | "lea 0x40(%1),%1 \n" |
| 164 | "sub $0x10,%2 \n" |
| 165 | "ja 1b \n" |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 166 | : "+r"(src_bg24), // %0 |
| 167 | "+r"(dst_argb), // %1 |
| 168 | "+r"(pix) // %2 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 169 | : "m"(kShuffleMaskBG24ToARGB) // %3 |
| 170 | : "memory", "cc" |
| 171 | #if defined(__SSE2__) |
| 172 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
| 173 | #endif |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 174 | ); |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 175 | } |
| 176 | |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 177 | 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] | 178 | asm volatile ( |
| 179 | "pcmpeqb %%xmm5,%%xmm5 \n" // generate mask 0xff000000 |
| 180 | "pslld $0x18,%%xmm5 \n" |
| 181 | "movdqa %3,%%xmm4 \n" |
| 182 | "1: \n" |
| 183 | "movdqa (%0),%%xmm0 \n" |
| 184 | "movdqa 0x10(%0),%%xmm1 \n" |
| 185 | "movdqa 0x20(%0),%%xmm3 \n" |
| 186 | "lea 0x30(%0),%0 \n" |
| 187 | "movdqa %%xmm3,%%xmm2 \n" |
| 188 | "palignr $0x8,%%xmm1,%%xmm2 \n" // xmm2 = { xmm3[0:3] xmm1[8:15] } |
| 189 | "pshufb %%xmm4,%%xmm2 \n" |
| 190 | "por %%xmm5,%%xmm2 \n" |
| 191 | "palignr $0xc,%%xmm0,%%xmm1 \n" // xmm1 = { xmm3[0:7] xmm0[12:15] } |
| 192 | "pshufb %%xmm4,%%xmm0 \n" |
| 193 | "movdqa %%xmm2,0x20(%1) \n" |
| 194 | "por %%xmm5,%%xmm0 \n" |
| 195 | "pshufb %%xmm4,%%xmm1 \n" |
| 196 | "movdqa %%xmm0,(%1) \n" |
| 197 | "por %%xmm5,%%xmm1 \n" |
| 198 | "palignr $0x4,%%xmm3,%%xmm3 \n" // xmm3 = { xmm3[4:15] } |
| 199 | "pshufb %%xmm4,%%xmm3 \n" |
| 200 | "movdqa %%xmm1,0x10(%1) \n" |
| 201 | "por %%xmm5,%%xmm3 \n" |
| 202 | "movdqa %%xmm3,0x30(%1) \n" |
| 203 | "lea 0x40(%1),%1 \n" |
| 204 | "sub $0x10,%2 \n" |
| 205 | "ja 1b \n" |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 206 | : "+r"(src_raw), // %0 |
| 207 | "+r"(dst_argb), // %1 |
| 208 | "+r"(pix) // %2 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 209 | : "m"(kShuffleMaskRAWToARGB) // %3 |
| 210 | : "memory", "cc" |
| 211 | #if defined(__SSE2__) |
| 212 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
| 213 | #endif |
| 214 | ); |
| 215 | } |
| 216 | |
| 217 | 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] | 218 | asm volatile ( |
| 219 | "movdqa %4,%%xmm5 \n" |
| 220 | "movdqa %3,%%xmm4 \n" |
| 221 | "1: \n" |
| 222 | "movdqa (%0),%%xmm0 \n" |
| 223 | "movdqa 0x10(%0),%%xmm1 \n" |
| 224 | "movdqa 0x20(%0),%%xmm2 \n" |
| 225 | "movdqa 0x30(%0),%%xmm3 \n" |
| 226 | "pmaddubsw %%xmm4,%%xmm0 \n" |
| 227 | "pmaddubsw %%xmm4,%%xmm1 \n" |
| 228 | "pmaddubsw %%xmm4,%%xmm2 \n" |
| 229 | "pmaddubsw %%xmm4,%%xmm3 \n" |
| 230 | "lea 0x40(%0),%0 \n" |
| 231 | "phaddw %%xmm1,%%xmm0 \n" |
| 232 | "phaddw %%xmm3,%%xmm2 \n" |
| 233 | "psrlw $0x7,%%xmm0 \n" |
| 234 | "psrlw $0x7,%%xmm2 \n" |
| 235 | "packuswb %%xmm2,%%xmm0 \n" |
| 236 | "paddb %%xmm5,%%xmm0 \n" |
| 237 | "movdqa %%xmm0,(%1) \n" |
| 238 | "lea 0x10(%1),%1 \n" |
| 239 | "sub $0x10,%2 \n" |
| 240 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 241 | : "+r"(src_argb), // %0 |
| 242 | "+r"(dst_y), // %1 |
| 243 | "+r"(pix) // %2 |
| 244 | : "m"(kARGBToY), // %3 |
| 245 | "m"(kAddY16) // %4 |
| 246 | : "memory", "cc" |
| 247 | #if defined(__SSE2__) |
| 248 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" |
| 249 | #endif |
| 250 | |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 251 | ); |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 252 | } |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 253 | #endif |
fbarchard@google.com | 585a126 | 2011-10-28 23:51:08 +0000 | [diff] [blame] | 254 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 255 | #ifdef HAS_ARGBTOUVROW_SSSE3 |
| 256 | void ARGBToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb, |
| 257 | uint8* dst_u, uint8* dst_v, int width) { |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 258 | asm volatile ( |
| 259 | "movdqa %0,%%xmm4 \n" |
| 260 | "movdqa %1,%%xmm3 \n" |
| 261 | "movdqa %2,%%xmm5 \n" |
fbarchard@google.com | d93d448 | 2011-11-10 18:26:20 +0000 | [diff] [blame] | 262 | : |
| 263 | : "m"(kARGBToU), // %0 |
| 264 | "m"(kARGBToV), // %1 |
| 265 | "m"(kAddUV128) // %2 |
| 266 | : |
| 267 | #if defined(__SSE2__) |
| 268 | "xmm3", "xmm4", "xmm5" |
| 269 | #endif |
| 270 | ); |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 271 | asm volatile ( |
| 272 | "sub %1,%2 \n" |
| 273 | "1: \n" |
| 274 | "movdqa (%0),%%xmm0 \n" |
| 275 | "movdqa 0x10(%0),%%xmm1 \n" |
| 276 | "movdqa 0x20(%0),%%xmm2 \n" |
| 277 | "movdqa 0x30(%0),%%xmm6 \n" |
| 278 | "pavgb (%0,%4,1),%%xmm0 \n" |
| 279 | "pavgb 0x10(%0,%4,1),%%xmm1 \n" |
| 280 | "pavgb 0x20(%0,%4,1),%%xmm2 \n" |
| 281 | "pavgb 0x30(%0,%4,1),%%xmm6 \n" |
| 282 | "lea 0x40(%0),%0 \n" |
| 283 | "movdqa %%xmm0,%%xmm7 \n" |
| 284 | "shufps $0x88,%%xmm1,%%xmm0 \n" |
| 285 | "shufps $0xdd,%%xmm1,%%xmm7 \n" |
| 286 | "pavgb %%xmm7,%%xmm0 \n" |
| 287 | "movdqa %%xmm2,%%xmm7 \n" |
| 288 | "shufps $0x88,%%xmm6,%%xmm2 \n" |
| 289 | "shufps $0xdd,%%xmm6,%%xmm7 \n" |
| 290 | "pavgb %%xmm7,%%xmm2 \n" |
| 291 | "movdqa %%xmm0,%%xmm1 \n" |
| 292 | "movdqa %%xmm2,%%xmm6 \n" |
| 293 | "pmaddubsw %%xmm4,%%xmm0 \n" |
| 294 | "pmaddubsw %%xmm4,%%xmm2 \n" |
| 295 | "pmaddubsw %%xmm3,%%xmm1 \n" |
| 296 | "pmaddubsw %%xmm3,%%xmm6 \n" |
| 297 | "phaddw %%xmm2,%%xmm0 \n" |
| 298 | "phaddw %%xmm6,%%xmm1 \n" |
| 299 | "psraw $0x8,%%xmm0 \n" |
| 300 | "psraw $0x8,%%xmm1 \n" |
| 301 | "packsswb %%xmm1,%%xmm0 \n" |
| 302 | "paddb %%xmm5,%%xmm0 \n" |
| 303 | "movlps %%xmm0,(%1) \n" |
| 304 | "movhps %%xmm0,(%1,%2,1) \n" |
| 305 | "lea 0x8(%1),%1 \n" |
| 306 | "sub $0x10,%3 \n" |
| 307 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 308 | : "+r"(src_argb0), // %0 |
| 309 | "+r"(dst_u), // %1 |
| 310 | "+r"(dst_v), // %2 |
| 311 | "+rm"(width) // %3 |
fbarchard@google.com | d93d448 | 2011-11-10 18:26:20 +0000 | [diff] [blame] | 312 | : "r"(static_cast<intptr_t>(src_stride_argb)) |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 313 | : "memory", "cc" |
| 314 | #if defined(__SSE2__) |
fbarchard@google.com | d93d448 | 2011-11-10 18:26:20 +0000 | [diff] [blame] | 315 | , "xmm0", "xmm1", "xmm2", "xmm6", "xmm7" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 316 | #endif |
| 317 | ); |
| 318 | } |
| 319 | #endif |
| 320 | |
| 321 | // The following code requires 6 registers and prefers 7 registers. |
| 322 | // 7 registers requires -fpic to be off, and -fomit-frame-pointer |
| 323 | #ifdef HAS_FASTCONVERTYUVTOARGBROW_SSE2 |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 324 | #if defined(__x86_64__) |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 325 | #define REG_a "rax" |
| 326 | #define REG_d "rdx" |
| 327 | #else |
| 328 | #define REG_a "eax" |
| 329 | #define REG_d "edx" |
| 330 | #endif |
| 331 | #if defined(__APPLE__) || defined(__x86_64__) |
| 332 | #define OMITFP |
| 333 | #else |
| 334 | #define OMITFP __attribute__((optimize("omit-frame-pointer"))) |
| 335 | #endif |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 336 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 337 | #define CLOBBER "%"REG_a, "%"REG_d |
| 338 | // This version produces 2 pixels |
| 339 | #define YUVTORGB \ |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 340 | "1: \n" \ |
| 341 | "movzb (%1),%%"REG_a" \n" \ |
| 342 | "lea 1(%1),%1 \n" \ |
| 343 | "movzb (%2),%%"REG_d" \n" \ |
| 344 | "lea 1(%2),%2 \n" \ |
| 345 | "movq 2048(%5,%%"REG_a",8),%%xmm0 \n" \ |
| 346 | "movzb 0(%0),%%"REG_a" \n" \ |
| 347 | "movq 4096(%5,%%"REG_d",8),%%xmm1 \n" \ |
| 348 | "paddsw %%xmm1,%%xmm0 \n" \ |
| 349 | "movzb 1(%0),%%"REG_d" \n" \ |
| 350 | "punpcklqdq %%xmm0,%%xmm0 \n" \ |
| 351 | "lea 2(%0),%0 \n" \ |
| 352 | "movq 0(%5,%%"REG_a",8),%%xmm1 \n" \ |
| 353 | "movhps 0(%5,%%"REG_d",8),%%xmm1 \n" \ |
| 354 | "paddsw %%xmm0,%%xmm1 \n" \ |
| 355 | "psraw $6,%%xmm1 \n" \ |
| 356 | "packuswb %%xmm1,%%xmm1 \n" \ |
| 357 | "movq %%xmm1,0(%3) \n" \ |
| 358 | "lea 8(%3),%3 \n" \ |
| 359 | "sub $0x2,%4 \n" \ |
| 360 | "ja 1b \n" |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 361 | // This version produces 4 pixels |
| 362 | #define YUVTORGB4 \ |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 363 | "1: \n" \ |
| 364 | "movzb 0(%1),%%"REG_a" \n" \ |
| 365 | "movzb 0(%2),%%"REG_d" \n" \ |
| 366 | "movq 2048(%5,%%"REG_a",8),%%xmm0 \n" \ |
| 367 | "movzb 0(%0),%%"REG_a" \n" \ |
| 368 | "movq 4096(%5,%%"REG_d",8),%%xmm1 \n" \ |
| 369 | "paddsw %%xmm1,%%xmm0 \n" \ |
| 370 | "movzb 1(%0),%%"REG_d" \n" \ |
| 371 | "punpcklqdq %%xmm0,%%xmm0 \n" \ |
| 372 | "movq 0(%5,%%"REG_a",8),%%xmm2 \n" \ |
| 373 | "movhps 0(%5,%%"REG_d",8),%%xmm2 \n" \ |
| 374 | "paddsw %%xmm0,%%xmm2 \n" \ |
| 375 | "psraw $6,%%xmm2 \n" \ |
| 376 | "movzb 1(%1),%%"REG_a" \n" \ |
| 377 | "movzb 1(%2),%%"REG_d" \n" \ |
| 378 | "movq 2048(%5,%%"REG_a",8),%%xmm0 \n" \ |
| 379 | "movzb 2(%0),%%"REG_a" \n" \ |
| 380 | "movq 4096(%5,%%"REG_d",8),%%xmm1 \n" \ |
| 381 | "paddsw %%xmm1,%%xmm0 \n" \ |
| 382 | "movzb 3(%0),%%"REG_d" \n" \ |
| 383 | "punpcklqdq %%xmm0,%%xmm0 \n" \ |
| 384 | "movq 0(%5,%%"REG_a",8),%%xmm3 \n" \ |
| 385 | "movhps 0(%5,%%"REG_d",8),%%xmm3 \n" \ |
| 386 | "paddsw %%xmm0,%%xmm3 \n" \ |
| 387 | "psraw $6,%%xmm3 \n" \ |
| 388 | "lea 2(%1),%1 \n" \ |
| 389 | "lea 2(%2),%2 \n" \ |
| 390 | "lea 4(%0),%0 \n" \ |
| 391 | "packuswb %%xmm3,%%xmm2 \n" \ |
| 392 | "movdqa %%xmm2,0(%3) \n" \ |
| 393 | "lea 16(%3),%3 \n" \ |
| 394 | "sub $0x4,%4 \n" \ |
| 395 | "ja 1b \n" \ |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 396 | |
| 397 | // 6 or 7 registers |
| 398 | void OMITFP FastConvertYUVToARGBRow_SSE2(const uint8* y_buf, // rdi |
| 399 | const uint8* u_buf, // rsi |
| 400 | const uint8* v_buf, // rdx |
| 401 | uint8* rgb_buf, // rcx |
| 402 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 403 | asm volatile ( |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 404 | YUVTORGB |
fbarchard@google.com | 3faa0f1 | 2011-10-20 06:04:16 +0000 | [diff] [blame] | 405 | : "+r"(y_buf), // %0 |
| 406 | "+r"(u_buf), // %1 |
| 407 | "+r"(v_buf), // %2 |
| 408 | "+r"(rgb_buf), // %3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 409 | "+rm"(width) // %4 |
| 410 | : "r" (kCoefficientsRgbY) // %5 |
| 411 | : "memory", "cc", CLOBBER |
| 412 | #if defined(__SSE2__) |
| 413 | , "xmm0", "xmm1", "xmm2", "xmm3" |
| 414 | #endif |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 415 | ); |
| 416 | } |
| 417 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 418 | // 6 or 7 registers |
| 419 | void OMITFP FastConvertYUVToARGBRow4_SSE2(const uint8* y_buf, // rdi |
| 420 | const uint8* u_buf, // rsi |
| 421 | const uint8* v_buf, // rdx |
| 422 | uint8* rgb_buf, // rcx |
| 423 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 424 | asm volatile ( |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 425 | YUVTORGB4 |
fbarchard@google.com | 3faa0f1 | 2011-10-20 06:04:16 +0000 | [diff] [blame] | 426 | : "+r"(y_buf), // %0 |
| 427 | "+r"(u_buf), // %1 |
| 428 | "+r"(v_buf), // %2 |
| 429 | "+r"(rgb_buf), // %3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 430 | "+rm"(width) // %4 |
| 431 | : "r" (kCoefficientsRgbY) // %5 |
| 432 | : "memory", "cc", CLOBBER |
| 433 | #if defined(__SSE2__) |
| 434 | , "xmm0", "xmm1", "xmm2", "xmm3" |
| 435 | #endif |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 436 | ); |
| 437 | } |
| 438 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 439 | void OMITFP FastConvertYUVToBGRARow_SSE2(const uint8* y_buf, // rdi |
| 440 | const uint8* u_buf, // rsi |
| 441 | const uint8* v_buf, // rdx |
| 442 | uint8* rgb_buf, // rcx |
| 443 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 444 | asm volatile ( |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 445 | YUVTORGB |
fbarchard@google.com | 3faa0f1 | 2011-10-20 06:04:16 +0000 | [diff] [blame] | 446 | : "+r"(y_buf), // %0 |
| 447 | "+r"(u_buf), // %1 |
| 448 | "+r"(v_buf), // %2 |
| 449 | "+r"(rgb_buf), // %3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 450 | "+rm"(width) // %4 |
| 451 | : "r" (kCoefficientsBgraY) // %5 |
| 452 | : "memory", "cc", CLOBBER |
| 453 | #if defined(__SSE2__) |
| 454 | , "xmm0", "xmm1", "xmm2", "xmm3" |
| 455 | #endif |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 456 | ); |
| 457 | } |
| 458 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 459 | void OMITFP FastConvertYUVToABGRRow_SSE2(const uint8* y_buf, // rdi |
| 460 | const uint8* u_buf, // rsi |
| 461 | const uint8* v_buf, // rdx |
| 462 | uint8* rgb_buf, // rcx |
| 463 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 464 | asm volatile ( |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 465 | YUVTORGB |
| 466 | : "+r"(y_buf), // %0 |
| 467 | "+r"(u_buf), // %1 |
| 468 | "+r"(v_buf), // %2 |
| 469 | "+r"(rgb_buf), // %3 |
| 470 | "+rm"(width) // %4 |
| 471 | : "r" (kCoefficientsAbgrY) // %5 |
| 472 | : "memory", "cc", CLOBBER |
| 473 | #if defined(__SSE2__) |
| 474 | , "xmm0", "xmm1", "xmm2", "xmm3" |
| 475 | #endif |
| 476 | ); |
| 477 | } |
| 478 | |
| 479 | // 6 registers |
| 480 | void OMITFP FastConvertYUV444ToARGBRow_SSE2(const uint8* y_buf, // rdi |
| 481 | const uint8* u_buf, // rsi |
| 482 | const uint8* v_buf, // rdx |
| 483 | uint8* rgb_buf, // rcx |
| 484 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 485 | asm volatile ( |
| 486 | "1: \n" |
| 487 | "movzb (%1),%%"REG_a" \n" |
| 488 | "lea 1(%1),%1 \n" |
| 489 | "movq 2048(%5,%%"REG_a",8),%%xmm0 \n" |
| 490 | "movzb (%2),%%"REG_a" \n" |
| 491 | "lea 1(%2),%2 \n" |
| 492 | "movq 4096(%5,%%"REG_a",8),%%xmm1 \n" |
| 493 | "paddsw %%xmm1,%%xmm0 \n" |
| 494 | "movzb (%0),%%"REG_a" \n" |
| 495 | "lea 1(%0),%0 \n" |
| 496 | "movq 0(%5,%%"REG_a",8),%%xmm2 \n" |
| 497 | "paddsw %%xmm0,%%xmm2 \n" |
| 498 | "shufps $0x44,%%xmm2,%%xmm2 \n" |
| 499 | "psraw $0x6,%%xmm2 \n" |
| 500 | "packuswb %%xmm2,%%xmm2 \n" |
| 501 | "movd %%xmm2,0x0(%3) \n" |
| 502 | "lea 4(%3),%3 \n" |
| 503 | "sub $0x1,%4 \n" |
| 504 | "ja 1b \n" |
fbarchard@google.com | 3faa0f1 | 2011-10-20 06:04:16 +0000 | [diff] [blame] | 505 | : "+r"(y_buf), // %0 |
| 506 | "+r"(u_buf), // %1 |
| 507 | "+r"(v_buf), // %2 |
| 508 | "+r"(rgb_buf), // %3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 509 | "+rm"(width) // %4 |
| 510 | : "r" (kCoefficientsRgbY) // %5 |
| 511 | : "memory", "cc", "%"REG_a |
| 512 | #if defined(__SSE2__) |
| 513 | , "xmm0", "xmm1", "xmm2" |
| 514 | #endif |
mikhal@webrtc.org | 120d5e7 | 2011-10-07 17:57:17 +0000 | [diff] [blame] | 515 | ); |
| 516 | } |
| 517 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 518 | // 5 registers |
| 519 | void FastConvertYToARGBRow_SSE2(const uint8* y_buf, // rdi |
| 520 | uint8* rgb_buf, // rcx |
| 521 | int width) { // r8 |
fbarchard@google.com | f7a5048 | 2011-11-10 22:41:20 +0000 | [diff] [blame] | 522 | asm volatile ( |
| 523 | "1: \n" |
| 524 | "movzb (%0),%%"REG_a" \n" |
| 525 | "movzb 0x1(%0),%%"REG_d" \n" |
| 526 | "movq (%3,%%"REG_a",8),%%xmm2 \n" |
| 527 | "lea 2(%0),%0 \n" |
| 528 | "movhps (%3,%%"REG_d",8),%%xmm2 \n" |
| 529 | "psraw $0x6,%%xmm2 \n" |
| 530 | "packuswb %%xmm2,%%xmm2 \n" |
| 531 | "movq %%xmm2,0x0(%1) \n" |
| 532 | "lea 8(%1),%1 \n" |
| 533 | "sub $0x2,%2 \n" |
| 534 | "ja 1b \n" |
fbarchard@google.com | 3faa0f1 | 2011-10-20 06:04:16 +0000 | [diff] [blame] | 535 | : "+r"(y_buf), // %0 |
| 536 | "+r"(rgb_buf), // %1 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 537 | "+rm"(width) // %2 |
| 538 | : "r" (kCoefficientsRgbY) // %3 |
| 539 | : "memory", "cc", "%"REG_a, "%"REG_d |
| 540 | #if defined(__SSE2__) |
| 541 | , "xmm0", "xmm1", "xmm2" |
| 542 | #endif |
mikhal@webrtc.org | 120d5e7 | 2011-10-07 17:57:17 +0000 | [diff] [blame] | 543 | ); |
| 544 | } |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 545 | #endif |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 546 | |
frkoenig@google.com | e518542 | 2011-11-07 23:07:57 +0000 | [diff] [blame] | 547 | #ifdef HAS_ARGBTOYROW_SSSE3 |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 548 | void ABGRToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) { |
| 549 | SIMD_ALIGNED(uint8 row[kMaxStride]); |
| 550 | ABGRToARGBRow_SSSE3(src_argb, row, pix); |
| 551 | ARGBToYRow_SSSE3(row, dst_y, pix); |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 552 | } |
| 553 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 554 | void BGRAToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix) { |
| 555 | SIMD_ALIGNED(uint8 row[kMaxStride]); |
| 556 | BGRAToARGBRow_SSSE3(src_argb, row, pix); |
| 557 | ARGBToYRow_SSSE3(row, dst_y, pix); |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 558 | } |
frkoenig@google.com | e518542 | 2011-11-07 23:07:57 +0000 | [diff] [blame] | 559 | #endif |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 560 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 561 | #ifdef HAS_ARGBTOUVROW_SSSE3 |
| 562 | void ABGRToUVRow_SSSE3(const uint8* src_argb, int src_stride_argb, |
| 563 | uint8* dst_u, uint8* dst_v, int pix) { |
| 564 | SIMD_ALIGNED(uint8 row[kMaxStride * 2]); |
| 565 | ABGRToARGBRow_SSSE3(src_argb, row, pix); |
| 566 | ABGRToARGBRow_SSSE3(src_argb + src_stride_argb, row + kMaxStride, pix); |
| 567 | ARGBToUVRow_SSSE3(row, kMaxStride, dst_u, dst_v, pix); |
mikhal@webrtc.org | 43575c8 | 2011-10-12 18:49:21 +0000 | [diff] [blame] | 568 | } |
| 569 | |
fbarchard@google.com | b614976 | 2011-11-07 21:58:52 +0000 | [diff] [blame] | 570 | void BGRAToUVRow_SSSE3(const uint8* src_argb, int src_stride_argb, |
| 571 | uint8* dst_u, uint8* dst_v, int pix) { |
| 572 | SIMD_ALIGNED(uint8 row[kMaxStride * 2]); |
| 573 | BGRAToARGBRow_SSSE3(src_argb, row, pix); |
| 574 | BGRAToARGBRow_SSSE3(src_argb + src_stride_argb, row + kMaxStride, pix); |
| 575 | ARGBToUVRow_SSSE3(row, kMaxStride, dst_u, dst_v, pix); |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 576 | } |
mikhal@webrtc.org | 120d5e7 | 2011-10-07 17:57:17 +0000 | [diff] [blame] | 577 | #endif |
fbarchard@google.com | 9394ed9 | 2011-10-31 21:36:47 +0000 | [diff] [blame] | 578 | |
mikhal@webrtc.org | aed1cc9 | 2011-09-28 00:06:25 +0000 | [diff] [blame] | 579 | } // extern "C" |