From patchwork Thu Feb 12 23:06:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 439354 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 292D0140129 for ; Fri, 13 Feb 2015 10:07:34 +1100 (AEDT) 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=UV2rfG5xr5VMdmhSWcj7HZtY7bS1x dKU+f2NOr8gAUpRgwPotKoUnCSIPsDbix83cRR9nC6x0aiasyeR1lsDxzXkpiYf1 x9bOcYPwW7YXzwqpp3Tlpo2uQ0vaLN2rK+TlsqWMZ0QfGRuFEP4UJd+LgrIMRbQl LbqiqxQLmKdgLo= 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=wuSqxi9MoXlOgAER2CK2vo6sqqw=; b=iGz iJk+5q6VMQgxoBIXYUCJLqUZna6wIVJwnsX1yEz1bRHhC8fkq8NOMo6nVUUNElLT 8aDgag4azXpCF2fgrDo6zPeNbYT6i2OqxrEC/vwgOb6xIcJ41mmz4eGT3E+FpyEV 0YfxY8nUjszzjUWZsah5Lshq55jF5xyx+RtB+G5I= Received: (qmail 32150 invoked by alias); 12 Feb 2015 23:06:53 -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 32103 invoked by uid 89); 12 Feb 2015 23:06:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Thu, 12 Feb 2015 23:06:43 +0000 From: Joseph Myers To: Subject: Fix powerpc software sqrt (bug 17964) [committed] Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 As Adhemerval noted in , the powerpc sqrt implementation for when _ARCH_PPCSQ is not defined is inaccurate in some cases. The problem is that this code relies on fused multiply-add, and relies on the compiler contracting a * b + c to get a fused operation. But sysdeps/ieee754/dbl-64/Makefile disables contraction for e_sqrt.c, because the implementation in that directory relies on *not* having contracted operations. While it would be possible to arrange makefiles so that an earlier sysdeps directory can disable the setting in sysdeps/ieee754/dbl-64/Makefile, it seems a lot cleaner to make the dependence on fused operations explicit in the .c file. GCC 4.6 introduced support for __builtin_fma on powerpc and other architectures with such instructions, so we can rely on that; this patch duly makes the code use __builtin_fma for all such fused operations. Tested for powerpc32 (hard float). Committed. 2015-02-12 Joseph Myers [BZ #17964] * sysdeps/powerpc/fpu/e_sqrt.c (__slow_ieee754_sqrt): Use __builtin_fma instead of relying on contraction of a * b + c. diff --git a/sysdeps/powerpc/fpu/e_sqrt.c b/sysdeps/powerpc/fpu/e_sqrt.c index 0934faa..9b55ef8 100644 --- a/sysdeps/powerpc/fpu/e_sqrt.c +++ b/sysdeps/powerpc/fpu/e_sqrt.c @@ -99,38 +99,41 @@ __slow_ieee754_sqrt (double x) /* Here we have three Newton-Raphson iterations each of a division and a square root and the remainder of the argument reduction, all interleaved. */ - sd = -(sg * sg - sx); + sd = -__builtin_fma (sg, sg, -sx); fsgi = (xi0 + 0x40000000) >> 1 & 0x7ff00000; sy2 = sy + sy; - sg = sy * sd + sg; /* 16-bit approximation to sqrt(sx). */ + sg = __builtin_fma (sy, sd, sg); /* 16-bit approximation to + sqrt(sx). */ /* schedule the INSERT_WORDS (fsg, fsgi, 0) to get separation between the store and the load. */ INSERT_WORDS (fsg, fsgi, 0); iw_u.parts.msw = fsgi; iw_u.parts.lsw = (0); - e = -(sy * sg - almost_half); - sd = -(sg * sg - sx); + e = -__builtin_fma (sy, sg, -almost_half); + sd = -__builtin_fma (sg, sg, -sx); if ((xi0 & 0x7ff00000) == 0) goto denorm; - sy = sy + e * sy2; - sg = sg + sy * sd; /* 32-bit approximation to sqrt(sx). */ + sy = __builtin_fma (e, sy2, sy); + sg = __builtin_fma (sy, sd, sg); /* 32-bit approximation to + sqrt(sx). */ sy2 = sy + sy; /* complete the INSERT_WORDS (fsg, fsgi, 0) operation. */ fsg = iw_u.value; - e = -(sy * sg - almost_half); - sd = -(sg * sg - sx); - sy = sy + e * sy2; + e = -__builtin_fma (sy, sg, -almost_half); + sd = -__builtin_fma (sg, sg, -sx); + sy = __builtin_fma (e, sy2, sy); shx = sx * fsg; - sg = sg + sy * sd; /* 64-bit approximation to sqrt(sx), - but perhaps rounded incorrectly. */ + sg = __builtin_fma (sy, sd, sg); /* 64-bit approximation to + sqrt(sx), but perhaps + rounded incorrectly. */ sy2 = sy + sy; g = sg * fsg; - e = -(sy * sg - almost_half); - d = -(g * sg - shx); - sy = sy + e * sy2; + e = -__builtin_fma (sy, sg, -almost_half); + d = -__builtin_fma (g, sg, -shx); + sy = __builtin_fma (e, sy2, sy); fesetenv_register (fe); - return g + sy * d; + return __builtin_fma (sy, d, g); denorm: /* For denormalised numbers, we normalise, calculate the square root, and return an adjusted result. */