From patchwork Fri Dec 11 12:11:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 58274 Delivered-To: patch@linaro.org Received: by 10.112.157.166 with SMTP id wn6csp90334lbb; Fri, 11 Dec 2015 04:12:51 -0800 (PST) X-Received: by 10.66.150.198 with SMTP id uk6mr24287089pab.70.1449835971462; Fri, 11 Dec 2015 04:12:51 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b73si954423pfd.70.2015.12.11.04.12.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Dec 2015 04:12:51 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-65496-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-65496-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-65496-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=yhZD6ioOFVyMyeaCZ0+WNpZBHcHHN8L hTH0Zkt1wgsb7ishZUohHujaDtzBiEw4J8FtQyUWIpqdNeT5La23xLRbOPL4UIlu uid8Spngwb2Mjr60MMvsSO4Bft+VCxWi6YxYwSxBL1fWUfvUKY+4Mtd5M0WhOwxP nJayhD1RJCJk= 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=Xi7XpZpsfM4zpHvEX8zaD+ehvaE=; b=d/SLm p56CZH91bRaHEKMJ01KUvuBlRYSCOC7KfpDfI2ZM9hgyFnh12jrJVt7aG3iUXxqu 2UQ4siYSYcLY3+670IlW3tKxo3HE7nKM7Nd2zvv++PdD3/e2pDs5wDogMPOiBwGW IZDKYGkfNY0x8De7lKSURLiV0qLJcZ8wSASuA0= Received: (qmail 56221 invoked by alias); 11 Dec 2015 12:12:41 -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 55866 invoked by uid 89); 11 Dec 2015 12:12:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 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-f181.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=TuYKhXVI8V9sH8aFlivNvbionPVRlWciQutzJNa37rM=; b=RxZJ38GnGIsisSZPqjtwmI3sPYDqHVabajtLDPqHo4OeeS4+XjWKi7pjnl3wltQoKI 6L3a2LKTAE9HvnxDCKYW7JWi2dmZl/ybHU8KNs568zLEiLZhSk5hYh2L0bCkk/KouKJG ErFsKKVGxkSIVrK81ShjtzrhehAxauhHfGWOtKStukAnaqxuPjxfHj0nRO//R+Aef7l7 /Ok8WRZrSb5EYE6UowJbcuqnH9gESWqMRNwRO5LDbZbHQWC0Qj6hd6eb3lERaVjTcjYW N47AjURIFgYr2pTBNuvCVYVBas4Z69iZ7Hg+bukB/stdF9ekONFC0RffGyVAJyPPTw39 tNYg== X-Gm-Message-State: ALoCoQl3Psv1GcgCdAzelgPRUADSYemQTFwkxYFPqf0myNsgOFg0M9ZJM3EOLLN30cfRslQGUukwcceDa9yTxm+p5RbAiyAp1A== X-Received: by 10.98.69.80 with SMTP id s77mr265176pfa.42.1449835950289; Fri, 11 Dec 2015 04:12:30 -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: Fri, 11 Dec 2015 17:41:49 +0530 Message-Id: <1449835910-4651-3-git-send-email-siddhesh.poyarekar@linaro.org> In-Reply-To: <1449835910-4651-1-git-send-email-siddhesh.poyarekar@linaro.org> References: <1449835910-4651-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_sincos.c (__sin_local, __cos_local): Move common code... (do_sincos_2): ... a new function. (__sincos): Call do_sincos_2 for sin as well as cos. --- sysdeps/ieee754/dbl-64/s_sincos.c | 231 ++++++++++++++------------------------ 1 file changed, 84 insertions(+), 147 deletions(-) -- 2.5.0 diff --git a/sysdeps/ieee754/dbl-64/s_sincos.c b/sysdeps/ieee754/dbl-64/s_sincos.c index 078d65d..24dc43c 100644 --- a/sysdeps/ieee754/dbl-64/s_sincos.c +++ b/sysdeps/ieee754/dbl-64/s_sincos.c @@ -33,8 +33,7 @@ static double __always_inline __sin_local (double x, int4 k) { - 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 m, n; double retval = 0; @@ -94,7 +93,7 @@ __sin_local (double x, int4 k) } /* else if (k < 0x400368fd) */ /*-------------------------- 2.426265<|x|< 105414350 ----------------------*/ - else if (k < 0x419921FB) + else { t = (x * hpinv + toint); xn = t - toint; @@ -159,82 +158,6 @@ __sin_local (double x, int4 k) } } /* else if (k < 0x419921FB ) */ -/*---------------------105414350 <|x|< 281474976710656 --------------------*/ - else - { - 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; - - 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; - } - } /* else if (k < 0x42F00000 ) */ - return retval; } @@ -245,8 +168,7 @@ static double __always_inline __cos_local (double x, int4 k) { - 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 m, n; @@ -366,79 +288,75 @@ __cos_local (double x, int4 k) } } /* else if (k < 0x419921FB ) */ - else + return retval; +} + +/* 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, unsigned int n) +{ + double res, retval, cor, xx; + mynumber u; + + double eps = 1.0e-24; + + switch (n) { - 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; - - switch (n) + case 2: + a = -a; + da = -da; + /* Fall through. */ + case 0: + xx = a * a; + if (xx < 0.01588) { - case 1: - case 3: - xx = a * a; - if (n == 1) - { - 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, db, y; + int m; + if (a > 0) { - 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); + m = 1; + t = a; + db = da; } 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)); + m = 0; + t = -a; + db = -da; } - break; + 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; + case 1: + case 3: + if (a < 0) + { + a = -a; + da = -da; } - } /* else if (k < 0x42F00000 ) */ + 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; } @@ -501,13 +419,32 @@ __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, k); *cosx = __cos_local (x, k); return; } + if (k < 0x42F00000) + { + double t = (x * hpinv + toint); + double xn = t - toint; + u.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 = u.i[LOW_HALF] & 3; + double da = xn1 * pp3; + t = y - da; + da = (y - t) - da; + da = (da - xn2 * pp3) - xn * pp4; + double a = t + da; + da = (t - a) + da; + + *sinx = do_sincos_2 (a, da, x, n); + *cosx = do_sincos_2 (a, da, x, (n + 1) & 3); + return; + } if (k < 0x7ff00000) { reduce_and_compute_sincos (x, sinx, cosx);