]>
git.ipfire.org Git - thirdparty/glibc.git/blob - 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.
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.
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.
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/>. */
19 #ifndef POWERPC_FENV_PRIVATE_H
20 #define POWERPC_FENV_PRIVATE_H 1
23 #include <fenv_libc.h>
24 #include <fpu_control.h>
26 static __always_inline
void
27 libc_feholdexcept_setround_ppc (fenv_t
*envp
, int r
)
29 fenv_union_t old
, new;
31 old
.fenv
= *envp
= fegetenv_register ();
33 __TEST_AND_ENTER_NON_STOP (old
.l
, 0ULL);
35 /* Clear everything and set the rounding mode. */
37 fesetenv_register (new.fenv
);
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
)
44 fenv_union_t old
, new;
47 old
.fenv
= fegetenv_register ();
49 /* Merge bits while masking unwanted bits from new and old env. */
50 new.l
= (old
.l
& old_mask
) | (new.l
& new_mask
);
52 __TEST_AND_EXIT_NON_STOP (old
.l
, new.l
);
53 __TEST_AND_ENTER_NON_STOP (old
.l
, new.l
);
55 /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
56 fesetenv_register (new.fenv
);
61 static __always_inline
void
62 libc_fesetenv_ppc (const fenv_t
*envp
)
64 /* Replace the entire environment. */
65 __libc_femergeenv_ppc (envp
, 0LL, -1LL);
68 static __always_inline
void
69 libc_feresetround_ppc (fenv_t
*envp
)
71 fenv_union_t
new = { .fenv
= *envp
};
72 fegetenv_and_set_rn (new.l
& FPSCR_RN_MASK
);
75 static __always_inline
int
76 libc_feupdateenv_test_ppc (fenv_t
*envp
, int ex
)
78 return __libc_femergeenv_ppc (envp
, ~FPSCR_CONTROL_MASK
,
79 ~FPSCR_STATUS_MASK
) & ex
;
82 static __always_inline
void
83 libc_feupdateenv_ppc (fenv_t
*e
)
85 libc_feupdateenv_test_ppc (e
, 0);
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
108 /* We have support for rounding mode context. */
109 #define HAVE_RM_CTX 1
111 static __always_inline
void
112 libc_feholdsetround_ppc_ctx (struct rm_ctx
*ctx
, int r
)
116 ctx
->env
= old
.fenv
= fegetenv_and_set_rn (r
);
117 ctx
->updated_status
= (r
!= (old
.l
& FPSCR_RN_MASK
));
120 static __always_inline
void
121 libc_feholdsetround_noex_ppc_ctx (struct rm_ctx
*ctx
, int r
)
123 fenv_union_t old
, new;
125 old
.fenv
= fegetenv_register ();
127 new.l
= (old
.l
& ~(FPSCR_ENABLES_MASK
|FPSCR_RN_MASK
)) | r
;
130 if (__glibc_unlikely (new.l
!= old
.l
))
132 __TEST_AND_ENTER_NON_STOP (old
.l
, 0ULL);
133 fesetenv_register (new.fenv
);
134 ctx
->updated_status
= true;
137 ctx
->updated_status
= false;
140 static __always_inline
void
141 libc_fesetenv_ppc_ctx (struct rm_ctx
*ctx
)
143 libc_fesetenv_ppc (&ctx
->env
);
146 static __always_inline
void
147 libc_feupdateenv_ppc_ctx (struct rm_ctx
*ctx
)
149 if (__glibc_unlikely (ctx
->updated_status
))
150 libc_feresetround_ppc (&ctx
->env
);
153 static __always_inline
void
154 libc_feresetround_ppc_ctx (struct rm_ctx
*ctx
)
156 if (__glibc_unlikely (ctx
->updated_status
))
157 libc_feresetround_ppc (&ctx
->env
);
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
176 #include_next <fenv_private.h>