From 90cf2faccb27adb19ce330bbe7c7ec62c53c7018 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Tue, 2 Jan 2024 19:19:32 +0000 Subject: [PATCH] Fix boundary case in log2_extended_precision_half_safe. log2_extended_precision_half_safe is a modified version of log2_extended_precision_half_unsafe that avoids denormal intermediate results via scaling. The unsafe version gives one input, 0x39f6, special treatment because the approximation is known to be incorrect, but the safe version did not translate this special treatment correctly: the special casing happens before downscaling, therefore the constant needs to be upscaled. This fixes a pow test failure on FTZ targets. --- .../abacus/include/abacus/internal/log2_extended_precision.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/compiler/builtins/abacus/include/abacus/internal/log2_extended_precision.h b/modules/compiler/builtins/abacus/include/abacus/internal/log2_extended_precision.h index 70f2cfcef..b498d6f06 100644 --- a/modules/compiler/builtins/abacus/include/abacus/internal/log2_extended_precision.h +++ b/modules/compiler/builtins/abacus/include/abacus/internal/log2_extended_precision.h @@ -280,7 +280,8 @@ T log2_extended_precision_half_safe(const T &x, T *ans_lo, T *hiExp, T *loExp) { // Single awkward boundary value fix: const SignedType edge(abacus::detail::cast::as(x) == 0x39f6); - remainder = __abacus_select(remainder, T(-0.000144362f16), edge); + // -0.14783 ==> -0.000144362 * 2^10 + remainder = __abacus_select(remainder, T(-0.14783f16), edge); // Set return parameters *hiExp = abacus::detail::cast::convert(hiExpI);