Fix ServiceInterceptor::getValueAsType
[hiphop-php.git] / hphp / util / bits.h
blob99b8e244859cbd47caff12a6318a12beedefc1b7
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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 #pragma once
19 namespace HPHP {
20 ///////////////////////////////////////////////////////////////////////////////
22 template <typename T>
23 struct BitInfo {
24 static const T NumBits = sizeof(T) * 8;
25 static const T HighMask = 0x1 << (NumBits - 1);
28 template <unsigned int i, unsigned int m>
29 struct BitCountImpl {
30 enum { value = ((i & m) ? 1 : 0) + BitCountImpl< i, (m >> 1) >::value };
33 template <unsigned int i>
34 struct BitCountImpl<i, 0> {
35 enum { value = 0 };
38 template <unsigned int i>
39 struct BitCount: public BitCountImpl<i,
40 BitInfo<unsigned int>::HighMask>
41 {};
43 template <unsigned int i, bool p, unsigned int m>
44 struct BitPhaseImpl {
45 enum {
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> {
53 enum { value = 0 };
56 template <unsigned int i>
57 struct BitPhase : public BitPhaseImpl<i,
58 i & BitInfo<unsigned int>::HighMask,
59 BitInfo<unsigned int>::HighMask>
60 {};
62 ///////////////////////////////////////////////////////////////////////////////