blob: a7e2bfd5591cd4e0484f66270f81a2545bcffac9 [file] [log] [blame]
Elliott Hughes2f5829b2023-02-24 00:15:29 +00001/*-
2 * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08003 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
Elliott Hughes2f5829b2023-02-24 00:15:29 +00008 * 1. Redistributions of source code must retain the above copyright
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08009 * notice, this list of conditions and the following disclaimer.
Elliott Hughes2f5829b2023-02-24 00:15:29 +000010 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080013 *
Elliott Hughes2f5829b2023-02-24 00:15:29 +000014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080024 * SUCH DAMAGE.
Elliott Hughes2f5829b2023-02-24 00:15:29 +000025 *
26 * $FreeBSD: src/lib/msun/arm/fenv.c,v 1.1 2004/06/06 10:03:59 das Exp $
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080027 */
28
29#include <fenv.h>
30
Elliott Hughes2f5829b2023-02-24 00:15:29 +000031#define FPSCR_RMODE_SHIFT 22
Elliott Hughes9812a022014-06-09 13:57:57 -070032
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080033const fenv_t __fe_dfl_env = 0;
Elliott Hughes2f5829b2023-02-24 00:15:29 +000034
35int fegetenv(fenv_t* __envp) {
36 fenv_t _fpscr;
37 __asm__ __volatile__("vmrs %0,fpscr" : "=r"(_fpscr));
38 *__envp = _fpscr;
39 return 0;
40}
41
42int fesetenv(const fenv_t* __envp) {
43 fenv_t _fpscr = *__envp;
44 __asm__ __volatile__("vmsr fpscr,%0" : : "ri"(_fpscr));
45 return 0;
46}
47
48int feclearexcept(int __excepts) {
49 fexcept_t __fpscr;
50 fegetenv(&__fpscr);
51 __fpscr &= ~__excepts;
52 fesetenv(&__fpscr);
53 return 0;
54}
55
56int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
57 fexcept_t __fpscr;
58 fegetenv(&__fpscr);
59 *__flagp = __fpscr & __excepts;
60 return 0;
61}
62
63int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
64 fexcept_t __fpscr;
65 fegetenv(&__fpscr);
66 __fpscr &= ~__excepts;
67 __fpscr |= *__flagp & __excepts;
68 fesetenv(&__fpscr);
69 return 0;
70}
71
72int feraiseexcept(int __excepts) {
73 fexcept_t __ex = __excepts;
74 fesetexceptflag(&__ex, __excepts);
75 return 0;
76}
77
78int fetestexcept(int __excepts) {
79 fexcept_t __fpscr;
80 fegetenv(&__fpscr);
81 return (__fpscr & __excepts);
82}
83
84int fegetround(void) {
85 fenv_t _fpscr;
86 fegetenv(&_fpscr);
87 return ((_fpscr >> FPSCR_RMODE_SHIFT) & 0x3);
88}
89
90int fesetround(int __round) {
91 fenv_t _fpscr;
92 fegetenv(&_fpscr);
93 _fpscr &= ~(0x3 << FPSCR_RMODE_SHIFT);
94 _fpscr |= (__round << FPSCR_RMODE_SHIFT);
95 fesetenv(&_fpscr);
96 return 0;
97}
98
99int feholdexcept(fenv_t* __envp) {
100 fenv_t __env;
101 fegetenv(&__env);
102 *__envp = __env;
103 __env &= ~FE_ALL_EXCEPT;
104 fesetenv(&__env);
105 return 0;
106}
107
108int feupdateenv(const fenv_t* __envp) {
109 fexcept_t __fpscr;
110 fegetenv(&__fpscr);
111 fesetenv(__envp);
112 feraiseexcept(__fpscr & FE_ALL_EXCEPT);
113 return 0;
114}
115
116int feenableexcept(int __mask __unused) {
117 return -1;
118}
119
120int fedisableexcept(int __mask __unused) {
121 return 0;
122}
123
124int fegetexcept(void) {
125 return 0;
126}