|
5 | 5 | #ifndef PARTPLAY_LOCAL_PARTICLE_SET_HPP |
6 | 6 | #define PARTPLAY_LOCAL_PARTICLE_SET_HPP |
7 | 7 |
|
| 8 | +#ifdef _MSC_VER |
| 9 | +#include <intrin.h> |
| 10 | + |
| 11 | +// from https://github.com/llvm-mirror/libcxx/blob/9dcbb46826fd4d29b1485f25e8986d36019a6dca/include/support/win32/support.h#L106-L182 |
| 12 | +// (c) Copyright (c) 2009-2017 by the contributors listed in https://github.com/llvm-mirror/libcxx/blob/9dcbb46826fd4d29b1485f25e8986d36019a6dca/CREDITS.TXT |
| 13 | +// Returns the number of leading 0-bits in x, starting at the most significant |
| 14 | +// bit position. If x is 0, the result is undefined. |
| 15 | +inline int __builtin_clzll(unsigned long long mask) |
| 16 | +{ |
| 17 | + unsigned long where; |
| 18 | +// BitScanReverse scans from MSB to LSB for first set bit. |
| 19 | +// Returns 0 if no set bit is found. |
| 20 | +#if defined(_LIBCPP_HAS_BITSCAN64) |
| 21 | + if (_BitScanReverse64(&where, mask)) |
| 22 | + return static_cast<int>(63 - where); |
| 23 | +#else |
| 24 | + // Scan the high 32 bits. |
| 25 | + if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32))) |
| 26 | + return static_cast<int>(63 - |
| 27 | + (where + 32)); // Create a bit offset from the MSB. |
| 28 | + // Scan the low 32 bits. |
| 29 | + if (_BitScanReverse(&where, static_cast<unsigned long>(mask))) |
| 30 | + return static_cast<int>(63 - where); |
| 31 | +#endif |
| 32 | + return 64; // Undefined Behavior. |
| 33 | +} |
| 34 | + |
| 35 | +inline int __builtin_clzl(unsigned long mask) |
| 36 | +{ |
| 37 | + unsigned long where; |
| 38 | + // Search from LSB to MSB for first set bit. |
| 39 | + // Returns zero if no set bit is found. |
| 40 | + if (_BitScanReverse(&where, mask)) |
| 41 | + return static_cast<int>(31 - where); |
| 42 | + return 32; // Undefined Behavior. |
| 43 | +} |
| 44 | + |
| 45 | +inline int __builtin_clz(unsigned int x) |
| 46 | +{ |
| 47 | + return __builtin_clzl(x); |
| 48 | +} |
| 49 | + |
| 50 | +#endif |
| 51 | + |
8 | 52 | class LocalParticleCellSet { |
9 | 53 |
|
10 | 54 | public: |
|
0 commit comments