File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments