Skip to content

Commit

Permalink
msvc: implement optimized bsf64/bsr64 for 32-bit builds
Browse files Browse the repository at this point in the history
  • Loading branch information
pps83 committed Mar 19, 2024
1 parent 5d15bce commit 9de2c4f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,16 @@ bsr64(u64 v)

_BitScanReverse64(&i, v);
return i;
#elif defined(_MSC_VER)
unsigned long i;

if ((u32)(v >> 32)) {
_BitScanReverse(&i, (u32)(v >> 32));
return i + 32;
} else {
_BitScanReverse(&i, (u32)v);
return i;
}
#else
unsigned i = 0;

Expand Down Expand Up @@ -694,6 +704,16 @@ bsf64(u64 v)

_BitScanForward64(&i, v);
return i;
#elif defined(_MSC_VER) && defined(_WIN64)
unsigned long i;

if ((u32)v) {
_BitScanForward(&i, (u32)v);
return i;
} else {
_BitScanForward(&i, (u32)(v >> 32));
return i + 32;
}
#else
unsigned i = 0;

Expand Down

0 comments on commit 9de2c4f

Please sign in to comment.