diff options
author | Boris Brezillon <boris.brezillon@collabora.com> | 2020-08-17 13:44:01 -0700 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2020-08-17 13:45:43 -0700 |
commit | 3a7051d9c28e3dd6da5048d91b74fad830728e93 (patch) | |
tree | de1a01f64e1aed7080bdaab6e4789a8ea6cd152b /libclc | |
parent | 45cc86b09bcd499c9d26b83e70114f0be8ecfa85 (diff) | |
download | llvm-3a7051d9c28e3dd6da5048d91b74fad830728e93.zip llvm-3a7051d9c28e3dd6da5048d91b74fad830728e93.tar.gz llvm-3a7051d9c28e3dd6da5048d91b74fad830728e93.tar.bz2 |
libclc: Fix FP_ILOGBNAN definition
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@collabora.com>
Reviewed By: jvesely
Differential Revision: https://reviews.llvm.org/D83473
Diffstat (limited to 'libclc')
-rw-r--r-- | libclc/generic/include/clc/float/definitions.h | 2 | ||||
-rw-r--r-- | libclc/generic/lib/math/ilogb.cl | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/libclc/generic/include/clc/float/definitions.h b/libclc/generic/include/clc/float/definitions.h index 43335a7..6250123 100644 --- a/libclc/generic/include/clc/float/definitions.h +++ b/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 diff --git a/libclc/generic/lib/math/ilogb.cl b/libclc/generic/lib/math/ilogb.cl index 7ab7899..050239c 100644 --- a/libclc/generic/lib/math/ilogb.cl +++ b/libclc/generic/lib/math/ilogb.cl @@ -31,7 +31,15 @@ _CLC_OVERLOAD _CLC_DEF int ilogb(float x) { 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_ILOGB0 : 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; } @@ -47,7 +55,15 @@ _CLC_OVERLOAD _CLC_DEF int ilogb(double x) { int r = (int) (ax >> EXPSHIFTBITS_DP64) - EXPBIAS_DP64; int rs = -1011 - (int) clz(ax & MANTBITS_DP64); r = ax < 0x0010000000000000UL ? rs : r; - r = ax > 0x7ff0000000000000UL | ax == 0UL ? 0x80000000 : r; + r = ax == 0UL ? FP_ILOGB0 : r; + + // We could merge those 2 tests and have: + // + // r = ax >= 0x7ff0000000000000UL ? 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 > 0x7ff0000000000000UL ? FP_ILOGBNAN : r; r = ax == 0x7ff0000000000000UL ? 0x7fffffff : r; return r; } |