Skip to content

Commit b77fc2b

Browse files
authored
Merge pull request #1733 from brechtvl/lzcnt
Bump internal copy of half to fix issues on older x86_64 CPUs on Windows
2 parents 28453c1 + 30a5fd2 commit b77fc2b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

openvdb/openvdb/math/Half.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,14 @@ imath_half_to_float (imath_half_bits_t h)
342342
// other compilers may provide count-leading-zeros primitives,
343343
// but we need the community to inform us of the variants
344344
uint32_t lc;
345-
# if defined(_MSC_VER) && (_M_IX86 || _M_X64)
346-
lc = __lzcnt (hexpmant);
345+
# if defined(_MSC_VER)
346+
// The direct intrinsic for this is __lznct, but that is not supported
347+
// on older x86_64 hardware or ARM. Instead uses the bsr instruction
348+
// and one additional subtraction. This assumes hexpmant != 0, for 0
349+
// bsr and lznct would behave differently.
350+
unsigned long bsr;
351+
_BitScanReverse (&bsr, hexpmant);
352+
lc = (31 - bsr);
347353
# elif defined(__GNUC__) || defined(__clang__)
348354
lc = (uint32_t) __builtin_clz (hexpmant);
349355
# else

0 commit comments

Comments
 (0)