Changeset 1cdfa82 for src/Common/utility.h
- Timestamp:
- Apr 25, 2018, 4:55:53 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- 42107b4
- Parents:
- 2efe4b8 (diff), 9d5fb67 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r2efe4b8 r1cdfa82 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr Aug 17 11:38:00 201713 // Update Count : 3 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 20 22:35:33 2018 13 // Update Count : 38 14 14 // 15 15 … … 433 433 } 434 434 435 // ----------------------------------------------------------------------------- 436 // O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most 437 // significant bit (single instruction on x86) 438 439 template<typename T> 440 inline constexpr T ilog2(const T & t) { 441 if ( std::is_integral<T>::value ) { 442 const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1; 443 if ( sizeof(T) == sizeof(unsigned int ) ) return r - __builtin_clz( t ); 444 if ( sizeof(T) == sizeof(unsigned long) ) return r - __builtin_clzl( t ); 445 if ( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t ); 446 } // if 447 return -1; 448 } // ilong2 435 449 436 450
Note: See TracChangeset
for help on using the changeset viewer.