fpgetround.c revision 125733
1125733Sgrehan/* $NetBSD: fpgetround.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $ */ 2125733Sgrehan 3125733Sgrehan/* 4125733Sgrehan * Copyright (c) 1999 The NetBSD Foundation, Inc. 5125733Sgrehan * All rights reserved. 6125733Sgrehan * 7125733Sgrehan * This code is derived from software contributed to The NetBSD Foundation 8125733Sgrehan * by Dan Winship. 9125733Sgrehan * 10125733Sgrehan * Redistribution and use in source and binary forms, with or without 11125733Sgrehan * modification, are permitted provided that the following conditions 12125733Sgrehan * are met: 13125733Sgrehan * 1. Redistributions of source code must retain the above copyright 14125733Sgrehan * notice, this list of conditions and the following disclaimer. 15125733Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 16125733Sgrehan * notice, this list of conditions and the following disclaimer in the 17125733Sgrehan * documentation and/or other materials provided with the distribution. 18125733Sgrehan * 3. All advertising materials mentioning features or use of this software 19125733Sgrehan * must display the following acknowledgement: 20125733Sgrehan * This product includes software developed by the NetBSD 21125733Sgrehan * Foundation, Inc. and its contributors. 22125733Sgrehan * 4. Neither the name of The NetBSD Foundation nor the names of its 23125733Sgrehan * contributors may be used to endorse or promote products derived 24125733Sgrehan * from this software without specific prior written permission. 25125733Sgrehan * 26125733Sgrehan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27125733Sgrehan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28125733Sgrehan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29125733Sgrehan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30125733Sgrehan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31125733Sgrehan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32125733Sgrehan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33125733Sgrehan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34125733Sgrehan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35125733Sgrehan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36125733Sgrehan * POSSIBILITY OF SUCH DAMAGE. 37125733Sgrehan * 38125733Sgrehan */ 39125733Sgrehan 40125733Sgrehan#include <sys/cdefs.h> 41125733Sgrehan__FBSDID("$FreeBSD: head/lib/libc/powerpc/gen/fpgetround.c 125733 2004-02-12 09:11:06Z grehan $"); 42125733Sgrehan 43125733Sgrehan#include <sys/types.h> 44125733Sgrehan#include <ieeefp.h> 45125733Sgrehan 46125733Sgrehanfp_rnd_t 47125733Sgrehanfpgetround() 48125733Sgrehan{ 49125733Sgrehan u_int64_t fpscr; 50125733Sgrehan 51125733Sgrehan __asm__("mffs %0" : "=f"(fpscr)); 52125733Sgrehan return ((fp_rnd_t)(fpscr & 0x3)); 53125733Sgrehan} 54