Path: blob/main/lib/libc/powerpcspe/gen/flt_rounds.c
39536 views
/* $NetBSD: flt_rounds.c,v 1.4.10.3 2002/03/22 20:41:53 nathanw Exp $ */12/*3* Copyright (c) 2016 Justin Hibbits4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. All advertising materials mentioning features or use of this software15* must display the following acknowledgement:16* This product includes software developed by Mark Brinicombe17* for the NetBSD Project.18* 4. The name of the author may not be used to endorse or promote products19* derived from this software without specific prior written permission20*21* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR22* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES23* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.24* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,25* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT26* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF30* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233#include <sys/types.h>34#include <machine/float.h>35#include <machine/spr.h>3637#ifndef _SOFT_FLOAT38static const int map[] = {391, /* round to nearest */400, /* round to zero */412, /* round to positive infinity */423 /* round to negative infinity */43};4445int46__flt_rounds()47{48uint32_t fpscr;4950__asm__ __volatile("mfspr %0, %1" : "=r"(fpscr) : "K"(SPR_SPEFSCR));51return map[(fpscr & 0x03)];52}53#endif545556