File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -59,16 +59,19 @@ inline int MostSignificantBit(uint32_t n) {
5959#if defined(__GNUC__)
6060 return 31 ^ __builtin_clz (n);
6161#elif defined(_MSC_VER)
62-
6362 unsigned long where;
6463 _BitScanReverse (&where, n);
6564 return (int )where;
6665#else
67- // TODO(fgalligan): Optimize this code.
68- int msb = -1 ;
69- while (n != 0 ) {
70- msb++;
71- n >>= 1 ;
66+ uint32_t msb = 0 ;
67+ if (n) {
68+ if (0xFFFF0000 & n) { n >>= (1 << 4 ); msb |= (1 << 4 ); }
69+ if (0x0000FF00 & n) { n >>= (1 << 3 ); msb |= (1 << 3 ); }
70+ if (0x000000F0 & n) { n >>= (1 << 2 ); msb |= (1 << 2 ); }
71+ if (0x0000000C & n) { n >>= (1 << 1 ); msb |= (1 << 1 ); }
72+ if (0x00000002 & n) { msb |= (1 << 0 ); }
73+ } else {
74+ msb = -1 ;
7275 }
7376 return msb;
7477#endif
You can’t perform that action at this time.
0 commit comments