| 37 | } |
| 38 | |
| 39 | int32_t bitScanReverse(uint32_t source) |
| 40 | { |
| 41 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) // Visual Studio 2005 |
| 42 | unsigned long i; |
| 43 | uint8_t success = _BitScanReverse(&i, source); |
| 44 | return success != 0 ? i : -1; |
| 45 | #elif defined(__GNUC__) |
| 46 | auto result = source == 0 ? -1 : __builtin_clz(source) ^ 31; |
| 47 | return result; |
| 48 | #else |
| 49 | #pragma message "Falling back to iterative bitscan reverse, consider using intrinsics" |
| 50 | if (source != 0) |
| 51 | { |
| 52 | for (int32_t i = 31; i > -1; i--) |
| 53 | { |
| 54 | if (source & (1u << i)) |
| 55 | { |
| 56 | return i; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | return -1; |
| 61 | #endif |
| 62 | } |
| 63 | } |
no outgoing calls