Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "libyuv/basic_types.h" |
michael@0 | 12 | #include "libyuv/row.h" |
michael@0 | 13 | |
michael@0 | 14 | #ifdef __cplusplus |
michael@0 | 15 | namespace libyuv { |
michael@0 | 16 | extern "C" { |
michael@0 | 17 | #endif |
michael@0 | 18 | |
michael@0 | 19 | #if !defined(LIBYUV_DISABLE_X86) && (defined(__x86_64__) || defined(__i386__)) |
michael@0 | 20 | |
michael@0 | 21 | uint32 SumSquareError_SSE2(const uint8* src_a, const uint8* src_b, int count) { |
michael@0 | 22 | uint32 sse; |
michael@0 | 23 | asm volatile ( // NOLINT |
michael@0 | 24 | "pxor %%xmm0,%%xmm0 \n" |
michael@0 | 25 | "pxor %%xmm5,%%xmm5 \n" |
michael@0 | 26 | LABELALIGN |
michael@0 | 27 | "1: \n" |
michael@0 | 28 | "movdqa " MEMACCESS(0) ",%%xmm1 \n" |
michael@0 | 29 | "lea " MEMLEA(0x10, 0) ",%0 \n" |
michael@0 | 30 | "movdqa " MEMACCESS(1) ",%%xmm2 \n" |
michael@0 | 31 | "lea " MEMLEA(0x10, 1) ",%1 \n" |
michael@0 | 32 | "sub $0x10,%2 \n" |
michael@0 | 33 | "movdqa %%xmm1,%%xmm3 \n" |
michael@0 | 34 | "psubusb %%xmm2,%%xmm1 \n" |
michael@0 | 35 | "psubusb %%xmm3,%%xmm2 \n" |
michael@0 | 36 | "por %%xmm2,%%xmm1 \n" |
michael@0 | 37 | "movdqa %%xmm1,%%xmm2 \n" |
michael@0 | 38 | "punpcklbw %%xmm5,%%xmm1 \n" |
michael@0 | 39 | "punpckhbw %%xmm5,%%xmm2 \n" |
michael@0 | 40 | "pmaddwd %%xmm1,%%xmm1 \n" |
michael@0 | 41 | "pmaddwd %%xmm2,%%xmm2 \n" |
michael@0 | 42 | "paddd %%xmm1,%%xmm0 \n" |
michael@0 | 43 | "paddd %%xmm2,%%xmm0 \n" |
michael@0 | 44 | "jg 1b \n" |
michael@0 | 45 | |
michael@0 | 46 | "pshufd $0xee,%%xmm0,%%xmm1 \n" |
michael@0 | 47 | "paddd %%xmm1,%%xmm0 \n" |
michael@0 | 48 | "pshufd $0x1,%%xmm0,%%xmm1 \n" |
michael@0 | 49 | "paddd %%xmm1,%%xmm0 \n" |
michael@0 | 50 | "movd %%xmm0,%3 \n" |
michael@0 | 51 | |
michael@0 | 52 | : "+r"(src_a), // %0 |
michael@0 | 53 | "+r"(src_b), // %1 |
michael@0 | 54 | "+r"(count), // %2 |
michael@0 | 55 | "=g"(sse) // %3 |
michael@0 | 56 | : |
michael@0 | 57 | : "memory", "cc" |
michael@0 | 58 | #if defined(__SSE2__) |
michael@0 | 59 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm5" |
michael@0 | 60 | #endif |
michael@0 | 61 | ); // NOLINT |
michael@0 | 62 | return sse; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | #endif // defined(__x86_64__) || defined(__i386__) |
michael@0 | 66 | |
michael@0 | 67 | #if !defined(LIBYUV_DISABLE_X86) && \ |
michael@0 | 68 | (defined(__x86_64__) || (defined(__i386__) && !defined(__pic__))) |
michael@0 | 69 | #define HAS_HASHDJB2_SSE41 |
michael@0 | 70 | static uvec32 kHash16x33 = { 0x92d9e201, 0, 0, 0 }; // 33 ^ 16 |
michael@0 | 71 | static uvec32 kHashMul0 = { |
michael@0 | 72 | 0x0c3525e1, // 33 ^ 15 |
michael@0 | 73 | 0xa3476dc1, // 33 ^ 14 |
michael@0 | 74 | 0x3b4039a1, // 33 ^ 13 |
michael@0 | 75 | 0x4f5f0981, // 33 ^ 12 |
michael@0 | 76 | }; |
michael@0 | 77 | static uvec32 kHashMul1 = { |
michael@0 | 78 | 0x30f35d61, // 33 ^ 11 |
michael@0 | 79 | 0x855cb541, // 33 ^ 10 |
michael@0 | 80 | 0x040a9121, // 33 ^ 9 |
michael@0 | 81 | 0x747c7101, // 33 ^ 8 |
michael@0 | 82 | }; |
michael@0 | 83 | static uvec32 kHashMul2 = { |
michael@0 | 84 | 0xec41d4e1, // 33 ^ 7 |
michael@0 | 85 | 0x4cfa3cc1, // 33 ^ 6 |
michael@0 | 86 | 0x025528a1, // 33 ^ 5 |
michael@0 | 87 | 0x00121881, // 33 ^ 4 |
michael@0 | 88 | }; |
michael@0 | 89 | static uvec32 kHashMul3 = { |
michael@0 | 90 | 0x00008c61, // 33 ^ 3 |
michael@0 | 91 | 0x00000441, // 33 ^ 2 |
michael@0 | 92 | 0x00000021, // 33 ^ 1 |
michael@0 | 93 | 0x00000001, // 33 ^ 0 |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | uint32 HashDjb2_SSE41(const uint8* src, int count, uint32 seed) { |
michael@0 | 97 | uint32 hash; |
michael@0 | 98 | asm volatile ( // NOLINT |
michael@0 | 99 | "movd %2,%%xmm0 \n" |
michael@0 | 100 | "pxor %%xmm7,%%xmm7 \n" |
michael@0 | 101 | "movdqa %4,%%xmm6 \n" |
michael@0 | 102 | LABELALIGN |
michael@0 | 103 | "1: \n" |
michael@0 | 104 | "movdqu " MEMACCESS(0) ",%%xmm1 \n" |
michael@0 | 105 | "lea " MEMLEA(0x10, 0) ",%0 \n" |
michael@0 | 106 | "pmulld %%xmm6,%%xmm0 \n" |
michael@0 | 107 | "movdqa %5,%%xmm5 \n" |
michael@0 | 108 | "movdqa %%xmm1,%%xmm2 \n" |
michael@0 | 109 | "punpcklbw %%xmm7,%%xmm2 \n" |
michael@0 | 110 | "movdqa %%xmm2,%%xmm3 \n" |
michael@0 | 111 | "punpcklwd %%xmm7,%%xmm3 \n" |
michael@0 | 112 | "pmulld %%xmm5,%%xmm3 \n" |
michael@0 | 113 | "movdqa %6,%%xmm5 \n" |
michael@0 | 114 | "movdqa %%xmm2,%%xmm4 \n" |
michael@0 | 115 | "punpckhwd %%xmm7,%%xmm4 \n" |
michael@0 | 116 | "pmulld %%xmm5,%%xmm4 \n" |
michael@0 | 117 | "movdqa %7,%%xmm5 \n" |
michael@0 | 118 | "punpckhbw %%xmm7,%%xmm1 \n" |
michael@0 | 119 | "movdqa %%xmm1,%%xmm2 \n" |
michael@0 | 120 | "punpcklwd %%xmm7,%%xmm2 \n" |
michael@0 | 121 | "pmulld %%xmm5,%%xmm2 \n" |
michael@0 | 122 | "movdqa %8,%%xmm5 \n" |
michael@0 | 123 | "punpckhwd %%xmm7,%%xmm1 \n" |
michael@0 | 124 | "pmulld %%xmm5,%%xmm1 \n" |
michael@0 | 125 | "paddd %%xmm4,%%xmm3 \n" |
michael@0 | 126 | "paddd %%xmm2,%%xmm1 \n" |
michael@0 | 127 | "sub $0x10,%1 \n" |
michael@0 | 128 | "paddd %%xmm3,%%xmm1 \n" |
michael@0 | 129 | "pshufd $0xe,%%xmm1,%%xmm2 \n" |
michael@0 | 130 | "paddd %%xmm2,%%xmm1 \n" |
michael@0 | 131 | "pshufd $0x1,%%xmm1,%%xmm2 \n" |
michael@0 | 132 | "paddd %%xmm2,%%xmm1 \n" |
michael@0 | 133 | "paddd %%xmm1,%%xmm0 \n" |
michael@0 | 134 | "jg 1b \n" |
michael@0 | 135 | "movd %%xmm0,%3 \n" |
michael@0 | 136 | : "+r"(src), // %0 |
michael@0 | 137 | "+r"(count), // %1 |
michael@0 | 138 | "+rm"(seed), // %2 |
michael@0 | 139 | "=g"(hash) // %3 |
michael@0 | 140 | : "m"(kHash16x33), // %4 |
michael@0 | 141 | "m"(kHashMul0), // %5 |
michael@0 | 142 | "m"(kHashMul1), // %6 |
michael@0 | 143 | "m"(kHashMul2), // %7 |
michael@0 | 144 | "m"(kHashMul3) // %8 |
michael@0 | 145 | : "memory", "cc" |
michael@0 | 146 | #if defined(__SSE2__) |
michael@0 | 147 | , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" |
michael@0 | 148 | #endif |
michael@0 | 149 | ); // NOLINT |
michael@0 | 150 | return hash; |
michael@0 | 151 | } |
michael@0 | 152 | #endif // defined(__x86_64__) || (defined(__i386__) && !defined(__pic__))) |
michael@0 | 153 | |
michael@0 | 154 | #ifdef __cplusplus |
michael@0 | 155 | } // extern "C" |
michael@0 | 156 | } // namespace libyuv |
michael@0 | 157 | #endif |
michael@0 | 158 |