xref: /freebsd/lib/libc/powerpcspe/gen/flt_rounds.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1*dc9b124dSJustin Hibbits /*	$NetBSD: flt_rounds.c,v 1.4.10.3 2002/03/22 20:41:53 nathanw 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  * Redistribution and use in source and binary forms, with or without
8*dc9b124dSJustin Hibbits  * modification, are permitted provided that the following conditions
9*dc9b124dSJustin Hibbits  * are met:
10*dc9b124dSJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
11*dc9b124dSJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
12*dc9b124dSJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
13*dc9b124dSJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
14*dc9b124dSJustin Hibbits  *    documentation and/or other materials provided with the distribution.
15*dc9b124dSJustin Hibbits  * 3. All advertising materials mentioning features or use of this software
16*dc9b124dSJustin Hibbits  *    must display the following acknowledgement:
17*dc9b124dSJustin Hibbits  *      This product includes software developed by Mark Brinicombe
18*dc9b124dSJustin Hibbits  *	for the NetBSD Project.
19*dc9b124dSJustin Hibbits  * 4. The name of the author may not be used to endorse or promote products
20*dc9b124dSJustin Hibbits  *    derived from this software without specific prior written permission
21*dc9b124dSJustin Hibbits  *
22*dc9b124dSJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23*dc9b124dSJustin Hibbits  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24*dc9b124dSJustin Hibbits  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25*dc9b124dSJustin Hibbits  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26*dc9b124dSJustin Hibbits  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27*dc9b124dSJustin Hibbits  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28*dc9b124dSJustin Hibbits  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29*dc9b124dSJustin Hibbits  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30*dc9b124dSJustin Hibbits  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31*dc9b124dSJustin Hibbits  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*dc9b124dSJustin Hibbits  */
33*dc9b124dSJustin Hibbits 
34*dc9b124dSJustin Hibbits #include <sys/types.h>
35*dc9b124dSJustin Hibbits #include <machine/float.h>
36*dc9b124dSJustin Hibbits #include <machine/spr.h>
37*dc9b124dSJustin Hibbits 
38*dc9b124dSJustin Hibbits #ifndef _SOFT_FLOAT
39*dc9b124dSJustin Hibbits static const int map[] = {
40*dc9b124dSJustin Hibbits 	1,	/* round to nearest */
41*dc9b124dSJustin Hibbits 	0,	/* round to zero */
42*dc9b124dSJustin Hibbits 	2,	/* round to positive infinity */
43*dc9b124dSJustin Hibbits 	3	/* round to negative infinity */
44*dc9b124dSJustin Hibbits };
45*dc9b124dSJustin Hibbits 
46*dc9b124dSJustin Hibbits int
__flt_rounds()47*dc9b124dSJustin Hibbits __flt_rounds()
48*dc9b124dSJustin Hibbits {
49*dc9b124dSJustin Hibbits 	uint32_t fpscr;
50*dc9b124dSJustin Hibbits 
51*dc9b124dSJustin Hibbits 	__asm__ __volatile("mfspr %0, %1" : "=r"(fpscr) : "K"(SPR_SPEFSCR));
52*dc9b124dSJustin Hibbits 	return map[(fpscr & 0x03)];
53*dc9b124dSJustin Hibbits }
54*dc9b124dSJustin Hibbits #endif
55