From: Ethan Rublee Date: Mon, 24 Jan 2011 16:59:14 +0000 (+0000) Subject: revert the hamming distance to use unsigned long, on 64bit machines, using size_t X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~7840 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a47b6c23f5986dced109d0121ebfb2a5c0f1c553;p=platform%2Fupstream%2Fopencv.git revert the hamming distance to use unsigned long, on 64bit machines, using size_t with __build_popcountl doesn't return correct number of bits. the ll version should work, but for simplicity, locking it down to long for now. TODO add a unit test for the Hamming distance. --- diff --git a/modules/features2d/src/brief.cpp b/modules/features2d/src/brief.cpp index f7924de..675b42c 100644 --- a/modules/features2d/src/brief.cpp +++ b/modules/features2d/src/brief.cpp @@ -138,13 +138,16 @@ Hamming::ResultType Hamming::operator()(const unsigned char* a, const unsigned c } else #endif + //for portability just use unsigned long -- and use the __builtin_popcountl (see docs for __builtin_popcountl) + //as opposed to size_t -- TODO smart switching, if the size_t is a 64bits, use __builtin_popcountll + typedef unsigned long pop_t; size_t i; - const size_t modulo = size % sizeof(size_t); + const size_t modulo = size % sizeof(pop_t); const size_t end = size - modulo; - for (i = 0; i < end; i += sizeof(size_t)) + for (i = 0; i < end; i += sizeof(pop_t)) { - size_t a2 = *reinterpret_cast (a + i); - size_t b2 = *reinterpret_cast (b + i); + size_t a2 = *reinterpret_cast (a + i); + size_t b2 = *reinterpret_cast (b + i); result += __builtin_popcountl(a2 ^ b2); } if (modulo)