Changeset 90152a4 for src/Common/utility.h
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (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
rf9feab8 r90152a4 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 : 3411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 6 22:24:16 2018 13 // Update Count : 40 14 14 // 15 15 … … 31 31 #include "Common/Indenter.h" 32 32 33 class Expression; 34 33 35 template< typename T > 34 36 static inline T * maybeClone( const T *orig ) { … … 98 100 } 99 101 102 template< typename SrcContainer, typename DestContainer, typename Predicate > 103 void cloneAll_if( const SrcContainer &src, DestContainer &dest, Predicate pred ) { 104 std::back_insert_iterator< DestContainer > out( dest ); 105 for ( auto x : src ) { 106 if ( pred(x) ) { 107 *out++ = x->clone(); 108 } 109 } // while 110 } 111 100 112 template< typename Container > 101 113 void assertAll( const Container &container ) { … … 151 163 return os.str(); 152 164 } 165 166 #define toCString( ... ) toString( __VA_ARGS__ ).c_str() 153 167 154 168 // replace element of list with all elements of another list … … 424 438 } 425 439 426 440 // ----------------------------------------------------------------------------- 441 // O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most 442 // significant bit (single instruction on x86) 443 444 template<typename T> 445 inline 446 #if defined(__GNUC__) && __GNUC__ > 4 447 constexpr 448 #endif 449 T ilog2(const T & t) { 450 if(std::is_integral<T>::value) { 451 const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1; 452 if( sizeof(T) == sizeof(unsigned int) ) return r - __builtin_clz ( t ); 453 if( sizeof(T) == sizeof(unsigned long) ) return r - __builtin_clzl ( t ); 454 if( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t ); 455 } 456 assert(false); 457 return -1; 458 } // ilog2 459 460 // ----------------------------------------------------------------------------- 461 /// evaluates expr as a long long int. If second is false, expr could not be evaluated 462 std::pair<long long int, bool> eval(Expression * expr); 427 463 428 464 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.