From patchwork Thu Mar 27 16:51:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 315 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx20.g.dreamhost.com (caibbdcaaahc.dreamhost.com [208.113.200.72]) by wilcox.dreamhost.com (Postfix) with ESMTP id E0A31360495 for ; Thu, 27 Mar 2014 09:52:05 -0700 (PDT) Received: by homiemail-mx20.g.dreamhost.com (Postfix, from userid 14307373) id 9024240C42A2B; Thu, 27 Mar 2014 09:52:05 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx20.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx20.g.dreamhost.com (Postfix) with ESMTPS id 6909140C42A2B for ; Thu, 27 Mar 2014 09:52:05 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=twE9YzKblQX5x6MtCnRtdrSB6ScZE VQKtnGnqbhG4gwOYQjNdI4VSxYQFIZ8d6JVmnCISrUH719KmsMaviyJICXyanXXA 6yVu8hPEePGrVZbDs9OO4vSJAgHUCFDA3QnNFCx8KMSls01cOjQRyzmzUStA6M3t lx824uCT9fadYA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=ZMQtosxzxZ+Ra0cQaw68m5XdYgg=; b=HlN 0DsVVVnAKXn2Kq061EBAXsMjRXHWcYZ7tTvLZRknrwE+CutA4ffRb+/4vheUKMGC Z/pPUPB/gwkEnSXd579o9Vcb0U2+gvTbAOP511qUnrd+2EuUtkypRyst89mioBjs q2HoVcl7LbYIj095zGuCJHNSrffl/pkhwuBDhasY= Received: (qmail 3097 invoked by alias); 27 Mar 2014 16:52:03 -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 3084 invoked by uid 89); 27 Mar 2014 16:52:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Thu, 27 Mar 2014 16:51:48 +0000 From: "Joseph S. Myers" To: Subject: Fix x86/x86_64 expl/exp10l spurious underflows (bug 16348) Message-ID: MIME-Version: 1.0 X-DH-Original-To: glibc@patchwork.siddhesh.in This patch fixes bug 16348, spurious underflows from x86/x86_64 expl on arguments close to 0. These implementations effectively use expm1 (on the fractional part of the argument) internally, so resulting in spurious underflows when the result is very close to 1. For arguments small enough that the round-to-nearest correct result is 1, this patch uses 1+x instead. These implementations are also used for exp10l and so the patch fixes similar issues there (the 0x1p-67 threshold being small enough to be correct for exp10l as well as expl). But because of spurious underflows in other exp10 implementations (bug 16560), the tests aren't added for exp10 at this point - they can be added when the other exp10 parts of that bug are fixed. Tested x86_64 and x86; no ulps updates needed. (auto-libm-test-out diffs omitted below.) 2014-03-27 Joseph Myers [BZ #16348] * sysdeps/i386/fpu/e_expl.S (IEEE754_EXPL) [!USE_AS_EXPM1L]: Use 1+x for argument with exponent below -67. * sysdeps/x86_64/fpu/e_expl.S (IEEE754_EXPL) [!USE_AS_EXPM1L]: Likewise. * math/auto-libm-test-in: Add more tests of exp. * math/auto-libm-test-out: Regenerated. diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in index 7c80192..7ad407c 100644 --- a/math/auto-libm-test-in +++ b/math/auto-libm-test-in @@ -843,6 +843,24 @@ exp -7.4444006192138124e+02 exp -0x1.75f113c30b1c8p+9 exp -max exp -11342.8125 +exp 0x1p-10 +exp -0x1p-10 +exp 0x1p-20 +exp -0x1p-20 +exp 0x1p-30 +exp -0x1p-30 +exp 0x1p-40 +exp -0x1p-40 +exp 0x1p-50 +exp -0x1p-50 +exp 0x1p-60 +exp -0x1p-60 +exp 0x1p-100 +exp -0x1p-100 +exp min +exp -min +exp min_subnorm +exp -min_subnorm exp10 0 exp10 -0 diff --git a/sysdeps/i386/fpu/e_expl.S b/sysdeps/i386/fpu/e_expl.S index 5917f57..eb4086b 100644 --- a/sysdeps/i386/fpu/e_expl.S +++ b/sysdeps/i386/fpu/e_expl.S @@ -112,8 +112,14 @@ ENTRY(IEEE754_EXPL) movzwl 4+8(%esp), %eax andl $0x7fff, %eax cmpl $0x400d, %eax - jle 3f - /* Overflow, underflow or infinity or NaN as argument. */ + jg 5f + cmpl $0x3fbc, %eax + jge 3f + /* Argument's exponent below -67, result rounds to 1. */ + fld1 + faddp + jmp 2f +5: /* Overflow, underflow or infinity or NaN as argument. */ fstsw %ax movb $0x45, %dh andb %ah, %dh diff --git a/sysdeps/x86_64/fpu/e_expl.S b/sysdeps/x86_64/fpu/e_expl.S index 36d30c2..338527b 100644 --- a/sysdeps/x86_64/fpu/e_expl.S +++ b/sysdeps/x86_64/fpu/e_expl.S @@ -109,8 +109,14 @@ ENTRY(IEEE754_EXPL) movzwl 8+8(%rsp), %eax andl $0x7fff, %eax cmpl $0x400d, %eax - jle 3f - /* Overflow, underflow or infinity or NaN as argument. */ + jg 5f + cmpl $0x3fbc, %eax + jge 3f + /* Argument's exponent below -67, result rounds to 1. */ + fld1 + faddp + jmp 2f +5: /* Overflow, underflow or infinity or NaN as argument. */ fstsw %ax movb $0x45, %dh andb %ah, %dh