diff options
author | Martynas Venckus <martynas@cvs.openbsd.org> | 2009-07-15 20:08:44 +0000 |
---|---|---|
committer | Martynas Venckus <martynas@cvs.openbsd.org> | 2009-07-15 20:08:44 +0000 |
commit | 2d64145026946ef281fa3700543852ff2b5a745b (patch) | |
tree | 5c7aad949a11031d8f055f90da16c096b0541447 /lib/libm | |
parent | 12e3a4da1c068fbc83b1a41ab5fd05e9cb9e3403 (diff) |
round, roundf, trunc, truncf for hppa; ok kettenis@
Diffstat (limited to 'lib/libm')
-rw-r--r-- | lib/libm/Makefile | 5 | ||||
-rw-r--r-- | lib/libm/arch/hppa/s_round.c | 27 | ||||
-rw-r--r-- | lib/libm/arch/hppa/s_roundf.c | 27 | ||||
-rw-r--r-- | lib/libm/arch/hppa/s_trunc.c | 27 | ||||
-rw-r--r-- | lib/libm/arch/hppa/s_truncf.c | 27 |
5 files changed, 111 insertions, 2 deletions
diff --git a/lib/libm/Makefile b/lib/libm/Makefile index 80ecc5dd1ac..46cec8c24ab 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.66 2009/04/19 16:48:02 martynas Exp $ +# $OpenBSD: Makefile,v 1.67 2009/07/15 20:08:43 martynas Exp $ # $NetBSD: Makefile,v 1.28 1995/11/20 22:06:19 jtc Exp $ # # @(#)Makefile 5.1beta 93/09/24 @@ -54,7 +54,8 @@ ARCH_SRCS = e_acos.S e_asin.S e_atanh.S e_cosh.S e_exp.S e_log.S e_log10.S \ .elif (${MACHINE_ARCH} == "hppa") .PATH: ${.CURDIR}/arch/hppa ARCH_SRCS = e_sqrt.c e_sqrtf.c e_remainder.c e_remainderf.c \ - s_ceil.c s_ceilf.c s_floor.c s_floorf.c s_rint.c s_rintf.c + s_ceil.c s_ceilf.c s_floor.c s_floorf.c s_rint.c s_rintf.c \ + s_round.c s_roundf.c s_trunc.c s_truncf.c .elif (${MACHINE_ARCH} == "sh") .PATH: ${.CURDIR}/arch/sh ARCH_SRCS = e_sqrt.c e_sqrtf.c s_fabsf.c diff --git a/lib/libm/arch/hppa/s_round.c b/lib/libm/arch/hppa/s_round.c new file mode 100644 index 00000000000..2182450b841 --- /dev/null +++ b/lib/libm/arch/hppa/s_round.c @@ -0,0 +1,27 @@ +/* + * Written by Michael Shalayeff. Public Domain + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: s_round.c,v 1.1 2009/07/15 20:08:43 martynas Exp $"; +#endif + +#include <sys/types.h> +#include <machine/ieeefp.h> +#include "math.h" + +double +round(double x) +{ + u_int64_t ofpsr, fpsr; + + __asm__ __volatile__("fstds %%fr0,0(%1)" : "=m" (ofpsr) : "r" (&ofpsr)); + fpsr = (ofpsr & ~((u_int64_t)FP_RM << (9 + 32))) | + ((u_int64_t)FP_RN << (9 + 32)); + __asm__ __volatile__("fldds 0(%0), %%fr0" :: "r" (&fpsr)); + + __asm__ __volatile__("frnd,dbl %0,%0" : "+f" (x)); + + __asm__ __volatile__("fldds 0(%0), %%fr0" :: "r" (&ofpsr)); + return (x); +} diff --git a/lib/libm/arch/hppa/s_roundf.c b/lib/libm/arch/hppa/s_roundf.c new file mode 100644 index 00000000000..a1e44d5bd23 --- /dev/null +++ b/lib/libm/arch/hppa/s_roundf.c @@ -0,0 +1,27 @@ +/* + * Written by Michael Shalayeff. Public Domain + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: s_roundf.c,v 1.1 2009/07/15 20:08:43 martynas Exp $"; +#endif + +#include <sys/types.h> +#include <machine/ieeefp.h> +#include "math.h" + +float +roundf(float x) +{ + u_int64_t ofpsr, fpsr; + + __asm__ __volatile__("fstds %%fr0,0(%1)" : "=m" (ofpsr) : "r" (&ofpsr)); + fpsr = (ofpsr & ~((u_int64_t)FP_RM << (9 + 32))) | + ((u_int64_t)FP_RN << (9 + 32)); + __asm__ __volatile__("fldds 0(%0), %%fr0" :: "r" (&fpsr)); + + __asm__ __volatile__("frnd,sgl %0,%0" : "+f" (x)); + + __asm__ __volatile__("fldds 0(%0), %%fr0" :: "r" (&ofpsr)); + return (x); +} diff --git a/lib/libm/arch/hppa/s_trunc.c b/lib/libm/arch/hppa/s_trunc.c new file mode 100644 index 00000000000..b253948d9dc --- /dev/null +++ b/lib/libm/arch/hppa/s_trunc.c @@ -0,0 +1,27 @@ +/* + * Written by Michael Shalayeff. Public Domain + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: s_trunc.c,v 1.1 2009/07/15 20:08:43 martynas Exp $"; +#endif + +#include <sys/types.h> +#include <machine/ieeefp.h> +#include "math.h" + +double +trunc(double x) +{ + u_int64_t ofpsr, fpsr; + + __asm__ __volatile__("fstds %%fr0,0(%1)" : "=m" (ofpsr) : "r" (&ofpsr)); + fpsr = (ofpsr & ~((u_int64_t)FP_RM << (9 + 32))) | + ((u_int64_t)FP_RZ << (9 + 32)); + __asm__ __volatile__("fldds 0(%0), %%fr0" :: "r" (&fpsr)); + + __asm__ __volatile__("frnd,dbl %0,%0" : "+f" (x)); + + __asm__ __volatile__("fldds 0(%0), %%fr0" :: "r" (&ofpsr)); + return (x); +} diff --git a/lib/libm/arch/hppa/s_truncf.c b/lib/libm/arch/hppa/s_truncf.c new file mode 100644 index 00000000000..c8459f1f660 --- /dev/null +++ b/lib/libm/arch/hppa/s_truncf.c @@ -0,0 +1,27 @@ +/* + * Written by Michael Shalayeff. Public Domain + */ + +#if defined(LIBM_SCCS) && !defined(lint) +static char rcsid[] = "$OpenBSD: s_truncf.c,v 1.1 2009/07/15 20:08:43 martynas Exp $"; +#endif + +#include <sys/types.h> +#include <machine/ieeefp.h> +#include "math.h" + +float +truncf(float x) +{ + u_int64_t ofpsr, fpsr; + + __asm__ __volatile__("fstds %%fr0,0(%1)" : "=m" (ofpsr) : "r" (&ofpsr)); + fpsr = (ofpsr & ~((u_int64_t)FP_RM << (9 + 32))) | + ((u_int64_t)FP_RZ << (9 + 32)); + __asm__ __volatile__("fldds 0(%0), %%fr0" :: "r" (&fpsr)); + + __asm__ __volatile__("frnd,sgl %0,%0" : "+f" (x)); + + __asm__ __volatile__("fldds 0(%0), %%fr0" :: "r" (&ofpsr)); + return (x); +} |