From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 44413 invoked by alias); 19 Oct 2018 13:39:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 44374 invoked by uid 89); 19 Oct 2018 13:39:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=formula, contrast, H*f:CAEFO, H*i:CAEFO X-HELO: EUR04-DB3-obe.outbound.protection.outlook.com Received: from mail-eopbgr60040.outbound.protection.outlook.com (HELO EUR04-DB3-obe.outbound.protection.outlook.com) (40.107.6.40) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Oct 2018 13:39:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4/s719QV3/EzAtSxtmIWKvh+Uooxc6Hj+3PqZHyPj78=; b=QYJkO0lk2raOI2r9gwf5L2Mywz6yVLeAyVOuaslZI4gem4qxHxZy4oypo2k0q5SGjkZ+hmpQQWgD3BeROX9FaUl4Q2PhKHGq6A/RGZoahTOIcy0CaP2l2nOpBPE4mn5BLP8Oww78cMhC5kOYLSIjOYr77d+NwjxG954wSAOLZqY= Received: from DB5PR08MB1030.eurprd08.prod.outlook.com (10.166.14.15) by DB5PR08MB0645.eurprd08.prod.outlook.com (10.169.32.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.26; Fri, 19 Oct 2018 13:39:01 +0000 Received: from DB5PR08MB1030.eurprd08.prod.outlook.com ([fe80::f8ba:6473:782c:1f26]) by DB5PR08MB1030.eurprd08.prod.outlook.com ([fe80::f8ba:6473:782c:1f26%3]) with mapi id 15.20.1250.028; Fri, 19 Oct 2018 13:39:01 +0000 From: Wilco Dijkstra To: Giuliano Augusto Faulin Belinassi CC: GCC Patches , "giuliano.belinassi@gmail.com" , nd , Jeff Law Subject: Re: [PATCH] Add sinh(tanh(x)) and cosh(tanh(x)) rules Date: Fri, 19 Oct 2018 13:46:00 -0000 Message-ID: References: , In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-SW-Source: 2018-10/txt/msg01192.txt.bz2 Hi, >> Did you enable FMA? I'd expect 1 - x*x to be accurate with FMA, so the r= elative error >> should be much better. If there is no FMA, 2*(1-fabs(x)) - (1-fabs(x))^2= should be >> more accurate when abs(x)>0.5 and still much faster. > >No, but I will check how to enable it if FMA is available. > I did a minor test with your formula and the precision improved a lot. > But now I am puzzled about how did you come up with that formula :-). > I am able to proof equality, but how did you know it was going to be > more precise? Basically when x is close to 1, x the top N bits in the mantissa will be on= es. Then x*x has one bits in the top 2*N bits in the mantissa. Ie. we lose N bi= ts of useful information in the multiply - problematic when N gets close to the n= umber of mantissa bits. In contrast FMA computes the fully accurate result due to cancellation of the top 2*N one-bits in the subtract. If we can use (1-x) instead of x in the evaluation, we avoid losing accurac= y in the multiply when x is close to 1. Then it's basic algebra to find an equivalen= t formula that can produce 1-x^2 using 1-x. For example (1+x)*(1-x) will work fine to= o=20 (using 1+x loses 1 low bit of x). Note that these alternative evaluations lose accuracy close to 0 in exactly= the same way, so if no FMA is available you'd need to select between the 2 case= s. Wilco