11.2Sjoerg/* $NetBSD: flt_rounds.c,v 1.2 2015/03/19 21:22:59 joerg Exp $ */ 21.1Sross 31.1Sross/* 41.1Sross * Copyright (c) 1996 Mark Brinicombe 51.1Sross * All rights reserved. 61.1Sross * 71.1Sross * Redistribution and use in source and binary forms, with or without 81.1Sross * modification, are permitted provided that the following conditions 91.1Sross * are met: 101.1Sross * 1. Redistributions of source code must retain the above copyright 111.1Sross * notice, this list of conditions and the following disclaimer. 121.1Sross * 2. Redistributions in binary form must reproduce the above copyright 131.1Sross * notice, this list of conditions and the following disclaimer in the 141.1Sross * documentation and/or other materials provided with the distribution. 151.1Sross * 3. All advertising materials mentioning features or use of this software 161.1Sross * must display the following acknowledgement: 171.1Sross * This product includes software developed by Mark Brinicombe 181.1Sross * for the NetBSD Project. 191.1Sross * 4. The name of the author may not be used to endorse or promote products 201.1Sross * derived from this software without specific prior written permission 211.1Sross * 221.1Sross * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 231.1Sross * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 241.1Sross * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 251.1Sross * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 261.1Sross * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 271.1Sross * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 281.1Sross * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 291.1Sross * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 301.1Sross * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 311.1Sross * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 321.1Sross */ 331.1Sross 341.1Sross#include <sys/cdefs.h> 351.1Sross#if defined(LIBC_SCCS) && !defined(lint) 361.2Sjoerg__RCSID("$NetBSD: flt_rounds.c,v 1.2 2015/03/19 21:22:59 joerg Exp $"); 371.1Sross#endif /* LIBC_SCCS and not lint */ 381.1Sross 391.2Sjoerg#include "namespace.h" 401.1Sross#include <ieeefp.h> 411.1Sross#include <float.h> 421.1Sross#include <stdint.h> 431.1Sross#include <powerpc/fpu.h> 441.1Sross 451.1Srossstatic const int map[] = { 461.1Sross 1, /* round to nearest */ 471.1Sross 0, /* round to zero */ 481.1Sross 2, /* round to positive infinity */ 491.1Sross 3 /* round to negative infinity */ 501.1Sross}; 511.1Sross 521.1Srossint 531.1Sross__flt_rounds(void) 541.1Sross{ 551.1Sross#ifdef _SOFT_FLOAT 561.1Sross return map[fpgetround()]; 571.1Sross#else 581.1Sross uint64_t fpscr; 591.1Sross 601.1Sross __asm volatile("mffs %0" : "=f"(fpscr)); 611.1Sross return map[((uint32_t)fpscr & FPSCR_RN)]; 621.1Sross#endif 631.1Sross} 64