From patchwork Mon Dec 14 19:24:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 58366 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp1680817lbv; Mon, 14 Dec 2015 11:25:06 -0800 (PST) X-Received: by 10.98.79.212 with SMTP id f81mr13764857pfj.36.1450121106475; Mon, 14 Dec 2015 11:25:06 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id hh1si10347482pac.44.2015.12.14.11.25.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Dec 2015 11:25:06 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-65587-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libc-alpha-return-65587-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-65587-patch=linaro.org@sourceware.org; dkim=pass header.i=@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=MQD3sPHDvZjoC4qXkZdLLwiqH7a3eWX vucZtDwgpyz4ZHou5q+gMVOXJflgC6SJKdw3KUsSkVyOXtgdeBENSQlw98873gHk +DtxK6LQLdrsCzULoo9ZTCL9AMMrDMdtTArBcQc3wkKVzL/fWp0FESRcZqtkuoor eF4dVooEPXKA= 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:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=TOYNZ5i1tfU80VwZVkAMm0R6YfM=; b=dzd2W XsynDR4Xz1TcxjIf1CX7u4pQy2/o3qLO8Q5/kk9nz3znMYV8vru7Om7RF6ISAyHs bbCcS2e3edM1XGrH8O/KLpffKArVgR8+FKhykyrFrAxP1VTZv/31jUuIfmTn+J0z 16rEM2rm/cHNss3XNJ03t8cp/Q9zs1ymE8BFOE= Received: (qmail 112727 invoked by alias); 14 Dec 2015 19:24:48 -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 112622 invoked by uid 89); 14 Dec 2015 19:24:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pf0-f174.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=P55ppH3mZ2jE7qKN5fcAePzdJtaGYHG2rHhK3sldYQU=; b=YcXCDpkyLADmHvyM7HaSGzsbBzoAVXxFllEm3eSzJVctUP8B71ZqY/yojya1XyeIPt qKHoOpx5pm5+9MUI80NIX4FtXWvi2sPe/klk3Pa6AhyLBNVIqtNZxRo51wwrkDhJwj7P s1XGPxUR3yxDrM63NtnYpzQAbepS+g9eRLK3UeYu4Rzshhu3hAQ6kehPFvxenz+nUisq jdMicVXukohu7LkEcWPnIe7QuWweJeLqlTCV6i1oo2tnmebRavnUHil11jeZSASXiTns IK5B85/4BTeTgI7GyQz4UR5tl5GsmAgeEZGW84FK4SUeRITQqst88hyEJVhzkhzfU6zS YvMg== X-Gm-Message-State: ALoCoQm5Vbyh6Xw+uFdHoQtDbGF5SRehg2nB0oaTlk54aAaItju2vgproCCUGMsHUXmGJ3b3s0D8fqpkGj7jaPFM+/mWZDHA+Q== X-Received: by 10.98.87.83 with SMTP id l80mr38543872pfb.126.1450121084423; Mon, 14 Dec 2015 11:24:44 -0800 (PST) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: Siddhesh Poyarekar Subject: [PATCH 2/3] Consolidate sin and cos code for 105414350 <|x|< 281474976710656 Date: Tue, 15 Dec 2015 00:54:10 +0530 Message-Id: <1450121051-19759-3-git-send-email-siddhesh.poyarekar@linaro.org> In-Reply-To: <1450121051-19759-1-git-send-email-siddhesh.poyarekar@linaro.org> References: <1450121051-19759-1-git-send-email-siddhesh.poyarekar@linaro.org> The sin and cos computation for this range of input is identical except for a difference in quadrants by 1. Exploit that fact and the common argument reduction to reduce computations for sincos. Siddhesh * sysdeps/ieee754/dbl-64/s_sin.c (__sin, __cos): Move common code to new functions. (reduce_sincos_2, do_sincos_2): New functions. * sysdeps/ieee754/dbl-64/s_sincos.c (__sincos): Use them. --- sysdeps/ieee754/dbl-64/s_sin.c | 253 ++++++++++++++++---------------------- sysdeps/ieee754/dbl-64/s_sincos.c | 12 +- 2 files changed, 119 insertions(+), 146 deletions(-) -- 2.5.0 diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c index b619905..3b26a61 100644 --- a/sysdeps/ieee754/dbl-64/s_sin.c +++ b/sysdeps/ieee754/dbl-64/s_sin.c @@ -276,6 +276,104 @@ reduce_and_compute (double x, unsigned int k) return retval; } +static inline int4 +__always_inline +reduce_sincos_2 (double x, double *a, double *da) +{ + mynumber v; + + double t = (x * hpinv + toint); + double xn = t - toint; + v.x = t; + double xn1 = (xn + 8.0e22) - 8.0e22; + double xn2 = xn - xn1; + double y = ((((x - xn1 * mp1) - xn1 * mp2) - xn2 * mp1) - xn2 * mp2); + int4 n = v.i[LOW_HALF] & 3; + double db = xn1 * pp3; + t = y - db; + db = (y - t) - db; + db = (db - xn2 * pp3) - xn * pp4; + double b = t + db; + db = (t - b) + db; + + *a = b; + *da = db; + + return n; +} + +/* Compute sin (A + DA). cos can be computed by shifting the quadrant N + clockwise. */ +static double +__always_inline +do_sincos_2 (double a, double da, double x, int4 n, int4 k) +{ + double res, retval, cor, xx; + mynumber u; + + double eps = 1.0e-24; + + k = (n + k) & 3; + + switch (k) + { + case 2: + a = -a; + da = -da; + /* Fall through. */ + case 0: + xx = a * a; + if (xx < 0.01588) + { + /* Taylor series. */ + res = TAYLOR_SIN (xx, a, da, cor); + cor = (cor > 0) ? 1.02 * cor + eps : 1.02 * cor - eps; + retval = (res == res + cor) ? res : bsloww (a, da, x, n); + } + else + { + double t, db, y; + int m; + if (a > 0) + { + m = 1; + t = a; + db = da; + } + else + { + m = 0; + t = -a; + db = -da; + } + u.x = big + t; + y = t - (u.x - big); + res = do_sin (u, y, db, &cor); + cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps; + retval = ((res == res + cor) ? ((m) ? res : -res) + : bsloww1 (a, da, x, n)); + } + break; + + case 1: + case 3: + if (a < 0) + { + a = -a; + da = -da; + } + u.x = big + a; + double y = a - (u.x - big) + da; + res = do_cos (u, y, &cor); + cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps; + retval = ((res == res + cor) ? ((n & 2) ? -res : res) + : bsloww2 (a, da, x, n)); + break; + } + + return retval; +} + /*******************************************************************/ /* An ultimate sin routine. Given an IEEE double machine number x */ /* it computes the correctly rounded (to nearest) value of sin(x) */ @@ -288,8 +386,7 @@ SECTION #endif __sin (double x) { - double xx, res, t, cor, y, s, c, sn, ssn, cs, ccs, xn, a, da, db, eps, xn1, - xn2; + double xx, res, t, cor, y, s, c, sn, ssn, cs, ccs, xn, a, da, eps; mynumber u, v; int4 k, m, n; double retval = 0; @@ -421,83 +518,16 @@ __sin (double x) } } /* else if (k < 0x419921FB ) */ +#ifndef IN_SINCOS /*---------------------105414350 <|x|< 281474976710656 --------------------*/ else if (k < 0x42F00000) { - t = (x * hpinv + toint); - xn = t - toint; - v.x = t; - xn1 = (xn + 8.0e22) - 8.0e22; - xn2 = xn - xn1; - y = ((((x - xn1 * mp1) - xn1 * mp2) - xn2 * mp1) - xn2 * mp2); - n = v.i[LOW_HALF] & 3; - da = xn1 * pp3; - t = y - da; - da = (y - t) - da; - da = (da - xn2 * pp3) - xn * pp4; - a = t + da; - da = (t - a) + da; - eps = 1.0e-24; + double a, da; - switch (n) - { - case 0: - case 2: - xx = a * a; - if (n) - { - a = -a; - da = -da; - } - if (xx < 0.01588) - { - /* Taylor series. */ - res = TAYLOR_SIN (xx, a, da, cor); - cor = (cor > 0) ? 1.02 * cor + eps : 1.02 * cor - eps; - retval = (res == res + cor) ? res : bsloww (a, da, x, n); - } - else - { - double t; - if (a > 0) - { - m = 1; - t = a; - db = da; - } - else - { - m = 0; - t = -a; - db = -da; - } - u.x = big + t; - y = t - (u.x - big); - res = do_sin (u, y, db, &cor); - cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps; - retval = ((res == res + cor) ? ((m) ? res : -res) - : bsloww1 (a, da, x, n)); - } - break; - - case 1: - case 3: - if (a < 0) - { - a = -a; - da = -da; - } - u.x = big + a; - y = a - (u.x - big) + da; - res = do_cos (u, y, &cor); - cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps; - retval = ((res == res + cor) ? ((n & 2) ? -res : res) - : bsloww2 (a, da, x, n)); - break; - } + int4 n = reduce_sincos_2 (x, &a, &da); + retval = do_sincos_2 (a, da, x, n, 0); } /* else if (k < 0x42F00000 ) */ -#ifndef IN_SINCOS /* -----------------281474976710656 <|x| <2^1024----------------------------*/ else if (k < 0x7ff00000) retval = reduce_and_compute (x, 0); @@ -528,8 +558,7 @@ SECTION #endif __cos (double x) { - double y, xx, res, t, cor, xn, a, da, db, eps, xn1, - xn2; + double y, xx, res, t, cor, xn, a, da, eps; mynumber u, v; int4 k, m, n; @@ -657,81 +686,15 @@ __cos (double x) } } /* else if (k < 0x419921FB ) */ +#ifndef IN_SINCOS else if (k < 0x42F00000) { - t = (x * hpinv + toint); - xn = t - toint; - v.x = t; - xn1 = (xn + 8.0e22) - 8.0e22; - xn2 = xn - xn1; - y = ((((x - xn1 * mp1) - xn1 * mp2) - xn2 * mp1) - xn2 * mp2); - n = v.i[LOW_HALF] & 3; - da = xn1 * pp3; - t = y - da; - da = (y - t) - da; - da = (da - xn2 * pp3) - xn * pp4; - a = t + da; - da = (t - a) + da; - eps = 1.0e-24; + double a, da; - switch (n) - { - case 1: - case 3: - xx = a * a; - if (n == 1) - { - a = -a; - da = -da; - } - if (xx < 0.01588) - { - res = TAYLOR_SIN (xx, a, da, cor); - cor = (cor > 0) ? 1.02 * cor + eps : 1.02 * cor - eps; - retval = (res == res + cor) ? res : bsloww (a, da, x, n); - } - else - { - double t; - if (a > 0) - { - m = 1; - t = a; - db = da; - } - else - { - m = 0; - t = -a; - db = -da; - } - u.x = big + t; - y = t - (u.x - big); - res = do_sin (u, y, db, &cor); - cor = (cor > 0) ? 1.035 * cor + eps : 1.035 * cor - eps; - retval = ((res == res + cor) ? ((m) ? res : -res) - : bsloww1 (a, da, x, n)); - } - break; - - case 0: - case 2: - if (a < 0) - { - a = -a; - da = -da; - } - u.x = big + a; - y = a - (u.x - big) + da; - res = do_cos (u, y, &cor); - cor = (cor > 0) ? 1.025 * cor + eps : 1.025 * cor - eps; - retval = ((res == res + cor) ? ((n) ? -res : res) - : bsloww2 (a, da, x, n)); - break; - } + int4 n = reduce_sincos_2 (x, &a, &da); + retval = do_sincos_2 (a, da, x, n, 1); } /* else if (k < 0x42F00000 ) */ -#ifndef IN_SINCOS /* 281474976710656 <|x| <2^1024 */ else if (k < 0x7ff00000) retval = reduce_and_compute (x, 1); diff --git a/sysdeps/ieee754/dbl-64/s_sincos.c b/sysdeps/ieee754/dbl-64/s_sincos.c index f50ffa6..7f78b41 100644 --- a/sysdeps/ieee754/dbl-64/s_sincos.c +++ b/sysdeps/ieee754/dbl-64/s_sincos.c @@ -69,12 +69,22 @@ __sincos (double x, double *sinx, double *cosx) u.x = x; k = 0x7fffffff & u.i[HIGH_HALF]; - if (k < 0x42F00000) + if (k < 0x419921FB) { *sinx = __sin_local (x); *cosx = __cos_local (x); return; } + if (k < 0x42F00000) + { + double a, da; + int4 n = reduce_sincos_2 (x, &a, &da); + + *sinx = do_sincos_2 (a, da, x, n, 0); + *cosx = do_sincos_2 (a, da, x, n, 1); + + return; + } if (k < 0x7ff00000) { reduce_and_compute_sincos (x, sinx, cosx);