diff options
author | Stephen Hines <srhines@google.com> | 2021-02-18 22:25:25 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-18 22:25:25 +0000 |
commit | a738f586f15db2566055279ac2de08559d40b8d1 (patch) | |
tree | bf795792c727b7d3d47af92580a2ac7157e72cd1 | |
parent | de7ecd98d97b69bdade712e289e39cc47fbfd445 (diff) | |
parent | c2b391b0768dbf3ddf46ab0472e8f79afdf1eba6 (diff) | |
download | FP16-a738f586f15db2566055279ac2de08559d40b8d1.tar.gz |
Fix undefined behavior (UB) from calling builtin_clz(0) am: c2b391b076android-s-beta-4android-s-beta-3android-s-beta-2android-s-beta-1android-s-beta-4
Original change: https://android-review.googlesource.com/c/platform/external/FP16/+/1592859
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I60fa6df65faf5bc160772bf1727264b3bdc514fe
-rw-r--r-- | include/fp16/fp16.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/include/fp16/fp16.h b/include/fp16/fp16.h index 2b61fff..a283d67 100644 --- a/include/fp16/fp16.h +++ b/include/fp16/fp16.h @@ -64,7 +64,7 @@ static inline uint32_t fp16_ieee_to_fp32_bits(uint16_t h) { _BitScanReverse(&nonsign_bsr, (unsigned long) nonsign); uint32_t renorm_shift = (uint32_t) nonsign_bsr ^ 31; #else - uint32_t renorm_shift = __builtin_clz(nonsign); + uint32_t renorm_shift = nonsign ? __builtin_clz(nonsign) : 32; #endif renorm_shift = renorm_shift > 5 ? renorm_shift - 5 : 0; /* @@ -293,7 +293,7 @@ static inline uint32_t fp16_alt_to_fp32_bits(uint16_t h) { _BitScanReverse(&nonsign_bsr, (unsigned long) nonsign); uint32_t renorm_shift = (uint32_t) nonsign_bsr ^ 31; #else - uint32_t renorm_shift = __builtin_clz(nonsign); + uint32_t renorm_shift = nonsign ? __builtin_clz(nonsign) : 32; #endif renorm_shift = renorm_shift > 5 ? renorm_shift - 5 : 0; /* |