This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: different results for expf on x86_64
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: paul zimmermann <Paul dot Zimmermann at inria dot fr>
- Cc: 'GNU C Library' <libc-alpha at sourceware dot org>
- Date: Tue, 4 Feb 2020 11:29:34 +0000
- Subject: Re: different results for expf on x86_64
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bBC3fe2OF9q5x3YCy69VHSVrCcefazJ3nlI5bdcnwiI=; b=eM5mI1I40KYdpnFG4hRSwu9cL68crdf+nGPWUj1LtwOTOYtEyEfK08cwIYUEUcj06jd2JeVYFRM7klaSfMsQuL8L9JS7S5+fD/SnCStNl21bvvoQ6ZiXXlX57C/HZRiMQ0hr+e5oy2h6U6i4ZM+E0QCo4Gj3k2HqH36vVRSs7XA8QB0AfjAHAyhCmMymSI6kBhEtbiYIqqbmTzTbYNKTHJ8zX8EdNerSmg5OY1AbgAyXXPYQYZ0eUa8d873g3B9Km6/pz14HDIhKjVVEUnaU48c/hoTJ7NxoJwFtZ4EqCYdC2dSi+50EXVYyRbfCOkmr/GnjfDO4i2z5Z875bwi3Ww==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h22gpmPToYKgOgBJprL/CnOQsqa9tjjS5IquKrGxym0MK2BYeJEe+cCx5AoZWatpHpyZ9R7s2P8icJz+mmoaki84nASgtCuwQ1eKLxnLD3qjU7PdljbpsfiBNKoIsVnHYeAzNpaxkghixIx1QjP4ZyquRHwpfzRjPN5KACDwugBZDdCYAlv0rPzuRwRod4a+RWTsY6E38pOutP05z6G2NkaeZHk9JsdfoOKiEU36gAfe51Z2B0vktxfEW1q0pgf9Lj4b1oJvKuQGdamVd0ovmGI+zd6WLAB3yNoDkYpEBfkRrpwjwQRhONJSijTGDiD5Ofwxsa+7XwRX4gnmJXBJwA==
- Original-authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco dot Dijkstra at arm dot com;
Hi Paul,
> sorry if I ask a dummy question, I'm new to the list.
>
> While performing my exhaustive tests on binary32 math functions on x86_64,
> I've noticed that for some functions, I get different numbers of incorrectly
> rounded results on different processors (all with the brand new glibc-2.31).
>
> For example for expf, on a i5-4590, I get 170648 incorrectly rounded results,
> while on a E7540, I get only 170646, i.e., 2 less.
>
> The two inputs are 3.256463242e+01 and -6.309946060e+01. For example
> on the i5-4590 I get exp(3.256463242e+01) = 1.388801499e+14.
>
> After investigating more, if I simply add printf ("z=%.16e\n", z) after
> z = InvLn2N * xd (line 80) in e_expf.c, I get 1.388801415e+14 instead,
> like on the E7540.
>
> Is that issue known? How many "flavours" of x86_64 can we have? To which
> flavour does correspond the "Wrong count: 170635" at the top of e_expf.c?
x86 has a large number of target specific implementations, including for math
functions. So you can expect different results depending on the CPU. Even on
the same CPU there are huge differences between 32-bit and 64-bit mode.
In this particular case x86_64 uses the generic math code, but compiles expf
with and without FMA. FMA causes minor rounding differences, but this is fine
since the new math functions have been designed to be used with FMA (AArch64
uses FMA by default so there is only one version).
One of the goals of rewriting math functions has been to remove the many target
specific math functions since they are often inaccurate as well as slow. The generic
math code in C outperforms existing assembler implementations by a large factor!
Cheers,
Wilco