Ignore:
Timestamp:
Apr 25, 2018, 4:55:53 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
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.
Message:

Merge remote-tracking branch 'origin/master' into with_gc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r2efe4b8 r1cdfa82  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 11:38:00 2017
    13 // Update Count     : 34
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Apr 20 22:35:33 2018
     13// Update Count     : 38
    1414//
    1515
     
    433433}
    434434
     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
     439template<typename T>
     440inline 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
    435449
    436450
Note: See TracChangeset for help on using the changeset viewer.