[PATCH] D83473: libclc: Fix FP_ILOGBNAN definition

Boris Brezillon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 04:46:21 PDT 2020


bbrezillon created this revision.
Herald added subscribers: llvm-commits, jvesely, Anastasia.
Herald added a project: LLVM.

Fix FP_ILOGBNAN definition to match the opencl-c-base.h one and
guarantee that FP_ILOGBNAN and FP_ILOGB0 are different. Doing that
implies fixing ilogb() implementation to return the right value.

Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83473

Files:
  libclc/generic/include/clc/float/definitions.h
  libclc/generic/lib/math/ilogb.cl


Index: libclc/generic/lib/math/ilogb.cl
===================================================================
--- libclc/generic/lib/math/ilogb.cl
+++ libclc/generic/lib/math/ilogb.cl
@@ -31,7 +31,15 @@
     int rs = -118 - (int) clz(ux & MANTBITS_SP32);
     int r = (int) (ax >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32;
     r = ax < 0x00800000U ? rs : r;
-    r = ax > EXPBITS_SP32 | ax == 0 ? 0x80000000 : r;
+    r = ax == 0 ? FP_ILOGBNAN : r;
+
+    // We could merge those 2 tests and have:
+    //
+    //    r = ax >= EXPBITS_SP32 ? 0x7fffffff : r
+    //
+    // since FP_ILOGBNAN is set to INT_MAX, but it's clearer this way and
+    // FP_ILOGBNAN can change without requiring changes to ilogb() code.
+    r = ax > EXPBITS_SP32 ? FP_ILOGBNAN : r;
     r = ax == EXPBITS_SP32 ? 0x7fffffff : r;
     return r;
 }
Index: libclc/generic/include/clc/float/definitions.h
===================================================================
--- libclc/generic/include/clc/float/definitions.h
+++ libclc/generic/include/clc/float/definitions.h
@@ -15,7 +15,7 @@
 #define FLT_EPSILON     0x1.0p-23f
 
 #define FP_ILOGB0 (-2147483647 - 1)
-#define FP_ILOGBNAN (-2147483647 - 1)
+#define FP_ILOGBNAN 2147483647
 
 #define M_E_F           0x1.5bf0a8p+1f
 #define M_LOG2E_F       0x1.715476p+0f


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83473.276705.patch
Type: text/x-patch
Size: 1286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200709/44504b7e/attachment.bin>


More information about the llvm-commits mailing list