Bitcoin ABC 0.30.7
P2P Digital Currency
bitmanip.h
Go to the documentation of this file.
1// Copyright (c) 2019 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_UTIL_BITMANIP_H
6#define BITCOIN_UTIL_BITMANIP_H
7
8#include <config/bitcoin-config.h>
9
10#include <cstdint>
11
12inline uint32_t countBits(uint32_t v) {
13#if HAVE_DECL___BUILTIN_POPCOUNT
14 return __builtin_popcount(v);
15#else
23 v = v - ((v >> 1) & 0x55555555);
24 v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
25 return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
26#endif
27}
28
29#endif // BITCOIN_UTIL_BITMANIP_H
uint32_t countBits(uint32_t v)
Definition: bitmanip.h:12