projects
/
platform
/
upstream
/
opencv.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
f2dc445
)
Use a faster way to count 1's (used by Hamming)
author
Peng Xiao
<pengxiao@outlook.com>
Sat, 13 Apr 2013 06:34:30 +0000
(14:34 +0800)
committer
Peng Xiao
<pengxiao@outlook.com>
Sat, 13 Apr 2013 06:34:30 +0000
(14:34 +0800)
modules/ocl/src/opencl/brute_force_match.cl
patch
|
blob
|
history
diff --git
a/modules/ocl/src/opencl/brute_force_match.cl
b/modules/ocl/src/opencl/brute_force_match.cl
index edc0bd147ca969270f8bd0105a4b36c3b5c7b0e0..8dcb9d20702733e2aceacc36693013c97ab8c60a 100644
(file)
--- a/
modules/ocl/src/opencl/brute_force_match.cl
+++ b/
modules/ocl/src/opencl/brute_force_match.cl
@@
-62,15
+62,12
@@
#define DIST_TYPE 0
#endif
-int bit1Count(int x)
+//http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
+int bit1Count(int v)
{
- int c = 0;
- for (int i = 0 ; i < 32 ; i++)
- {
- c += x & 1;
- x >>= 1;
- }
- return c;
+ v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
+ v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
+ return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
}
// dirty fix for non-template support