2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
20 ///////////////////////////////////////////////////////////////////////////////
24 static const T NumBits
= sizeof(T
) * 8;
25 static const T HighMask
= 0x1 << (NumBits
- 1);
28 template <unsigned int i
, unsigned int m
>
30 enum { value
= ((i
& m
) ? 1 : 0) + BitCountImpl
< i
, (m
>> 1) >::value
};
33 template <unsigned int i
>
34 struct BitCountImpl
<i
, 0> {
38 template <unsigned int i
>
39 struct BitCount
: public BitCountImpl
<i
,
40 BitInfo
<unsigned int>::HighMask
>
43 template <unsigned int i
, bool p
, unsigned int m
>
46 value
= ((i
& m
) ? (p
? 0 : 1) : (p
? 1 : 0)) +
47 BitPhaseImpl
<i
, ((i
& m
) != 0), (m
>> 1)>::value
51 template <unsigned int i
, bool p
>
52 struct BitPhaseImpl
<i
, p
, 0> {
56 template <unsigned int i
>
57 struct BitPhase
: public BitPhaseImpl
<i
,
58 i
& BitInfo
<unsigned int>::HighMask
,
59 BitInfo
<unsigned int>::HighMask
>
62 ///////////////////////////////////////////////////////////////////////////////