xref: /freebsd/lib/libc/powerpcspe/gen/fpgetround.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1*dc9b124dSJustin Hibbits /*	$NetBSD: fpgetround.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $	*/
2*dc9b124dSJustin Hibbits 
3*dc9b124dSJustin Hibbits /*
4*dc9b124dSJustin Hibbits  * Copyright (c) 2016 Justin Hibbits
5*dc9b124dSJustin Hibbits  * All rights reserved.
6*dc9b124dSJustin Hibbits  *
7*dc9b124dSJustin Hibbits  * This code is derived from software contributed to The NetBSD Foundation
8*dc9b124dSJustin Hibbits  * by Dan Winship.
9*dc9b124dSJustin Hibbits  *
10*dc9b124dSJustin Hibbits  * Redistribution and use in source and binary forms, with or without
11*dc9b124dSJustin Hibbits  * modification, are permitted provided that the following conditions
12*dc9b124dSJustin Hibbits  * are met:
13*dc9b124dSJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
14*dc9b124dSJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
15*dc9b124dSJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
16*dc9b124dSJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
17*dc9b124dSJustin Hibbits  *    documentation and/or other materials provided with the distribution.
18*dc9b124dSJustin Hibbits  *
19*dc9b124dSJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*dc9b124dSJustin Hibbits  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*dc9b124dSJustin Hibbits  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*dc9b124dSJustin Hibbits  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*dc9b124dSJustin Hibbits  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*dc9b124dSJustin Hibbits  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*dc9b124dSJustin Hibbits  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*dc9b124dSJustin Hibbits  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*dc9b124dSJustin Hibbits  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*dc9b124dSJustin Hibbits  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*dc9b124dSJustin Hibbits  * POSSIBILITY OF SUCH DAMAGE.
30*dc9b124dSJustin Hibbits  *
31*dc9b124dSJustin Hibbits  */
32*dc9b124dSJustin Hibbits 
33*dc9b124dSJustin Hibbits #include <sys/types.h>
34*dc9b124dSJustin Hibbits #include <machine/spr.h>
35*dc9b124dSJustin Hibbits #include <ieeefp.h>
36*dc9b124dSJustin Hibbits 
37*dc9b124dSJustin Hibbits #ifndef _SOFT_FLOAT
38*dc9b124dSJustin Hibbits fp_rnd_t
fpgetround()39*dc9b124dSJustin Hibbits fpgetround()
40*dc9b124dSJustin Hibbits {
41*dc9b124dSJustin Hibbits 	uint32_t fpscr;
42*dc9b124dSJustin Hibbits 
43*dc9b124dSJustin Hibbits 	__asm__ __volatile("mfspr %0, %1" : "=r"(fpscr) : "K"(SPR_SPEFSCR));
44*dc9b124dSJustin Hibbits 	return ((fp_rnd_t)(fpscr & 0x3));
45*dc9b124dSJustin Hibbits }
46*dc9b124dSJustin Hibbits #endif
47