xref: /freebsd/lib/libc/powerpc/gen/fpgetround.c (revision 56ae1bed483309cf68c5089a8b45f607d1e4773e)
188d2dd24SPeter Grehan /*	$NetBSD: fpgetround.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $	*/
288d2dd24SPeter Grehan 
388d2dd24SPeter Grehan /*
488d2dd24SPeter Grehan  * Copyright (c) 1999 The NetBSD Foundation, Inc.
588d2dd24SPeter Grehan  * All rights reserved.
688d2dd24SPeter Grehan  *
788d2dd24SPeter Grehan  * This code is derived from software contributed to The NetBSD Foundation
888d2dd24SPeter Grehan  * by Dan Winship.
988d2dd24SPeter Grehan  *
1088d2dd24SPeter Grehan  * Redistribution and use in source and binary forms, with or without
1188d2dd24SPeter Grehan  * modification, are permitted provided that the following conditions
1288d2dd24SPeter Grehan  * are met:
1388d2dd24SPeter Grehan  * 1. Redistributions of source code must retain the above copyright
1488d2dd24SPeter Grehan  *    notice, this list of conditions and the following disclaimer.
1588d2dd24SPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
1688d2dd24SPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
1788d2dd24SPeter Grehan  *    documentation and/or other materials provided with the distribution.
1888d2dd24SPeter Grehan  * 3. All advertising materials mentioning features or use of this software
1988d2dd24SPeter Grehan  *    must display the following acknowledgement:
2088d2dd24SPeter Grehan  *	This product includes software developed by the NetBSD
2188d2dd24SPeter Grehan  *	Foundation, Inc. and its contributors.
2288d2dd24SPeter Grehan  * 4. Neither the name of The NetBSD Foundation nor the names of its
2388d2dd24SPeter Grehan  *    contributors may be used to endorse or promote products derived
2488d2dd24SPeter Grehan  *    from this software without specific prior written permission.
2588d2dd24SPeter Grehan  *
2688d2dd24SPeter Grehan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2788d2dd24SPeter Grehan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2888d2dd24SPeter Grehan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2988d2dd24SPeter Grehan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3088d2dd24SPeter Grehan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3188d2dd24SPeter Grehan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3288d2dd24SPeter Grehan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3388d2dd24SPeter Grehan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3488d2dd24SPeter Grehan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3588d2dd24SPeter Grehan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3688d2dd24SPeter Grehan  * POSSIBILITY OF SUCH DAMAGE.
3788d2dd24SPeter Grehan  *
3888d2dd24SPeter Grehan  */
3988d2dd24SPeter Grehan 
4088d2dd24SPeter Grehan #include <sys/cdefs.h>
4188d2dd24SPeter Grehan __FBSDID("$FreeBSD$");
4288d2dd24SPeter Grehan 
4388d2dd24SPeter Grehan #include <sys/types.h>
4488d2dd24SPeter Grehan #include <ieeefp.h>
4588d2dd24SPeter Grehan 
4656ae1bedSRafal Jaworowski #ifndef _SOFT_FLOAT
4788d2dd24SPeter Grehan fp_rnd_t
4888d2dd24SPeter Grehan fpgetround()
4988d2dd24SPeter Grehan {
5088d2dd24SPeter Grehan 	u_int64_t fpscr;
5188d2dd24SPeter Grehan 
5288d2dd24SPeter Grehan 	__asm__("mffs %0" : "=f"(fpscr));
5388d2dd24SPeter Grehan 	return ((fp_rnd_t)(fpscr & 0x3));
5488d2dd24SPeter Grehan }
5556ae1bedSRafal Jaworowski #endif
56