From patchwork Wed Mar 21 17:55:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 26404 Received: (qmail 36522 invoked by alias); 21 Mar 2018 17:55:34 -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 36486 invoked by uid 89); 21 Mar 2018 17:55:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=0126 X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH 6/7] sin/cos slow paths: refactor duplicated code into dosin Date: Wed, 21 Mar 2018 17:55:28 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB1813; 7:WclsU+fCi+HBMgTctojdQSv+1tRADvWeTpJodkx2vS+yFaGrTAPpJ84AHXCQ1W4MMA6gxLlSftdNCgWAGOQEq9Eg9dNelCLXEbRhfqk3zPtRtz2EYhN/263AOJlBeXCdB019g3l7lnGZZSlySSqGhLljawEKEPI73DZU0OP+ll8/Hts65l65hEo/ztQvbnAhgtEGtfD//DVptBIuM8yjz/xio8pIwQybnml4tdubD5/Kr8WqSPXxOZkuIF3kkiJb x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 4445fc0a-2649-4d3a-112a-08d58f54eeca x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(2017052603328)(7153060)(7193020); SRVR:DB6PR0801MB1813; x-ms-traffictypediagnostic: DB6PR0801MB1813: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231221)(944501325)(52105095)(93006095)(93001095)(6055026)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DB6PR0801MB1813; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB1813; x-forefront-prvs: 0618E4E7E1 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(376002)(396003)(346002)(39860400002)(39380400002)(199004)(189003)(377424004)(54534003)(102836004)(478600001)(305945005)(8936002)(2351001)(9686003)(3660700001)(7696005)(5660300001)(66066001)(86362001)(55016002)(105586002)(6436002)(81166006)(5640700003)(8676002)(53936002)(6916009)(6116002)(106356001)(575784001)(2900100001)(3280700002)(6506007)(2906002)(81156014)(3846002)(25786009)(4326008)(68736007)(7736002)(99286004)(26005)(5250100002)(2501003)(14454004)(316002)(33656002)(97736004)(72206003)(74316002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB1813; H:DB6PR0801MB2053.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: MqnAMxhakdQWneDPDAacyh65O5KO6+LIhIcozs77tDNob72PDJgDvy28AsT0M05R67H6VDwT0pdEvVyqUjcekoOam6i/m1xeggnWgx5qTSb6VY2/OLu94+eL7gURKRSP4RZuz49+S5CuWgLebsnyRRomLNxBM44ny2EDhST13E3SEKos3FZ/7cwTQoI/Q/a9oZhHjl6IIDk0D6qrRZv3UAFX1IBGA2D2Zp3dbBAMTjCvzGsq+8/Nx0ySA8QL8Mj9ff/6aaFQk59ILhv96xGY3ZRljQcHfS7nefK+rX8GgLR8qPfaiPjnYqaWFor6nNmcxlAt7X1edxXdVfXRpfZ8iQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4445fc0a-2649-4d3a-112a-08d58f54eeca X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2018 17:55:28.8725 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1813 Refactor duplicated code into do_sin. Since all calls to do_sin use copysign to set the sign of the result, move it inside do_sin. Small inputs use a separate polynomial, so move this into do_sin as well (the check is based on the more conservative case when doing large range reduction, but could be relaxed). ChangeLog: 2018-03-20 Wilco Dijkstra * sysdeps/ieee754/dbl-64/s_sin.c (do_sin): Use TAYLOR_SIN for small inputs. Return correct sign. (do_sincos): Remove small input check before do_sin, let do_sin set the sign. (__sin): Likewise. (__cos): Likewise. diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c index 7a55636889f186849f638c4c510ee29dd007d655..e4a2153bb8d010d72d898c0d08e9253f4173f51d 100644 --- a/sysdeps/ieee754/dbl-64/s_sin.c +++ b/sysdeps/ieee754/dbl-64/s_sin.c @@ -124,6 +124,11 @@ static inline double __always_inline do_sin (double x, double dx) { + double xold = x; + /* Max ULP is 0.501 if |x| < 0.126, otherwise ULP is 0.518. */ + if (fabs (x) < 0.126) + return TAYLOR_SIN (x * x, x, dx); + mynumber u; if (x <= 0) @@ -137,7 +142,7 @@ do_sin (double x, double dx) c = x * dx + xx * (cs2 + xx * (cs4 + xx * cs6)); SINCOS_TABLE_LOOKUP (u, sn, ssn, cs, ccs); cor = (ssn + s * ccs - sn * c) + cs * s; - return sn + cor; + return __copysign (sn + cor, xold); } /* Reduce range of x to within PI/2 with abs (x) < 105414350. The high part @@ -181,14 +186,8 @@ do_sincos (double a, double da, int4 n) /* Max ULP is 0.513. */ retval = do_cos (a, da); else - { - double xx = a * a; - /* Max ULP is 0.501 if xx < 0.01588, otherwise ULP is 0.518. */ - if (xx < 0.01588) - retval = TAYLOR_SIN (xx, a, da); - else - retval = __copysign (do_sin (a, da), a); - } + /* Max ULP is 0.501 if xx < 0.01588, otherwise ULP is 0.518. */ + retval = do_sin (a, da); return (n & 2) ? -retval : retval; } @@ -207,7 +206,7 @@ SECTION __sin (double x) { #ifndef IN_SINCOS - double xx, t, a, da; + double t, a, da; mynumber u; int4 k, m, n; double retval = 0; @@ -228,20 +227,11 @@ __sin (double x) math_check_force_underflow (x); retval = x; } - /*---------------------------- 2^-26 < |x|< 0.25 ----------------------*/ - else if (k < 0x3fd00000) - { - xx = x * x; - /* Taylor series. */ - t = POLYNOMIAL (xx) * (xx * x); - /* Max ULP of x + t is 0.535. */ - retval = x + t; - } /* else if (k < 0x3fd00000) */ -/*---------------------------- 0.25<|x|< 0.855469---------------------- */ +/*--------------------------- 2^-26<|x|< 0.855469---------------------- */ else if (k < 0x3feb6000) { /* Max ULP is 0.548. */ - retval = __copysign (do_sin (x, 0), x); + retval = do_sin (x, 0); } /* else if (k < 0x3feb6000) */ /*----------------------- 0.855469 <|x|<2.426265 ----------------------*/ @@ -292,7 +282,7 @@ SECTION #endif __cos (double x) { - double y, xx, a, da; + double y, a, da; mynumber u; #ifndef IN_SINCOS int4 k, m, n; @@ -325,13 +315,9 @@ __cos (double x) y = hp0 - fabs (x); a = y + hp1; da = (y - a) + hp1; - xx = a * a; /* Max ULP is 0.501 if xx < 0.01588 or 0.518 otherwise. Range reduction uses 106 bits here which is sufficient. */ - if (xx < 0.01588) - retval = TAYLOR_SIN (xx, a, da); - else - retval = __copysign (do_sin (a, da), a); + retval = do_sin (a, da); } /* else if (k < 0x400368fd) */