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/arch/hppa/s_trunc.c | |
parent | 12e3a4da1c068fbc83b1a41ab5fd05e9cb9e3403 (diff) |
round, roundf, trunc, truncf for hppa; ok kettenis@
Diffstat (limited to 'lib/libm/arch/hppa/s_trunc.c')
-rw-r--r-- | lib/libm/arch/hppa/s_trunc.c | 27 |
1 files changed, 27 insertions, 0 deletions
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); +} |