From patchwork Mon Dec 14 19:24:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 58365 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp1680751lbv; Mon, 14 Dec 2015 11:24:58 -0800 (PST) X-Received: by 10.98.71.217 with SMTP id p86mr38707729pfi.162.1450121098227; Mon, 14 Dec 2015 11:24:58 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 28si177214pfj.63.2015.12.14.11.24.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Dec 2015 11:24:58 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-65586-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-65586-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-65586-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=QpyW+S5UH8Senl5RqyX5YDVvtVs5gah Ztcq1Nk7rThP1I4A/1O6hiCxCUdJVg42qExbJFx+mG2RDF08vx3cr1Z0POfHrduL yo+OK8FHL9RInZ3xHKNYbpmH40MJtCPUFS3uqLQ18XWqOvq4BjFKQJDxYIaKRST2 UYUeDxtpzZ6w= 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=/yFZJOpwt/AUmTRTXQMlLcMdCgg=; b=ni6PO Wf/rdLAIezCind6tR/GFnXlbL2z1CJ04qtsFPKthWxJUr6iu9tRJtQzngMVepoRB 6NlqpyBdyYk8sjzoaZPNBkT7Q62i225hcT2cKOcSB23FMpnPnX0KggwrqFESD1ld +Gme+9Ry1apWH6rpAjDPGt8dEEhCuSqkmimGrY= Received: (qmail 112563 invoked by alias); 14 Dec 2015 19:24:47 -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 112552 invoked by uid 89); 14 Dec 2015 19:24:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f48.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=aC2pjPiVcqzrPrb2iPd8Rywf1hahm76MTmCSpPRhRtk=; b=jz9GQ7QMOm0xTvJNf71NHc91Ao4zV0q/OyKS1huYTgSYdnfGPvLGN6BE0Fef7niPvs QgAZ7CklMFY+3s3aG1oWHS88jGXjU8nWQC9XNIbx8fJKOcr9SObfBHPMEsVMDNsIFBRW K7C2ZHiYVzh549Zv6fsx7NVR32XycbO/R0adtZN3vogUAVc2ku+AguQmCDnRM4p2rpeS 90F1+69FpleXBe0C3YcaVsvD7bHLHz5ZEvBRGNOoyupvCdlfTvvkdHEgYe6xMgtjhlSg ZtFUzKHTp/mBdMiM3cejcQqX7snlslPFAkv4eUM4GdcKzu0YM648xN/HhfORjmtjzXxG F5Zg== X-Gm-Message-State: ALoCoQlRFIBt2h0D/FA9+xTF4ca3umvupo4tpcBRh2Bwu7OkP1tTz8+hdNuljvmvsKSlK1vUXLdyWDYzWlO8wRTsdpJl33bTqg== X-Received: by 10.67.22.99 with SMTP id hr3mr47868485pad.10.1450121080324; Mon, 14 Dec 2015 11:24:40 -0800 (PST) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: Siddhesh Poyarekar Subject: [PATCH 1/3] Consolidate range reduction in sincos for x > 281474976710656 Date: Tue, 15 Dec 2015 00:54:09 +0530 Message-Id: <1450121051-19759-2-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> Range reduction needs to be done only once for sin and cos, so copy over all of the relevant functions (__sin, __cos, reduce_and_compute) and consolidate common code. Siddhesh * sysdeps/ieee754/dbl-64/s_sin.c (__sin) [!IN_SINCOS]: Skip common code for sincos. (__cos) [!IN_SINCOS]: Likewise. * sysdeps/ieee754/dbl-64/s_sincos.c (reduce_and_compute_sincos): New function. (__sincos): Use it. --- sysdeps/ieee754/dbl-64/s_sin.c | 4 +++ sysdeps/ieee754/dbl-64/s_sincos.c | 55 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) -- 2.5.0 diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c index a635a86..b619905 100644 --- a/sysdeps/ieee754/dbl-64/s_sin.c +++ b/sysdeps/ieee754/dbl-64/s_sin.c @@ -497,6 +497,7 @@ __sin (double x) } } /* else if (k < 0x42F00000 ) */ +#ifndef IN_SINCOS /* -----------------281474976710656 <|x| <2^1024----------------------------*/ else if (k < 0x7ff00000) retval = reduce_and_compute (x, 0); @@ -508,6 +509,7 @@ __sin (double x) __set_errno (EDOM); retval = x / x; } +#endif return retval; } @@ -729,6 +731,7 @@ __cos (double x) } } /* else if (k < 0x42F00000 ) */ +#ifndef IN_SINCOS /* 281474976710656 <|x| <2^1024 */ else if (k < 0x7ff00000) retval = reduce_and_compute (x, 1); @@ -739,6 +742,7 @@ __cos (double x) __set_errno (EDOM); retval = x / x; /* |x| > 2^1024 */ } +#endif return retval; } diff --git a/sysdeps/ieee754/dbl-64/s_sincos.c b/sysdeps/ieee754/dbl-64/s_sincos.c index 2a3fc06..f50ffa6 100644 --- a/sysdeps/ieee754/dbl-64/s_sincos.c +++ b/sysdeps/ieee754/dbl-64/s_sincos.c @@ -27,13 +27,64 @@ #define IN_SINCOS 1 #include "s_sin.c" +/* Consolidated version of reduce_and_compute in s_sin.c that does range + reduction only once and computes sin and cos together. */ +static inline void +__always_inline +reduce_and_compute_sincos (double x, double *sinx, double *cosx) +{ + double a, da; + unsigned int n = __branred (x, &a, &da); + + n = n & 3; + + if (n == 1 || n == 2) + { + a = -a; + da = -da; + } + + if (n & 1) + { + double *temp = cosx; + cosx = sinx; + sinx = temp; + } + + if (a * a < 0.01588) + *sinx = bsloww (a, da, x, n); + else + *sinx = bsloww1 (a, da, x, n); + *cosx = bsloww2 (a, da, x, n); +} + void __sincos (double x, double *sinx, double *cosx) { + mynumber u; + int k; + SET_RESTORE_ROUND_53BIT (FE_TONEAREST); - *sinx = __sin (x); - *cosx = __cos (x); + u.x = x; + k = 0x7fffffff & u.i[HIGH_HALF]; + + if (k < 0x42F00000) + { + *sinx = __sin_local (x); + *cosx = __cos_local (x); + return; + } + if (k < 0x7ff00000) + { + reduce_and_compute_sincos (x, sinx, cosx); + return; + } + + if (isinf (x)) + __set_errno (EDOM); + + *sinx = *cosx = x / x; } weak_alias (__sincos, sincos) #ifdef NO_LONG_DOUBLE