/* $NetBSD: flt_rounds.c,v 1.4.10.3 2002/03/22 20:41:53 nathanw Exp $ */12/*-3* SPDX-License-Identifier: BSD-4-Clause4*5* Copyright (c) 1996 Mark Brinicombe6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16* 3. All advertising materials mentioning features or use of this software17* must display the following acknowledgement:18* This product includes software developed by Mark Brinicombe19* for the NetBSD Project.20* 4. The name of the author may not be used to endorse or promote products21* derived from this software without specific prior written permission22*23* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR24* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES25* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.26* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,27* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT28* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,29* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY30* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT31* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF32* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435#include <sys/types.h>36#include <machine/float.h>3738#ifndef _SOFT_FLOAT39static const int map[] = {401, /* round to nearest */410, /* round to zero */422, /* round to positive infinity */433 /* round to negative infinity */44};4546int47__flt_rounds()48{49uint64_t fpscr;5051__asm__ __volatile("mffs %0" : "=f"(fpscr));52return map[(fpscr & 0x03)];53}54#endif555657