diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-17 13:57:45 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-19 13:44:40 +0000 |
commit | 6ec7b8da05d21a3878bd21c691b41e675d74bb1c (patch) | |
tree | b87f250bc19413750b9bb9cdbf2da20ef5014820 /chromium/third_party/libyuv/source | |
parent | ec02ee4181c49b61fce1c8fb99292dbb8139cc90 (diff) | |
download | qtwebengine-chromium-6ec7b8da05d21a3878bd21c691b41e675d74bb1c.tar.gz |
BASELINE: Update Chromium to 60.0.3112.70
Change-Id: I9911c2280a014d4632f254857876a395d4baed2d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/third_party/libyuv/source')
-rw-r--r-- | chromium/third_party/libyuv/source/compare.cc | 45 | ||||
-rw-r--r-- | chromium/third_party/libyuv/source/compare_common.cc | 44 | ||||
-rw-r--r-- | chromium/third_party/libyuv/source/compare_gcc.cc | 13 | ||||
-rw-r--r-- | chromium/third_party/libyuv/source/compare_neon.cc | 2 | ||||
-rw-r--r-- | chromium/third_party/libyuv/source/compare_neon64.cc | 34 | ||||
-rw-r--r-- | chromium/third_party/libyuv/source/compare_win.cc | 17 | ||||
-rw-r--r-- | chromium/third_party/libyuv/source/convert_from.cc | 69 | ||||
-rw-r--r-- | chromium/third_party/libyuv/source/cpu_id.cc | 35 | ||||
-rw-r--r-- | chromium/third_party/libyuv/source/row_dspr2.cc | 8 |
9 files changed, 249 insertions, 18 deletions
diff --git a/chromium/third_party/libyuv/source/compare.cc b/chromium/third_party/libyuv/source/compare.cc index 1facd27b1b7..3f7f14751ed 100644 --- a/chromium/third_party/libyuv/source/compare.cc +++ b/chromium/third_party/libyuv/source/compare.cc @@ -110,6 +110,51 @@ uint32 ARGBDetect(const uint8* argb, int stride_argb, int width, int height) { return fourcc; } +LIBYUV_API +uint64 ComputeHammingDistance(const uint8* src_a, + const uint8* src_b, + int count) { + const int kBlockSize = 65536; + int remainder = count & (kBlockSize - 1) & ~31; + uint64 diff = 0; + int i; + uint32 (*HammingDistance)(const uint8* src_a, const uint8* src_b, int count) = + HammingDistance_C; +#if defined(HAS_HAMMINGDISTANCE_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + HammingDistance = HammingDistance_NEON; + } +#endif +#if defined(HAS_HAMMINGDISTANCE_X86) + if (TestCpuFlag(kCpuHasX86)) { + HammingDistance = HammingDistance_X86; + } +#endif +#if defined(HAS_HAMMINGDISTANCE_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + HammingDistance = HammingDistance_AVX2; + } +#endif +#ifdef _OPENMP +#pragma omp parallel for reduction(+ : diff) +#endif + for (i = 0; i < (count - (kBlockSize - 1)); i += kBlockSize) { + diff += HammingDistance(src_a + i, src_b + i, kBlockSize); + } + src_a += count & ~(kBlockSize - 1); + src_b += count & ~(kBlockSize - 1); + if (remainder) { + diff += HammingDistance(src_a, src_b, remainder); + src_a += remainder; + src_b += remainder; + } + remainder = count & 31; + if (remainder) { + diff += HammingDistance_C(src_a, src_b, remainder); + } + return diff; +} + // TODO(fbarchard): Refactor into row function. LIBYUV_API uint64 ComputeSumSquareError(const uint8* src_a, diff --git a/chromium/third_party/libyuv/source/compare_common.cc b/chromium/third_party/libyuv/source/compare_common.cc index 42fc5893543..d3e46fb502b 100644 --- a/chromium/third_party/libyuv/source/compare_common.cc +++ b/chromium/third_party/libyuv/source/compare_common.cc @@ -17,6 +17,50 @@ namespace libyuv { extern "C" { #endif +#if ORIGINAL_OPT +uint32 HammingDistance_C(const uint8* src_a, const uint8* src_b, int count) { + uint32 diff = 0u; + + int i; + for (i = 0; i < count; ++i) { + int x = src_a[i] ^ src_b[i]; + if (x & 1) + ++diff; + if (x & 2) + ++diff; + if (x & 4) + ++diff; + if (x & 8) + ++diff; + if (x & 16) + ++diff; + if (x & 32) + ++diff; + if (x & 64) + ++diff; + if (x & 128) + ++diff; + } + return diff; +} +#endif + +// Hakmem method for hamming distance. +uint32 HammingDistance_C(const uint8* src_a, const uint8* src_b, int count) { + uint32 diff = 0u; + + int i; + for (i = 0; i < count - 3; i += 4) { + uint32 x = *((uint32*)src_a) ^ *((uint32*)src_b); + uint32 u = x - ((x >> 1) & 0x55555555); + u = ((u >> 2) & 0x33333333) + (u & 0x33333333); + diff += ((((u + (u >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24); + src_a += 4; + src_b += 4; + } + return diff; +} + uint32 SumSquareError_C(const uint8* src_a, const uint8* src_b, int count) { uint32 sse = 0u; int i; diff --git a/chromium/third_party/libyuv/source/compare_gcc.cc b/chromium/third_party/libyuv/source/compare_gcc.cc index 64522aaa343..994fb10fd59 100644 --- a/chromium/third_party/libyuv/source/compare_gcc.cc +++ b/chromium/third_party/libyuv/source/compare_gcc.cc @@ -22,6 +22,19 @@ extern "C" { #if !defined(LIBYUV_DISABLE_X86) && \ (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) +uint32 HammingDistance_X86(const uint8* src_a, const uint8* src_b, int count) { + uint32 diff = 0u; + + int i; + for (i = 0; i < count - 7; i += 8) { + uint64 x = *((uint64*)src_a) ^ *((uint64*)src_b); + src_a += 8; + src_b += 8; + diff += __builtin_popcountll(x); + } + return diff; +} + uint32 SumSquareError_SSE2(const uint8* src_a, const uint8* src_b, int count) { uint32 sse; asm volatile ( diff --git a/chromium/third_party/libyuv/source/compare_neon.cc b/chromium/third_party/libyuv/source/compare_neon.cc index 49aa3b4eefe..b7991c17136 100644 --- a/chromium/third_party/libyuv/source/compare_neon.cc +++ b/chromium/third_party/libyuv/source/compare_neon.cc @@ -22,7 +22,7 @@ extern "C" { !defined(__aarch64__) uint32 SumSquareError_NEON(const uint8* src_a, const uint8* src_b, int count) { - volatile uint32 sse; + uint32 sse; asm volatile ( "vmov.u8 q8, #0 \n" "vmov.u8 q10, #0 \n" diff --git a/chromium/third_party/libyuv/source/compare_neon64.cc b/chromium/third_party/libyuv/source/compare_neon64.cc index f9c7df98c89..fdd9e0f8770 100644 --- a/chromium/third_party/libyuv/source/compare_neon64.cc +++ b/chromium/third_party/libyuv/source/compare_neon64.cc @@ -20,8 +20,40 @@ extern "C" { #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) +// 256 bits at a time +uint32 HammingDistance_NEON(const uint8* src_a, const uint8* src_b, int count) { + uint32 diff; + asm volatile ( + "movi d4, #0 \n" + + "1: \n" + MEMACCESS(0) + "ld1 {v0.16b, v1.16b}, [%0], #32 \n" + MEMACCESS(1) + "ld1 {v2.16b, v3.16b}, [%1], #32 \n" + "subs %w2, %w2, #32 \n" + "eor v0.16b, v0.16b, v2.16b \n" + "eor v1.16b, v1.16b, v3.16b \n" + "cnt v0.16b, v0.16b \n" + "cnt v1.16b, v1.16b \n" + "uaddlv h0, v0.16b \n" + "uaddlv h1, v1.16b \n" + "add d4, d4, d0 \n" + "add d4, d4, d1 \n" + "b.gt 1b \n" + + "fmov %w3, s4 \n" + : "+r"(src_a), + "+r"(src_b), + "+r"(count), + "=r"(diff) + : + : "cc", "v0", "v1", "v2", "v3", "v4"); + return diff; +} + uint32 SumSquareError_NEON(const uint8* src_a, const uint8* src_b, int count) { - volatile uint32 sse; + uint32 sse; asm volatile ( "eor v16.16b, v16.16b, v16.16b \n" "eor v18.16b, v18.16b, v18.16b \n" diff --git a/chromium/third_party/libyuv/source/compare_win.cc b/chromium/third_party/libyuv/source/compare_win.cc index b17fc8e11c4..5ca59178dbc 100644 --- a/chromium/third_party/libyuv/source/compare_win.cc +++ b/chromium/third_party/libyuv/source/compare_win.cc @@ -13,6 +13,10 @@ #include "libyuv/compare_row.h" #include "libyuv/row.h" +#if defined(_MSC_VER) +#include <intrin.h> // For __popcnt +#endif + #ifdef __cplusplus namespace libyuv { extern "C" { @@ -21,6 +25,19 @@ extern "C" { // This module is for 32 bit Visual C x86 and clangcl #if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) +uint32 HammingDistance_X86(const uint8* src_a, const uint8* src_b, int count) { + uint32 diff = 0u; + + int i; + for (i = 0; i < count - 3; i += 4) { + uint32 x = *((uint32*)src_a) ^ *((uint32*)src_b); + src_a += 4; + src_b += 4; + diff += __popcnt(x); + } + return diff; +} + __declspec(naked) uint32 SumSquareError_SSE2(const uint8* src_a, const uint8* src_b, int count) { __asm { diff --git a/chromium/third_party/libyuv/source/convert_from.cc b/chromium/third_party/libyuv/source/convert_from.cc index ab5afc06133..d623731d9ff 100644 --- a/chromium/third_party/libyuv/source/convert_from.cc +++ b/chromium/third_party/libyuv/source/convert_from.cc @@ -890,6 +890,75 @@ int I420ToRGB565(const uint8* src_y, return 0; } +// Convert I422 to RGB565. +LIBYUV_API +int I422ToRGB565(const uint8* src_y, + int src_stride_y, + const uint8* src_u, + int src_stride_u, + const uint8* src_v, + int src_stride_v, + uint8* dst_rgb565, + int dst_stride_rgb565, + int width, + int height) { + int y; + void (*I422ToRGB565Row)(const uint8* y_buf, const uint8* u_buf, + const uint8* v_buf, uint8* rgb_buf, + const struct YuvConstants* yuvconstants, int width) = + I422ToRGB565Row_C; + if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { + return -1; + } + // Negative height means invert the image. + if (height < 0) { + height = -height; + dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; + dst_stride_rgb565 = -dst_stride_rgb565; + } +#if defined(HAS_I422TORGB565ROW_SSSE3) + if (TestCpuFlag(kCpuHasSSSE3)) { + I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_SSSE3; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I422ToRGB565Row = I422ToRGB565Row_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I422ToRGB565Row = I422ToRGB565Row_AVX2; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_NEON) + if (TestCpuFlag(kCpuHasNEON)) { + I422ToRGB565Row = I422ToRGB565Row_Any_NEON; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_NEON; + } + } +#endif +#if defined(HAS_I422TORGB565ROW_MSA) + if (TestCpuFlag(kCpuHasMSA)) { + I422ToRGB565Row = I422ToRGB565Row_Any_MSA; + if (IS_ALIGNED(width, 8)) { + I422ToRGB565Row = I422ToRGB565Row_MSA; + } + } +#endif + + for (y = 0; y < height; ++y) { + I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, &kYuvI601Constants, width); + dst_rgb565 += dst_stride_rgb565; + src_y += src_stride_y; + src_u += src_stride_u; + src_v += src_stride_v; + } + return 0; +} + // Ordered 8x8 dither for 888 to 565. Values from 0 to 7. static const uint8 kDither565_4x4[16] = { 0, 4, 1, 5, 6, 2, 7, 3, 1, 5, 0, 4, 7, 3, 6, 2, diff --git a/chromium/third_party/libyuv/source/cpu_id.cc b/chromium/third_party/libyuv/source/cpu_id.cc index afb5d282b4a..b3eef701dc0 100644 --- a/chromium/third_party/libyuv/source/cpu_id.cc +++ b/chromium/third_party/libyuv/source/cpu_id.cc @@ -43,6 +43,10 @@ extern "C" { #define SAFEBUFFERS #endif +// cpu_info_ variable for SIMD instruction sets detected. +LIBYUV_API int cpu_info_ = 0; + +// TODO(fbarchard): Consider using int for cpuid so casting is not needed. // Low level cpuid for X86. #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \ defined(__x86_64__)) && \ @@ -52,7 +56,7 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { #if defined(_MSC_VER) // Visual C version uses intrinsic or inline x86 assembly. #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) - __cpuidex((int*)(cpu_info), info_eax, info_ecx); + __cpuidex((int*)(cpu_info), info_eax, info_ecx); // NOLINT #elif defined(_M_IX86) __asm { mov eax, info_eax @@ -66,7 +70,7 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { } #else // Visual C but not x86 if (info_ecx == 0) { - __cpuid((int*)(cpu_info), info_eax); + __cpuid((int*)(cpu_info), info_eax); // NOLINT } else { cpu_info[3] = cpu_info[2] = cpu_info[1] = cpu_info[0] = 0u; } @@ -119,8 +123,9 @@ void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info) { // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers. int GetXCR0() { uint32 xcr0 = 0u; +// VS2010 SP1 required #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) - xcr0 = (uint32)(_xgetbv(0)); // VS2010 SP1 required. + xcr0 = (uint32)(_xgetbv(0)); // NOLINT #elif defined(__i386__) || defined(__x86_64__) asm(".byte 0x0f, 0x01, 0xd0" : "=a"(xcr0) : "c"(0) : "%edx"); #endif // defined(__i386__) || defined(__x86_64__) @@ -167,7 +172,7 @@ LIBYUV_API SAFEBUFFERS int ArmCpuCaps(const char* cpuinfo_name) { LIBYUV_API SAFEBUFFERS int MipsCpuCaps(const char* cpuinfo_name, const char ase[]) { char cpuinfo_line[512]; - int len = (int)strlen(ase); + int len = (int)strlen(ase); // NOLINT FILE* f = fopen(cpuinfo_name, "r"); if (!f) { // ase enabled if /proc/cpuinfo is unavailable. @@ -192,10 +197,6 @@ LIBYUV_API SAFEBUFFERS int MipsCpuCaps(const char* cpuinfo_name, return 0; } -// CPU detect function for SIMD instruction sets. -LIBYUV_API -int cpu_info_ = 0; // cpu_info is not initialized yet. - // Test environment variable for disabling CPU features. Any non-zero value // to disable. Zero ignored to make it easy to set the variable on/off. #if !defined(__native_client__) && !defined(_M_ARM) @@ -215,7 +216,7 @@ static LIBYUV_BOOL TestEnv(const char*) { } #endif -LIBYUV_API SAFEBUFFERS int InitCpuFlags(void) { +static SAFEBUFFERS int GetCpuFlags(void) { int cpu_info = 0; #if !defined(__pnacl__) && !defined(__CLR_VER) && defined(CPU_X86) uint32 cpu_info0[4] = {0, 0, 0, 0}; @@ -321,14 +322,24 @@ LIBYUV_API SAFEBUFFERS int InitCpuFlags(void) { cpu_info = 0; } cpu_info |= kCpuInitialized; - cpu_info_ = cpu_info; return cpu_info; } // Note that use of this function is not thread safe. LIBYUV_API -void MaskCpuFlags(int enable_flags) { - cpu_info_ = InitCpuFlags() & enable_flags; +int MaskCpuFlags(int enable_flags) { + int cpu_info = GetCpuFlags() & enable_flags; +#ifdef __ATOMIC_RELAXED + __atomic_store_n(&cpu_info_, cpu_info, __ATOMIC_RELAXED); +#else + cpu_info_ = cpu_info; +#endif + return cpu_info; +} + +LIBYUV_API +int InitCpuFlags(void) { + return MaskCpuFlags(-1); } #ifdef __cplusplus diff --git a/chromium/third_party/libyuv/source/row_dspr2.cc b/chromium/third_party/libyuv/source/row_dspr2.cc index 466dd5d91b2..11f78e0d2f1 100644 --- a/chromium/third_party/libyuv/source/row_dspr2.cc +++ b/chromium/third_party/libyuv/source/row_dspr2.cc @@ -68,7 +68,7 @@ void CopyRow_MIPS(const uint8* src, uint8* dst, int count) { "pref 0, 64(%[src]) \n" "pref 30, 32(%[dst]) \n" // In case the a1 > t9 don't use "pref 30" at all - "sgtu $v1, %[dst], $t9 \n" + "sltu $v1, $t9, %[dst] \n" "bgtz $v1, $loop16w \n" "nop \n" // otherwise, start with using pref30 @@ -119,7 +119,7 @@ void CopyRow_MIPS(const uint8* src, uint8* dst, int count) { "sw $t7, 60(%[dst]) \n" "addiu %[dst], %[dst], 64 \n" // adding 64 to dest - "sgtu $v1, %[dst], $t9 \n" + "sltu $v1, $t9, %[dst] \n" "bne %[dst], $a3, $loop16w \n" " addiu %[src], %[src], 64 \n" // adding 64 to src "move %[count], $t8 \n" @@ -221,7 +221,7 @@ void CopyRow_MIPS(const uint8* src, uint8* dst, int count) { "pref 30, 32(%[dst]) \n" // safe, as we have at least 64 bytes ahead // In case the a1 > t9 don't use "pref 30" at all - "sgtu $v1, %[dst], $t9 \n" + "sltu $v1, $t9, %[dst] \n" "bgtz $v1, $ua_loop16w \n" // skip "pref 30,64(a1)" for too short arrays " nop \n" @@ -292,7 +292,7 @@ void CopyRow_MIPS(const uint8* src, uint8* dst, int count) { "sw $t7, 60(%[dst]) \n" "addiu %[dst],%[dst],64 \n" // adding 64 to dest - "sgtu $v1,%[dst],$t9 \n" + "sltu $v1,$t9,%[dst] \n" "bne %[dst],$a3,$ua_loop16w \n" " addiu %[src],%[src],64 \n" // adding 64 to src "move %[count],$t8 \n" |