Ticket #61431: patch-openal-soft-alnumeric.h.diff

File patch-openal-soft-alnumeric.h.diff, 2.8 KB (added by Blokkendoos (Johan), 4 years ago)
  • common/alnumeric.h

    old new  
    9494 * and PopCount (population count/count 1 bits) methods, for 32- and 64-bit
    9595 * integers. The CountTrailingZeros results are *UNDEFINED* if the value is 0.
    9696 */
    97 template<typename T>
    98 inline int PopCount(T val) = delete;
    99 template<typename T>
    100 inline int CountTrailingZeros(T val) = delete;
    10197
    10298#ifdef __GNUC__
    10399
    104100/* Define variations for unsigned (long (long)) int, since we don't know what
    105101 * uint32/64_t are typedef'd to.
    106102 */
    107 template<>
    108103inline int PopCount(unsigned long long val) { return __builtin_popcountll(val); }
    109 template<>
    110104inline int PopCount(unsigned long val) { return __builtin_popcountl(val); }
    111 template<>
    112105inline int PopCount(unsigned int val) { return __builtin_popcount(val); }
    113106
    114 template<>
    115107inline int CountTrailingZeros(unsigned long long val) { return __builtin_ctzll(val); }
    116 template<>
    117108inline int CountTrailingZeros(unsigned long val) { return __builtin_ctzl(val); }
    118 template<>
    119109inline int CountTrailingZeros(unsigned int val) { return __builtin_ctz(val); }
    120110
    121111#else
     
    128118 * they're good enough if the GCC built-ins aren't available.
    129119 */
    130120template<>
    131 inline int PopCount(uint32_t v)
     121int PopCount(uint32_t v)
    132122{
    133123    v = v - ((v >> 1) & 0x55555555u);
    134124    v = (v & 0x33333333u) + ((v >> 2) & 0x33333333u);
     
    136126    return static_cast<int>((v * 0x01010101u) >> 24);
    137127}
    138128template<>
    139 inline int PopCount(uint64_t v)
     129int PopCount(uint64_t v)
    140130{
    141131    v = v - ((v >> 1) & 0x5555555555555555_u64);
    142132    v = (v & 0x3333333333333333_u64) + ((v >> 2) & 0x3333333333333333_u64);
     
    147137#if defined(_WIN64)
    148138
    149139template<>
    150 inline int CountTrailingZeros(uint32_t v)
     140int CountTrailingZeros(uint32_t v)
    151141{
    152142    unsigned long idx = 32;
    153143    _BitScanForward(&idx, v);
    154144    return static_cast<int>(idx);
    155145}
    156146template<>
    157 inline int CountTrailingZeros(uint64_t v)
     147int CountTrailingZeros(uint64_t v)
    158148{
    159149    unsigned long idx = 64;
    160150    _BitScanForward64(&idx, v);
     
    164154#elif defined(_WIN32)
    165155
    166156template<>
    167 inline int CountTrailingZeros(uint32_t v)
     157int CountTrailingZeros(uint32_t v)
    168158{
    169159    unsigned long idx = 32;
    170160    _BitScanForward(&idx, v);
    171161    return static_cast<int>(idx);
    172162}
    173163template<>
    174 inline int CountTrailingZeros(uint64_t v)
     164int CountTrailingZeros(uint64_t v)
    175165{
    176166    unsigned long idx = 64;
    177167    if(!_BitScanForward(&idx, static_cast<uint32_t>(v&0xffffffff)))
     
    185175#else
    186176
    187177template<>
    188 inline int CountTrailingZeros(uint32_t value)
     178int CountTrailingZeros(uint32_t value)
    189179{ return PopCount(~value & (value - 1)); }
    190180template<>
    191 inline int CountTrailingZeros(uint64_t value)
     181int CountTrailingZeros(uint64_t value)
    192182{ return PopCount(~value & (value - 1)); }
    193183
    194184#endif