Skip to content

Guard fp16 renorm shift against zero inputs#43

Open
bbopen wants to merge 1 commit into
Maratyszcza:masterfrom
bbopen:fix/clz-zero-guard
Open

Guard fp16 renorm shift against zero inputs#43
bbopen wants to merge 1 commit into
Maratyszcza:masterfrom
bbopen:fix/clz-zero-guard

Conversation

@bbopen
Copy link
Copy Markdown

@bbopen bbopen commented Oct 17, 2025

Fixes undefined behavior in fp16_ieee_to_fp32_bits (and the ARM alt variant) where __builtin_clz/_BitScanReverse were invoked with zero for half-precision zeros.

Repro:

cat <<'EOS' >/tmp/fp16_clz_ub.c
#include <stdint.h>
#include <fp16/fp16.h>

int main(void) {
  (void)fp16_ieee_to_fp32_bits(0x0000);  // +0.0h
  return 0;
}
EOS

Before the patch: UBSan reports "passing zero to clz()". After the patch: program runs cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant