Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Mar 2021 14:28:05 GMT
From:      Alex Richardson <arichardson@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 0e4ff0acbe80 - main - AArch64: Don't set flush-subnormals-to-zero flag on startup
Message-ID:  <202103011428.121ES5tq066994@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by arichardson:

URL: https://cgit.FreeBSD.org/src/commit/?id=0e4ff0acbe80c547988bede738af2e227c7eb47c

commit 0e4ff0acbe80c547988bede738af2e227c7eb47c
Author:     Alex Richardson <arichardson@FreeBSD.org>
AuthorDate: 2021-03-01 14:27:30 +0000
Commit:     Alex Richardson <arichardson@FreeBSD.org>
CommitDate: 2021-03-01 14:27:30 +0000

    AArch64: Don't set flush-subnormals-to-zero flag on startup
    
    This flag has been set on startup since 65618fdda0f272a823e6701966421bdca0efa301.
    However, This causes some of the math-related tests to fail as they report
    zero instead of a tiny number. This fixes at least
    /usr/tests/lib/msun/ldexp_test and possibly others.
    Additionally, setting this flag prevents printf() from printing subnormal
    numbers in decimal form.
    See also https://www.openwall.com/lists/musl/2021/02/26/1
    
    PR:             253847
    Reviewed By:    mmel
    Differential Revision: https://reviews.freebsd.org/D28938
---
 lib/libc/tests/stdio/printfloat_test.c | 35 +++++++++++++++++++++++++++++++++-
 sys/arm64/arm64/vm_machdep.c           |  2 +-
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/lib/libc/tests/stdio/printfloat_test.c b/lib/libc/tests/stdio/printfloat_test.c
index 97629fb0d2b1..736ba1b493ef 100644
--- a/lib/libc/tests/stdio/printfloat_test.c
+++ b/lib/libc/tests/stdio/printfloat_test.c
@@ -50,7 +50,7 @@ smash_stack(void)
 {
 	static uint32_t junk = 0xdeadbeef;
 	uint32_t buf[512];
-	int i;
+	size_t i;
 
 	for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++)
 		buf[i] = junk;
@@ -370,6 +370,37 @@ ATF_TC_BODY(hexadecimal_rounding, tc)
 	testfmt("0x1.83p+0", "%.2a", 1.51);
 }
 
+ATF_TC_WITHOUT_HEAD(subnormal_double);
+ATF_TC_BODY(subnormal_double, tc)
+{
+	/* Regression test for https://bugs.freebsd.org/253847 */
+	double positive = __DBL_DENORM_MIN__;
+	testfmt("4.9406564584124654418e-324", "%20.20g", positive);
+	testfmt("4.9406564584124654418E-324", "%20.20G", positive);
+	testfmt("0x1p-1074", "%a", positive);
+	testfmt("0X1P-1074", "%A", positive);
+	double negative = -__DBL_DENORM_MIN__;
+	testfmt("-4.9406564584124654418e-324", "%20.20g", negative);
+	testfmt("-4.9406564584124654418E-324", "%20.20G", negative);
+	testfmt("-0x1p-1074", "%a", negative);
+	testfmt("-0X1P-1074", "%A", negative);
+}
+
+ATF_TC_WITHOUT_HEAD(subnormal_float);
+ATF_TC_BODY(subnormal_float, tc)
+{
+	float positive = __FLT_DENORM_MIN__;
+	testfmt("1.4012984643248170709e-45", "%20.20g", positive);
+	testfmt("1.4012984643248170709E-45", "%20.20G", positive);
+	testfmt("0x1p-149", "%a", positive);
+	testfmt("0X1P-149", "%A", positive);
+	float negative = -__FLT_DENORM_MIN__;
+	testfmt("-1.4012984643248170709e-45", "%20.20g", negative);
+	testfmt("-1.4012984643248170709E-45", "%20.20G", negative);
+	testfmt("-0x1p-149", "%a", negative);
+	testfmt("-0X1P-149", "%A", negative);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -384,6 +415,8 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, decimal_rounding);
 	ATF_TP_ADD_TC(tp, hexadecimal_floating_point);
 	ATF_TP_ADD_TC(tp, hexadecimal_rounding);
+	ATF_TP_ADD_TC(tp, subnormal_double);
+	ATF_TP_ADD_TC(tp, subnormal_float);
 
 	return (atf_no_error());
 }
diff --git a/sys/arm64/arm64/vm_machdep.c b/sys/arm64/arm64/vm_machdep.c
index d4dd32caef06..9a496b40ec98 100644
--- a/sys/arm64/arm64/vm_machdep.c
+++ b/sys/arm64/arm64/vm_machdep.c
@@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/vfp.h>
 #endif
 
-uint32_t initial_fpcr = VFPCR_DN | VFPCR_FZ;
+uint32_t initial_fpcr = VFPCR_DN;
 
 #include <dev/psci/psci.h>
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103011428.121ES5tq066994>