xref: /openbsd/lib/libm/arch/hppa/s_trunc.c (revision 5af055cd)
1 /*	$OpenBSD: s_trunc.c,v 1.7 2015/01/20 04:41:01 krw 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 
26 __strong_alias(truncl, trunc);
27