Changeset da7fe39 for src/Common/utility.h
- Timestamp:
- Apr 23, 2018, 12:57:46 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 57acae0
- Parents:
- ba89e9b7 (diff), c8ad5d9 (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
-
src/Common/utility.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
rba89e9b7 rda7fe39 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 … … 436 436 } 437 437 438 // ----------------------------------------------------------------------------- 439 // O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most 440 // significant bit (single instruction on x86) 441 442 template<typename T> 443 inline constexpr T ilog2(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 } // if 450 return -1; 451 } // ilong2 438 452 439 453
Note:
See TracChangeset
for help on using the changeset viewer.