diff --git a/libclc/generic/lib/math/clc_fma.cl b/libclc/generic/lib/math/clc_fma.cl --- a/libclc/generic/lib/math/clc_fma.cl +++ b/libclc/generic/lib/math/clc_fma.cl @@ -46,18 +46,21 @@ b = __clc_flush_denormal_if_not_supported(b); c = __clc_flush_denormal_if_not_supported(c); - if (c == 0) + if (a == .0f || b == .0f) + return c; + + if (c == .0f) return a * b; struct fp st_a, st_b, st_c; - st_a.exponent = a == .0f ? 0 : ((as_uint(a) & 0x7f800000) >> 23) - 127; - st_b.exponent = b == .0f ? 0 : ((as_uint(b) & 0x7f800000) >> 23) - 127; - st_c.exponent = c == .0f ? 0 : ((as_uint(c) & 0x7f800000) >> 23) - 127; + st_a.exponent = ((as_uint(a) & 0x7f800000) >> 23) - 127; + st_b.exponent = ((as_uint(b) & 0x7f800000) >> 23) - 127; + st_c.exponent = ((as_uint(c) & 0x7f800000) >> 23) - 127; - st_a.mantissa = a == .0f ? 0 : (as_uint(a) & 0x7fffff) | 0x800000; - st_b.mantissa = b == .0f ? 0 : (as_uint(b) & 0x7fffff) | 0x800000; - st_c.mantissa = c == .0f ? 0 : (as_uint(c) & 0x7fffff) | 0x800000; + st_a.mantissa = (as_uint(a) & 0x7fffff) | 0x800000; + st_b.mantissa = (as_uint(b) & 0x7fffff) | 0x800000; + st_c.mantissa = (as_uint(c) & 0x7fffff) | 0x800000; st_a.sign = as_uint(a) & 0x80000000; st_b.sign = as_uint(b) & 0x80000000; @@ -73,7 +76,6 @@ st_mul.mantissa = (st_a.mantissa * st_b.mantissa) << 14ul; st_mul.exponent = st_mul.mantissa ? st_a.exponent + st_b.exponent : 0; - // FIXME: Detecting a == 0 || b == 0 above crashed GCN isel if (st_mul.exponent == 0 && st_mul.mantissa == 0) return c; diff --git a/libclc/generic/lib/math/math.h b/libclc/generic/lib/math/math.h --- a/libclc/generic/lib/math/math.h +++ b/libclc/generic/lib/math/math.h @@ -76,15 +76,14 @@ #define MANTLENGTH_SP32 24 #define BASEDIGITS_SP32 7 -_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) -{ - int ix = as_int(x); - if (!__clc_fp32_subnormals_supported() && - ((ix & EXPBITS_SP32) == 0) && ((ix & MANTBITS_SP32) != 0)) { - ix &= SIGNBIT_SP32; - x = as_float(ix); - } - return x; +_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) { + int ix = as_int(x); + if (!__clc_fp32_subnormals_supported() && ((ix & MANTBITS_SP32) != 0) && + ((ix & EXPBITS_SP32) == 0)) { + ix &= SIGNBIT_SP32; + x = as_float(ix); + } + return x; } #ifdef cl_khr_fp64