mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Precompute the divisor to ensure that no kind of compiler would process it on the fly at each call.
This commit is contained in:
parent
a84afb6334
commit
327f92cc46
@ -506,7 +506,7 @@ struct Hamming2
|
|||||||
const uint64_t* pa = reinterpret_cast<const uint64_t*>(a);
|
const uint64_t* pa = reinterpret_cast<const uint64_t*>(a);
|
||||||
const uint64_t* pb = reinterpret_cast<const uint64_t*>(b);
|
const uint64_t* pb = reinterpret_cast<const uint64_t*>(b);
|
||||||
ResultType result = 0;
|
ResultType result = 0;
|
||||||
size /= (sizeof(uint64_t)/sizeof(unsigned char));
|
size /= long_word_size_;
|
||||||
for(size_t i = 0; i < size; ++i ) {
|
for(size_t i = 0; i < size; ++i ) {
|
||||||
result += popcnt64(*pa ^ *pb);
|
result += popcnt64(*pa ^ *pb);
|
||||||
++pa;
|
++pa;
|
||||||
@ -516,7 +516,7 @@ struct Hamming2
|
|||||||
const uint32_t* pa = reinterpret_cast<const uint32_t*>(a);
|
const uint32_t* pa = reinterpret_cast<const uint32_t*>(a);
|
||||||
const uint32_t* pb = reinterpret_cast<const uint32_t*>(b);
|
const uint32_t* pb = reinterpret_cast<const uint32_t*>(b);
|
||||||
ResultType result = 0;
|
ResultType result = 0;
|
||||||
size /= (sizeof(uint32_t)/sizeof(unsigned char));
|
size /= long_word_size_;
|
||||||
for(size_t i = 0; i < size; ++i ) {
|
for(size_t i = 0; i < size; ++i ) {
|
||||||
result += popcnt32(*pa ^ *pb);
|
result += popcnt32(*pa ^ *pb);
|
||||||
++pa;
|
++pa;
|
||||||
@ -525,6 +525,13 @@ struct Hamming2
|
|||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
#ifdef FLANN_PLATFORM_64_BIT
|
||||||
|
static const size_t long_word_size_ = sizeof(uint64_t)/sizeof(unsigned char);
|
||||||
|
#else
|
||||||
|
static const size_t long_word_size_ = sizeof(uint32_t)/sizeof(unsigned char);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user