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