]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/fpu/math_private.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / powerpc / fpu / math_private.h
1 /* Private inline math functions for powerpc.
2 Copyright (C) 2006-2015 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 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _PPC_MATH_PRIVATE_H_
20 #define _PPC_MATH_PRIVATE_H_
21
22 #include <sysdep.h>
23 #include <ldsodefs.h>
24 #include <dl-procinfo.h>
25 #include <fenv_private.h>
26 #include_next <math_private.h>
27
28 # if __WORDSIZE == 64 || defined _ARCH_PWR4
29 # define __CPU_HAS_FSQRT 1
30 # else
31 # define __CPU_HAS_FSQRT ((GLRO(dl_hwcap) & PPC_FEATURE_64) != 0)
32 # endif
33
34 extern double __slow_ieee754_sqrt (double);
35 extern __always_inline double
36 __ieee754_sqrt (double __x)
37 {
38 double __z;
39
40 if (__CPU_HAS_FSQRT)
41 {
42 /* Volatile is required to prevent the compiler from moving the
43 fsqrt instruction above the branch. */
44 __asm __volatile ("fsqrt %0,%1" : "=f" (__z) : "f" (__x));
45 }
46 else
47 __z = __slow_ieee754_sqrt(__x);
48
49 return __z;
50 }
51
52 extern float __slow_ieee754_sqrtf (float);
53 extern __always_inline float
54 __ieee754_sqrtf (float __x)
55 {
56 float __z;
57
58 if (__CPU_HAS_FSQRT)
59 {
60 /* Volatile is required to prevent the compiler from moving the
61 fsqrts instruction above the branch. */
62 __asm __volatile ("fsqrts %0,%1" : "=f" (__z) : "f" (__x));
63 }
64 else
65 __z = __slow_ieee754_sqrtf(__x);
66
67 return __z;
68 }
69
70 #if defined _ARCH_PWR5X
71
72 # ifndef __round
73 # define __round(x) \
74 ({ double __z; \
75 __asm __volatile ( \
76 " frin %0,%1\n" \
77 : "=f" (__z) \
78 : "f" (x)); \
79 __z; })
80 # endif
81 # ifndef __roundf
82 # define __roundf(x) \
83 ({ float __z; \
84 __asm __volatile ( \
85 " frin %0,%1\n" \
86 " frsp %0,%0\n" \
87 : "=f" (__z) \
88 : "f" (x)); \
89 __z; })
90 # endif
91
92 # ifndef __trunc
93 # define __trunc(x) \
94 ({ double __z; \
95 __asm __volatile ( \
96 " friz %0,%1\n" \
97 : "=f" (__z) \
98 : "f" (x)); \
99 __z; })
100 # endif
101 # ifndef __truncf
102 # define __truncf(x) \
103 ({ float __z; \
104 __asm __volatile ( \
105 " friz %0,%1\n" \
106 " frsp %0,%0\n" \
107 : "=f" (__z) \
108 : "f" (x)); \
109 __z; })
110 # endif
111
112 # ifndef __ceil
113 # define __ceil(x) \
114 ({ double __z; \
115 __asm __volatile ( \
116 " frip %0,%1\n" \
117 : "=f" (__z) \
118 : "f" (x)); \
119 __z; })
120 # endif
121 # ifndef __ceilf
122 # define __ceilf(x) \
123 ({ float __z; \
124 __asm __volatile ( \
125 " frip %0,%1\n" \
126 " frsp %0,%0\n" \
127 : "=f" (__z) \
128 : "f" (x)); \
129 __z; })
130 # endif
131
132 # ifndef __floor
133 # define __floor(x) \
134 ({ double __z; \
135 __asm __volatile ( \
136 " frim %0,%1\n" \
137 : "=f" (__z) \
138 : "f" (x)); \
139 __z; })
140 # endif
141 # ifndef __floorf
142 # define __floorf(x) \
143 ({ float __z; \
144 __asm __volatile ( \
145 " frim %0,%1\n" \
146 " frsp %0,%0\n" \
147 : "=f" (__z) \
148 : "f" (x)); \
149 __z; })
150 # endif
151
152 #endif /* defined _ARCH_PWR5X */
153
154 #endif /* _PPC_MATH_PRIVATE_H_ */