NetBSD Problem Report #58782

From www@netbsd.org  Mon Oct 28 21:29:07 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 2E48A1A9238
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 28 Oct 2024 21:29:07 +0000 (UTC)
Message-Id: <20241028212905.E4EED1A923B@mollari.NetBSD.org>
Date: Mon, 28 Oct 2024 21:29:05 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: fpsetround flips all the other fpcsr bits on aarch64
X-Send-Pr-Version: www-1.0

>Number:         58782
>Category:       port-arm
>Synopsis:       fpsetround flips all the other fpcsr bits on aarch64
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    riastradh
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 28 21:30:00 +0000 2024
>Closed-Date:    Wed Nov 20 14:24:05 +0000 2024
>Last-Modified:  Wed Nov 20 14:24:05 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9
>Organization:
The NetBSD Roundfliption
>Environment:
>Description:
The aarch64 implementation of fpsetround() from <ieeefp.h> has the effect of flipping all bits _other_ than the rounding mode in the fpcr, the floating-point control register.

     48 	const uint32_t old_fpcr = reg_fpcr_read();
     49 	const uint32_t new_fpcr = (~old_fpcr & ~FPCR_RMODE)
     50 	    | __SHIFTIN(rnd, FPCR_RMODE);
     51 	reg_fpcr_write(new_fpcr);

https://nxr.netbsd.org/xref/src/lib/libc/arch/aarch64/gen/fpsetround.c?r=1.3#49

As a result, for example, setting the rounding mode has the side effect of toggling flush-to-zero (no gradual underflow) mode.
>How-To-Repeat:
$ cat noftz.c
#include <float.h>
#include <ieeefp.h>
#include <stdio.h>

int
main(void)
{
	volatile double x = DBL_MIN;
	volatile double y;

	y = x/2;
	printf("%a\n", y);
	fpsetround(FP_RN);
	y = x/2;
	printf("%a\n", y);
	fpsetround(FP_RN);
	y = x/2;
	printf("%a\n", y);
	fflush(stdout);
	return ferror(stdout);
}
$ make ftz
cc -O2    -o ftz ftz.c 
$ ./ftz
0x1p-1023
0x0p+0
0x1p-1023

>Fix:
nix the extra ~

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58782 CVS commit: src/tests/lib/libc/gen
Date: Mon, 28 Oct 2024 21:48:55 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Oct 28 21:48:55 UTC 2024

 Modified Files:
 	src/tests/lib/libc/gen: t_fpsetround.c

 Log Message:
 fpsetround(3): Test that this doesn't flip on FTZ by accident.

 PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64


 To generate a diff of this commit:
 cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/gen/t_fpsetround.c

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

Responsible-Changed-From-To: port-arm-maintainer->riastradh
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Tue, 29 Oct 2024 20:05:19 +0000
Responsible-Changed-Why:
mine


State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 29 Oct 2024 20:05:19 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-9 and pullup-10


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58782 CVS commit: src
Date: Tue, 29 Oct 2024 20:04:31 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Oct 29 20:04:30 UTC 2024

 Modified Files:
 	src/lib/libc/arch/aarch64/gen: fpsetround.c
 	src/tests/lib/libc/gen: t_fpsetround.c

 Log Message:
 fpsetround(3): Don't toggle all the other bits in fpcr on aarch64.

 PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64


 To generate a diff of this commit:
 cvs rdiff -u -r1.3 -r1.4 src/lib/libc/arch/aarch64/gen/fpsetround.c
 cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/gen/t_fpsetround.c

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

From: Rin Okuyama <rokuyama.rk@gmail.com>
To: gnats-bugs@netbsd.org, port-arm-maintainer@netbsd.org,
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: port-arm/58782: fpsetround flips all the other fpcsr bits on
 aarch64
Date: Thu, 31 Oct 2024 21:30:31 +0900

 I've requested pullup to netbsd-10 as [pullup-10 #996]:
 https://releng.netbsd.org/cgi-bin/req-10.cgi?show=996

 Needs tests and pullup also for netbsd-9.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58782 CVS commit: [netbsd-10] src
Date: Fri, 1 Nov 2024 14:58:08 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Nov  1 14:58:08 UTC 2024

 Modified Files:
 	src/lib/libc/arch/aarch64/gen [netbsd-10]: fpsetround.c
 	src/tests/lib/libc/gen [netbsd-10]: t_fpsetround.c

 Log Message:
 Pull up following revision(s) (requested by rin in ticket #996):

 	tests/lib/libc/gen/t_fpsetround.c: revision 1.7
 	tests/lib/libc/gen/t_fpsetround.c: revision 1.8
 	lib/libc/arch/aarch64/gen/fpsetround.c: revision 1.4

 fpsetround(3): Test that this doesn't flip on FTZ by accident.
 PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64

 fpsetround(3): Don't toggle all the other bits in fpcr on aarch64.
 PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.2.24.1 src/lib/libc/arch/aarch64/gen/fpsetround.c
 cvs rdiff -u -r1.6 -r1.6.52.1 src/tests/lib/libc/gen/t_fpsetround.c

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

State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sun, 17 Nov 2024 16:26:48 +0000
State-Changed-Why:
pullup-9 #1923 https://releng.netbsd.org/cgi-bin/req-9.cgi?show=1923


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58782 CVS commit: [netbsd-9] src
Date: Wed, 20 Nov 2024 14:04:55 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Wed Nov 20 14:04:55 UTC 2024

 Modified Files:
 	src/lib/libc/arch/aarch64/gen [netbsd-9]: fpsetround.c
 	src/tests/lib/libc/gen [netbsd-9]: t_fpsetround.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #1923):

 	tests/lib/libc/gen/t_fpsetround.c: revision 1.7
 	tests/lib/libc/gen/t_fpsetround.c: revision 1.8
 	lib/libc/arch/aarch64/gen/fpsetround.c: revision 1.4

 fpsetround(3): Test that this doesn't flip on FTZ by accident.
 PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64

 fpsetround(3): Don't toggle all the other bits in fpcr on aarch64.
 PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.2.16.1 src/lib/libc/arch/aarch64/gen/fpsetround.c
 cvs rdiff -u -r1.6 -r1.6.44.1 src/tests/lib/libc/gen/t_fpsetround.c

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

State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Wed, 20 Nov 2024 14:24:05 +0000
State-Changed-Why:
fixed in HEAD, pulled up to 9 and 10


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.