diff options
author | Stephen Hines <srhines@google.com> | 2021-02-18 23:12:19 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-18 23:12:19 +0000 |
commit | 39516316e3ebca9e30fe9c4c6194a7c2c120d47b (patch) | |
tree | bf795792c727b7d3d47af92580a2ac7157e72cd1 | |
parent | 7e3c8d7e5e368a889463a1f29928a5b6f4f69255 (diff) | |
parent | a738f586f15db2566055279ac2de08559d40b8d1 (diff) | |
download | FP16-39516316e3ebca9e30fe9c4c6194a7c2c120d47b.tar.gz |
Fix undefined behavior (UB) from calling builtin_clz(0) am: c2b391b076 am: a738f586f1
Original change: https://android-review.googlesource.com/c/platform/external/FP16/+/1592859
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: I0a4f64ac6ddd75c8176ae5c71313208bff133921
-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; /* |