Port-alpha archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

NetBSD 9.2 Alpha: error in handling of IEEE 754 binary 32-bit subnormals



The latest episode of the BSDNow podcast at

	https://www.bsdnow.tv/419

contains a story on Remy van Elst's report at

	https://raymii.org/s/articles/NetBSD_on_QEMU_Alpha.html

of creating a virtual machine for NetBSD 9.2 (really, 9.99.88, but
packages are still pulled from the 9.2 repository, which is currently
identical to the 9.0 repository).

Remy reported that NetBSD on Alpha requires a patch to QEMU, and I was
independently able to verify that on the latest QEMU release, 6.1.0,
which appeared on 24 August 2021.  With the patch, the VM startup hangs at the
same point that Remy reported. 

I applied Remy's proposed patch, successfully built qemu-system-alpha
for that release, and got the NetBSD installer to run to completion.

I now have an apparently stable running NetBSD on Alpha, with a few
irregularities: emacs seems to hang on startup, and the PostgreSQL
package collection is incomplete.  MySQL is installed: Ver 15.1
Distrib 10.3.31-MariaDB.

I've now begun testing on NetBSD Alpha a large mathematical library
that I'm developing, and already have running successfully on numerous
operating systems and CPU architectures (AMD64 (x86_64), ARM32, ARM64,
Alpha, HPPA (PA-RISC), M68K, MIPS32, MIPS64, RISC-V64, S390x, SPARC64,
and x86) in various physical and virtual machines in our large test
farm of more than 500 O/S--CPU pairs.

The Debian 11 Alpha port of my library passes all of its tests, and
test output matches satisfactorily with that from other CPU types.

However, for NetBSD Alpha, I quickly found an anomaly: IEEE 754 binary
32-bit subnormals are printed incorrectly.  The small Web site at

	http://www.math.utah.edu/~beebe/netbsd-alpha/

currently contains these files:

	-rw-rw-r-- 1 1591 Jul 23 15:39 show-float32.c
	-r--r--r-- 1 1526 Sep 14 10:35 show-float32.lst-Linux-alpha
	-r--r--r-- 1 1523 Jul 23 11:48 show-float32.lst-Linux-sparc64
	-r--r--r-- 1 1526 Sep 14 10:16 show-float32.lst-Linux-x86_64
	-r--r--r-- 1 1544 Sep 13 07:19 show-float32.lst-NetBSD-alpha
	-r--r--r-- 1 1526 Sep 14 10:54 show-float32.lst-NetBSD-alpha-mieee

	-rw-rw-r-- 1  803 Sep 11 09:20 ufl32.c
	-r--r--r-- 1 1493 Sep 14 10:33 ufl32.lst-Linux-alpha
	-r--r--r-- 1 1493 Sep 14 10:58 ufl32.lst-Linux-alpha-mieee
	-r--r--r-- 1 1493 Sep 14 10:31 ufl32.lst-Linux-sparc64
	-r--r--r-- 1 1493 Sep 14 10:29 ufl32.lst-Linux-x86_64
	-r--r--r-- 1 1399 Sep 14 10:30 ufl32.lst-NetBSD-alpha
	-r--r--r-- 1 1491 Sep 14 10:53 ufl32.lst-NetBSD-alpha-mieee

The test programs are run like this:

	cc show-float32.c -lm && ./a.out
	cc ufl32.c        -lm && ./a.out

The memory contents for the subnormals from show-float32.c are correct
and consistent with other platforms, but the decimal and hexadecimal
values are completely wrong: they far exceed the 32-bit exponent
range, and are near the underflow limits of the 64-bit format.

The test code is straightforward and short, and simply uses scalbnf()
to create the powers of two that are printed.  The memory patterns
exonerate scalbnf(): its returned values are correct.  However, the
printf() output is completely wrong.

The C compiler versions are gcc 10.2.1 on Debian, and 10.3.0 on
NetBSD.

Another anomaly is shown by the ufl32.c program: it reports the status
of the IEEE 754 floating-point underflow and inexact flags, and
whether the result is subnormal or not.  The SPARC64 flag settings are
as expected, and the AMD64 flags differ because of the different
rounding behavior of those two architectures. There is a discussion
and explanation here in the section that begins on page 10:

	http://www.math.utah.edu/~beebe/ufl/pages-13-21.pdf

However, the Linux and NetBSD outputs of ufl32.c show that the Linux
Alpha test shows correct expected exception flags, but the NetBSD
Alpha demonstrates that underflow is abrupt: subnormals are computed
as zero.

Adding the compiler flag -mieee to the tests produces the output in
the *.lst-*-mieee files.  For the ufl32.c test, that flag produces no
changes in the Linux output, but the NetBSD output now has nonzero
subnormals, and the exception flags are all unexpectedly zero.  The
NetBSD is consistent with what DEC did on our physical Alpha systems
(all now retired) on OSF/1 and Tru64: default to abrupt underflow, but
restore it with gcc's -mieee, or its equivalent, but differently
named, flag for DEC's native compilers.

Because both Debian and NetBSD VMs are running on QEMU (6.0.0 and
6.1.0, respectively), the Alpha architecture is almost 30 years old,
and QEMU is generally a solid and reliable emulation of numerous
architectures, the different flag behavior for subnormals is
unexpected, and it seems that NetBSD is wrong here too.


-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe%math.utah.edu@localhost  -
- 155 S 1400 E RM 233                       beebe%acm.org@localhost  beebe%computer.org@localhost -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------


Home | Main Index | Thread Index | Old Index