blob: de024cf3cbd6f6268bf2977d7cbfcc6514010f0c [file] [log] [blame]
Dan Albert75097b12016-11-04 11:39:16 -07001/*-
2 * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
3 * 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:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 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.
13 *
14 * 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
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: src/lib/msun/arm/fenv.c,v 1.1 2004/06/06 10:03:59 das Exp $
27 */
28
29#ifndef ANDROID_LEGACY_FENV_INLINES_ARM_H
30#define ANDROID_LEGACY_FENV_INLINES_ARM_H
31
Dan Albertb37e9aa2017-10-24 09:20:41 +000032#include <fenv.h>
Dan Albert75097b12016-11-04 11:39:16 -070033
Elliott Hughes5bc78c82016-11-16 11:35:43 -080034#if __ANDROID_API__ < __ANDROID_API_L__ && defined(__arm__)
Dan Albert75097b12016-11-04 11:39:16 -070035
36__BEGIN_DECLS
37
Dan Albert75097b12016-11-04 11:39:16 -070038#define FPSCR_RMODE_SHIFT 22
39
40static __inline int fegetenv(fenv_t* __envp) {
41 fenv_t _fpscr;
42 __asm__ __volatile__("vmrs %0,fpscr" : "=r" (_fpscr));
43 *__envp = _fpscr;
44 return 0;
45}
46
47static __inline int fesetenv(const fenv_t* __envp) {
48 fenv_t _fpscr = *__envp;
49 __asm__ __volatile__("vmsr fpscr,%0" : :"ri" (_fpscr));
50 return 0;
51}
52
53static __inline int feclearexcept(int __excepts) {
54 fexcept_t __fpscr;
55 fegetenv(&__fpscr);
56 __fpscr &= ~__excepts;
57 fesetenv(&__fpscr);
58 return 0;
59}
60
61static __inline int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
62 fexcept_t __fpscr;
63 fegetenv(&__fpscr);
64 *__flagp = __fpscr & __excepts;
65 return 0;
66}
67
68static __inline int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
69 fexcept_t __fpscr;
70 fegetenv(&__fpscr);
71 __fpscr &= ~__excepts;
72 __fpscr |= *__flagp & __excepts;
73 fesetenv(&__fpscr);
74 return 0;
75}
76
77static __inline int feraiseexcept(int __excepts) {
78 fexcept_t __ex = __excepts;
79 fesetexceptflag(&__ex, __excepts);
80 return 0;
81}
82
83static __inline int fetestexcept(int __excepts) {
84 fexcept_t __fpscr;
85 fegetenv(&__fpscr);
86 return (__fpscr & __excepts);
87}
88
89static __inline int fegetround(void) {
90 fenv_t _fpscr;
91 fegetenv(&_fpscr);
92 return ((_fpscr >> FPSCR_RMODE_SHIFT) & 0x3);
93}
94
95static __inline int fesetround(int __round) {
96 fenv_t _fpscr;
97 fegetenv(&_fpscr);
98 _fpscr &= ~(0x3 << FPSCR_RMODE_SHIFT);
99 _fpscr |= (__round << FPSCR_RMODE_SHIFT);
100 fesetenv(&_fpscr);
101 return 0;
102}
103
104static __inline int feholdexcept(fenv_t* __envp) {
105 fenv_t __env;
106 fegetenv(&__env);
107 *__envp = __env;
Elliott Hughesb6c7f6e2017-11-03 16:46:32 -0700108 __env &= ~FE_ALL_EXCEPT;
Dan Albert75097b12016-11-04 11:39:16 -0700109 fesetenv(&__env);
110 return 0;
111}
112
113static __inline int feupdateenv(const fenv_t* __envp) {
114 fexcept_t __fpscr;
115 fegetenv(&__fpscr);
116 fesetenv(__envp);
117 feraiseexcept(__fpscr & FE_ALL_EXCEPT);
118 return 0;
119}
120
Elliott Hughesb6c7f6e2017-11-03 16:46:32 -0700121static __inline int feenableexcept(int __mask __unused) {
122 return -1;
Dan Albert75097b12016-11-04 11:39:16 -0700123}
124
Elliott Hughesb6c7f6e2017-11-03 16:46:32 -0700125static __inline int fedisableexcept(int __mask __unused) {
126 return 0;
Dan Albert75097b12016-11-04 11:39:16 -0700127}
128
129static __inline int fegetexcept(void) {
Elliott Hughesb6c7f6e2017-11-03 16:46:32 -0700130 return 0;
Dan Albert75097b12016-11-04 11:39:16 -0700131}
132
Dan Albert75097b12016-11-04 11:39:16 -0700133#undef FPSCR_RMODE_SHIFT
134
135__END_DECLS
136
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800137#endif /* __ANDROID_API__ < __ANDROID_API_L__ && defined(__arm__) */
Dan Albert75097b12016-11-04 11:39:16 -0700138
139#endif /* ANDROID_LEGACY_FENV_INLINES_ARM_H */