From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22802 invoked by alias); 9 Mar 2018 15:53:02 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 22786 invoked by uid 89); 9 Mar 2018 15:53:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH 6/6] Remove slow paths from sin/cos Date: Fri, 09 Mar 2018 15:53:00 -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;DB6PR0801MB1256;7:oVEmI7kjZmJ8okkdk6u4sqyGu7X4JM4yDLaTCmdQzJgmam1JbS+Ydu33FjlU+0I+2mOAep1y2IgEED52MvBdSHv12UyAeUBq9zzXrQNPon5tX059UVfEC2IAMf68KuOz4CjjrTF3XHedhjpSAMvbUHbRX8VQcj6WBvKs83U+qDs8ZIq0gwJUA0WbjpckedpuV2rncOqqyh7GiHvCFCTyyUlWbtW9fLlJrjNqFkN/5/HojUd/aKHO8WGfvI1L0FZ9 x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: da73746d-2a77-4a5c-b2a3-08d585d5d2eb x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(2017052603328)(7153060)(7193020);SRVR:DB6PR0801MB1256; x-ms-traffictypediagnostic: DB6PR0801MB1256: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231220)(944501244)(52105095)(6055026)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DB6PR0801MB1256;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0801MB1256; x-forefront-prvs: 0606BBEB39 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(366004)(346002)(39380400002)(39860400002)(376002)(199004)(189003)(377424004)(54534003)(316002)(33656002)(7696005)(2501003)(2351001)(68736007)(5250100002)(3846002)(25786009)(4326008)(6116002)(99286004)(106356001)(5660300001)(3660700001)(6916009)(53936002)(2900100001)(105586002)(26005)(8936002)(55016002)(66066001)(81156014)(5640700003)(8676002)(81166006)(6436002)(9686003)(102836004)(3280700002)(575784001)(6506007)(86362001)(74316002)(2906002)(305945005)(59450400001)(478600001)(97736004)(72206003)(7736002)(14454004);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0801MB1256;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: VmLgx4V79taHFqZFldtu8+7mtBEzWSyUXXS01T3fTfmPlI5773PSgHb8NVSNxkhgFGeD5y3e3mKqONFCBcTZ2WyUdM1wfdlQ8Bs5TEJMwyUtbmj8MOgpn/71xN2LASkyQrAJnRxSbYHz88mn1d5mDp4Cer4XnRL1hUapyC2e3kWEY4eOtjzseGyAPHg1DOdA/ifVe+c2RoL4VZohFSiABxmAYKbw9AqMIzc1UDVLU4Vnp3RGmyvKAMmwvTrrbjXCNfst+m+i7Z+Z++05t/7PsP6YjHqtrNAu+CnOsNBTLODCSmLnPzbuQzUJWL50Bq5fRdVB7bNla/iB55Mx/HTUeA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: da73746d-2a77-4a5c-b2a3-08d585d5d2eb X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Mar 2018 15:52:55.5202 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1256 X-SW-Source: 2018-03/txt/msg00234.txt.bz2 Restructure the sincos implementation - rather than rely on odd partial inl= ining of preprocessed portions from sin and cos, explicitly write out the cases. ChangeLog: 2018-03-09 Wilco Dijkstra * sysdeps/ieee754/dbl-64/s_sin.c (__sin): Cleanup ifdefs. (__cos): Likewise. * sysdeps/ieee754/dbl-64/s_sin.c (__sincos): Reimplement using the same logic as sin and cos. -- diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c index 91b0abc9c3ac21dae0e673576940ef97bfd20c23..8f804a42e6d94652a62f81b2e0b= 053135cf9f03a 100644 --- a/sysdeps/ieee754/dbl-64/s_sin.c +++ b/sysdeps/ieee754/dbl-64/s_sin.c @@ -208,12 +208,9 @@ do_sincos (double a, double da, int4 n) /* An ultimate sin routine. Given an IEEE double machine number x */ /* it computes the correctly rounded (to nearest) value of sin(x) */ /*******************************************************************/ -#ifdef IN_SINCOS -static double -#else +#ifndef IN_SINCOS double SECTION -#endif __sin (double x) { double xx, t, a, da; @@ -221,9 +218,7 @@ __sin (double x) int4 k, m, n; double retval =3D 0; =20 -#ifndef IN_SINCOS SET_RESTORE_ROUND_53BIT (FE_TONEAREST); -#endif =20 u.x =3D x; m =3D u.i[HIGH_HALF]; @@ -257,7 +252,6 @@ __sin (double x) retval =3D __copysign (do_cos (t, hp1), x); } /* else if (k < 0x400368fd) */ =20 -#ifndef IN_SINCOS /*-------------------------- 2.426265<|x|< 105414350 ---------------------= -*/ else if (k < 0x419921FB) { @@ -278,12 +272,6 @@ __sin (double x) __set_errno (EDOM); retval =3D x / x; } -#else - /* Disable warning... */ - n =3D 0, n =3D n; - a =3D 0, a =3D a; - da =3D 0, da =3D da; -#endif =20 return retval; } @@ -294,12 +282,8 @@ __sin (double x) /* it computes the correctly rounded (to nearest) value of cos(x) */ /*******************************************************************/ =20 -#ifdef IN_SINCOS -static double -#else double SECTION -#endif __cos (double x) { double y, xx, a, da; @@ -308,9 +292,7 @@ __cos (double x) =20 double retval =3D 0; =20 -#ifndef IN_SINCOS SET_RESTORE_ROUND_53BIT (FE_TONEAREST); -#endif =20 u.x =3D x; m =3D u.i[HIGH_HALF]; @@ -340,8 +322,6 @@ __cos (double x) retval =3D __copysign (do_sin (a, da), a); } /* else if (k < 0x400368fd) */ =20 - -#ifndef IN_SINCOS else if (k < 0x419921FB) { /* 2.426265<|x|< 105414350 */ n =3D reduce_sincos (x, &a, &da); @@ -361,10 +341,6 @@ __cos (double x) __set_errno (EDOM); retval =3D x / x; /* |x| > 2^1024 */ } -#else - /* Disable warning... */ - n =3D 0, n =3D n; -#endif =20 return retval; } @@ -375,3 +351,5 @@ libm_alias_double (__cos, cos) #ifndef __sin libm_alias_double (__sin, sin) #endif + +#endif diff --git a/sysdeps/ieee754/dbl-64/s_sincos.c b/sysdeps/ieee754/dbl-64/s_s= incos.c index 4335ecbba3c9894e61c087ac970b392fa73abfab..c04972707b284e37b15e82933a0= 0250cda959985 100644 --- a/sysdeps/ieee754/dbl-64/s_sincos.c +++ b/sysdeps/ieee754/dbl-64/s_sincos.c @@ -23,9 +23,7 @@ #include #include =20 -#define __sin __sin_local -#define __cos __cos_local -#define IN_SINCOS 1 +#define IN_SINCOS #include "s_sin.c" =20 void @@ -37,31 +35,79 @@ __sincos (double x, double *sinx, double *cosx) SET_RESTORE_ROUND_53BIT (FE_TONEAREST); =20 u.x =3D x; - k =3D 0x7fffffff & u.i[HIGH_HALF]; + k =3D u.i[HIGH_HALF] & 0x7fffffff; =20 if (k < 0x400368fd) { - *sinx =3D __sin_local (x); - *cosx =3D __cos_local (x); - return; - } - if (k < 0x419921FB) - { - double a, da; - int4 n =3D reduce_sincos (x, &a, &da); - - *sinx =3D do_sincos (a, da, n); - *cosx =3D do_sincos (a, da, n + 1); + double t, xx, a, da, y; + /* |x| < 2^-27 =3D> cos (x) =3D 1, sin (x) =3D x. */ + if (k < 0x3e400000) + { + if (k < 0x3e500000) + math_check_force_underflow (x); + *sinx =3D x; + *cosx =3D 1.0; + return; + } + /* |x| < 0.855469. */ + else if (k < 0x3feb6000) + { + /* |x| < 0.25. */ + if (k < 0x3fd00000) + { + xx =3D x * x; + t =3D POLYNOMIAL (xx) * (xx * x); + *sinx =3D x + t; + } + else + *sinx =3D __copysign (do_sin (x, 0), x); + *cosx =3D do_cos (x, 0); + return; + } =20 + /* |x| < 2.426265. */ + y =3D hp0 - fabs (x); + a =3D y + hp1; + da =3D (y - a) + hp1; + *sinx =3D __copysign (do_cos (a, da), x); + xx =3D a * a; + if (xx < 0.01588) + *cosx =3D TAYLOR_SIN (xx, a, da); + else + *cosx =3D __copysign (do_sin (a, da), a); return; } + /* |x| < 2^1024. */ if (k < 0x7ff00000) { - double a, da; - int4 n =3D __branred (x, &a, &da); + double a, da, xx; + unsigned int n; =20 - *sinx =3D do_sincos (a, da, n); - *cosx =3D do_sincos (a, da, n + 1); + /* If |x| < 105414350 use simple range reduction. */ + n =3D k < 0x419921FB ? reduce_sincos (x, &a, &da) : __branred (x, &a= , &da); + n =3D n & 3; + + if (n =3D=3D 1 || n =3D=3D 2) + { + a =3D -a; + da =3D -da; + } + + if (n & 1) + { + double *temp =3D cosx; + cosx =3D sinx; + sinx =3D temp; + } + + xx =3D a * a; + if (xx < 0.01588) + *sinx =3D TAYLOR_SIN (xx, a, da); + else + *sinx =3D __copysign (do_sin (a, da), a); + xx =3D do_cos (a, da); + *cosx =3D (n & 2) ? -xx : xx; + return; } =20 if (isinf (x))