[libclc] [libclc] Move logb/ilogb to CLC library; optimize (PR #128028)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 20 08:43:25 PST 2025
================
@@ -0,0 +1,73 @@
+#if __CLC_FPSIZE == 32
+
+_CLC_OVERLOAD _CLC_DEF __CLC_INTN __clc_ilogb(__CLC_GENTYPE x) {
+ __CLC_UINTN ux = __CLC_AS_UINTN(x);
----------------
arsenm wrote:
This should be implemented in terms of frexp and avoid relying on the exponent bits.
Something like:
```
int ilogb(float x) {
int result;
(void)frexp(x, &result);
result = isnan(x) ? FP_ILOGBNAN : result;
result = isinf(x) ? INT_MAX : result;
return x == 0.0 ? FP_ILOGB0 : result;
}
```
Might be able to avoid the edge case handling too
```
https://github.com/llvm/llvm-project/pull/128028
More information about the cfe-commits
mailing list