Subject: Can someone please test enclosed code (for libc)
To: None <port-sparc@NetBSD.ORG>
From: J.T. Conklin <jtc@cygnus.com>
List: port-sparc
Date: 04/10/1995 12:05:30
Could someone please test the enclosed functions to make sure they
compile on a netbsd/sparc machine. They implement __flt_rounds(),
fpgetround(), fpgetmask(), and fpgetsticky(). These functions are
already implemented on the i386 and m68k.
I'm not sparc assembly hacker, so I wrote these using gcc's inline
assembly (to get at the floating point state register). If these
functions work, I'll get to fpsetround(), fpsetmask(), fpsetsticky(),
and a sparc version of <machine/ieeefp.h>.
--jtc
#!/bin/sh
# shar2: Shell Archiver (v1.22)
#
# Run the following text with /bin/sh to create:
# flt_rounds.c
# fpgetround.c
# fpgetmask.c
# fpgetsticky.c
#
sed 's/^X//' << 'SHAR_EOF' > flt_rounds.c &&
X/*
X * Written by J.T. Conklin, Apr 10, 1995
X * Public domain.
X */
X
Xstatic const int map[] = {
X 1, /* round to nearest */
X 0, /* round to zero */
X 3, /* round to negative infinity */
X 2 /* round to positive infinity */
X};
X
Xint
X__flt_rounds()
X{
X int x;
X
X __asm__("st %%fsr,%0" : "=m" (*&x));
X return map[(x >> 30) & 0x03];
X}
SHAR_EOF
chmod 0664 flt_rounds.c || echo "restore of flt_rounds.c fails"
sed 's/^X//' << 'SHAR_EOF' > fpgetround.c &&
X/*
X * Written by J.T. Conklin, Apr 10, 1995
X * Public domain.
X */
X
Xint
Xfpgetround()
X{
X int x;
X
X __asm__("st %%fsr,%0" : "=m" (*&x));
X return (x >> 30) & 0x03;
X}
SHAR_EOF
chmod 0666 fpgetround.c || echo "restore of fpgetround.c fails"
sed 's/^X//' << 'SHAR_EOF' > fpgetmask.c &&
X/*
X * Written by J.T. Conklin, Apr 10, 1995
X * Public domain.
X */
X
Xint
Xfpgetmask()
X{
X int x;
X
X __asm__("st %%fsr,%0" : "=m" (*&x));
X return (x >> 23) & 0x1f;
X}
SHAR_EOF
chmod 0666 fpgetmask.c || echo "restore of fpgetmask.c fails"
sed 's/^X//' << 'SHAR_EOF' > fpgetsticky.c &&
X/*
X * Written by J.T. Conklin, Apr 10, 1995
X * Public domain.
X */
X
Xint
Xfpgetsticky()
X{
X int x;
X
X __asm__("st %%fsr,%0" : "=m" (*&x));
X return (x >> 5) & 0x1f;
X}
SHAR_EOF
chmod 0666 fpgetsticky.c || echo "restore of fpgetsticky.c fails"
exit 0