1209878Snwhitehorn/* $NetBSD: flt_rounds.c,v 1.4.10.3 2002/03/22 20:41:53 nathanw Exp $ */ 2209878Snwhitehorn 3209878Snwhitehorn/* 4209878Snwhitehorn * Copyright (c) 1996 Mark Brinicombe 5209878Snwhitehorn * All rights reserved. 6209878Snwhitehorn * 7209878Snwhitehorn * Redistribution and use in source and binary forms, with or without 8209878Snwhitehorn * modification, are permitted provided that the following conditions 9209878Snwhitehorn * are met: 10209878Snwhitehorn * 1. Redistributions of source code must retain the above copyright 11209878Snwhitehorn * notice, this list of conditions and the following disclaimer. 12209878Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright 13209878Snwhitehorn * notice, this list of conditions and the following disclaimer in the 14209878Snwhitehorn * documentation and/or other materials provided with the distribution. 15209878Snwhitehorn * 3. All advertising materials mentioning features or use of this software 16209878Snwhitehorn * must display the following acknowledgement: 17209878Snwhitehorn * This product includes software developed by Mark Brinicombe 18209878Snwhitehorn * for the NetBSD Project. 19209878Snwhitehorn * 4. The name of the author may not be used to endorse or promote products 20209878Snwhitehorn * derived from this software without specific prior written permission 21209878Snwhitehorn * 22209878Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23209878Snwhitehorn * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24209878Snwhitehorn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25209878Snwhitehorn * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26209878Snwhitehorn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27209878Snwhitehorn * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28209878Snwhitehorn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29209878Snwhitehorn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30209878Snwhitehorn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31209878Snwhitehorn * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32209878Snwhitehorn */ 33209878Snwhitehorn 34209878Snwhitehorn#include <sys/cdefs.h> 35209878Snwhitehorn__FBSDID("$FreeBSD$"); 36209878Snwhitehorn 37209878Snwhitehorn#include <sys/types.h> 38209878Snwhitehorn#include <machine/float.h> 39209878Snwhitehorn 40209878Snwhitehorn#ifndef _SOFT_FLOAT 41209878Snwhitehornstatic const int map[] = { 42209878Snwhitehorn 1, /* round to nearest */ 43209878Snwhitehorn 0, /* round to zero */ 44209878Snwhitehorn 2, /* round to positive infinity */ 45209878Snwhitehorn 3 /* round to negative infinity */ 46209878Snwhitehorn}; 47209878Snwhitehorn 48209878Snwhitehornint 49209878Snwhitehorn__flt_rounds() 50209878Snwhitehorn{ 51209878Snwhitehorn uint64_t fpscr; 52209878Snwhitehorn 53209878Snwhitehorn __asm__ __volatile("mffs %0" : "=f"(fpscr)); 54209878Snwhitehorn return map[(fpscr & 0x03)]; 55209878Snwhitehorn} 56209878Snwhitehorn#endif 57