]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/fpu/fenv_private.h
[powerpc] fenv_private.h clean up
[thirdparty/glibc.git] / sysdeps / powerpc / fpu / fenv_private.h
1 /* Private floating point rounding and exceptions handling. PowerPC version.
2 Copyright (C) 2013-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #ifndef POWERPC_FENV_PRIVATE_H
20 #define POWERPC_FENV_PRIVATE_H 1
21
22 #include <fenv.h>
23 #include <fenv_libc.h>
24 #include <fpu_control.h>
25
26 static __always_inline void
27 libc_feholdexcept_setround_ppc (fenv_t *envp, int r)
28 {
29 fenv_union_t old, new;
30
31 old.fenv = *envp = fegetenv_register ();
32
33 __TEST_AND_ENTER_NON_STOP (old.l, 0ULL);
34
35 /* Clear everything and set the rounding mode. */
36 new.l = r;
37 fesetenv_register (new.fenv);
38 }
39
40 static __always_inline unsigned long long
41 __libc_femergeenv_ppc (const fenv_t *envp, unsigned long long old_mask,
42 unsigned long long new_mask)
43 {
44 fenv_union_t old, new;
45
46 new.fenv = *envp;
47 old.fenv = fegetenv_register ();
48
49 /* Merge bits while masking unwanted bits from new and old env. */
50 new.l = (old.l & old_mask) | (new.l & new_mask);
51
52 __TEST_AND_EXIT_NON_STOP (old.l, new.l);
53 __TEST_AND_ENTER_NON_STOP (old.l, new.l);
54
55 /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
56 fesetenv_register (new.fenv);
57
58 return old.l;
59 }
60
61 static __always_inline void
62 libc_fesetenv_ppc (const fenv_t *envp)
63 {
64 /* Replace the entire environment. */
65 __libc_femergeenv_ppc (envp, 0LL, -1LL);
66 }
67
68 static __always_inline void
69 libc_feresetround_ppc (fenv_t *envp)
70 {
71 fenv_union_t new = { .fenv = *envp };
72 fegetenv_and_set_rn (new.l & FPSCR_RN_MASK);
73 }
74
75 static __always_inline int
76 libc_feupdateenv_test_ppc (fenv_t *envp, int ex)
77 {
78 return __libc_femergeenv_ppc (envp, ~FPSCR_CONTROL_MASK,
79 ~FPSCR_STATUS_MASK) & ex;
80 }
81
82 static __always_inline void
83 libc_feupdateenv_ppc (fenv_t *e)
84 {
85 libc_feupdateenv_test_ppc (e, 0);
86 }
87
88 #define libc_feholdexceptf libc_feholdexcept_ppc
89 #define libc_feholdexcept libc_feholdexcept_ppc
90 #define libc_feholdexcept_setroundf libc_feholdexcept_setround_ppc
91 #define libc_feholdexcept_setround libc_feholdexcept_setround_ppc
92 #define libc_fetestexceptf libc_fetestexcept_ppc
93 #define libc_fetestexcept libc_fetestexcept_ppc
94 #define libc_fesetroundf libc_fesetround_ppc
95 #define libc_fesetround libc_fesetround_ppc
96 #define libc_fesetenvf libc_fesetenv_ppc
97 #define libc_fesetenv libc_fesetenv_ppc
98 #define libc_feupdateenv_testf libc_feupdateenv_test_ppc
99 #define libc_feupdateenv_test libc_feupdateenv_test_ppc
100 #define libc_feupdateenvf libc_feupdateenv_ppc
101 #define libc_feupdateenv libc_feupdateenv_ppc
102 #define libc_feholdsetroundf libc_feholdsetround_ppc
103 #define libc_feholdsetround libc_feholdsetround_ppc
104 #define libc_feresetroundf libc_feresetround_ppc
105 #define libc_feresetround libc_feresetround_ppc
106
107
108 /* We have support for rounding mode context. */
109 #define HAVE_RM_CTX 1
110
111 static __always_inline void
112 libc_feholdsetround_ppc_ctx (struct rm_ctx *ctx, int r)
113 {
114 fenv_union_t old;
115
116 ctx->env = old.fenv = fegetenv_and_set_rn (r);
117 ctx->updated_status = (r != (old.l & FPSCR_RN_MASK));
118 }
119
120 static __always_inline void
121 libc_feholdsetround_noex_ppc_ctx (struct rm_ctx *ctx, int r)
122 {
123 fenv_union_t old, new;
124
125 old.fenv = fegetenv_register ();
126
127 new.l = (old.l & ~(FPSCR_ENABLES_MASK|FPSCR_RN_MASK)) | r;
128
129 ctx->env = old.fenv;
130 if (__glibc_unlikely (new.l != old.l))
131 {
132 __TEST_AND_ENTER_NON_STOP (old.l, 0ULL);
133 fesetenv_register (new.fenv);
134 ctx->updated_status = true;
135 }
136 else
137 ctx->updated_status = false;
138 }
139
140 static __always_inline void
141 libc_fesetenv_ppc_ctx (struct rm_ctx *ctx)
142 {
143 libc_fesetenv_ppc (&ctx->env);
144 }
145
146 static __always_inline void
147 libc_feupdateenv_ppc_ctx (struct rm_ctx *ctx)
148 {
149 if (__glibc_unlikely (ctx->updated_status))
150 libc_feresetround_ppc (&ctx->env);
151 }
152
153 static __always_inline void
154 libc_feresetround_ppc_ctx (struct rm_ctx *ctx)
155 {
156 if (__glibc_unlikely (ctx->updated_status))
157 libc_feresetround_ppc (&ctx->env);
158 }
159
160 #define libc_fesetenv_ctx libc_fesetenv_ppc_ctx
161 #define libc_fesetenvf_ctx libc_fesetenv_ppc_ctx
162 #define libc_fesetenvl_ctx libc_fesetenv_ppc_ctx
163 #define libc_feholdsetround_ctx libc_feholdsetround_ppc_ctx
164 #define libc_feholdsetroundf_ctx libc_feholdsetround_ppc_ctx
165 #define libc_feholdsetroundl_ctx libc_feholdsetround_ppc_ctx
166 #define libc_feholdsetround_noex_ctx libc_feholdsetround_noex_ppc_ctx
167 #define libc_feholdsetround_noexf_ctx libc_feholdsetround_noex_ppc_ctx
168 #define libc_feholdsetround_noexl_ctx libc_feholdsetround_noex_ppc_ctx
169 #define libc_feresetround_ctx libc_feresetround_ppc_ctx
170 #define libc_feresetroundf_ctx libc_feresetround_ppc_ctx
171 #define libc_feresetroundl_ctx libc_feresetround_ppc_ctx
172 #define libc_feupdateenv_ctx libc_feupdateenv_ppc_ctx
173 #define libc_feupdateenvf_ctx libc_feupdateenv_ppc_ctx
174 #define libc_feupdateenvl_ctx libc_feupdateenv_ppc_ctx
175
176 #include_next <fenv_private.h>
177
178 #endif