================
@@ -44,8 +44,21 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_exp(__CLC_GENTYPE 
x) {
   const __CLC_GENTYPE ulim = 0x1.62e430p+6f;
   // ln(smallest_normal) = -87.33654475055310898657
   const __CLC_GENTYPE llim = -0x1.5d589ep+6f;
+  // ln(smallest_subnormal) = ln(2^-149) = -103.27892990343184
+  const __CLC_GENTYPE subnorm_llim = -0x1.9d1dap+6f;
 
-  r = x < llim ? 0.0f : r;
+  // The integer scaling above (as_int(y) + (p << 23)) cannot represent
+  // subnormal results, so inputs in [subnorm_llim, llim) whose result is a
+  // subnormal are flushed to zero by the plain "x < llim ? 0" path below.
+  // When subnormals are supported, recompute those via __clc_ldexp so the
+  // subnormal result is preserved. Inputs below subnorm_llim (including -inf)
+  // genuinely underflow to zero and must not go through ldexp, whose exponent
+  // argument would be ill-formed for such extreme inputs.
+  r = x < llim ? (__CLC_GENTYPE)0.0f : r;
----------------
arsenm wrote:

This feels like a bruteforce fixup of the result. Can you adjust the flow so 
this works out naturally? This code was probably ported from a variant of 
https://github.com/ROCm/llvm-project/blob/d48377e0c0ae0b148a811c2220b7bc9564cd7816/amd/device-libs/ocml/src/expF_base.h

https://github.com/llvm/llvm-project/pull/212696
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to