Changeset 70419 in webkit for trunk/JavaScriptCore/wtf/StdLibExtras.h
- Timestamp:
- Oct 24, 2010, 11:53:21 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/StdLibExtras.h
r65311 r70419 88 88 namespace WTF { 89 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 90 /* 91 * C++'s idea of a reinterpret_cast lacks sufficient cojones. 92 */ 93 template<typename TO, typename FROM> 94 inline TO bitwise_cast(FROM from) 95 { 96 COMPILE_ASSERT(sizeof(TO) == sizeof(FROM), WTF_bitwise_cast_sizeof_casted_types_is_equal); 97 union { 98 FROM from; 99 TO to; 100 } u; 101 u.from = from; 102 return u.to; 103 } 104 104 105 106 107 108 109 110 111 105 // Returns a count of the number of bits set in 'bits'. 106 inline size_t bitCount(unsigned bits) 107 { 108 bits = bits - ((bits >> 1) & 0x55555555); 109 bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333); 110 return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; 111 } 112 112 113 113 } // namespace WTF 114 114 115 #endif 115 #endif // WTF_StdLibExtras_h
Note:
See TracChangeset
for help on using the changeset viewer.