Skip to content

Commit

Permalink
Bump internal copy of half to fix issues on older x86_64 CPUs on Windows
Browse files Browse the repository at this point in the history
On some older CPUs without support for the lzcnt instruction, the
conversion from half to float was wrong.

See AcademySoftwareFoundation/Imath#358 for more details.

Thanks to Ray Molenkamp for tracking down this bug.

Signed-off-by: Brecht Van Lommel <[email protected]>
  • Loading branch information
brechtvl committed Dec 16, 2023
1 parent 41bb127 commit 30a5fd2
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 30a5fd2

Please sign in to comment.