NetBSD Problem Report #58781
From www@netbsd.org Mon Oct 28 19:12:50 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 970461A9238
for <gnats-bugs@gnats.NetBSD.org>; Mon, 28 Oct 2024 19:12:50 +0000 (UTC)
Message-Id: <20241028191249.00DD11A923B@mollari.NetBSD.org>
Date: Mon, 28 Oct 2024 19:12:48 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: fesetround and fpsetround are out of sync on some architectures
X-Send-Pr-Version: www-1.0
>Number: 58781
>Category: lib
>Synopsis: fesetround and fpsetround are out of sync on some architectures
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Oct 28 19:15:00 +0000 2024
>Last-Modified: Wed Oct 30 19:39:11 +0000 2024
>Originator: Taylor R Campbell
>Release: current, 10, 9, ...
>Organization:
The NetBSD Roundation
>Environment:
>Description:
On sparc64, fesetround sets %fsr (floating-point status register), but that only affects float and double arithmetic (IEEE 754 binary32 and binary64), which is computed in hardware by CPU instructions. Long double arithmetic is computed in software by libc softfloat, which doesn't respect %fsr and instead has its own global variable _softfloat_float_rounding_mode -- which in turn should really be a thread-local variable.
This is probably not the only mistake of this class. We need to audit the following architectures which have separate fesetround and fpsetround implementations:
1. [x] aarch64 (libc fpsetround, libm fesetround; libgcc_s softfloat128 (respects %fpcr) and/or compiler-rt softfloat128 (ignores %fpcr) for long double -- see PR lib/58789: aarch64 long double arithmetic is haunted <https://gnats.netbsd.org/58789>)
2. [x] alpha (libc fpsetround, fenv.h fesetround; long double is double, no separate softfloat long double)
3. [ ] arm (libc fpsetround, softfloat fpsetround, libm fesetround)
4. [ ] hppa (libc fpsetround, libm fesetround)
5. [ ] i386 (libc fpsetround, libm fesetround; remember to sync x87 and SSE state -- PR port-i386/57684: fpsetround(3) fails to set SSE rounding mode <https://gnats.netbsd.org/57684>)
6. [ ] ia64 (libc fpsetround, fenv.h fesetround; mind the shifted constants -- FP_* and FE_* are both shifted, but fpsetround shifts while fesetround does not, so fpsetround is broken)
7. [ ] m68k (libc hardfloat/fpsetround, softfloat fpsetround, fpfake.c fpsetround, fenv.h fesetround)
8. [ ] mips (libc fpsetround, softfloat fpsetround, fenv.h fesetround)
9. [ ] or1k (libc fpsetround, softfloat fpsetround, missing fesetround?)
10. [ ] powerpc (libc fpsetround, softfloat(?) fpsetround, fenv.h fesetround)
11. [ ] powerpc64 (libc fpsetround, softfloat(?) fpsetround, powerpc/fenv.h fesetround)
12. [ ] riscv (libc fpsetround, softfloat/softfloat128 fpsetround, libm fesetround)
13. [ ] sparc (libc fpsetround, softfloat128 fpsetround, libm fesetround)
14. [ ] sparc64 (libc fpsetround, softfloat128 fpsetround, libm fesetround)
15. [ ] x86_64 (libc fpsetround, libm fesetround; remember to sync x87 and SSE state)
Also need to make sure that fegetround, fpgetround, and FLT_ROUNDS all agree on which variable to query.
Looks like sh3 only has fesetround in fenv.h, no fpsetround at all -- which is maybe a separate bug that should be fixed (although fpsetround is a legacy BSD API that has been superseded by C99 fenv.h).
>How-To-Repeat:
On a sparc64 system:
cd /usr/tests/lib/libm && atf-run t_fe_round | atf-report
Notice lots of long double rounding operations in non-default rounding modes fail, like nearbyintl and rintl.
>Fix:
Yes, please!
>Release-Note:
>Audit-Trail:
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.