xref: /openbsd/lib/libm/arch/hppa/s_trunc.c (revision 642e4c0c)
1 /*	$OpenBSD: s_trunc.c,v 1.9 2023/01/27 16:43:33 miod 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
trunc(double x)11 trunc(double x)
12 {
13 	u_int64_t ofpsr, fpsr;
14 
15 	__asm__ volatile("fstds %%fr0,0(%1)" : "=m" (ofpsr) : "r" (&ofpsr));
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), "m" (fpsr));
19 
20 	__asm__ volatile("frnd,dbl %0,%0" : "+f" (x));
21 
22 	__asm__ volatile("fldds 0(%0), %%fr0" :: "r" (&ofpsr), "m" (ofpsr));
23 	return (x);
24 }
25 DEF_STD(trunc);
26 LDBL_UNUSED_CLONE(trunc);
27