xref: /freebsd/lib/libc/powerpc64/gen/flt_rounds.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1840b91ccSNathan Whitehorn /*	$NetBSD: flt_rounds.c,v 1.4.10.3 2002/03/22 20:41:53 nathanw Exp $	*/
2840b91ccSNathan Whitehorn 
3d915a14eSPedro F. Giffuni /*-
4*b61a5730SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
5d915a14eSPedro F. Giffuni  *
6840b91ccSNathan Whitehorn  * Copyright (c) 1996 Mark Brinicombe
7840b91ccSNathan Whitehorn  * All rights reserved.
8840b91ccSNathan Whitehorn  *
9840b91ccSNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
10840b91ccSNathan Whitehorn  * modification, are permitted provided that the following conditions
11840b91ccSNathan Whitehorn  * are met:
12840b91ccSNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
13840b91ccSNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
14840b91ccSNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
15840b91ccSNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
16840b91ccSNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
17840b91ccSNathan Whitehorn  * 3. All advertising materials mentioning features or use of this software
18840b91ccSNathan Whitehorn  *    must display the following acknowledgement:
19840b91ccSNathan Whitehorn  *      This product includes software developed by Mark Brinicombe
20840b91ccSNathan Whitehorn  *	for the NetBSD Project.
21840b91ccSNathan Whitehorn  * 4. The name of the author may not be used to endorse or promote products
22840b91ccSNathan Whitehorn  *    derived from this software without specific prior written permission
23840b91ccSNathan Whitehorn  *
24840b91ccSNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25840b91ccSNathan Whitehorn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26840b91ccSNathan Whitehorn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27840b91ccSNathan Whitehorn  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28840b91ccSNathan Whitehorn  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29840b91ccSNathan Whitehorn  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30840b91ccSNathan Whitehorn  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31840b91ccSNathan Whitehorn  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32840b91ccSNathan Whitehorn  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33840b91ccSNathan Whitehorn  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34840b91ccSNathan Whitehorn  */
35840b91ccSNathan Whitehorn 
36840b91ccSNathan Whitehorn #include <sys/types.h>
37840b91ccSNathan Whitehorn #include <machine/float.h>
38840b91ccSNathan Whitehorn 
39840b91ccSNathan Whitehorn #ifndef _SOFT_FLOAT
40840b91ccSNathan Whitehorn static const int map[] = {
41840b91ccSNathan Whitehorn 	1,	/* round to nearest */
42840b91ccSNathan Whitehorn 	0,	/* round to zero */
43840b91ccSNathan Whitehorn 	2,	/* round to positive infinity */
44840b91ccSNathan Whitehorn 	3	/* round to negative infinity */
45840b91ccSNathan Whitehorn };
46840b91ccSNathan Whitehorn 
47840b91ccSNathan Whitehorn int
__flt_rounds()48840b91ccSNathan Whitehorn __flt_rounds()
49840b91ccSNathan Whitehorn {
50840b91ccSNathan Whitehorn 	uint64_t fpscr;
51840b91ccSNathan Whitehorn 
52840b91ccSNathan Whitehorn 	__asm__ __volatile("mffs %0" : "=f"(fpscr));
53840b91ccSNathan Whitehorn 	return map[(fpscr & 0x03)];
54840b91ccSNathan Whitehorn }
55840b91ccSNathan Whitehorn #endif
56