xref: /freebsd/lib/libc/powerpc/gen/fpgetround.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
188d2dd24SPeter Grehan /*	$NetBSD: fpgetround.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $	*/
288d2dd24SPeter Grehan 
3d915a14eSPedro F. Giffuni /*-
4*b61a5730SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
5d915a14eSPedro F. Giffuni  *
688d2dd24SPeter Grehan  * Copyright (c) 1999 The NetBSD Foundation, Inc.
788d2dd24SPeter Grehan  * All rights reserved.
888d2dd24SPeter Grehan  *
988d2dd24SPeter Grehan  * This code is derived from software contributed to The NetBSD Foundation
1088d2dd24SPeter Grehan  * by Dan Winship.
1188d2dd24SPeter Grehan  *
1288d2dd24SPeter Grehan  * Redistribution and use in source and binary forms, with or without
1388d2dd24SPeter Grehan  * modification, are permitted provided that the following conditions
1488d2dd24SPeter Grehan  * are met:
1588d2dd24SPeter Grehan  * 1. Redistributions of source code must retain the above copyright
1688d2dd24SPeter Grehan  *    notice, this list of conditions and the following disclaimer.
1788d2dd24SPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
1888d2dd24SPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
1988d2dd24SPeter Grehan  *    documentation and/or other materials provided with the distribution.
2088d2dd24SPeter Grehan  *
2188d2dd24SPeter Grehan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2288d2dd24SPeter Grehan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2388d2dd24SPeter Grehan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2488d2dd24SPeter Grehan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2588d2dd24SPeter Grehan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2688d2dd24SPeter Grehan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2788d2dd24SPeter Grehan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2888d2dd24SPeter Grehan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2988d2dd24SPeter Grehan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3088d2dd24SPeter Grehan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3188d2dd24SPeter Grehan  * POSSIBILITY OF SUCH DAMAGE.
3288d2dd24SPeter Grehan  *
3388d2dd24SPeter Grehan  */
3488d2dd24SPeter Grehan 
3588d2dd24SPeter Grehan #include <sys/types.h>
3688d2dd24SPeter Grehan #include <ieeefp.h>
3788d2dd24SPeter Grehan 
3856ae1bedSRafal Jaworowski #ifndef _SOFT_FLOAT
3988d2dd24SPeter Grehan fp_rnd_t
fpgetround()4088d2dd24SPeter Grehan fpgetround()
4188d2dd24SPeter Grehan {
4288d2dd24SPeter Grehan 	u_int64_t fpscr;
4388d2dd24SPeter Grehan 
4488d2dd24SPeter Grehan 	__asm__("mffs %0" : "=f"(fpscr));
4588d2dd24SPeter Grehan 	return ((fp_rnd_t)(fpscr & 0x3));
4688d2dd24SPeter Grehan }
4756ae1bedSRafal Jaworowski #endif
48