Skip to content

Commit

Permalink
Fix another use of __builtin_clz on Microsoft compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Marat Dukhan committed Oct 10, 2018
1 parent c091e51 commit 34d4bf0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/fp16/fp16.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,13 @@ static inline uint32_t fp16_alt_to_fp32_bits(uint16_t h) {
* denormalized nonsign by renorm_shift, the unit bit of mantissa will shift into exponent, turning the
* biased exponent into 1, and making mantissa normalized (i.e. without leading 1).
*/
#ifdef _MSC_VER
unsigned long nonsign_bsr;
_BitScanReverse(&nonsign_bsr, (unsigned long) nonsign);
uint32_t renorm_shift = (uint32_t) nonsign_bsr ^ 31;
#else
uint32_t renorm_shift = __builtin_clz(nonsign);
#endif
renorm_shift = renorm_shift > 5 ? renorm_shift - 5 : 0;
/*
* Iff nonsign is 0, it overflows into 0xFFFFFFFF, turning bit 31 into 1. Otherwise, bit 31 remains 0.
Expand Down

1 comment on commit 34d4bf0

@lygstate
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.,

Please sign in to comment.