]>
Commit | Line | Data |
---|---|---|
7ad6d73d | 1 | /* Inline floating-point environment handling functions for powerpc. |
04277e02 | 2 | Copyright (C) 1995-2019 Free Software Foundation, Inc. |
7ad6d73d UD |
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 | |
41bdb6e2 AJ |
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. | |
7ad6d73d UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
7ad6d73d | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
7ad6d73d | 18 | |
4a3d3999 | 19 | #if defined __GNUC__ && !defined _SOFT_FLOAT && !defined __NO_FPRS__ |
7ad6d73d | 20 | |
3db85a98 PC |
21 | /* Inline definitions for fegetround. */ |
22 | # define __fegetround_ISA300() \ | |
23 | (__extension__ ({ \ | |
24 | union { double __d; unsigned long long __ll; } __u; \ | |
25 | __asm__ __volatile__ ( \ | |
26 | ".machine push; .machine \"power9\"; mffsl %0; .machine pop" \ | |
27 | : "=f" (__u.__d)); \ | |
28 | __u.__ll & 0x0000000000000003LL; \ | |
29 | })) | |
30 | ||
31 | # define __fegetround_ISA2() \ | |
32 | (__extension__ ({ \ | |
33 | int __fegetround_result; \ | |
34 | __asm__ __volatile__ ("mcrfs 7,7 ; mfcr %0" \ | |
35 | : "=r"(__fegetround_result) : : "cr7"); \ | |
36 | __fegetround_result & 3; \ | |
37 | })) | |
38 | ||
39 | # ifdef _ARCH_PWR9 | |
40 | # define __fegetround() __fegetround_ISA300() | |
41 | # elif defined __BUILTIN_CPU_SUPPORTS__ | |
42 | # define __fegetround() \ | |
43 | (__glibc_likely (__builtin_cpu_supports ("arch_3_00")) \ | |
44 | ? __fegetround_ISA300() \ | |
45 | : __fegetround_ISA2() \ | |
46 | ) | |
47 | # else | |
48 | # define __fegetround() __fegetround_ISA2() | |
49 | # endif | |
50 | ||
4a3d3999 | 51 | # define fegetround() __fegetround () |
7ad6d73d | 52 | |
4a3d3999 | 53 | # ifndef __NO_MATH_INLINES |
7ad6d73d UD |
54 | /* The weird 'i#*X' constraints on the following suppress a gcc |
55 | warning when __excepts is not a constant. Otherwise, they mean the | |
56 | same as just plain 'i'. */ | |
57 | ||
183a34dc GG |
58 | # if __GNUC_PREREQ(3, 4) |
59 | ||
7ad6d73d | 60 | /* Inline definition for feraiseexcept. */ |
183a34dc | 61 | # define feraiseexcept(__excepts) \ |
85b29045 AZ |
62 | (__extension__ ({ \ |
63 | int __e = __excepts; \ | |
64 | int __ret; \ | |
65 | if (__builtin_constant_p (__e) \ | |
66 | && (__e & (__e - 1)) == 0 \ | |
67 | && __e != FE_INVALID) \ | |
68 | { \ | |
69 | if (__e != 0) \ | |
183a34dc GG |
70 | __asm__ __volatile__ ("mtfsb1 %0" \ |
71 | : : "i#*X" (__builtin_clz (__e))); \ | |
85b29045 AZ |
72 | __ret = 0; \ |
73 | } \ | |
74 | else \ | |
75 | __ret = feraiseexcept (__e); \ | |
76 | __ret; \ | |
77 | })) | |
7ad6d73d UD |
78 | |
79 | /* Inline definition for feclearexcept. */ | |
183a34dc | 80 | # define feclearexcept(__excepts) \ |
85b29045 AZ |
81 | (__extension__ ({ \ |
82 | int __e = __excepts; \ | |
83 | int __ret; \ | |
84 | if (__builtin_constant_p (__e) \ | |
85 | && (__e & (__e - 1)) == 0 \ | |
86 | && __e != FE_INVALID) \ | |
87 | { \ | |
88 | if (__e != 0) \ | |
183a34dc GG |
89 | __asm__ __volatile__ ("mtfsb0 %0" \ |
90 | : : "i#*X" (__builtin_clz (__e))); \ | |
85b29045 AZ |
91 | __ret = 0; \ |
92 | } \ | |
93 | else \ | |
94 | __ret = feclearexcept (__e); \ | |
95 | __ret; \ | |
96 | })) | |
7ad6d73d | 97 | |
183a34dc GG |
98 | # endif /* __GNUC_PREREQ(3, 4). */ |
99 | ||
4a3d3999 JM |
100 | # endif /* !__NO_MATH_INLINES. */ |
101 | ||
59981e9b | 102 | #endif /* __GNUC__ && !_SOFT_FLOAT && !__NO_FPRS__ */ |