NetBSD Problem Report #54232

From gson@gson.org  Sun May 26 11:30:01 2019
Return-Path: <gson@gson.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 0400D7A156
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 26 May 2019 11:30:00 +0000 (UTC)
Message-Id: <20190526112956.54354989DF5@guava.gson.org>
Date: Sun, 26 May 2019 14:29:56 +0300 (EEST)
From: gson@gson.org (Andreas Gustafsson)
Reply-To: gson@gson.org (Andreas Gustafsson)
To: gnats-bugs@NetBSD.org
Subject: lib/libm/t_cos:cosf_angles regression on i386
X-Send-Pr-Version: 3.95

>Number:         54232
>Category:       lib
>Synopsis:       lib/libm/t_cos:cosf_angles regression on i386
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May 26 11:35:00 +0000 2019
>Closed-Date:    Mon May 27 17:32:03 +0000 2019
>Last-Modified:  Mon May 27 17:32:03 +0000 2019
>Originator:     Andreas Gustafsson
>Release:        NetBSD-current, source date >= 2018.11.08.20.29.37
>Organization:

>Environment:
System: NetBSD
Architecture: i386
Machine: i386
>Description:

The cosf_angles test case of the lib/libm/t_cos test program is
failing on i386, but not on amd64, since November 2018.  It started
failing some time between Nov 5 and Nov 8, during a period when the
system failed to build and/or install.

It's failing both in qemu and on real hardware:

  http://releng.netbsd.org/b5reports/i386/commits-2018.11.html#2018.11.08.20.29.37

  http://www.gson.org/netbsd/bugs/build/i386-baremetal/2019/2019.05.09.05.00.31/test.html#lib_libm_t_cos_cosf_angles

>How-To-Repeat:

Run the test on i386.

>Fix:

>Release-Note:

>Audit-Trail:
From: coypu@sdf.org
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/54232: lib/libm/t_cos:cosf_angles regression on i386
Date: Sun, 26 May 2019 22:47:48 +0000

 Riastradh suggested checking FLT_EVAL_METHOD.
 amd64: 0
 i386: 2

 So it's doing these calculations with long double.

From: coypu@sdf.org
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/54232: lib/libm/t_cos:cosf_angles regression on i386
Date: Sun, 26 May 2019 22:30:05 +0000

 The commits switched x86 (32 and 64bit) to stop using x87 trigonometric functions.
 So, this calculation (from lib/libm/src/k_sinf.c:44)* differs, and possibly other things too:
 * This is part of the code that runs in this calculation.


 #!/bin/sh
 cat << EOF > AAAtest.c
 #include <stdio.h>
 static const float
 half =  5.0000000000e-01,/* 0x3f000000 */
 S1  = -1.6666667163e-01, /* 0xbe2aaaab */
 S2  =  8.3333337680e-03, /* 0x3c088889 */
 S3  = -1.9841270114e-04, /* 0xb9500d01 */
 S4  =  2.7557314297e-06, /* 0x3638ef1b */
 S5  = -2.5050759689e-08, /* 0xb2d72f34 */
 S6  =  1.5896910177e-10; /* 0x2f2ec9d3 */
 int main() {
 	float z = 0.274155766;
 	printf("%.18g\n", S2+z*(S3+z*(S4+z*(S5+z*S6))));
 	return 0;
 }
 EOF
 gcc AAAtest.c -m32 -o 32
 gcc AAAtest.c -o 64
 ./32
 ./64


 outputs:
 0.00827914439122296592
 0.0082791447639465332

 Switching to more precision gets a result closer to the 32bit version.

 I don't understand why this is calculated very differently.

From: "Maya Rashish" <maya@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54232 CVS commit: src/tests/lib/libm
Date: Mon, 27 May 2019 00:10:36 +0000

 Module Name:	src
 Committed By:	maya
 Date:		Mon May 27 00:10:36 UTC 2019

 Modified Files:
 	src/tests/lib/libm: t_cos.c

 Log Message:
 on i386 with FLT_EVAL_METHOD=2, the computation inside cosf was done in
 binary80 arithmetic and never rounded to binary32 at the end, so it
 appeared farther from the correctly rounded result in binary32 than expected.

 Force binary32 using volatile float.

 PR lib/54232: lib/libm/t_cos:cosf_angles regression on i386

 From Riastradh.


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libm/t_cos.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: maya@NetBSD.org
State-Changed-When: Mon, 27 May 2019 01:19:57 +0000
State-Changed-Why:
Is this suceeding for you now?


State-Changed-From-To: feedback->closed
State-Changed-By: gson@NetBSD.org
State-Changed-When: Mon, 27 May 2019 17:32:03 +0000
State-Changed-Why:
The test now passes.  Thank you!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.