From e23b27d040f6b1d63ddc76dbd5bd0f3b51b8ee80 Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Mon, 9 Oct 2017 19:56:42 -0700 Subject: [PATCH] Reduce HammingDistance block size to 32k to avoid overflow Bug: libyuv:701 Test: HammingDistance unittest with large size Change-Id: Id41a2c27eb8922d03b3a21dab32fa2e7b015ba38 Reviewed-on: https://chromium-review.googlesource.com/708335 Reviewed-by: Cheng Wang Commit-Queue: Frank Barchard --- source/compare.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/compare.cc b/source/compare.cc index 986b097c0..bfb8c080d 100644 --- a/source/compare.cc +++ b/source/compare.cc @@ -110,11 +110,14 @@ uint32 ARGBDetect(const uint8* argb, int stride_argb, int width, int height) { return fourcc; } +// NEON version accumulates in 16 bit shorts which overflow at 65536 bytes. +// So actual maximum is 1 less loop, which is 64436 - 32 bytes. + LIBYUV_API uint64 ComputeHammingDistance(const uint8* src_a, const uint8* src_b, int count) { - const int kBlockSize = 65536; + const int kBlockSize = 1 << 15; // 32768; const int kSimdSize = 64; // SIMD for multiple of 64, and C for remainder int remainder = count & (kBlockSize - 1) & ~(kSimdSize - 1);