mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-08-13 20:05:59 +08:00
Support MSVC intrinsic in MostSignificantBit() (#270)
This commit is contained in:
parent
0ec5ed3380
commit
c5a7054091
@ -21,6 +21,10 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include <intrin.h>
|
||||||
|
#endif // defined(_MSC_VER)
|
||||||
|
|
||||||
namespace draco {
|
namespace draco {
|
||||||
namespace bits {
|
namespace bits {
|
||||||
|
|
||||||
@ -54,6 +58,10 @@ inline void CopyBits32(uint32_t *dst, int dst_offset, uint32_t src,
|
|||||||
inline int MostSignificantBit(uint32_t n) {
|
inline int MostSignificantBit(uint32_t n) {
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
return 31 ^ __builtin_clz(n);
|
return 31 ^ __builtin_clz(n);
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
unsigned long where;
|
||||||
|
_BitScanReverse(&where, n);
|
||||||
|
return (int)where;
|
||||||
#else
|
#else
|
||||||
// TODO(fgalligan): Optimize this code.
|
// TODO(fgalligan): Optimize this code.
|
||||||
int msb = -1;
|
int msb = -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user