Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
3ac48de1
Commit
3ac48de1
authored
Mar 28, 2011
by
Vincent Rabaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- speed up the Hamming distance
parent
cbdc9188
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
17 deletions
+14
-17
brief.cpp
modules/features2d/src/brief.cpp
+14
-17
No files found.
modules/features2d/src/brief.cpp
View file @
3ac48de1
...
...
@@ -138,27 +138,24 @@ 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
;
//for portability just use unsigned long -- and use the __builtin_popcountll (see docs for __builtin_popcountll)
typedef
unsigned
long
long
pop_t
;
const
size_t
modulo
=
size
%
sizeof
(
pop_t
);
const
size_t
end
=
size
-
modulo
;
for
(
i
=
0
;
i
<
end
;
i
+=
sizeof
(
pop_t
))
{
pop_t
a2
=
*
reinterpret_cast
<
const
pop_t
*>
(
a
+
i
);
pop_t
b2
=
*
reinterpret_cast
<
const
pop_t
*>
(
b
+
i
);
result
+=
__builtin_popcountl
(
a2
^
b2
);
}
const
pop_t
*
a2
=
reinterpret_cast
<
const
pop_t
*>
(
a
)
;
const
pop_t
*
b2
=
reinterpret_cast
<
const
pop_t
*>
(
b
);
const
pop_t
*
a2_end
=
a2
+
(
size
/
sizeof
(
pop_t
));
for
(;
a2
!=
a2_end
;
++
a2
,
++
b2
)
result
+=
__builtin_popcountl
l
((
*
a2
)
^
(
*
b2
)
);
if
(
modulo
)
{
//in the case where size is not divisible by sizeof(size_t)
//need to mask of the bits at the end
pop_t
a2
=
0
,
b2
=
0
;
memcpy
(
&
a2
,
a
+
end
,
modulo
);
memcpy
(
&
b2
,
b
+
end
,
modulo
);
//std::cout << std::hex << (a2^b2) << std::endl;
result
+=
__builtin_popcountl
(
a2
^
b2
);
//need to mask off the bits at the end
pop_t
a_final
=
0
,
b_final
=
0
;
memcpy
(
&
a_final
,
a2
,
modulo
);
memcpy
(
&
b_final
,
b2
,
modulo
);
result
+=
__builtin_popcountll
(
a_final
^
b_final
);
}
return
result
;
#else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment