Skip to content

Commit

Permalink
Merge pull request #1733 from brechtvl/lzcnt
Browse files Browse the repository at this point in the history
Bump internal copy of half to fix issues on older x86_64 CPUs on Windows
  • Loading branch information
Idclip authored Jan 5, 2024
2 parents 28453c1 + 30a5fd2 commit b77fc2b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions openvdb/openvdb/math/Half.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,14 @@ imath_half_to_float (imath_half_bits_t h)
// other compilers may provide count-leading-zeros primitives,
// but we need the community to inform us of the variants
uint32_t lc;
# if defined(_MSC_VER) && (_M_IX86 || _M_X64)
lc = __lzcnt (hexpmant);
# if defined(_MSC_VER)
// The direct intrinsic for this is __lznct, but that is not supported
// on older x86_64 hardware or ARM. Instead uses the bsr instruction
// and one additional subtraction. This assumes hexpmant != 0, for 0
// bsr and lznct would behave differently.
unsigned long bsr;
_BitScanReverse (&bsr, hexpmant);
lc = (31 - bsr);
# elif defined(__GNUC__) || defined(__clang__)
lc = (uint32_t) __builtin_clz (hexpmant);
# else
Expand Down

0 comments on commit b77fc2b

Please sign in to comment.