From patchwork Sat Jul 2 08:58:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 13576 Received: (qmail 110675 invoked by alias); 2 Jul 2016 08:58:59 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 110663 invoked by uid 89); 2 Jul 2016 08:58:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=2016-07-02, nan, NaN, 00000 X-HELO: hall.aurel32.net From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Aurelien Jarno Subject: [PATCH] alpha: fix truncf and trunc for big input values Date: Sat, 2 Jul 2016 10:58:40 +0200 Message-Id: <1467449920-2372-1-git-send-email-aurelien@aurel32.net> The alpha specific version of trunc and truncf always add and subtract 0x1.0p23 or 0x1.0p52 even for big values. This causes this kind of errors in the testsuite: Failure: Test: trunc_towardzero (0x1p107) Result: is: 1.6225927682921334e+32 0x1.fffffffffffffp+106 should be: 1.6225927682921336e+32 0x1.0000000000000p+107 difference: 1.8014398509481984e+16 0x1.0000000000000p+54 ulp : 0.5000 max.ulp : 0.0000 Change this by returning the input value when its absolute value is greater than 0x1.0p23 or 0x1.0p52. NaN have to go through the add and subtract operations to get possibly silenced. Finally remove the code to handle inexact exception, trunc should never generate such an exception. Changelog: * sysdeps/alpha/fpu/s_truncf.c (__truncf): Return the input value when its absolute value is greater than 0x1.0p23. [_IEEE_FP_INEXACT] Remove. * sysdeps/alpha/fpu/s_trunc.c (__trunc): Return the input value when its absolute value is greater than 0x1.0p52. [_IEEE_FP_INEXACT] Remove. --- ChangeLog | 9 +++++++++ sysdeps/alpha/fpu/s_trunc.c | 7 +++---- sysdeps/alpha/fpu/s_truncf.c | 7 +++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7ca1ff..eda80f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2016-07-02 Aurelien Jarno + + * sysdeps/alpha/fpu/s_truncf.c (__truncf): Return the input value + when its absolute value is greater than 0x1.0p23. + [_IEEE_FP_INEXACT] Remove. + * sysdeps/alpha/fpu/s_trunc.c (__trunc): Return the input value + when its absolute value is greater than 0x1.0p52. + [_IEEE_FP_INEXACT] Remove. + 2016-07-01 Aurelien Jarno * sparc/sparc32/sparcv9/fpu/s_nearbyint.S (__nearbyint): Trigger an diff --git a/sysdeps/alpha/fpu/s_trunc.c b/sysdeps/alpha/fpu/s_trunc.c index 16cb114..c072c26 100644 --- a/sysdeps/alpha/fpu/s_trunc.c +++ b/sysdeps/alpha/fpu/s_trunc.c @@ -28,12 +28,11 @@ __trunc (double x) double two52 = copysign (0x1.0p52, x); double r, tmp; + if (!isnan(x) && fabs(x) >= 0x1.0p52) + return x; + __asm ( -#ifdef _IEEE_FP_INEXACT - "addt/suic %2, %3, %1\n\tsubt/suic %1, %3, %0" -#else "addt/suc %2, %3, %1\n\tsubt/suc %1, %3, %0" -#endif : "=&f"(r), "=&f"(tmp) : "f"(x), "f"(two52)); diff --git a/sysdeps/alpha/fpu/s_truncf.c b/sysdeps/alpha/fpu/s_truncf.c index 2290f28..3dbe2ad 100644 --- a/sysdeps/alpha/fpu/s_truncf.c +++ b/sysdeps/alpha/fpu/s_truncf.c @@ -27,12 +27,11 @@ __truncf (float x) float two23 = copysignf (0x1.0p23, x); float r, tmp; + if (!isnan(x) && fabs(x) >= 0x1.0p23) + return x; + __asm ( -#ifdef _IEEE_FP_INEXACT - "adds/suic %2, %3, %1\n\tsubs/suic %1, %3, %0" -#else "adds/suc %2, %3, %1\n\tsubs/suc %1, %3, %0" -#endif : "=&f"(r), "=&f"(tmp) : "f"(x), "f"(two23));