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 94 94 * and PopCount (population count/count 1 bits) methods, for 32- and 64-bit 95 95 * integers. The CountTrailingZeros results are *UNDEFINED* if the value is 0. 96 96 */ 97 template<typename T>98 inline int PopCount(T val) = delete;99 template<typename T>100 inline int CountTrailingZeros(T val) = delete;101 97 102 98 #ifdef __GNUC__ 103 99 104 100 /* Define variations for unsigned (long (long)) int, since we don't know what 105 101 * uint32/64_t are typedef'd to. 106 102 */ 107 template<>108 103 inline int PopCount(unsigned long long val) { return __builtin_popcountll(val); } 109 template<>110 104 inline int PopCount(unsigned long val) { return __builtin_popcountl(val); } 111 template<>112 105 inline int PopCount(unsigned int val) { return __builtin_popcount(val); } 113 106 114 template<>115 107 inline int CountTrailingZeros(unsigned long long val) { return __builtin_ctzll(val); } 116 template<>117 108 inline int CountTrailingZeros(unsigned long val) { return __builtin_ctzl(val); } 118 template<>119 109 inline int CountTrailingZeros(unsigned int val) { return __builtin_ctz(val); } 120 110 121 111 #else … … 128 118 * they're good enough if the GCC built-ins aren't available. 129 119 */ 130 120 template<> 131 in line int PopCount(uint32_t v)121 int PopCount(uint32_t v) 132 122 { 133 123 v = v - ((v >> 1) & 0x55555555u); 134 124 v = (v & 0x33333333u) + ((v >> 2) & 0x33333333u); … … 136 126 return static_cast<int>((v * 0x01010101u) >> 24); 137 127 } 138 128 template<> 139 in line int PopCount(uint64_t v)129 int PopCount(uint64_t v) 140 130 { 141 131 v = v - ((v >> 1) & 0x5555555555555555_u64); 142 132 v = (v & 0x3333333333333333_u64) + ((v >> 2) & 0x3333333333333333_u64); … … 147 137 #if defined(_WIN64) 148 138 149 139 template<> 150 in line int CountTrailingZeros(uint32_t v)140 int CountTrailingZeros(uint32_t v) 151 141 { 152 142 unsigned long idx = 32; 153 143 _BitScanForward(&idx, v); 154 144 return static_cast<int>(idx); 155 145 } 156 146 template<> 157 in line int CountTrailingZeros(uint64_t v)147 int CountTrailingZeros(uint64_t v) 158 148 { 159 149 unsigned long idx = 64; 160 150 _BitScanForward64(&idx, v); … … 164 154 #elif defined(_WIN32) 165 155 166 156 template<> 167 in line int CountTrailingZeros(uint32_t v)157 int CountTrailingZeros(uint32_t v) 168 158 { 169 159 unsigned long idx = 32; 170 160 _BitScanForward(&idx, v); 171 161 return static_cast<int>(idx); 172 162 } 173 163 template<> 174 in line int CountTrailingZeros(uint64_t v)164 int CountTrailingZeros(uint64_t v) 175 165 { 176 166 unsigned long idx = 64; 177 167 if(!_BitScanForward(&idx, static_cast<uint32_t>(v&0xffffffff))) … … 185 175 #else 186 176 187 177 template<> 188 in line int CountTrailingZeros(uint32_t value)178 int CountTrailingZeros(uint32_t value) 189 179 { return PopCount(~value & (value - 1)); } 190 180 template<> 191 in line int CountTrailingZeros(uint64_t value)181 int CountTrailingZeros(uint64_t value) 192 182 { return PopCount(~value & (value - 1)); } 193 183 194 184 #endif