Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
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
capnproto
Commits
801ae24d
Commit
801ae24d
authored
Apr 05, 2016
by
Harris Hancock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add kj::popCount to abstract over compiler differences
parent
e780e3ed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletion
+14
-1
serialize-packed.c++
c++/src/capnp/serialize-packed.c++
+1
-1
common.h
c++/src/kj/common.h
+13
-0
No files found.
c++/src/capnp/serialize-packed.c++
View file @
801ae24d
...
...
@@ -483,7 +483,7 @@ size_t computeUnpackedSizeInWords(kj::ArrayPtr<const byte> packedBytes) {
size_t
total
=
0
;
while
(
ptr
<
end
)
{
uint
tag
=
*
ptr
;
size_t
count
=
__builtin_popc
ount
(
tag
);
size_t
count
=
kj
::
popC
ount
(
tag
);
total
+=
1
;
KJ_REQUIRE
(
end
-
ptr
>=
count
,
"invalid packed data"
);
ptr
+=
count
+
1
;
...
...
c++/src/kj/common.h
View file @
801ae24d
...
...
@@ -85,6 +85,10 @@
#undef _GLIBCXX_HAVE_GETS
#endif
#if defined(_MSC_VER)
#include <intrin.h> // __popcnt
#endif
// =======================================================================================
namespace
kj
{
...
...
@@ -597,6 +601,15 @@ float nan();
inline
constexpr
bool
isNaN
(
float
f
)
{
return
f
!=
f
;
}
inline
constexpr
bool
isNaN
(
double
f
)
{
return
f
!=
f
;
}
inline
int
popCount
(
unsigned
int
x
)
{
#if defined(_MSC_VER)
return
__popcnt
(
x
);
// Note: __popcnt returns unsigned int, but the value is clearly guaranteed to fit into an int
#else
return
__builtin_popcount
(
x
);
#endif
}
// =======================================================================================
// Useful fake containers
...
...
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