Changeset 36e120a


Ignore:
Timestamp:
Jan 25, 2024, 12:44:20 PM (11 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
01fb70a
Parents:
68cf1d4 (diff), 8ca60e4 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r68cf1d4 r36e120a  
    111111};
    112112
    113 // -----------------------------------------------------------------------------
    114 // O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most
    115 // significant bit (single instruction on x86)
    116 
    117 template<typename T>
    118 inline
    119 #if defined(__GNUC__) && __GNUC__ > 4
    120 constexpr
    121 #endif
    122 T ilog2(const T & t) {
    123         if(std::is_integral<T>::value) {
    124                 const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1;
    125                 if( sizeof(T) == sizeof(unsigned       int) ) return r - __builtin_clz  ( t );
    126                 if( sizeof(T) == sizeof(unsigned      long) ) return r - __builtin_clzl ( t );
    127                 if( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t );
    128         }
    129         assert(false);
    130         return -1;
    131 } // ilog2
    132 
    133113// Local Variables: //
    134114// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.