1717#define wasm_support_bits_definitions
1818#include " support/bits.h"
1919
20+ namespace wasm {
21+
2022template <>
21- int wasm:: PopCount<uint8_t >(uint8_t v) {
23+ int PopCount<uint8_t >(uint8_t v) {
2224 // Small table lookup.
2325 static const uint8_t tbl[32 ] = {
2426 0 , 1 , 1 , 2 , 1 , 2 , 2 , 3 , 1 , 2 , 2 , 3 , 2 , 3 , 3 , 4 ,
@@ -28,12 +30,12 @@ int wasm::PopCount<uint8_t>(uint8_t v) {
2830}
2931
3032template <>
31- int wasm:: PopCount<uint16_t >(uint16_t v) {
33+ int PopCount<uint16_t >(uint16_t v) {
3234 return PopCount ((uint8_t )(v & 0xff )) + PopCount ((uint8_t )(v >> 8 ));
3335}
3436
3537template <>
36- int wasm:: PopCount<uint32_t >(uint32_t v) {
38+ int PopCount<uint32_t >(uint32_t v) {
3739 // See Stanford bithacks, counting bits set in parallel, "best method":
3840 // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
3941 v = v - ((v >> 1 ) & 0x55555555 );
@@ -42,12 +44,12 @@ int wasm::PopCount<uint32_t>(uint32_t v) {
4244}
4345
4446template <>
45- int wasm:: PopCount<uint64_t >(uint64_t v) {
47+ int PopCount<uint64_t >(uint64_t v) {
4648 return PopCount ((uint32_t )v) + PopCount ((uint32_t )(v >> 32 ));
4749}
4850
4951template <>
50- uint32_t wasm:: BitReverse<uint32_t >(uint32_t v) {
52+ uint32_t BitReverse<uint32_t >(uint32_t v) {
5153 // See Hacker's Delight, first edition, figure 7-1.
5254 v = ((v & 0x55555555 ) << 1 ) | ((v >> 1 ) & 0x55555555 );
5355 v = ((v & 0x33333333 ) << 2 ) | ((v >> 2 ) & 0x33333333 );
@@ -57,7 +59,7 @@ uint32_t wasm::BitReverse<uint32_t>(uint32_t v) {
5759}
5860
5961template <>
60- int wasm:: CountTrailingZeroes<uint32_t >(uint32_t v) {
62+ int CountTrailingZeroes<uint32_t >(uint32_t v) {
6163 // See Stanford bithacks, count the consecutive zero bits (trailing) on the
6264 // right with multiply and lookup:
6365 // http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup
@@ -69,13 +71,13 @@ int wasm::CountTrailingZeroes<uint32_t>(uint32_t v) {
6971}
7072
7173template <>
72- int wasm:: CountTrailingZeroes<uint64_t >(uint64_t v) {
74+ int CountTrailingZeroes<uint64_t >(uint64_t v) {
7375 return (uint32_t )v ? CountTrailingZeroes ((uint32_t )v)
7476 : 32 + CountTrailingZeroes ((uint32_t )(v >> 32 ));
7577}
7678
7779template <>
78- int wasm:: CountLeadingZeroes<uint32_t >(uint32_t v) {
80+ int CountLeadingZeroes<uint32_t >(uint32_t v) {
7981 // See Stanford bithacks, find the log base 2 of an N-bit integer in
8082 // O(lg(N)) operations with multiply and lookup:
8183 // http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
@@ -92,7 +94,9 @@ int wasm::CountLeadingZeroes<uint32_t>(uint32_t v) {
9294}
9395
9496template <>
95- int wasm:: CountLeadingZeroes<uint64_t >(uint64_t v) {
97+ int CountLeadingZeroes<uint64_t >(uint64_t v) {
9698 return v >> 32 ? CountLeadingZeroes ((uint32_t )(v >> 32 ))
9799 : 32 + CountLeadingZeroes ((uint32_t )v);
98100}
101+
102+ } // namespace wasm
0 commit comments