11.8Sandvar/* $NetBSD: flt_rounds.c,v 1.8 2022/04/08 10:17:52 andvar Exp $ */ 21.1Smsaitoh 31.1Smsaitoh/* 41.1Smsaitoh * Copyright (c) 1996 Mark Brinicombe 51.1Smsaitoh * All rights reserved. 61.1Smsaitoh * 71.1Smsaitoh * Redistribution and use in source and binary forms, with or without 81.1Smsaitoh * modification, are permitted provided that the following conditions 91.1Smsaitoh * are met: 101.1Smsaitoh * 1. Redistributions of source code must retain the above copyright 111.1Smsaitoh * notice, this list of conditions and the following disclaimer. 121.1Smsaitoh * 2. Redistributions in binary form must reproduce the above copyright 131.1Smsaitoh * notice, this list of conditions and the following disclaimer in the 141.1Smsaitoh * documentation and/or other materials provided with the distribution. 151.1Smsaitoh * 3. All advertising materials mentioning features or use of this software 161.1Smsaitoh * must display the following acknowledgement: 171.1Smsaitoh * This product includes software developed by Mark Brinicombe 181.1Smsaitoh * for the NetBSD Project. 191.1Smsaitoh * 4. The name of the author may not be used to endorse or promote products 201.1Smsaitoh * derived from this software without specific prior written permission 211.1Smsaitoh * 221.1Smsaitoh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 231.1Smsaitoh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 241.1Smsaitoh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 251.1Smsaitoh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 261.1Smsaitoh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 271.1Smsaitoh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 281.1Smsaitoh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 291.1Smsaitoh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 301.1Smsaitoh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 311.1Smsaitoh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 321.1Smsaitoh */ 331.1Smsaitoh 341.2Slukem#include <sys/cdefs.h> 351.2Slukem#if defined(LIBC_SCCS) && !defined(lint) 361.8Sandvar__RCSID("$NetBSD: flt_rounds.c,v 1.8 2022/04/08 10:17:52 andvar Exp $"); 371.2Slukem#endif /* LIBC_SCCS and not lint */ 381.2Slukem 391.6Sjoerg#include "namespace.h" 401.1Smsaitoh#include <sys/types.h> 411.1Smsaitoh#include <ieeefp.h> 421.1Smsaitoh 431.1Smsaitohstatic const int map[] = { 441.1Smsaitoh 1, /* round to nearest */ 451.7Schs 3, /* round to positive infinity */ 461.7Schs 2, /* round to negative infinity */ 471.1Smsaitoh 0 /* round to zero */ 481.1Smsaitoh}; 491.1Smsaitoh 501.1Smsaitoh/* 511.1Smsaitoh * Return the current FP rounding mode 521.1Smsaitoh * 531.1Smsaitoh * Returns: 541.1Smsaitoh * 0 - round to zero 551.1Smsaitoh * 1 - round to nearest 561.8Sandvar * 2 - round to positive infinity 571.1Smsaitoh * 3 - round to negative infinity 581.1Smsaitoh * 591.1Smsaitoh * ok all we need to do is get the current FP rounding mode 601.1Smsaitoh * index our map table and return the appropriate value. 611.1Smsaitoh * 621.1Smsaitoh * HOWEVER: 631.1Smsaitoh * The ARM FPA codes the rounding mode into the actual FP instructions 641.1Smsaitoh * so there is no such thing as a global rounding mode. 651.3Swiz * The default is round to nearest if rounding is not explicitly specified. 661.1Smsaitoh * FP instructions generated by GCC will not explicitly specify a rounding 671.1Smsaitoh * mode. 681.1Smsaitoh * 691.1Smsaitoh * So the best we can do it to return the rounding mode FP instructions 701.1Smsaitoh * use if rounding is not specified which is round to nearest. 711.1Smsaitoh * 721.1Smsaitoh * This could change in the future with new floating point emulators or 731.1Smsaitoh * soft float FP libraries. 741.1Smsaitoh */ 751.1Smsaitoh 761.1Smsaitohextern int __flt_rounds __P((void)); 771.1Smsaitoh 781.1Smsaitohint 791.5She__flt_rounds(void) 801.1Smsaitoh{ 811.1Smsaitoh return(map[fpgetround()]); 821.1Smsaitoh} 83