diff options
| author | christos <christos@NetBSD.org> | 2011-03-26 19:51:41 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2011-03-26 19:51:41 +0000 |
| commit | e4e8b603b9faca61bed3b6e6a2cec8d5fdbfa1af (patch) | |
| tree | baf0eec759a1337c5477481340726870c1e1df9c /lib/libc | |
| parent | 2ad467a9ee42e17c25a47216a0b7f15c5702f753 (diff) | |
add fpgetprec/fpsetprec
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/arch/i386/gen/Makefile.inc | 5 | ||||
| -rw-r--r-- | lib/libc/arch/i386/gen/fpgetprec.S | 22 | ||||
| -rw-r--r-- | lib/libc/arch/i386/gen/fpsetprec.S | 34 | ||||
| -rw-r--r-- | lib/libc/arch/x86_64/gen/Makefile.inc | 5 | ||||
| -rw-r--r-- | lib/libc/arch/x86_64/gen/fpgetprec.S | 25 | ||||
| -rw-r--r-- | lib/libc/arch/x86_64/gen/fpsetprec.S | 39 | ||||
| -rw-r--r-- | lib/libc/gen/Makefile.inc | 5 | ||||
| -rw-r--r-- | lib/libc/gen/fpgetmask.3 | 78 | ||||
| -rw-r--r-- | lib/libc/include/namespace.h | 4 |
9 files changed, 187 insertions, 30 deletions
diff --git a/lib/libc/arch/i386/gen/Makefile.inc b/lib/libc/arch/i386/gen/Makefile.inc index 4c845e75eb9..66449fb2fe1 100644 --- a/lib/libc/arch/i386/gen/Makefile.inc +++ b/lib/libc/arch/i386/gen/Makefile.inc @@ -1,9 +1,10 @@ -# $NetBSD: Makefile.inc,v 1.26 2009/12/06 07:12:17 uebayasi Exp $ +# $NetBSD: Makefile.inc,v 1.27 2011/03/26 19:51:41 christos Exp $ # objects built from assembler sources (need lint stubs) SRCS+= alloca.S byte_swap_2.S byte_swap_4.S fabs.S \ flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S \ - fpsetmask.S fpsetround.S fpsetsticky.S + fpsetmask.S fpsetround.S fpsetsticky.S fpgetprec.S \ + fpsetprec.S SRCS+= setjmp.S _setjmp.S sigsetjmp.S diff --git a/lib/libc/arch/i386/gen/fpgetprec.S b/lib/libc/arch/i386/gen/fpgetprec.S new file mode 100644 index 00000000000..1514bb480d7 --- /dev/null +++ b/lib/libc/arch/i386/gen/fpgetprec.S @@ -0,0 +1,22 @@ +/* $NetBSD: fpgetprec.S,v 1.1 2011/03/26 19:51:41 christos Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include <machine/asm.h> + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetprec, _fpgetprec) +ENTRY(_fpgetprec) +#else +ENTRY(fpgetprec) +#endif + subl $4,%esp + fnstcw (%esp) + movl (%esp),%eax + rorl $8,%eax + andl $3,%eax + addl $4,%esp + ret diff --git a/lib/libc/arch/i386/gen/fpsetprec.S b/lib/libc/arch/i386/gen/fpsetprec.S new file mode 100644 index 00000000000..c587ed2c53c --- /dev/null +++ b/lib/libc/arch/i386/gen/fpsetprec.S @@ -0,0 +1,34 @@ +/* $NetBSD: fpsetprec.S,v 1.1 2011/03/26 19:51:41 christos Exp $ */ + +/* + * Written by Charles M. Hannum, Apr 9, 1995 + * Public domain. + */ + +#include <machine/asm.h> + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetprec, _fpsetprec) +ENTRY(_fpsetprec) +#else +ENTRY(fpsetprec) +#endif + subl $4,%esp + + fnstcw (%esp) + movl (%esp),%eax + + rorl $8,%eax + movl %eax,%edx + andl $3,%eax + + subl %eax,%edx + movl 8(%esp),%ecx + andl $3,%ecx + orl %ecx,%edx + roll $8,%edx + movl %edx,(%esp) + fldcw (%esp) + + addl $4,%esp + ret diff --git a/lib/libc/arch/x86_64/gen/Makefile.inc b/lib/libc/arch/x86_64/gen/Makefile.inc index 3f794563a11..de53e99df9f 100644 --- a/lib/libc/arch/x86_64/gen/Makefile.inc +++ b/lib/libc/arch/x86_64/gen/Makefile.inc @@ -1,9 +1,10 @@ -# $NetBSD: Makefile.inc,v 1.15 2010/01/14 02:09:46 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.16 2011/03/26 19:51:42 christos Exp $ # objects built from assembler sources (need lint stubs) SRCS+= alloca.S byte_swap_2.S byte_swap_4.S byte_swap_8.S fabs.S \ flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S \ - fpsetmask.S fpsetround.S fpsetsticky.S + fpsetmask.S fpsetround.S fpsetsticky.S fpgetprec.S \ + fpsetprec.S SRCS+= __setjmp14.S SRCS+= _setjmp.S diff --git a/lib/libc/arch/x86_64/gen/fpgetprec.S b/lib/libc/arch/x86_64/gen/fpgetprec.S new file mode 100644 index 00000000000..d3728fa3bc9 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpgetprec.S @@ -0,0 +1,25 @@ +/* $NetBSD: fpgetprec.S,v 1.1 2011/03/26 19:51:42 christos Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX store only x87 state. If an application only uses the fp* + * interface, this should be in sync with the SSE mxcsr register. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetprec, _fpgetprec) +ENTRY(_fpgetprec) +#else +ENTRY(fpgetprec) +#endif + fnstcw -4(%rsp) + movl -4(%rsp),%eax + rorl $8,%eax + andl $3,%eax + ret diff --git a/lib/libc/arch/x86_64/gen/fpsetprec.S b/lib/libc/arch/x86_64/gen/fpsetprec.S new file mode 100644 index 00000000000..43410c61aa5 --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpsetprec.S @@ -0,0 +1,39 @@ +/* $NetBSD: fpsetprec.S,v 1.1 2011/03/26 19:51:42 christos Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD. + * Public domain. + */ + +#include <machine/asm.h> + +/* + * XXX set both the x87 control word and the SSE mxcsr register. + * Applications should only set exception and round flags + * via the fp*() interface, otherwise the status words + * will get our of sync. + */ + + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetprec, _fpsetprec) +ENTRY(_fpsetprec) +#else +ENTRY(fpsetprec) +#endif + fnstcw -4(%rsp) + + andl $3,%edi + + movl -4(%rsp),%edx + rorl $8,%edx + movl %edx,%eax + andl $3,%eax + + andl $~3,%edx + orl %edi,%edx + roll $8,%edx + movl %edx,-4(%rsp) + + fldcw -4(%rsp) + ret diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 8de8e67f32e..5f658913e49 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.177 2011/03/16 01:30:24 erh Exp $ +# $NetBSD: Makefile.inc,v 1.178 2011/03/26 19:51:42 christos Exp $ # from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # gen sources @@ -96,7 +96,8 @@ MLINKS+=extattr.3 extattr_namespace_to_string.3 \ extattr.3 extattr_string_to_namespace.3 MLINKS+=fpgetmask.3 fpgetround.3 fpgetmask.3 fpgetsticky.3 \ fpgetmask.3 fpsetmask.3 fpgetmask.3 fpsetround.3 \ - fpgetmask.3 fpsetsticky.3 + fpgetmask.3 fpsetsticky.3 fpgetmask.3 fpgetprec.3 \ + fpgetmask.3 fpsetprec.3 MLINKS+=fts.3 fts_open.3 fts.3 fts_read.3 fts.3 fts_children.3 \ fts.3 fts_set.3 fts.3 fts_close.3 MLINKS+=ftw.3 nftw.3 diff --git a/lib/libc/gen/fpgetmask.3 b/lib/libc/gen/fpgetmask.3 index 04b27ff1f13..d28a6fd6585 100644 --- a/lib/libc/gen/fpgetmask.3 +++ b/lib/libc/gen/fpgetmask.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fpgetmask.3,v 1.10 2008/04/30 13:10:50 martin Exp $ +.\" $NetBSD: fpgetmask.3,v 1.11 2011/03/26 19:51:42 christos Exp $ .\" .\" Copyright (c) 1999 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,14 +27,16 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 4, 2004 +.Dd March 26, 2011 .Dt FPGETMASK 3 .Os .Sh NAME .Nm fpgetmask , +.Nm fpgetprec , .Nm fpgetround , .Nm fpgetsticky , .Nm fpsetmask , +.Nm fpsetprec , .Nm fpsetround , .Nm fpsetsticky .Nd IEEE FP mode control @@ -42,35 +44,37 @@ .Lb libc .Sh SYNOPSIS .In ieeefp.h -.Ft fp_except +.Ft fp_except_t .Fn fpgetmask void -.Ft fp_rnd +.Ft fp_prec_t +.Fn fpgetprec void +.Ft fp_rnd_t .Fn fpgetround void -.Ft fp_except +.Ft fp_except_t .Fn fpgetsticky void -.Ft fp_except -.Fn fpsetmask fp_except\ mask -.Ft fp_rnd -.Fn fpsetround fp_rnd\ rnd_dir -.Ft fp_except -.Fn fpsetsticky fp_except\ sticky +.Ft fp_except_t +.Fn fpsetmask "fp_except_t mask" +.Ft fp_prec_t +.Fn fpsetprec "fp_prec_t prec" +.Ft fp_rnd_t +.Fn fpsetround "fp_rnd_t rnd_dir" +.Ft fp_except_t +.Fn fpsetsticky "fp_except_t sticky" .Sh DESCRIPTION -A rounding mode is one of -.Dv FP_RZ , FP_RM , FP_RN , -or -.Dv FP_RP , -for rounding towards zero, rounding -.Pq Em Minus infinity -down, rounding to -.Em nearest , -and rounding -.Pq Em Plus infinity -up. +A rounding mode +.Ft fp_rnd_t +is one of: +.Bl -column -offset indent FP_RZ +.It Dv FP_RZ Ta rounding towards Em zero +.It Dv FP_RM Ta rounding down to Pq Em Minus infinity +.It Dv FP_RN Ta rounding to Em nearest +.It Dv FP_RP Ta rounding down to Pq Em Plus infinity +.El The default mode is .Dv FP_RN . .Pp An -.Ft fp_except +.Ft fp_except_t value is a bitmask specifying an exception type and containing any of the values listed below. .Bl -column -offset indent FP_X_UFLxx @@ -82,6 +86,16 @@ the values listed below. .It Dv FP_X_IOV Ta Integer\ Overflow .El .Pp +An +.Ft fp_prec_t +specifies the precision of the floating point operations listed below. +.Bl -column -offset indent FP_RPS +.It Dv FP_PS Ta Dv 24 bit (single-precision) +.It Dv FP_PRS Ta reserved +.It Dv FP_PD Ta Dv 53 bit (double-precision) +.It Dv FP_PE Ta Dv 64 bit (extended-precision) +.El +.Pp The .Fn fpsetmask function will set the current exception mask, i.e., it will cause @@ -92,6 +106,14 @@ The .Fn fpgetmask function will return the current exception mask. .Pp +The +.Fn fpgetprec +function will return the current floating point precision. +The +.Fn fpsetprec +function will set the floating point precision and will return +the previous precision. +.Pp The .Fn fpsetround function will cause future operations to use the specified dynamic @@ -138,3 +160,13 @@ functions return the exception mask and exception history bits. .Sh SEE ALSO .Xr sigaction 2 +.Xr fenv 3 +.Sh BUGS +There is no way to return an unsupported value. +Not all processors support all the modes. +These interfaces are deprecated and the ones +in +.Xr fenv 3 +should be used, although the interfaces in +.Xr fenv 3 +don't support getting or setting the precision. diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h index 1b953fec6b2..80928ec7094 100644 --- a/lib/libc/include/namespace.h +++ b/lib/libc/include/namespace.h @@ -1,4 +1,4 @@ -/* $NetBSD: namespace.h,v 1.147 2011/03/12 19:52:48 christos Exp $ */ +/* $NetBSD: namespace.h,v 1.148 2011/03/26 19:51:42 christos Exp $ */ /*- * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. @@ -265,9 +265,11 @@ #define fnmatch _fnmatch #define fparseln _fparseln #define fpgetmask _fpgetmask +#define fpgetprec _fpgetprec #define fpgetround _fpgetround #define fpgetsticky _fpgetsticky #define fpsetmask _fpsetmask +#define fpsetprec _fpsetprec #define fpsetround _fpsetround #define fpsetsticky _fpsetsticky #define freenetconfigent _freenetconfigent |
