fpgetround.c revision 209878
1209878Snwhitehorn/* $NetBSD: fpgetround.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $ */ 2209878Snwhitehorn 3209878Snwhitehorn/* 4209878Snwhitehorn * Copyright (c) 1999 The NetBSD Foundation, Inc. 5209878Snwhitehorn * All rights reserved. 6209878Snwhitehorn * 7209878Snwhitehorn * This code is derived from software contributed to The NetBSD Foundation 8209878Snwhitehorn * by Dan Winship. 9209878Snwhitehorn * 10209878Snwhitehorn * Redistribution and use in source and binary forms, with or without 11209878Snwhitehorn * modification, are permitted provided that the following conditions 12209878Snwhitehorn * are met: 13209878Snwhitehorn * 1. Redistributions of source code must retain the above copyright 14209878Snwhitehorn * notice, this list of conditions and the following disclaimer. 15209878Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright 16209878Snwhitehorn * notice, this list of conditions and the following disclaimer in the 17209878Snwhitehorn * documentation and/or other materials provided with the distribution. 18209878Snwhitehorn * 3. All advertising materials mentioning features or use of this software 19209878Snwhitehorn * must display the following acknowledgement: 20209878Snwhitehorn * This product includes software developed by the NetBSD 21209878Snwhitehorn * Foundation, Inc. and its contributors. 22209878Snwhitehorn * 4. Neither the name of The NetBSD Foundation nor the names of its 23209878Snwhitehorn * contributors may be used to endorse or promote products derived 24209878Snwhitehorn * from this software without specific prior written permission. 25209878Snwhitehorn * 26209878Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27209878Snwhitehorn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28209878Snwhitehorn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29209878Snwhitehorn * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30209878Snwhitehorn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31209878Snwhitehorn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32209878Snwhitehorn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33209878Snwhitehorn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34209878Snwhitehorn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35209878Snwhitehorn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36209878Snwhitehorn * POSSIBILITY OF SUCH DAMAGE. 37209878Snwhitehorn * 38209878Snwhitehorn */ 39209878Snwhitehorn 40209878Snwhitehorn#include <sys/cdefs.h> 41209878Snwhitehorn__FBSDID("$FreeBSD: head/lib/libc/powerpc64/gen/fpgetround.c 209878 2010-07-10 14:45:03Z nwhitehorn $"); 42209878Snwhitehorn 43209878Snwhitehorn#include <sys/types.h> 44209878Snwhitehorn#include <ieeefp.h> 45209878Snwhitehorn 46209878Snwhitehorn#ifndef _SOFT_FLOAT 47209878Snwhitehornfp_rnd_t 48209878Snwhitehornfpgetround() 49209878Snwhitehorn{ 50209878Snwhitehorn u_int64_t fpscr; 51209878Snwhitehorn 52209878Snwhitehorn __asm__("mffs %0" : "=f"(fpscr)); 53209878Snwhitehorn return ((fp_rnd_t)(fpscr & 0x3)); 54209878Snwhitehorn} 55209878Snwhitehorn#endif 56