xref: /openbsd/lib/libm/arch/hppa/s_trunc.c (revision 09467b48)
1 /*	$OpenBSD: s_trunc.c,v 1.8 2016/09/12 19:47:02 guenther Exp $	*/
2 /*
3  * Written by Michael Shalayeff. Public Domain
4  */
5 
6 #include <sys/types.h>
7 #include <machine/ieeefp.h>
8 #include "math.h"
9 
10 double
11 trunc(double x)
12 {
13 	u_int64_t ofpsr, fpsr;
14 
15 	__asm__ volatile("fstds %%fr0,0(%0)" :: "r" (&ofpsr) : "memory");
16 	fpsr = (ofpsr & ~((u_int64_t)FP_RM << (9 + 32))) |
17 	    ((u_int64_t)FP_RZ << (9 + 32));
18 	__asm__ volatile("fldds 0(%0), %%fr0" :: "r" (&fpsr) : "memory");
19 
20 	__asm__ volatile("frnd,dbl %0,%0" : "+f" (x));
21 
22 	__asm__ volatile("fldds 0(%0), %%fr0" :: "r" (&ofpsr) : "memory");
23 	return (x);
24 }
25 DEF_STD(trunc);
26 LDBL_UNUSED_CLONE(trunc);
27