Changeset 270


Ignore:
Timestamp:
Jan 23, 2011, 6:46:14 PM (10 years ago)
Author:
sam
Message:

Add a utility function to compute the power of two above.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/matrix.h

    r244 r270  
    141141GLOBALS(3)
    142142
     143/* A few utility functions */
     144template <typename T> static inline T PotUp(T val)
     145{
     146    val = val - 1;
     147    //if (sizeof(val) > 8) val = val | (val >> 64);
     148    //if (sizeof(val) > 4) val = val | (val >> 32);
     149    if (sizeof(val) > 2) val = val | (val >> 16);
     150    if (sizeof(val) > 1) val = val | (val >> 8);
     151    val = val | (val >> 4);
     152    val = val | (val >> 2);
     153    val = val | (val >> 1);
     154    return val + 1;
     155}
     156
    143157#endif // __DH_MATRIX_H__
    144158
Note: See TracChangeset for help on using the changeset viewer.