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 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_BITS_H_
18 #define incl_HPHP_BITS_H_
21 ///////////////////////////////////////////////////////////////////////////////
25 static const T NumBits
= sizeof(T
) * 8;
26 static const T HighMask
= 0x1 << (NumBits
- 1);
29 template <unsigned int i
, unsigned int m
>
31 enum { value
= ((i
& m
) ? 1 : 0) + BitCountImpl
< i
, (m
>> 1) >::value
};
34 template <unsigned int i
>
35 struct BitCountImpl
<i
, 0> {
39 template <unsigned int i
>
40 struct BitCount
: public BitCountImpl
<i
,
41 BitInfo
<unsigned int>::HighMask
>
44 template <unsigned int i
, bool p
, unsigned int m
>
47 value
= ((i
& m
) ? (p
? 0 : 1) : (p
? 1 : 0)) +
48 BitPhaseImpl
<i
, ((i
& m
) != 0), (m
>> 1)>::value
52 template <unsigned int i
, bool p
>
53 struct BitPhaseImpl
<i
, p
, 0> {
57 template <unsigned int i
>
58 struct BitPhase
: public BitPhaseImpl
<i
,
59 i
& BitInfo
<unsigned int>::HighMask
,
60 BitInfo
<unsigned int>::HighMask
>
63 ///////////////////////////////////////////////////////////////////////////////
66 #endif // incl_HPHP_BITS_H_