188d2dd24SPeter Grehan /* $NetBSD: flt_rounds.c,v 1.4.10.3 2002/03/22 20:41:53 nathanw Exp $ */
288d2dd24SPeter Grehan
3*d915a14eSPedro F. Giffuni /*-
4*d915a14eSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause
5*d915a14eSPedro F. Giffuni *
688d2dd24SPeter Grehan * Copyright (c) 1996 Mark Brinicombe
788d2dd24SPeter Grehan * All rights reserved.
888d2dd24SPeter Grehan *
988d2dd24SPeter Grehan * Redistribution and use in source and binary forms, with or without
1088d2dd24SPeter Grehan * modification, are permitted provided that the following conditions
1188d2dd24SPeter Grehan * are met:
1288d2dd24SPeter Grehan * 1. Redistributions of source code must retain the above copyright
1388d2dd24SPeter Grehan * notice, this list of conditions and the following disclaimer.
1488d2dd24SPeter Grehan * 2. Redistributions in binary form must reproduce the above copyright
1588d2dd24SPeter Grehan * notice, this list of conditions and the following disclaimer in the
1688d2dd24SPeter Grehan * documentation and/or other materials provided with the distribution.
1788d2dd24SPeter Grehan * 3. All advertising materials mentioning features or use of this software
1888d2dd24SPeter Grehan * must display the following acknowledgement:
1988d2dd24SPeter Grehan * This product includes software developed by Mark Brinicombe
2088d2dd24SPeter Grehan * for the NetBSD Project.
2188d2dd24SPeter Grehan * 4. The name of the author may not be used to endorse or promote products
2288d2dd24SPeter Grehan * derived from this software without specific prior written permission
2388d2dd24SPeter Grehan *
2488d2dd24SPeter Grehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2588d2dd24SPeter Grehan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2688d2dd24SPeter Grehan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2788d2dd24SPeter Grehan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2888d2dd24SPeter Grehan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2988d2dd24SPeter Grehan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3088d2dd24SPeter Grehan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3188d2dd24SPeter Grehan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3288d2dd24SPeter Grehan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3388d2dd24SPeter Grehan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3488d2dd24SPeter Grehan */
3588d2dd24SPeter Grehan
3688d2dd24SPeter Grehan #include <sys/types.h>
3788d2dd24SPeter Grehan #include <machine/float.h>
3888d2dd24SPeter Grehan
3956ae1bedSRafal Jaworowski #ifndef _SOFT_FLOAT
4088d2dd24SPeter Grehan static const int map[] = {
4188d2dd24SPeter Grehan 1, /* round to nearest */
4288d2dd24SPeter Grehan 0, /* round to zero */
4388d2dd24SPeter Grehan 2, /* round to positive infinity */
4488d2dd24SPeter Grehan 3 /* round to negative infinity */
4588d2dd24SPeter Grehan };
4688d2dd24SPeter Grehan
4788d2dd24SPeter Grehan int
__flt_rounds()4888d2dd24SPeter Grehan __flt_rounds()
4988d2dd24SPeter Grehan {
5088d2dd24SPeter Grehan uint64_t fpscr;
5188d2dd24SPeter Grehan
5288d2dd24SPeter Grehan __asm__ __volatile("mffs %0" : "=f"(fpscr));
5388d2dd24SPeter Grehan return map[(fpscr & 0x03)];
5488d2dd24SPeter Grehan }
5556ae1bedSRafal Jaworowski #endif
56