1840b91ccSNathan Whitehorn /* $NetBSD: fpgetround.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $ */
2840b91ccSNathan Whitehorn
3d915a14eSPedro F. Giffuni /*-
4*b61a5730SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
5d915a14eSPedro F. Giffuni *
6840b91ccSNathan Whitehorn * Copyright (c) 1999 The NetBSD Foundation, Inc.
7840b91ccSNathan Whitehorn * All rights reserved.
8840b91ccSNathan Whitehorn *
9840b91ccSNathan Whitehorn * This code is derived from software contributed to The NetBSD Foundation
10840b91ccSNathan Whitehorn * by Dan Winship.
11840b91ccSNathan Whitehorn *
12840b91ccSNathan Whitehorn * Redistribution and use in source and binary forms, with or without
13840b91ccSNathan Whitehorn * modification, are permitted provided that the following conditions
14840b91ccSNathan Whitehorn * are met:
15840b91ccSNathan Whitehorn * 1. Redistributions of source code must retain the above copyright
16840b91ccSNathan Whitehorn * notice, this list of conditions and the following disclaimer.
17840b91ccSNathan Whitehorn * 2. Redistributions in binary form must reproduce the above copyright
18840b91ccSNathan Whitehorn * notice, this list of conditions and the following disclaimer in the
19840b91ccSNathan Whitehorn * documentation and/or other materials provided with the distribution.
20840b91ccSNathan Whitehorn *
21840b91ccSNathan Whitehorn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22840b91ccSNathan Whitehorn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23840b91ccSNathan Whitehorn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24840b91ccSNathan Whitehorn * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25840b91ccSNathan Whitehorn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26840b91ccSNathan Whitehorn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27840b91ccSNathan Whitehorn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28840b91ccSNathan Whitehorn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29840b91ccSNathan Whitehorn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30840b91ccSNathan Whitehorn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31840b91ccSNathan Whitehorn * POSSIBILITY OF SUCH DAMAGE.
32840b91ccSNathan Whitehorn *
33840b91ccSNathan Whitehorn */
34840b91ccSNathan Whitehorn
35840b91ccSNathan Whitehorn #include <sys/types.h>
36840b91ccSNathan Whitehorn #include <ieeefp.h>
37840b91ccSNathan Whitehorn
38840b91ccSNathan Whitehorn #ifndef _SOFT_FLOAT
39840b91ccSNathan Whitehorn fp_rnd_t
fpgetround()40840b91ccSNathan Whitehorn fpgetround()
41840b91ccSNathan Whitehorn {
42840b91ccSNathan Whitehorn u_int64_t fpscr;
43840b91ccSNathan Whitehorn
44840b91ccSNathan Whitehorn __asm__("mffs %0" : "=f"(fpscr));
45840b91ccSNathan Whitehorn return ((fp_rnd_t)(fpscr & 0x3));
46840b91ccSNathan Whitehorn }
47840b91ccSNathan Whitehorn #endif
48