| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #include "libyuv/rotate.h" |
| 12 |
| 13 | #include "libyuv/cpu_id.h" |
| 14 | #include "libyuv/convert.h" |
| 15 | #include "libyuv/planar_functions.h" |
| 16 | #include "libyuv/row.h" |
| 17 |
| 18 | #ifdef __cplusplus |
| 19 | namespace libyuv { |
| 20 | extern "C" { |
| 21 | #endif |
| 22 |
| 23 | #if !defined(LIBYUV_DISABLE_X86) && \ |
| 24 | (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)) |
| 25 | #if defined(__APPLE__) && defined(__i386__) |
| 26 | #define DECLARE_FUNCTION(name) \ |
| 27 | ".text \n" \ |
| 28 | ".private_extern _" #name " \n" \ |
| 29 | ".align 4,0x90 \n" \ |
| 30 | "_" #name ": \n" |
| 31 | #elif defined(__MINGW32__) || defined(__CYGWIN__) && defined(__i386__) |
| 32 | #define DECLARE_FUNCTION(name) \ |
| 33 | ".text \n" \ |
| 34 | ".align 4,0x90 \n" \ |
| 35 | "_" #name ": \n" |
| 36 | #else |
| 37 | #define DECLARE_FUNCTION(name) \ |
| 38 | ".text \n" \ |
| 39 | ".align 4,0x90 \n" \ |
| 40 | #name ": \n" |
| 41 | #endif |
| 42 | #endif |
| 43 |
| 44 | #if !defined(LIBYUV_DISABLE_NEON) && !defined(__native_client__) && \ |
| 45 | (defined(__ARM_NEON__) || defined(LIBYUV_NEON)) |
| 46 | #define HAS_MIRRORROW_NEON |
| 47 | void MirrorRow_NEON(const uint8* src, uint8* dst, int width); |
| 48 | #define HAS_MIRRORROW_UV_NEON |
| 49 | void MirrorUVRow_NEON(const uint8* src, uint8* dst_a, uint8* dst_b, int width); |
| 50 | #define HAS_TRANSPOSE_WX8_NEON |
| 51 | void TransposeWx8_NEON(const uint8* src, int src_stride, |
| 52 | uint8* dst, int dst_stride, int width); |
| 53 | #define HAS_TRANSPOSE_UVWX8_NEON |
| 54 | void TransposeUVWx8_NEON(const uint8* src, int src_stride, |
| 55 | uint8* dst_a, int dst_stride_a, |
| 56 | uint8* dst_b, int dst_stride_b, |
| 57 | int width); |
| 58 | #elif !defined(LIBYUV_DISABLE_NEON) && !defined(__native_client__) && \ |
| 59 | (defined(__aarch64__) || defined(LIBYUV_NEON)) |
| 60 | // #define HAS_MIRRORROW_NEON |
| 61 | // void MirrorRow_NEON(const uint8* src, uint8* dst, int width); |
| 62 | // #define HAS_MIRRORROW_UV_NEON |
| 63 | // void MirrorUVRow_NEON(const uint8* src, uint8* dst_a, uint8* dst_b, int width); |
| 64 | // #define HAS_TRANSPOSE_WX8_NEON |
| 65 | // void TransposeWx8_NEON(const uint8* src, int src_stride, |
| 66 | // uint8* dst, int dst_stride, int width); |
| 67 | // #define HAS_TRANSPOSE_UVWX8_NEON |
| 68 | // void TransposeUVWx8_NEON(const uint8* src, int src_stride, |
| 69 | // uint8* dst_a, int dst_stride_a, |
| 70 | // uint8* dst_b, int dst_stride_b, |
| 71 | // int width); |
| 72 | #endif // defined(__ARM_NEON__) |
| 73 |
| 74 | #if !defined(LIBYUV_DISABLE_MIPS) && !defined(__native_client__) && \ |
| 75 | defined(__mips__) && \ |
| 76 | defined(__mips_dsp) && (__mips_dsp_rev >= 2) |
| 77 | #define HAS_TRANSPOSE_WX8_MIPS_DSPR2 |
| 78 | void TransposeWx8_MIPS_DSPR2(const uint8* src, int src_stride, |
| 79 | uint8* dst, int dst_stride, int width); |
| 80 |
| 81 | void TransposeWx8_FAST_MIPS_DSPR2(const uint8* src, int src_stride, |
| 82 | uint8* dst, int dst_stride, int width); |
| 83 | #define HAS_TRANSPOSE_UVWx8_MIPS_DSPR2 |
| 84 | void TransposeUVWx8_MIPS_DSPR2(const uint8* src, int src_stride, |
| 85 | uint8* dst_a, int dst_stride_a, |
| 86 | uint8* dst_b, int dst_stride_b, |
| 87 | int width); |
| 88 | #endif // defined(__mips__) |
| 89 |
| 90 | #if !defined(LIBYUV_DISABLE_X86) && \ |
| 91 | defined(_M_IX86) && defined(_MSC_VER) |
| 92 | #define HAS_TRANSPOSE_WX8_SSSE3 |
| 93 | __declspec(naked) __declspec(align(16)) |
| 94 | static void TransposeWx8_SSSE3(const uint8* src, int src_stride, |
| 95 | uint8* dst, int dst_stride, int width) { |
| 96 | __asm { |
| 97 | push edi |
| 98 | push esi |
| 99 | push ebp |
| 100 | mov eax, [esp + 12 + 4] // src |
| 101 | mov edi, [esp + 12 + 8] // src_stride |
| 102 | mov edx, [esp + 12 + 12] // dst |
| 103 | mov esi, [esp + 12 + 16] // dst_stride |
| 104 | mov ecx, [esp + 12 + 20] // width |
| 105 |
| 106 | // Read in the data from the source pointer. |
| 107 | // First round of bit swap. |
| 108 | align 4 |
| 109 | convertloop: |
| 110 | movq xmm0, qword ptr [eax] |
| 111 | lea ebp, [eax + 8] |
| 112 | movq xmm1, qword ptr [eax + edi] |
| 113 | lea eax, [eax + 2 * edi] |
| 114 | punpcklbw xmm0, xmm1 |
| 115 | movq xmm2, qword ptr [eax] |
| 116 | movdqa xmm1, xmm0 |
| 117 | palignr xmm1, xmm1, 8 |
| 118 | movq xmm3, qword ptr [eax + edi] |
| 119 | lea eax, [eax + 2 * edi] |
| 120 | punpcklbw xmm2, xmm3 |
| 121 | movdqa xmm3, xmm2 |
| 122 | movq xmm4, qword ptr [eax] |
| 123 | palignr xmm3, xmm3, 8 |
| 124 | movq xmm5, qword ptr [eax + edi] |
| 125 | punpcklbw xmm4, xmm5 |
| 126 | lea eax, [eax + 2 * edi] |
| 127 | movdqa xmm5, xmm4 |
| 128 | movq xmm6, qword ptr [eax] |
| 129 | palignr xmm5, xmm5, 8 |
| 130 | movq xmm7, qword ptr [eax + edi] |
| 131 | punpcklbw xmm6, xmm7 |
| 132 | mov eax, ebp |
| 133 | movdqa xmm7, xmm6 |
| 134 | palignr xmm7, xmm7, 8 |
| 135 | // Second round of bit swap. |
| 136 | punpcklwd xmm0, xmm2 |
| 137 | punpcklwd xmm1, xmm3 |
| 138 | movdqa xmm2, xmm0 |
| 139 | movdqa xmm3, xmm1 |
| 140 | palignr xmm2, xmm2, 8 |
| 141 | palignr xmm3, xmm3, 8 |
| 142 | punpcklwd xmm4, xmm6 |
| 143 | punpcklwd xmm5, xmm7 |
| 144 | movdqa xmm6, xmm4 |
| 145 | movdqa xmm7, xmm5 |
| 146 | palignr xmm6, xmm6, 8 |
| 147 | palignr xmm7, xmm7, 8 |
| 148 | // Third round of bit swap. |
| 149 | // Write to the destination pointer. |
| 150 | punpckldq xmm0, xmm4 |
| 151 | movq qword ptr [edx], xmm0 |
| 152 | movdqa xmm4, xmm0 |
| 153 | palignr xmm4, xmm4, 8 |
| 154 | movq qword ptr [edx + esi], xmm4 |
| 155 | lea edx, [edx + 2 * esi] |
| 156 | punpckldq xmm2, xmm6 |
| 157 | movdqa xmm6, xmm2 |
| 158 | palignr xmm6, xmm6, 8 |
| 159 | movq qword ptr [edx], xmm2 |
| 160 | punpckldq xmm1, xmm5 |
| 161 | movq qword ptr [edx + esi], xmm6 |
| 162 | lea edx, [edx + 2 * esi] |
| 163 | movdqa xmm5, xmm1 |
| 164 | movq qword ptr [edx], xmm1 |
| 165 | palignr xmm5, xmm5, 8 |
| 166 | punpckldq xmm3, xmm7 |
| 167 | movq qword ptr [edx + esi], xmm5 |
| 168 | lea edx, [edx + 2 * esi] |
| 169 | movq qword ptr [edx], xmm3 |
| 170 | movdqa xmm7, xmm3 |
| 171 | palignr xmm7, xmm7, 8 |
| 172 | sub ecx, 8 |
| 173 | movq qword ptr [edx + esi], xmm7 |
| 174 | lea edx, [edx + 2 * esi] |
| 175 | jg convertloop |
| 176 |
| 177 | pop ebp |
| 178 | pop esi |
| 179 | pop edi |
| 180 | ret |
| 181 | } |
| 182 | } |
| 183 |
| 184 | #define HAS_TRANSPOSE_UVWX8_SSE2 |
| 185 | __declspec(naked) __declspec(align(16)) |
| 186 | static void TransposeUVWx8_SSE2(const uint8* src, int src_stride, |
| 187 | uint8* dst_a, int dst_stride_a, |
| 188 | uint8* dst_b, int dst_stride_b, |
| 189 | int w) { |
| 190 | __asm { |
| 191 | push ebx |
| 192 | push esi |
| 193 | push edi |
| 194 | push ebp |
| 195 | mov eax, [esp + 16 + 4] // src |
| 196 | mov edi, [esp + 16 + 8] // src_stride |
| 197 | mov edx, [esp + 16 + 12] // dst_a |
| 198 | mov esi, [esp + 16 + 16] // dst_stride_a |
| 199 | mov ebx, [esp + 16 + 20] // dst_b |
| 200 | mov ebp, [esp + 16 + 24] // dst_stride_b |
| 201 | mov ecx, esp |
| 202 | sub esp, 4 + 16 |
| 203 | and esp, ~15 |
| 204 | mov [esp + 16], ecx |
| 205 | mov ecx, [ecx + 16 + 28] // w |
| 206 |
| 207 | align 4 |
| 208 | convertloop: |
| 209 | // Read in the data from the source pointer. |
| 210 | // First round of bit swap. |
| 211 | movdqa xmm0, [eax] |
| 212 | movdqa xmm1, [eax + edi] |
| 213 | lea eax, [eax + 2 * edi] |
| 214 | movdqa xmm7, xmm0 // use xmm7 as temp register. |
| 215 | punpcklbw xmm0, xmm1 |
| 216 | punpckhbw xmm7, xmm1 |
| 217 | movdqa xmm1, xmm7 |
| 218 | movdqa xmm2, [eax] |
| 219 | movdqa xmm3, [eax + edi] |
| 220 | lea eax, [eax + 2 * edi] |
| 221 | movdqa xmm7, xmm2 |
| 222 | punpcklbw xmm2, xmm3 |
| 223 | punpckhbw xmm7, xmm3 |
| 224 | movdqa xmm3, xmm7 |
| 225 | movdqa xmm4, [eax] |
| 226 | movdqa xmm5, [eax + edi] |
| 227 | lea eax, [eax + 2 * edi] |
| 228 | movdqa xmm7, xmm4 |
| 229 | punpcklbw xmm4, xmm5 |
| 230 | punpckhbw xmm7, xmm5 |
| 231 | movdqa xmm5, xmm7 |
| 232 | movdqa xmm6, [eax] |
| 233 | movdqa xmm7, [eax + edi] |
| 234 | lea eax, [eax + 2 * edi] |
| 235 | movdqa [esp], xmm5 // backup xmm5 |
| 236 | neg edi |
| 237 | movdqa xmm5, xmm6 // use xmm5 as temp register. |
| 238 | punpcklbw xmm6, xmm7 |
| 239 | punpckhbw xmm5, xmm7 |
| 240 | movdqa xmm7, xmm5 |
| 241 | lea eax, [eax + 8 * edi + 16] |
| 242 | neg edi |
| 243 | // Second round of bit swap. |
| 244 | movdqa xmm5, xmm0 |
| 245 | punpcklwd xmm0, xmm2 |
| 246 | punpckhwd xmm5, xmm2 |
| 247 | movdqa xmm2, xmm5 |
| 248 | movdqa xmm5, xmm1 |
| 249 | punpcklwd xmm1, xmm3 |
| 250 | punpckhwd xmm5, xmm3 |
| 251 | movdqa xmm3, xmm5 |
| 252 | movdqa xmm5, xmm4 |
| 253 | punpcklwd xmm4, xmm6 |
| 254 | punpckhwd xmm5, xmm6 |
| 255 | movdqa xmm6, xmm5 |
| 256 | movdqa xmm5, [esp] // restore xmm5 |
| 257 | movdqa [esp], xmm6 // backup xmm6 |
| 258 | movdqa xmm6, xmm5 // use xmm6 as temp register. |
| 259 | punpcklwd xmm5, xmm7 |
| 260 | punpckhwd xmm6, xmm7 |
| 261 | movdqa xmm7, xmm6 |
| 262 | // Third round of bit swap. |
| 263 | // Write to the destination pointer. |
| 264 | movdqa xmm6, xmm0 |
| 265 | punpckldq xmm0, xmm4 |
| 266 | punpckhdq xmm6, xmm4 |
| 267 | movdqa xmm4, xmm6 |
| 268 | movdqa xmm6, [esp] // restore xmm6 |
| 269 | movlpd qword ptr [edx], xmm0 |
| 270 | movhpd qword ptr [ebx], xmm0 |
| 271 | movlpd qword ptr [edx + esi], xmm4 |
| 272 | lea edx, [edx + 2 * esi] |
| 273 | movhpd qword ptr [ebx + ebp], xmm4 |
| 274 | lea ebx, [ebx + 2 * ebp] |
| 275 | movdqa xmm0, xmm2 // use xmm0 as the temp register. |
| 276 | punpckldq xmm2, xmm6 |
| 277 | movlpd qword ptr [edx], xmm2 |
| 278 | movhpd qword ptr [ebx], xmm2 |
| 279 | punpckhdq xmm0, xmm6 |
| 280 | movlpd qword ptr [edx + esi], xmm0 |
| 281 | lea edx, [edx + 2 * esi] |
| 282 | movhpd qword ptr [ebx + ebp], xmm0 |
| 283 | lea ebx, [ebx + 2 * ebp] |
| 284 | movdqa xmm0, xmm1 // use xmm0 as the temp register. |
| 285 | punpckldq xmm1, xmm5 |
| 286 | movlpd qword ptr [edx], xmm1 |
| 287 | movhpd qword ptr [ebx], xmm1 |
| 288 | punpckhdq xmm0, xmm5 |
| 289 | movlpd qword ptr [edx + esi], xmm0 |
| 290 | lea edx, [edx + 2 * esi] |
| 291 | movhpd qword ptr [ebx + ebp], xmm0 |
| 292 | lea ebx, [ebx + 2 * ebp] |
| 293 | movdqa xmm0, xmm3 // use xmm0 as the temp register. |
| 294 | punpckldq xmm3, xmm7 |
| 295 | movlpd qword ptr [edx], xmm3 |
| 296 | movhpd qword ptr [ebx], xmm3 |
| 297 | punpckhdq xmm0, xmm7 |
| 298 | sub ecx, 8 |
| 299 | movlpd qword ptr [edx + esi], xmm0 |
| 300 | lea edx, [edx + 2 * esi] |
| 301 | movhpd qword ptr [ebx + ebp], xmm0 |
| 302 | lea ebx, [ebx + 2 * ebp] |
| 303 | jg convertloop |
| 304 |
| 305 | mov esp, [esp + 16] |
| 306 | pop ebp |
| 307 | pop edi |
| 308 | pop esi |
| 309 | pop ebx |
| 310 | ret |
| 311 | } |
| 312 | } |
| 313 | #elif !defined(LIBYUV_DISABLE_X86) && \ |
| 314 | (defined(__i386__) || (defined(__x86_64__) && !defined(__native_client__))) |
| 315 | #define HAS_TRANSPOSE_WX8_SSSE3 |
| 316 | static void TransposeWx8_SSSE3(const uint8* src, int src_stride, |
| 317 | uint8* dst, int dst_stride, int width) { |
| 318 | asm volatile ( |
| 319 | // Read in the data from the source pointer. |
| 320 | // First round of bit swap. |
| 321 | ".p2align 2 \n" |
| 322 | "1: \n" |
| 323 | "movq (%0),%%xmm0 \n" |
| 324 | "movq (%0,%3),%%xmm1 \n" |
| 325 | "lea (%0,%3,2),%0 \n" |
| 326 | "punpcklbw %%xmm1,%%xmm0 \n" |
| 327 | "movq (%0),%%xmm2 \n" |
| 328 | "movdqa %%xmm0,%%xmm1 \n" |
| 329 | "palignr $0x8,%%xmm1,%%xmm1 \n" |
| 330 | "movq (%0,%3),%%xmm3 \n" |
| 331 | "lea (%0,%3,2),%0 \n" |
| 332 | "punpcklbw %%xmm3,%%xmm2 \n" |
| 333 | "movdqa %%xmm2,%%xmm3 \n" |
| 334 | "movq (%0),%%xmm4 \n" |
| 335 | "palignr $0x8,%%xmm3,%%xmm3 \n" |
| 336 | "movq (%0,%3),%%xmm5 \n" |
| 337 | "lea (%0,%3,2),%0 \n" |
| 338 | "punpcklbw %%xmm5,%%xmm4 \n" |
| 339 | "movdqa %%xmm4,%%xmm5 \n" |
| 340 | "movq (%0),%%xmm6 \n" |
| 341 | "palignr $0x8,%%xmm5,%%xmm5 \n" |
| 342 | "movq (%0,%3),%%xmm7 \n" |
| 343 | "lea (%0,%3,2),%0 \n" |
| 344 | "punpcklbw %%xmm7,%%xmm6 \n" |
| 345 | "neg %3 \n" |
| 346 | "movdqa %%xmm6,%%xmm7 \n" |
| 347 | "lea 0x8(%0,%3,8),%0 \n" |
| 348 | "palignr $0x8,%%xmm7,%%xmm7 \n" |
| 349 | "neg %3 \n" |
| 350 | // Second round of bit swap. |
| 351 | "punpcklwd %%xmm2,%%xmm0 \n" |
| 352 | "punpcklwd %%xmm3,%%xmm1 \n" |
| 353 | "movdqa %%xmm0,%%xmm2 \n" |
| 354 | "movdqa %%xmm1,%%xmm3 \n" |
| 355 | "palignr $0x8,%%xmm2,%%xmm2 \n" |
| 356 | "palignr $0x8,%%xmm3,%%xmm3 \n" |
| 357 | "punpcklwd %%xmm6,%%xmm4 \n" |
| 358 | "punpcklwd %%xmm7,%%xmm5 \n" |
| 359 | "movdqa %%xmm4,%%xmm6 \n" |
| 360 | "movdqa %%xmm5,%%xmm7 \n" |
| 361 | "palignr $0x8,%%xmm6,%%xmm6 \n" |
| 362 | "palignr $0x8,%%xmm7,%%xmm7 \n" |
| 363 | // Third round of bit swap. |
| 364 | // Write to the destination pointer. |
| 365 | "punpckldq %%xmm4,%%xmm0 \n" |
| 366 | "movq %%xmm0,(%1) \n" |
| 367 | "movdqa %%xmm0,%%xmm4 \n" |
| 368 | "palignr $0x8,%%xmm4,%%xmm4 \n" |
| 369 | "movq %%xmm4,(%1,%4) \n" |
| 370 | "lea (%1,%4,2),%1 \n" |
| 371 | "punpckldq %%xmm6,%%xmm2 \n" |
| 372 | "movdqa %%xmm2,%%xmm6 \n" |
| 373 | "movq %%xmm2,(%1) \n" |
| 374 | "palignr $0x8,%%xmm6,%%xmm6 \n" |
| 375 | "punpckldq %%xmm5,%%xmm1 \n" |
| 376 | "movq %%xmm6,(%1,%4) \n" |
| 377 | "lea (%1,%4,2),%1 \n" |
| 378 | "movdqa %%xmm1,%%xmm5 \n" |
| 379 | "movq %%xmm1,(%1) \n" |
| 380 | "palignr $0x8,%%xmm5,%%xmm5 \n" |
| 381 | "movq %%xmm5,(%1,%4) \n" |
| 382 | "lea (%1,%4,2),%1 \n" |
| 383 | "punpckldq %%xmm7,%%xmm3 \n" |
| 384 | "movq %%xmm3,(%1) \n" |
| 385 | "movdqa %%xmm3,%%xmm7 \n" |
| 386 | "palignr $0x8,%%xmm7,%%xmm7 \n" |
| 387 | "sub $0x8,%2 \n" |
| 388 | "movq %%xmm7,(%1,%4) \n" |
| 389 | "lea (%1,%4,2),%1 \n" |
| 390 | "jg 1b \n" |
| 391 | : "+r"(src), // %0 |
| 392 | "+r"(dst), // %1 |
| 393 | "+r"(width) // %2 |
| 394 | : "r"((intptr_t)(src_stride)), // %3 |
| 395 | "r"((intptr_t)(dst_stride)) // %4 |
| 396 | : "memory", "cc" |
| 397 | #if defined(__SSE2__) |
| 398 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" |
| 399 | #endif |
| 400 | ); |
| 401 | } |
| 402 |
| 403 | #if !defined(LIBYUV_DISABLE_X86) && defined(__i386__) |
| 404 | #define HAS_TRANSPOSE_UVWX8_SSE2 |
| 405 | void TransposeUVWx8_SSE2(const uint8* src, int src_stride, |
| 406 | uint8* dst_a, int dst_stride_a, |
| 407 | uint8* dst_b, int dst_stride_b, |
| 408 | int w); |
| 409 | asm ( |
| 410 | DECLARE_FUNCTION(TransposeUVWx8_SSE2) |
| 411 | "push %ebx \n" |
| 412 | "push %esi \n" |
| 413 | "push %edi \n" |
| 414 | "push %ebp \n" |
| 415 | "mov 0x14(%esp),%eax \n" |
| 416 | "mov 0x18(%esp),%edi \n" |
| 417 | "mov 0x1c(%esp),%edx \n" |
| 418 | "mov 0x20(%esp),%esi \n" |
| 419 | "mov 0x24(%esp),%ebx \n" |
| 420 | "mov 0x28(%esp),%ebp \n" |
| 421 | "mov %esp,%ecx \n" |
| 422 | "sub $0x14,%esp \n" |
| 423 | "and $0xfffffff0,%esp \n" |
| 424 | "mov %ecx,0x10(%esp) \n" |
| 425 | "mov 0x2c(%ecx),%ecx \n" |
| 426 |
| 427 | "1: \n" |
| 428 | "movdqa (%eax),%xmm0 \n" |
| 429 | "movdqa (%eax,%edi,1),%xmm1 \n" |
| 430 | "lea (%eax,%edi,2),%eax \n" |
| 431 | "movdqa %xmm0,%xmm7 \n" |
| 432 | "punpcklbw %xmm1,%xmm0 \n" |
| 433 | "punpckhbw %xmm1,%xmm7 \n" |
| 434 | "movdqa %xmm7,%xmm1 \n" |
| 435 | "movdqa (%eax),%xmm2 \n" |
| 436 | "movdqa (%eax,%edi,1),%xmm3 \n" |
| 437 | "lea (%eax,%edi,2),%eax \n" |
| 438 | "movdqa %xmm2,%xmm7 \n" |
| 439 | "punpcklbw %xmm3,%xmm2 \n" |
| 440 | "punpckhbw %xmm3,%xmm7 \n" |
| 441 | "movdqa %xmm7,%xmm3 \n" |
| 442 | "movdqa (%eax),%xmm4 \n" |
| 443 | "movdqa (%eax,%edi,1),%xmm5 \n" |
| 444 | "lea (%eax,%edi,2),%eax \n" |
| 445 | "movdqa %xmm4,%xmm7 \n" |
| 446 | "punpcklbw %xmm5,%xmm4 \n" |
| 447 | "punpckhbw %xmm5,%xmm7 \n" |
| 448 | "movdqa %xmm7,%xmm5 \n" |
| 449 | "movdqa (%eax),%xmm6 \n" |
| 450 | "movdqa (%eax,%edi,1),%xmm7 \n" |
| 451 | "lea (%eax,%edi,2),%eax \n" |
| 452 | "movdqa %xmm5,(%esp) \n" |
| 453 | "neg %edi \n" |
| 454 | "movdqa %xmm6,%xmm5 \n" |
| 455 | "punpcklbw %xmm7,%xmm6 \n" |
| 456 | "punpckhbw %xmm7,%xmm5 \n" |
| 457 | "movdqa %xmm5,%xmm7 \n" |
| 458 | "lea 0x10(%eax,%edi,8),%eax \n" |
| 459 | "neg %edi \n" |
| 460 | "movdqa %xmm0,%xmm5 \n" |
| 461 | "punpcklwd %xmm2,%xmm0 \n" |
| 462 | "punpckhwd %xmm2,%xmm5 \n" |
| 463 | "movdqa %xmm5,%xmm2 \n" |
| 464 | "movdqa %xmm1,%xmm5 \n" |
| 465 | "punpcklwd %xmm3,%xmm1 \n" |
| 466 | "punpckhwd %xmm3,%xmm5 \n" |
| 467 | "movdqa %xmm5,%xmm3 \n" |
| 468 | "movdqa %xmm4,%xmm5 \n" |
| 469 | "punpcklwd %xmm6,%xmm4 \n" |
| 470 | "punpckhwd %xmm6,%xmm5 \n" |
| 471 | "movdqa %xmm5,%xmm6 \n" |
| 472 | "movdqa (%esp),%xmm5 \n" |
| 473 | "movdqa %xmm6,(%esp) \n" |
| 474 | "movdqa %xmm5,%xmm6 \n" |
| 475 | "punpcklwd %xmm7,%xmm5 \n" |
| 476 | "punpckhwd %xmm7,%xmm6 \n" |
| 477 | "movdqa %xmm6,%xmm7 \n" |
| 478 | "movdqa %xmm0,%xmm6 \n" |
| 479 | "punpckldq %xmm4,%xmm0 \n" |
| 480 | "punpckhdq %xmm4,%xmm6 \n" |
| 481 | "movdqa %xmm6,%xmm4 \n" |
| 482 | "movdqa (%esp),%xmm6 \n" |
| 483 | "movlpd %xmm0,(%edx) \n" |
| 484 | "movhpd %xmm0,(%ebx) \n" |
| 485 | "movlpd %xmm4,(%edx,%esi,1) \n" |
| 486 | "lea (%edx,%esi,2),%edx \n" |
| 487 | "movhpd %xmm4,(%ebx,%ebp,1) \n" |
| 488 | "lea (%ebx,%ebp,2),%ebx \n" |
| 489 | "movdqa %xmm2,%xmm0 \n" |
| 490 | "punpckldq %xmm6,%xmm2 \n" |
| 491 | "movlpd %xmm2,(%edx) \n" |
| 492 | "movhpd %xmm2,(%ebx) \n" |
| 493 | "punpckhdq %xmm6,%xmm0 \n" |
| 494 | "movlpd %xmm0,(%edx,%esi,1) \n" |
| 495 | "lea (%edx,%esi,2),%edx \n" |
| 496 | "movhpd %xmm0,(%ebx,%ebp,1) \n" |
| 497 | "lea (%ebx,%ebp,2),%ebx \n" |
| 498 | "movdqa %xmm1,%xmm0 \n" |
| 499 | "punpckldq %xmm5,%xmm1 \n" |
| 500 | "movlpd %xmm1,(%edx) \n" |
| 501 | "movhpd %xmm1,(%ebx) \n" |
| 502 | "punpckhdq %xmm5,%xmm0 \n" |
| 503 | "movlpd %xmm0,(%edx,%esi,1) \n" |
| 504 | "lea (%edx,%esi,2),%edx \n" |
| 505 | "movhpd %xmm0,(%ebx,%ebp,1) \n" |
| 506 | "lea (%ebx,%ebp,2),%ebx \n" |
| 507 | "movdqa %xmm3,%xmm0 \n" |
| 508 | "punpckldq %xmm7,%xmm3 \n" |
| 509 | "movlpd %xmm3,(%edx) \n" |
| 510 | "movhpd %xmm3,(%ebx) \n" |
| 511 | "punpckhdq %xmm7,%xmm0 \n" |
| 512 | "sub $0x8,%ecx \n" |
| 513 | "movlpd %xmm0,(%edx,%esi,1) \n" |
| 514 | "lea (%edx,%esi,2),%edx \n" |
| 515 | "movhpd %xmm0,(%ebx,%ebp,1) \n" |
| 516 | "lea (%ebx,%ebp,2),%ebx \n" |
| 517 | "jg 1b \n" |
| 518 | "mov 0x10(%esp),%esp \n" |
| 519 | "pop %ebp \n" |
| 520 | "pop %edi \n" |
| 521 | "pop %esi \n" |
| 522 | "pop %ebx \n" |
| 523 | #if defined(__native_client__) |
| 524 | "pop %ecx \n" |
| 525 | "and $0xffffffe0,%ecx \n" |
| 526 | "jmp *%ecx \n" |
| 527 | #else |
| 528 | "ret \n" |
| 529 | #endif |
| 530 | ); |
| 531 | #elif !defined(LIBYUV_DISABLE_X86) && !defined(__native_client__) && \ |
| 532 | defined(__x86_64__) |
| 533 | // 64 bit version has enough registers to do 16x8 to 8x16 at a time. |
| 534 | #define HAS_TRANSPOSE_WX8_FAST_SSSE3 |
| 535 | static void TransposeWx8_FAST_SSSE3(const uint8* src, int src_stride, |
| 536 | uint8* dst, int dst_stride, int width) { |
| 537 | asm volatile ( |
| 538 | // Read in the data from the source pointer. |
| 539 | // First round of bit swap. |
| 540 | ".p2align 2 \n" |
| 541 | "1: \n" |
| 542 | "movdqa (%0),%%xmm0 \n" |
| 543 | "movdqa (%0,%3),%%xmm1 \n" |
| 544 | "lea (%0,%3,2),%0 \n" |
| 545 | "movdqa %%xmm0,%%xmm8 \n" |
| 546 | "punpcklbw %%xmm1,%%xmm0 \n" |
| 547 | "punpckhbw %%xmm1,%%xmm8 \n" |
| 548 | "movdqa (%0),%%xmm2 \n" |
| 549 | "movdqa %%xmm0,%%xmm1 \n" |
| 550 | "movdqa %%xmm8,%%xmm9 \n" |
| 551 | "palignr $0x8,%%xmm1,%%xmm1 \n" |
| 552 | "palignr $0x8,%%xmm9,%%xmm9 \n" |
| 553 | "movdqa (%0,%3),%%xmm3 \n" |
| 554 | "lea (%0,%3,2),%0 \n" |
| 555 | "movdqa %%xmm2,%%xmm10 \n" |
| 556 | "punpcklbw %%xmm3,%%xmm2 \n" |
| 557 | "punpckhbw %%xmm3,%%xmm10 \n" |
| 558 | "movdqa %%xmm2,%%xmm3 \n" |
| 559 | "movdqa %%xmm10,%%xmm11 \n" |
| 560 | "movdqa (%0),%%xmm4 \n" |
| 561 | "palignr $0x8,%%xmm3,%%xmm3 \n" |
| 562 | "palignr $0x8,%%xmm11,%%xmm11 \n" |
| 563 | "movdqa (%0,%3),%%xmm5 \n" |
| 564 | "lea (%0,%3,2),%0 \n" |
| 565 | "movdqa %%xmm4,%%xmm12 \n" |
| 566 | "punpcklbw %%xmm5,%%xmm4 \n" |
| 567 | "punpckhbw %%xmm5,%%xmm12 \n" |
| 568 | "movdqa %%xmm4,%%xmm5 \n" |
| 569 | "movdqa %%xmm12,%%xmm13 \n" |
| 570 | "movdqa (%0),%%xmm6 \n" |
| 571 | "palignr $0x8,%%xmm5,%%xmm5 \n" |
| 572 | "palignr $0x8,%%xmm13,%%xmm13 \n" |
| 573 | "movdqa (%0,%3),%%xmm7 \n" |
| 574 | "lea (%0,%3,2),%0 \n" |
| 575 | "movdqa %%xmm6,%%xmm14 \n" |
| 576 | "punpcklbw %%xmm7,%%xmm6 \n" |
| 577 | "punpckhbw %%xmm7,%%xmm14 \n" |
| 578 | "neg %3 \n" |
| 579 | "movdqa %%xmm6,%%xmm7 \n" |
| 580 | "movdqa %%xmm14,%%xmm15 \n" |
| 581 | "lea 0x10(%0,%3,8),%0 \n" |
| 582 | "palignr $0x8,%%xmm7,%%xmm7 \n" |
| 583 | "palignr $0x8,%%xmm15,%%xmm15 \n" |
| 584 | "neg %3 \n" |
| 585 | // Second round of bit swap. |
| 586 | "punpcklwd %%xmm2,%%xmm0 \n" |
| 587 | "punpcklwd %%xmm3,%%xmm1 \n" |
| 588 | "movdqa %%xmm0,%%xmm2 \n" |
| 589 | "movdqa %%xmm1,%%xmm3 \n" |
| 590 | "palignr $0x8,%%xmm2,%%xmm2 \n" |
| 591 | "palignr $0x8,%%xmm3,%%xmm3 \n" |
| 592 | "punpcklwd %%xmm6,%%xmm4 \n" |
| 593 | "punpcklwd %%xmm7,%%xmm5 \n" |
| 594 | "movdqa %%xmm4,%%xmm6 \n" |
| 595 | "movdqa %%xmm5,%%xmm7 \n" |
| 596 | "palignr $0x8,%%xmm6,%%xmm6 \n" |
| 597 | "palignr $0x8,%%xmm7,%%xmm7 \n" |
| 598 | "punpcklwd %%xmm10,%%xmm8 \n" |
| 599 | "punpcklwd %%xmm11,%%xmm9 \n" |
| 600 | "movdqa %%xmm8,%%xmm10 \n" |
| 601 | "movdqa %%xmm9,%%xmm11 \n" |
| 602 | "palignr $0x8,%%xmm10,%%xmm10 \n" |
| 603 | "palignr $0x8,%%xmm11,%%xmm11 \n" |
| 604 | "punpcklwd %%xmm14,%%xmm12 \n" |
| 605 | "punpcklwd %%xmm15,%%xmm13 \n" |
| 606 | "movdqa %%xmm12,%%xmm14 \n" |
| 607 | "movdqa %%xmm13,%%xmm15 \n" |
| 608 | "palignr $0x8,%%xmm14,%%xmm14 \n" |
| 609 | "palignr $0x8,%%xmm15,%%xmm15 \n" |
| 610 | // Third round of bit swap. |
| 611 | // Write to the destination pointer. |
| 612 | "punpckldq %%xmm4,%%xmm0 \n" |
| 613 | "movq %%xmm0,(%1) \n" |
| 614 | "movdqa %%xmm0,%%xmm4 \n" |
| 615 | "palignr $0x8,%%xmm4,%%xmm4 \n" |
| 616 | "movq %%xmm4,(%1,%4) \n" |
| 617 | "lea (%1,%4,2),%1 \n" |
| 618 | "punpckldq %%xmm6,%%xmm2 \n" |
| 619 | "movdqa %%xmm2,%%xmm6 \n" |
| 620 | "movq %%xmm2,(%1) \n" |
| 621 | "palignr $0x8,%%xmm6,%%xmm6 \n" |
| 622 | "punpckldq %%xmm5,%%xmm1 \n" |
| 623 | "movq %%xmm6,(%1,%4) \n" |
| 624 | "lea (%1,%4,2),%1 \n" |
| 625 | "movdqa %%xmm1,%%xmm5 \n" |
| 626 | "movq %%xmm1,(%1) \n" |
| 627 | "palignr $0x8,%%xmm5,%%xmm5 \n" |
| 628 | "movq %%xmm5,(%1,%4) \n" |
| 629 | "lea (%1,%4,2),%1 \n" |
| 630 | "punpckldq %%xmm7,%%xmm3 \n" |
| 631 | "movq %%xmm3,(%1) \n" |
| 632 | "movdqa %%xmm3,%%xmm7 \n" |
| 633 | "palignr $0x8,%%xmm7,%%xmm7 \n" |
| 634 | "movq %%xmm7,(%1,%4) \n" |
| 635 | "lea (%1,%4,2),%1 \n" |
| 636 | "punpckldq %%xmm12,%%xmm8 \n" |
| 637 | "movq %%xmm8,(%1) \n" |
| 638 | "movdqa %%xmm8,%%xmm12 \n" |
| 639 | "palignr $0x8,%%xmm12,%%xmm12 \n" |
| 640 | "movq %%xmm12,(%1,%4) \n" |
| 641 | "lea (%1,%4,2),%1 \n" |
| 642 | "punpckldq %%xmm14,%%xmm10 \n" |
| 643 | "movdqa %%xmm10,%%xmm14 \n" |
| 644 | "movq %%xmm10,(%1) \n" |
| 645 | "palignr $0x8,%%xmm14,%%xmm14 \n" |
| 646 | "punpckldq %%xmm13,%%xmm9 \n" |
| 647 | "movq %%xmm14,(%1,%4) \n" |
| 648 | "lea (%1,%4,2),%1 \n" |
| 649 | "movdqa %%xmm9,%%xmm13 \n" |
| 650 | "movq %%xmm9,(%1) \n" |
| 651 | "palignr $0x8,%%xmm13,%%xmm13 \n" |
| 652 | "movq %%xmm13,(%1,%4) \n" |
| 653 | "lea (%1,%4,2),%1 \n" |
| 654 | "punpckldq %%xmm15,%%xmm11 \n" |
| 655 | "movq %%xmm11,(%1) \n" |
| 656 | "movdqa %%xmm11,%%xmm15 \n" |
| 657 | "palignr $0x8,%%xmm15,%%xmm15 \n" |
| 658 | "sub $0x10,%2 \n" |
| 659 | "movq %%xmm15,(%1,%4) \n" |
| 660 | "lea (%1,%4,2),%1 \n" |
| 661 | "jg 1b \n" |
| 662 | : "+r"(src), // %0 |
| 663 | "+r"(dst), // %1 |
| 664 | "+r"(width) // %2 |
| 665 | : "r"((intptr_t)(src_stride)), // %3 |
| 666 | "r"((intptr_t)(dst_stride)) // %4 |
| 667 | : "memory", "cc", |
| 668 | "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", |
| 669 | "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" |
| 670 | ); |
| 671 | } |
| 672 |
| 673 | #define HAS_TRANSPOSE_UVWX8_SSE2 |
| 674 | static void TransposeUVWx8_SSE2(const uint8* src, int src_stride, |
| 675 | uint8* dst_a, int dst_stride_a, |
| 676 | uint8* dst_b, int dst_stride_b, |
| 677 | int w) { |
| 678 | asm volatile ( |
| 679 | // Read in the data from the source pointer. |
| 680 | // First round of bit swap. |
| 681 | ".p2align 2 \n" |
| 682 | "1: \n" |
| 683 | "movdqa (%0),%%xmm0 \n" |
| 684 | "movdqa (%0,%4),%%xmm1 \n" |
| 685 | "lea (%0,%4,2),%0 \n" |
| 686 | "movdqa %%xmm0,%%xmm8 \n" |
| 687 | "punpcklbw %%xmm1,%%xmm0 \n" |
| 688 | "punpckhbw %%xmm1,%%xmm8 \n" |
| 689 | "movdqa %%xmm8,%%xmm1 \n" |
| 690 | "movdqa (%0),%%xmm2 \n" |
| 691 | "movdqa (%0,%4),%%xmm3 \n" |
| 692 | "lea (%0,%4,2),%0 \n" |
| 693 | "movdqa %%xmm2,%%xmm8 \n" |
| 694 | "punpcklbw %%xmm3,%%xmm2 \n" |
| 695 | "punpckhbw %%xmm3,%%xmm8 \n" |
| 696 | "movdqa %%xmm8,%%xmm3 \n" |
| 697 | "movdqa (%0),%%xmm4 \n" |
| 698 | "movdqa (%0,%4),%%xmm5 \n" |
| 699 | "lea (%0,%4,2),%0 \n" |
| 700 | "movdqa %%xmm4,%%xmm8 \n" |
| 701 | "punpcklbw %%xmm5,%%xmm4 \n" |
| 702 | "punpckhbw %%xmm5,%%xmm8 \n" |
| 703 | "movdqa %%xmm8,%%xmm5 \n" |
| 704 | "movdqa (%0),%%xmm6 \n" |
| 705 | "movdqa (%0,%4),%%xmm7 \n" |
| 706 | "lea (%0,%4,2),%0 \n" |
| 707 | "movdqa %%xmm6,%%xmm8 \n" |
| 708 | "punpcklbw %%xmm7,%%xmm6 \n" |
| 709 | "neg %4 \n" |
| 710 | "lea 0x10(%0,%4,8),%0 \n" |
| 711 | "punpckhbw %%xmm7,%%xmm8 \n" |
| 712 | "movdqa %%xmm8,%%xmm7 \n" |
| 713 | "neg %4 \n" |
| 714 | // Second round of bit swap. |
| 715 | "movdqa %%xmm0,%%xmm8 \n" |
| 716 | "movdqa %%xmm1,%%xmm9 \n" |
| 717 | "punpckhwd %%xmm2,%%xmm8 \n" |
| 718 | "punpckhwd %%xmm3,%%xmm9 \n" |
| 719 | "punpcklwd %%xmm2,%%xmm0 \n" |
| 720 | "punpcklwd %%xmm3,%%xmm1 \n" |
| 721 | "movdqa %%xmm8,%%xmm2 \n" |
| 722 | "movdqa %%xmm9,%%xmm3 \n" |
| 723 | "movdqa %%xmm4,%%xmm8 \n" |
| 724 | "movdqa %%xmm5,%%xmm9 \n" |
| 725 | "punpckhwd %%xmm6,%%xmm8 \n" |
| 726 | "punpckhwd %%xmm7,%%xmm9 \n" |
| 727 | "punpcklwd %%xmm6,%%xmm4 \n" |
| 728 | "punpcklwd %%xmm7,%%xmm5 \n" |
| 729 | "movdqa %%xmm8,%%xmm6 \n" |
| 730 | "movdqa %%xmm9,%%xmm7 \n" |
| 731 | // Third round of bit swap. |
| 732 | // Write to the destination pointer. |
| 733 | "movdqa %%xmm0,%%xmm8 \n" |
| 734 | "punpckldq %%xmm4,%%xmm0 \n" |
| 735 | "movlpd %%xmm0,(%1) \n" // Write back U channel |
| 736 | "movhpd %%xmm0,(%2) \n" // Write back V channel |
| 737 | "punpckhdq %%xmm4,%%xmm8 \n" |
| 738 | "movlpd %%xmm8,(%1,%5) \n" |
| 739 | "lea (%1,%5,2),%1 \n" |
| 740 | "movhpd %%xmm8,(%2,%6) \n" |
| 741 | "lea (%2,%6,2),%2 \n" |
| 742 | "movdqa %%xmm2,%%xmm8 \n" |
| 743 | "punpckldq %%xmm6,%%xmm2 \n" |
| 744 | "movlpd %%xmm2,(%1) \n" |
| 745 | "movhpd %%xmm2,(%2) \n" |
| 746 | "punpckhdq %%xmm6,%%xmm8 \n" |
| 747 | "movlpd %%xmm8,(%1,%5) \n" |
| 748 | "lea (%1,%5,2),%1 \n" |
| 749 | "movhpd %%xmm8,(%2,%6) \n" |
| 750 | "lea (%2,%6,2),%2 \n" |
| 751 | "movdqa %%xmm1,%%xmm8 \n" |
| 752 | "punpckldq %%xmm5,%%xmm1 \n" |
| 753 | "movlpd %%xmm1,(%1) \n" |
| 754 | "movhpd %%xmm1,(%2) \n" |
| 755 | "punpckhdq %%xmm5,%%xmm8 \n" |
| 756 | "movlpd %%xmm8,(%1,%5) \n" |
| 757 | "lea (%1,%5,2),%1 \n" |
| 758 | "movhpd %%xmm8,(%2,%6) \n" |
| 759 | "lea (%2,%6,2),%2 \n" |
| 760 | "movdqa %%xmm3,%%xmm8 \n" |
| 761 | "punpckldq %%xmm7,%%xmm3 \n" |
| 762 | "movlpd %%xmm3,(%1) \n" |
| 763 | "movhpd %%xmm3,(%2) \n" |
| 764 | "punpckhdq %%xmm7,%%xmm8 \n" |
| 765 | "sub $0x8,%3 \n" |
| 766 | "movlpd %%xmm8,(%1,%5) \n" |
| 767 | "lea (%1,%5,2),%1 \n" |
| 768 | "movhpd %%xmm8,(%2,%6) \n" |
| 769 | "lea (%2,%6,2),%2 \n" |
| 770 | "jg 1b \n" |
| 771 | : "+r"(src), // %0 |
| 772 | "+r"(dst_a), // %1 |
| 773 | "+r"(dst_b), // %2 |
| 774 | "+r"(w) // %3 |
| 775 | : "r"((intptr_t)(src_stride)), // %4 |
| 776 | "r"((intptr_t)(dst_stride_a)), // %5 |
| 777 | "r"((intptr_t)(dst_stride_b)) // %6 |
| 778 | : "memory", "cc", |
| 779 | "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", |
| 780 | "xmm8", "xmm9" |
| 781 | ); |
| 782 | } |
| 783 | #endif |
| 784 | #endif |
| 785 |
| 786 | static void TransposeWx8_C(const uint8* src, int src_stride, |
| 787 | uint8* dst, int dst_stride, |
| 788 | int width) { |
| 789 | int i; |
| 790 | for (i = 0; i < width; ++i) { |
| 791 | dst[0] = src[0 * src_stride]; |
| 792 | dst[1] = src[1 * src_stride]; |
| 793 | dst[2] = src[2 * src_stride]; |
| 794 | dst[3] = src[3 * src_stride]; |
| 795 | dst[4] = src[4 * src_stride]; |
| 796 | dst[5] = src[5 * src_stride]; |
| 797 | dst[6] = src[6 * src_stride]; |
| 798 | dst[7] = src[7 * src_stride]; |
| 799 | ++src; |
| 800 | dst += dst_stride; |
| 801 | } |
| 802 | } |
| 803 |
| 804 | static void TransposeWxH_C(const uint8* src, int src_stride, |
| 805 | uint8* dst, int dst_stride, |
| 806 | int width, int height) { |
| 807 | int i; |
| 808 | for (i = 0; i < width; ++i) { |
| 809 | int j; |
| 810 | for (j = 0; j < height; ++j) { |
| 811 | dst[i * dst_stride + j] = src[j * src_stride + i]; |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 |
| 816 | LIBYUV_API |
| 817 | void TransposePlane(const uint8* src, int src_stride, |
| 818 | uint8* dst, int dst_stride, |
| 819 | int width, int height) { |
| 820 | int i = height; |
| 821 | void (*TransposeWx8)(const uint8* src, int src_stride, |
| 822 | uint8* dst, int dst_stride, |
| 823 | int width) = TransposeWx8_C; |
| 824 | #if defined(HAS_TRANSPOSE_WX8_NEON) |
| 825 | if (TestCpuFlag(kCpuHasNEON)) { |
| 826 | TransposeWx8 = TransposeWx8_NEON; |
| 827 | } |
| 828 | #endif |
| 829 | #if defined(HAS_TRANSPOSE_WX8_SSSE3) |
| 830 | if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 8)) { |
| 831 | TransposeWx8 = TransposeWx8_SSSE3; |
| 832 | } |
| 833 | #endif |
| 834 | #if defined(HAS_TRANSPOSE_WX8_FAST_SSSE3) |
| 835 | if (TestCpuFlag(kCpuHasSSSE3) && |
| 836 | IS_ALIGNED(width, 16) && |
| 837 | IS_ALIGNED(src, 16) && IS_ALIGNED(src_stride, 16)) { |
| 838 | TransposeWx8 = TransposeWx8_FAST_SSSE3; |
| 839 | } |
| 840 | #endif |
| 841 | #if defined(HAS_TRANSPOSE_WX8_MIPS_DSPR2) |
| 842 | if (TestCpuFlag(kCpuHasMIPS_DSPR2)) { |
| 843 | if (IS_ALIGNED(width, 4) && |
| 844 | IS_ALIGNED(src, 4) && IS_ALIGNED(src_stride, 4)) { |
| 845 | TransposeWx8 = TransposeWx8_FAST_MIPS_DSPR2; |
| 846 | } else { |
| 847 | TransposeWx8 = TransposeWx8_MIPS_DSPR2; |
| 848 | } |
| 849 | } |
| 850 | #endif |
| 851 |
| 852 | // Work across the source in 8x8 tiles |
| 853 | while (i >= 8) { |
| 854 | TransposeWx8(src, src_stride, dst, dst_stride, width); |
| 855 | src += 8 * src_stride; // Go down 8 rows. |
| 856 | dst += 8; // Move over 8 columns. |
| 857 | i -= 8; |
| 858 | } |
| 859 |
| 860 | TransposeWxH_C(src, src_stride, dst, dst_stride, width, i); |
| 861 | } |
| 862 |
| 863 | LIBYUV_API |
| 864 | void RotatePlane90(const uint8* src, int src_stride, |
| 865 | uint8* dst, int dst_stride, |
| 866 | int width, int height) { |
| 867 | // Rotate by 90 is a transpose with the source read |
| 868 | // from bottom to top. So set the source pointer to the end |
| 869 | // of the buffer and flip the sign of the source stride. |
| 870 | src += src_stride * (height - 1); |
| 871 | src_stride = -src_stride; |
| 872 | TransposePlane(src, src_stride, dst, dst_stride, width, height); |
| 873 | } |
| 874 |
| 875 | LIBYUV_API |
| 876 | void RotatePlane270(const uint8* src, int src_stride, |
| 877 | uint8* dst, int dst_stride, |
| 878 | int width, int height) { |
| 879 | // Rotate by 270 is a transpose with the destination written |
| 880 | // from bottom to top. So set the destination pointer to the end |
| 881 | // of the buffer and flip the sign of the destination stride. |
| 882 | dst += dst_stride * (width - 1); |
| 883 | dst_stride = -dst_stride; |
| 884 | TransposePlane(src, src_stride, dst, dst_stride, width, height); |
| 885 | } |
| 886 |
| 887 | LIBYUV_API |
| 888 | void RotatePlane180(const uint8* src, int src_stride, |
| 889 | uint8* dst, int dst_stride, |
| 890 | int width, int height) { |
| 891 | // Swap first and last row and mirror the content. Uses a temporary row. |
| 892 | align_buffer_64(row, width); |
| 893 | const uint8* src_bot = src + src_stride * (height - 1); |
| 894 | uint8* dst_bot = dst + dst_stride * (height - 1); |
| 895 | int half_height = (height + 1) >> 1; |
| 896 | int y; |
| 897 | void (*MirrorRow)(const uint8* src, uint8* dst, int width) = MirrorRow_C; |
| 898 | void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; |
| 899 | #if defined(HAS_MIRRORROW_NEON) |
| 900 | if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 16)) { |
| 901 | MirrorRow = MirrorRow_NEON; |
| 902 | } |
| 903 | #endif |
| 904 | #if defined(HAS_MIRRORROW_SSE2) |
| 905 | if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 16) && |
| 906 | IS_ALIGNED(src, 16) && IS_ALIGNED(src_stride, 16) && |
| 907 | IS_ALIGNED(dst, 16) && IS_ALIGNED(dst_stride, 16)) { |
| 908 | MirrorRow = MirrorRow_SSE2; |
| 909 | } |
| 910 | #endif |
| 911 | #if defined(HAS_MIRRORROW_SSSE3) |
| 912 | if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 16) && |
| 913 | IS_ALIGNED(src, 16) && IS_ALIGNED(src_stride, 16) && |
| 914 | IS_ALIGNED(dst, 16) && IS_ALIGNED(dst_stride, 16)) { |
| 915 | MirrorRow = MirrorRow_SSSE3; |
| 916 | } |
| 917 | #endif |
| 918 | #if defined(HAS_MIRRORROW_AVX2) |
| 919 | if (TestCpuFlag(kCpuHasAVX2) && IS_ALIGNED(width, 32)) { |
| 920 | MirrorRow = MirrorRow_AVX2; |
| 921 | } |
| 922 | #endif |
| 923 | #if defined(HAS_MIRRORROW_MIPS_DSPR2) |
| 924 | if (TestCpuFlag(kCpuHasMIPS_DSPR2) && |
| 925 | IS_ALIGNED(src, 4) && IS_ALIGNED(src_stride, 4) && |
| 926 | IS_ALIGNED(dst, 4) && IS_ALIGNED(dst_stride, 4)) { |
| 927 | MirrorRow = MirrorRow_MIPS_DSPR2; |
| 928 | } |
| 929 | #endif |
| 930 | #if defined(HAS_COPYROW_NEON) |
| 931 | if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 32)) { |
| 932 | CopyRow = CopyRow_NEON; |
| 933 | } |
| 934 | #endif |
| 935 | #if defined(HAS_COPYROW_X86) |
| 936 | if (TestCpuFlag(kCpuHasX86) && IS_ALIGNED(width, 4)) { |
| 937 | CopyRow = CopyRow_X86; |
| 938 | } |
| 939 | #endif |
| 940 | #if defined(HAS_COPYROW_SSE2) |
| 941 | if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 32) && |
| 942 | IS_ALIGNED(src, 16) && IS_ALIGNED(src_stride, 16) && |
| 943 | IS_ALIGNED(dst, 16) && IS_ALIGNED(dst_stride, 16)) { |
| 944 | CopyRow = CopyRow_SSE2; |
| 945 | } |
| 946 | #endif |
| 947 | #if defined(HAS_COPYROW_ERMS) |
| 948 | if (TestCpuFlag(kCpuHasERMS)) { |
| 949 | CopyRow = CopyRow_ERMS; |
| 950 | } |
| 951 | #endif |
| 952 | #if defined(HAS_COPYROW_MIPS) |
| 953 | if (TestCpuFlag(kCpuHasMIPS)) { |
| 954 | CopyRow = CopyRow_MIPS; |
| 955 | } |
| 956 | #endif |
| 957 |
| 958 | // Odd height will harmlessly mirror the middle row twice. |
| 959 | for (y = 0; y < half_height; ++y) { |
| 960 | MirrorRow(src, row, width); // Mirror first row into a buffer |
| 961 | src += src_stride; |
| 962 | MirrorRow(src_bot, dst, width); // Mirror last row into first row |
| 963 | dst += dst_stride; |
| 964 | CopyRow(row, dst_bot, width); // Copy first mirrored row into last |
| 965 | src_bot -= src_stride; |
| 966 | dst_bot -= dst_stride; |
| 967 | } |
| 968 | free_aligned_buffer_64(row); |
| 969 | } |
| 970 |
| 971 | static void TransposeUVWx8_C(const uint8* src, int src_stride, |
| 972 | uint8* dst_a, int dst_stride_a, |
| 973 | uint8* dst_b, int dst_stride_b, |
| 974 | int width) { |
| 975 | int i; |
| 976 | for (i = 0; i < width; ++i) { |
| 977 | dst_a[0] = src[0 * src_stride + 0]; |
| 978 | dst_b[0] = src[0 * src_stride + 1]; |
| 979 | dst_a[1] = src[1 * src_stride + 0]; |
| 980 | dst_b[1] = src[1 * src_stride + 1]; |
| 981 | dst_a[2] = src[2 * src_stride + 0]; |
| 982 | dst_b[2] = src[2 * src_stride + 1]; |
| 983 | dst_a[3] = src[3 * src_stride + 0]; |
| 984 | dst_b[3] = src[3 * src_stride + 1]; |
| 985 | dst_a[4] = src[4 * src_stride + 0]; |
| 986 | dst_b[4] = src[4 * src_stride + 1]; |
| 987 | dst_a[5] = src[5 * src_stride + 0]; |
| 988 | dst_b[5] = src[5 * src_stride + 1]; |
| 989 | dst_a[6] = src[6 * src_stride + 0]; |
| 990 | dst_b[6] = src[6 * src_stride + 1]; |
| 991 | dst_a[7] = src[7 * src_stride + 0]; |
| 992 | dst_b[7] = src[7 * src_stride + 1]; |
| 993 | src += 2; |
| 994 | dst_a += dst_stride_a; |
| 995 | dst_b += dst_stride_b; |
| 996 | } |
| 997 | } |
| 998 |
| 999 | static void TransposeUVWxH_C(const uint8* src, int src_stride, |
| 1000 | uint8* dst_a, int dst_stride_a, |
| 1001 | uint8* dst_b, int dst_stride_b, |
| 1002 | int width, int height) { |
| 1003 | int i; |
| 1004 | for (i = 0; i < width * 2; i += 2) { |
| 1005 | int j; |
| 1006 | for (j = 0; j < height; ++j) { |
| 1007 | dst_a[j + ((i >> 1) * dst_stride_a)] = src[i + (j * src_stride)]; |
| 1008 | dst_b[j + ((i >> 1) * dst_stride_b)] = src[i + (j * src_stride) + 1]; |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 |
| 1013 | LIBYUV_API |
| 1014 | void TransposeUV(const uint8* src, int src_stride, |
| 1015 | uint8* dst_a, int dst_stride_a, |
| 1016 | uint8* dst_b, int dst_stride_b, |
| 1017 | int width, int height) { |
| 1018 | int i = height; |
| 1019 | void (*TransposeUVWx8)(const uint8* src, int src_stride, |
| 1020 | uint8* dst_a, int dst_stride_a, |
| 1021 | uint8* dst_b, int dst_stride_b, |
| 1022 | int width) = TransposeUVWx8_C; |
| 1023 | #if defined(HAS_TRANSPOSE_UVWX8_NEON) |
| 1024 | if (TestCpuFlag(kCpuHasNEON)) { |
| 1025 | TransposeUVWx8 = TransposeUVWx8_NEON; |
| 1026 | } |
| 1027 | #elif defined(HAS_TRANSPOSE_UVWX8_SSE2) |
| 1028 | if (TestCpuFlag(kCpuHasSSE2) && |
| 1029 | IS_ALIGNED(width, 8) && |
| 1030 | IS_ALIGNED(src, 16) && IS_ALIGNED(src_stride, 16)) { |
| 1031 | TransposeUVWx8 = TransposeUVWx8_SSE2; |
| 1032 | } |
| 1033 | #elif defined(HAS_TRANSPOSE_UVWx8_MIPS_DSPR2) |
| 1034 | if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 2) && |
| 1035 | IS_ALIGNED(src, 4) && IS_ALIGNED(src_stride, 4)) { |
| 1036 | TransposeUVWx8 = TransposeUVWx8_MIPS_DSPR2; |
| 1037 | } |
| 1038 | #endif |
| 1039 |
| 1040 | // Work through the source in 8x8 tiles. |
| 1041 | while (i >= 8) { |
| 1042 | TransposeUVWx8(src, src_stride, |
| 1043 | dst_a, dst_stride_a, |
| 1044 | dst_b, dst_stride_b, |
| 1045 | width); |
| 1046 | src += 8 * src_stride; // Go down 8 rows. |
| 1047 | dst_a += 8; // Move over 8 columns. |
| 1048 | dst_b += 8; // Move over 8 columns. |
| 1049 | i -= 8; |
| 1050 | } |
| 1051 |
| 1052 | TransposeUVWxH_C(src, src_stride, |
| 1053 | dst_a, dst_stride_a, |
| 1054 | dst_b, dst_stride_b, |
| 1055 | width, i); |
| 1056 | } |
| 1057 |
| 1058 | LIBYUV_API |
| 1059 | void RotateUV90(const uint8* src, int src_stride, |
| 1060 | uint8* dst_a, int dst_stride_a, |
| 1061 | uint8* dst_b, int dst_stride_b, |
| 1062 | int width, int height) { |
| 1063 | src += src_stride * (height - 1); |
| 1064 | src_stride = -src_stride; |
| 1065 |
| 1066 | TransposeUV(src, src_stride, |
| 1067 | dst_a, dst_stride_a, |
| 1068 | dst_b, dst_stride_b, |
| 1069 | width, height); |
| 1070 | } |
| 1071 |
| 1072 | LIBYUV_API |
| 1073 | void RotateUV270(const uint8* src, int src_stride, |
| 1074 | uint8* dst_a, int dst_stride_a, |
| 1075 | uint8* dst_b, int dst_stride_b, |
| 1076 | int width, int height) { |
| 1077 | dst_a += dst_stride_a * (width - 1); |
| 1078 | dst_b += dst_stride_b * (width - 1); |
| 1079 | dst_stride_a = -dst_stride_a; |
| 1080 | dst_stride_b = -dst_stride_b; |
| 1081 |
| 1082 | TransposeUV(src, src_stride, |
| 1083 | dst_a, dst_stride_a, |
| 1084 | dst_b, dst_stride_b, |
| 1085 | width, height); |
| 1086 | } |
| 1087 |
| 1088 | // Rotate 180 is a horizontal and vertical flip. |
| 1089 | LIBYUV_API |
| 1090 | void RotateUV180(const uint8* src, int src_stride, |
| 1091 | uint8* dst_a, int dst_stride_a, |
| 1092 | uint8* dst_b, int dst_stride_b, |
| 1093 | int width, int height) { |
| 1094 | int i; |
| 1095 | void (*MirrorRowUV)(const uint8* src, uint8* dst_u, uint8* dst_v, int width) = |
| 1096 | MirrorUVRow_C; |
| 1097 | #if defined(HAS_MIRRORUVROW_NEON) |
| 1098 | if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 8)) { |
| 1099 | MirrorRowUV = MirrorUVRow_NEON; |
| 1100 | } |
| 1101 | #elif defined(HAS_MIRRORROW_UV_SSSE3) |
| 1102 | if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(width, 16) && |
| 1103 | IS_ALIGNED(src, 16) && IS_ALIGNED(src_stride, 16)) { |
| 1104 | MirrorRowUV = MirrorUVRow_SSSE3; |
| 1105 | } |
| 1106 | #elif defined(HAS_MIRRORUVROW_MIPS_DSPR2) |
| 1107 | if (TestCpuFlag(kCpuHasMIPS_DSPR2) && |
| 1108 | IS_ALIGNED(src, 4) && IS_ALIGNED(src_stride, 4)) { |
| 1109 | MirrorRowUV = MirrorUVRow_MIPS_DSPR2; |
| 1110 | } |
| 1111 | #endif |
| 1112 |
| 1113 | dst_a += dst_stride_a * (height - 1); |
| 1114 | dst_b += dst_stride_b * (height - 1); |
| 1115 |
| 1116 | for (i = 0; i < height; ++i) { |
| 1117 | MirrorRowUV(src, dst_a, dst_b, width); |
| 1118 | src += src_stride; |
| 1119 | dst_a -= dst_stride_a; |
| 1120 | dst_b -= dst_stride_b; |
| 1121 | } |
| 1122 | } |
| 1123 |
| 1124 | LIBYUV_API |
| 1125 | int RotatePlane(const uint8* src, int src_stride, |
| 1126 | uint8* dst, int dst_stride, |
| 1127 | int width, int height, |
| 1128 | enum RotationMode mode) { |
| 1129 | if (!src || width <= 0 || height == 0 || !dst) { |
| 1130 | return -1; |
| 1131 | } |
| 1132 |
| 1133 | // Negative height means invert the image. |
| 1134 | if (height < 0) { |
| 1135 | height = -height; |
| 1136 | src = src + (height - 1) * src_stride; |
| 1137 | src_stride = -src_stride; |
| 1138 | } |
| 1139 |
| 1140 | switch (mode) { |
| 1141 | case kRotate0: |
| 1142 | // copy frame |
| 1143 | CopyPlane(src, src_stride, |
| 1144 | dst, dst_stride, |
| 1145 | width, height); |
| 1146 | return 0; |
| 1147 | case kRotate90: |
| 1148 | RotatePlane90(src, src_stride, |
| 1149 | dst, dst_stride, |
| 1150 | width, height); |
| 1151 | return 0; |
| 1152 | case kRotate270: |
| 1153 | RotatePlane270(src, src_stride, |
| 1154 | dst, dst_stride, |
| 1155 | width, height); |
| 1156 | return 0; |
| 1157 | case kRotate180: |
| 1158 | RotatePlane180(src, src_stride, |
| 1159 | dst, dst_stride, |
| 1160 | width, height); |
| 1161 | return 0; |
| 1162 | default: |
| 1163 | break; |
| 1164 | } |
| 1165 | return -1; |
| 1166 | } |
| 1167 |
| 1168 | LIBYUV_API |
| 1169 | int I420Rotate(const uint8* src_y, int src_stride_y, |
| 1170 | const uint8* src_u, int src_stride_u, |
| 1171 | const uint8* src_v, int src_stride_v, |
| 1172 | uint8* dst_y, int dst_stride_y, |
| 1173 | uint8* dst_u, int dst_stride_u, |
| 1174 | uint8* dst_v, int dst_stride_v, |
| 1175 | int width, int height, |
| 1176 | enum RotationMode mode) { |
| 1177 | int halfwidth = (width + 1) >> 1; |
| 1178 | int halfheight = (height + 1) >> 1; |
| 1179 | if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || |
| 1180 | !dst_y || !dst_u || !dst_v) { |
| 1181 | return -1; |
| 1182 | } |
| 1183 |
| 1184 | // Negative height means invert the image. |
| 1185 | if (height < 0) { |
| 1186 | height = -height; |
| 1187 | halfheight = (height + 1) >> 1; |
| 1188 | src_y = src_y + (height - 1) * src_stride_y; |
| 1189 | src_u = src_u + (halfheight - 1) * src_stride_u; |
| 1190 | src_v = src_v + (halfheight - 1) * src_stride_v; |
| 1191 | src_stride_y = -src_stride_y; |
| 1192 | src_stride_u = -src_stride_u; |
| 1193 | src_stride_v = -src_stride_v; |
| 1194 | } |
| 1195 |
| 1196 | switch (mode) { |
| 1197 | case kRotate0: |
| 1198 | // copy frame |
| 1199 | return I420Copy(src_y, src_stride_y, |
| 1200 | src_u, src_stride_u, |
| 1201 | src_v, src_stride_v, |
| 1202 | dst_y, dst_stride_y, |
| 1203 | dst_u, dst_stride_u, |
| 1204 | dst_v, dst_stride_v, |
| 1205 | width, height); |
| 1206 | case kRotate90: |
| 1207 | RotatePlane90(src_y, src_stride_y, |
| 1208 | dst_y, dst_stride_y, |
| 1209 | width, height); |
| 1210 | RotatePlane90(src_u, src_stride_u, |
| 1211 | dst_u, dst_stride_u, |
| 1212 | halfwidth, halfheight); |
| 1213 | RotatePlane90(src_v, src_stride_v, |
| 1214 | dst_v, dst_stride_v, |
| 1215 | halfwidth, halfheight); |
| 1216 | return 0; |
| 1217 | case kRotate270: |
| 1218 | RotatePlane270(src_y, src_stride_y, |
| 1219 | dst_y, dst_stride_y, |
| 1220 | width, height); |
| 1221 | RotatePlane270(src_u, src_stride_u, |
| 1222 | dst_u, dst_stride_u, |
| 1223 | halfwidth, halfheight); |
| 1224 | RotatePlane270(src_v, src_stride_v, |
| 1225 | dst_v, dst_stride_v, |
| 1226 | halfwidth, halfheight); |
| 1227 | return 0; |
| 1228 | case kRotate180: |
| 1229 | RotatePlane180(src_y, src_stride_y, |
| 1230 | dst_y, dst_stride_y, |
| 1231 | width, height); |
| 1232 | RotatePlane180(src_u, src_stride_u, |
| 1233 | dst_u, dst_stride_u, |
| 1234 | halfwidth, halfheight); |
| 1235 | RotatePlane180(src_v, src_stride_v, |
| 1236 | dst_v, dst_stride_v, |
| 1237 | halfwidth, halfheight); |
| 1238 | return 0; |
| 1239 | default: |
| 1240 | break; |
| 1241 | } |
| 1242 | return -1; |
| 1243 | } |
| 1244 |
| 1245 | LIBYUV_API |
| 1246 | int NV12ToI420Rotate(const uint8* src_y, int src_stride_y, |
| 1247 | const uint8* src_uv, int src_stride_uv, |
| 1248 | uint8* dst_y, int dst_stride_y, |
| 1249 | uint8* dst_u, int dst_stride_u, |
| 1250 | uint8* dst_v, int dst_stride_v, |
| 1251 | int width, int height, |
| 1252 | enum RotationMode mode) { |
| 1253 | int halfwidth = (width + 1) >> 1; |
| 1254 | int halfheight = (height + 1) >> 1; |
| 1255 | if (!src_y || !src_uv || width <= 0 || height == 0 || |
| 1256 | !dst_y || !dst_u || !dst_v) { |
| 1257 | return -1; |
| 1258 | } |
| 1259 |
| 1260 | // Negative height means invert the image. |
| 1261 | if (height < 0) { |
| 1262 | height = -height; |
| 1263 | halfheight = (height + 1) >> 1; |
| 1264 | src_y = src_y + (height - 1) * src_stride_y; |
| 1265 | src_uv = src_uv + (halfheight - 1) * src_stride_uv; |
| 1266 | src_stride_y = -src_stride_y; |
| 1267 | src_stride_uv = -src_stride_uv; |
| 1268 | } |
| 1269 |
| 1270 | switch (mode) { |
| 1271 | case kRotate0: |
| 1272 | // copy frame |
| 1273 | return NV12ToI420(src_y, src_stride_y, |
| 1274 | src_uv, src_stride_uv, |
| 1275 | dst_y, dst_stride_y, |
| 1276 | dst_u, dst_stride_u, |
| 1277 | dst_v, dst_stride_v, |
| 1278 | width, height); |
| 1279 | case kRotate90: |
| 1280 | RotatePlane90(src_y, src_stride_y, |
| 1281 | dst_y, dst_stride_y, |
| 1282 | width, height); |
| 1283 | RotateUV90(src_uv, src_stride_uv, |
| 1284 | dst_u, dst_stride_u, |
| 1285 | dst_v, dst_stride_v, |
| 1286 | halfwidth, halfheight); |
| 1287 | return 0; |
| 1288 | case kRotate270: |
| 1289 | RotatePlane270(src_y, src_stride_y, |
| 1290 | dst_y, dst_stride_y, |
| 1291 | width, height); |
| 1292 | RotateUV270(src_uv, src_stride_uv, |
| 1293 | dst_u, dst_stride_u, |
| 1294 | dst_v, dst_stride_v, |
| 1295 | halfwidth, halfheight); |
| 1296 | return 0; |
| 1297 | case kRotate180: |
| 1298 | RotatePlane180(src_y, src_stride_y, |
| 1299 | dst_y, dst_stride_y, |
| 1300 | width, height); |
| 1301 | RotateUV180(src_uv, src_stride_uv, |
| 1302 | dst_u, dst_stride_u, |
| 1303 | dst_v, dst_stride_v, |
| 1304 | halfwidth, halfheight); |
| 1305 | return 0; |
| 1306 | default: |
| 1307 | break; |
| 1308 | } |
| 1309 | return -1; |
| 1310 | } |
| 1311 |
| 1312 | #ifdef __cplusplus |
| 1313 | } // extern "C" |
| 1314 | } // namespace libyuv |
| 1315 | #endif |
| 1316 |