Changes in src/Common/utility.h [9dc31c10:babeeda]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r9dc31c10 rbabeeda 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Th u Apr 19 16:21:44 201813 // Update Count : 3 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 17 11:38:00 2017 13 // Update Count : 34 14 14 // 15 15 … … 436 436 } 437 437 438 // -----------------------------------------------------------------------------439 // O(1) polymorphic integer log2, using clz, which returns the number of leading 0-bits, starting at the most440 // significant bit (single instruction on x86)441 442 template<typename T>443 inline constexpr T log2(const T & t) {444 if ( std::is_integral<T>::value ) {445 const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1;446 if ( sizeof(T) == sizeof(unsigned int ) ) return r - __builtin_clz( t );447 if ( sizeof(T) == sizeof(unsigned long) ) return r - __builtin_clzl( t );448 if ( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t );449 } // if450 return -1;451 }452 438 453 439
Note:
See TracChangeset
for help on using the changeset viewer.