]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/m68k/bits/mathinline.h
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / m68k / bits / mathinline.h
1 /* Definitions of inline math functions implemented by the m68881/2.
2    Copyright (C) 1991,92,93,94,96,97,98,99,2000,2002, 2003, 2004
3      Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 #ifdef  __GNUC__
21
22 #ifdef __USE_ISOC99
23 /* GCC 3.1 and up have builtins that actually can be used.  */
24 # if !__GNUC_PREREQ (3,1)
25 /* ISO C99 defines some macros to perform unordered comparisons.  The
26    m68k FPU supports this with special opcodes and we should use them.
27    These must not be inline functions since we have to be able to handle
28    all floating-point types.  */
29 #  undef isgreater
30 #  undef isgreaterequal
31 #  undef isless
32 #  undef islessequal
33 #  undef islessgreater
34 #  undef isunordered
35 #  define isgreater(x, y)                                       \
36    __extension__                                        \
37    ({ char __result;                                    \
38       __asm__ ("fcmp%.x %2,%1; fsogt %0"                \
39                : "=dm" (__result) : "f" (x), "f" (y));  \
40       __result != 0; })
41
42 #  define isgreaterequal(x, y)                          \
43    __extension__                                        \
44    ({ char __result;                                    \
45       __asm__ ("fcmp%.x %2,%1; fsoge %0"                \
46                : "=dm" (__result) : "f" (x), "f" (y));  \
47       __result != 0; })
48
49 #  define isless(x, y)                                  \
50    __extension__                                        \
51    ({ char __result;                                    \
52       __asm__ ("fcmp%.x %2,%1; fsolt %0"                \
53                : "=dm" (__result) : "f" (x), "f" (y));  \
54       __result != 0; })
55
56 #  define islessequal(x, y)                             \
57    __extension__                                        \
58    ({ char __result;                                    \
59       __asm__ ("fcmp%.x %2,%1; fsole %0"                \
60                : "=dm" (__result) : "f" (x), "f" (y));  \
61       __result != 0; })
62
63 #  define islessgreater(x, y)                           \
64    __extension__                                        \
65    ({ char __result;                                    \
66       __asm__ ("fcmp%.x %2,%1; fsogl %0"                \
67                : "=dm" (__result) : "f" (x), "f" (y));  \
68       __result != 0; })
69
70 #  define isunordered(x, y)                             \
71    __extension__                                        \
72    ({ char __result;                                    \
73       __asm__ ("fcmp%.x %2,%1; fsun %0"                 \
74                : "=dm" (__result) : "f" (x), "f" (y));  \
75       __result != 0; })
76 # endif /* GCC 3.1 */
77 #endif
78
79
80 #if (!defined __NO_MATH_INLINES && defined __OPTIMIZE__) \
81     || defined __LIBC_INTERNAL_MATH_INLINES
82
83 #ifdef  __LIBC_INTERNAL_MATH_INLINES
84 /* This is used when defining the functions themselves.  Define them with
85    __ names, and with `static inline' instead of `extern inline' so the
86    bodies will always be used, never an external function call.  */
87 # define __m81_u(x)             __CONCAT(__,x)
88 # define __m81_inline           static __inline
89 #else
90 # define __m81_u(x)             x
91 # ifdef __cplusplus
92 #  define __m81_inline          __inline
93 # else
94 #  define __m81_inline          extern __inline
95 # endif
96 # define __M81_MATH_INLINES     1
97 #endif
98
99 /* Define a const math function.  */
100 #define __m81_defun(rettype, func, args)                                      \
101   __m81_inline rettype __attribute__((__const__))                             \
102   __m81_u(func) args
103
104 /* Define the three variants of a math function that has a direct
105    implementation in the m68k fpu.  FUNC is the name for C (which will be
106    suffixed with f and l for the float and long double version, resp).  OP
107    is the name of the fpu operation (without leading f).  */
108
109 #if defined __USE_MISC || defined __USE_ISOC99
110 # define __inline_mathop(func, op)                      \
111   __inline_mathop1(double, func, op)                    \
112   __inline_mathop1(float, __CONCAT(func,f), op) \
113   __inline_mathop1(long double, __CONCAT(func,l), op)
114 #else
115 # define __inline_mathop(func, op)                      \
116   __inline_mathop1(double, func, op)
117 #endif
118
119 #define __inline_mathop1(float_type,func, op)                                 \
120   __m81_defun (float_type, func, (float_type __mathop_x))                     \
121   {                                                                           \
122     float_type __result;                                                      \
123     __asm__("f" __STRING(op) "%.x %1, %0" : "=f" (__result) : "f" (__mathop_x));\
124     return __result;                                                          \
125   }
126
127 __inline_mathop(__atan, atan)
128 __inline_mathop(__cos, cos)
129 __inline_mathop(__sin, sin)
130 __inline_mathop(__tan, tan)
131 __inline_mathop(__tanh, tanh)
132 __inline_mathop(__fabs, abs)
133
134 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
135 __inline_mathop(__rint, int)
136 __inline_mathop(__expm1, etoxm1)
137 __inline_mathop(__log1p, lognp1)
138 #endif
139
140 #ifdef __USE_MISC
141 __inline_mathop(__significand, getman)
142 #endif
143
144 #ifdef __USE_ISOC99
145 __inline_mathop(__trunc, intrz)
146 #endif
147
148 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
149
150 __inline_mathop(atan, atan)
151 __inline_mathop(cos, cos)
152 __inline_mathop(sin, sin)
153 __inline_mathop(tan, tan)
154 __inline_mathop(tanh, tanh)
155
156 # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
157 __inline_mathop(rint, int)
158 __inline_mathop(expm1, etoxm1)
159 __inline_mathop(log1p, lognp1)
160 # endif
161
162 # ifdef __USE_MISC
163 __inline_mathop(significand, getman)
164 # endif
165
166 # ifdef __USE_ISOC99
167 __inline_mathop(trunc, intrz)
168 # endif
169
170 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
171
172 /* This macro contains the definition for the rest of the inline
173    functions, using FLOAT_TYPE as the domain type and S as the suffix
174    for the function names.  */
175
176 #define __inline_functions(float_type, s)                                 \
177 __m81_defun (float_type, __CONCAT(__floor,s), (float_type __x))   \
178 {                                                                         \
179   float_type __result;                                                    \
180   unsigned long int __ctrl_reg;                                           \
181   __asm__ __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg));                  \
182   /* Set rounding towards negative infinity.  */                          \
183   __asm__ __volatile__ ("fmove%.l %0, %!" : /* No outputs.  */            \
184                       : "dmi" ((__ctrl_reg & ~0x10) | 0x20));             \
185   /* Convert X to an integer, using -Inf rounding.  */                    \
186   __asm__ __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x));          \
187   /* Restore the previous rounding mode.  */                              \
188   __asm__ __volatile__ ("fmove%.l %0, %!" : /* No outputs.  */            \
189                       : "dmi" (__ctrl_reg));                              \
190   return __result;                                                        \
191 }                                                                         \
192                                                                           \
193 __m81_defun (float_type, __CONCAT(__ceil,s), (float_type __x))            \
194 {                                                                         \
195   float_type __result;                                                    \
196   unsigned long int __ctrl_reg;                                           \
197   __asm__ __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg));                  \
198   /* Set rounding towards positive infinity.  */                          \
199   __asm__ __volatile__ ("fmove%.l %0, %!" : /* No outputs.  */            \
200                       : "dmi" (__ctrl_reg | 0x30));                       \
201   /* Convert X to an integer, using +Inf rounding.  */                    \
202   __asm__ __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x));          \
203   /* Restore the previous rounding mode.  */                              \
204   __asm__ __volatile__ ("fmove%.l %0, %!" : /* No outputs.  */            \
205                       : "dmi" (__ctrl_reg));                              \
206   return __result;                                                        \
207 }
208
209 __inline_functions(double,)
210 #if defined __USE_MISC || defined __USE_ISOC99
211 __inline_functions(float,f)
212 __inline_functions(long double,l)
213 #endif
214 #undef __inline_functions
215
216 #ifdef __USE_MISC
217
218 # define __inline_functions(float_type, s)                                \
219 __m81_defun (int, __CONCAT(__isinf,s), (float_type __value))              \
220 {                                                                         \
221   /* There is no branch-condition for infinity,                           \
222      so we must extract and examine the condition codes manually.  */     \
223   unsigned long int __fpsr;                                               \
224   __asm__("ftst%.x %1\n"                                                          \
225         "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value));          \
226   return (__fpsr & (2 << 24)) ? (__fpsr & (8 << 24) ? -1 : 1) : 0;        \
227 }                                                                         \
228                                                                           \
229 __m81_defun (int, __CONCAT(__finite,s), (float_type __value))             \
230 {                                                                         \
231   /* There is no branch-condition for infinity, so we must extract and    \
232      examine the condition codes manually.  */                            \
233   unsigned long int __fpsr;                                               \
234   __asm__ ("ftst%.x %1\n"                                                         \
235          "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value));         \
236   return (__fpsr & (3 << 24)) == 0;                                       \
237 }                                                                         \
238                                                                           \
239 __m81_defun (float_type, __CONCAT(__scalbn,s),                            \
240              (float_type __x, int __n))                                   \
241 {                                                                         \
242   float_type __result;                                                    \
243   __asm__ ("fscale%.l %1, %0" : "=f" (__result) : "dmi" (__n), "0" (__x));  \
244   return __result;                                                        \
245 }
246
247 __inline_functions(double,)
248 __inline_functions(float,f)
249 __inline_functions(long double,l)
250 # undef __inline_functions
251
252 #endif /* Use misc.  */
253
254 #if defined __USE_MISC || defined __USE_XOPEN
255
256 # define __inline_functions(float_type, s)                                \
257 __m81_defun (int, __CONCAT(__isnan,s), (float_type __value))              \
258 {                                                                         \
259   char __result;                                                          \
260   __asm__("ftst%.x %1\n"                                                          \
261         "fsun %0" : "=dm" (__result) : "f" (__value));                    \
262   return __result;                                                        \
263 }
264
265 __inline_functions(double,)
266 # ifdef __USE_MISC
267 __inline_functions(float,f)
268 __inline_functions(long double,l)
269 # endif
270 # undef __inline_functions
271
272 #endif
273
274 #ifdef __USE_ISOC99
275
276 # define __inline_functions(float_type, s)                                \
277 __m81_defun (int, __CONCAT(__signbit,s), (float_type __value))            \
278 {                                                                         \
279   /* There is no branch-condition for the sign bit, so we must extract    \
280      and examine the condition codes manually.  */                        \
281   unsigned long int __fpsr;                                               \
282   __asm__ ("ftst%.x %1\n"                                                         \
283          "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value));         \
284   return (__fpsr >> 27) & 1;                                              \
285 }                                                                         \
286                                                                           \
287   __m81_defun (float_type, __CONCAT(__scalbln,s),                         \
288              (float_type __x, long int __n))                              \
289 {                                                                         \
290   return __CONCAT(__scalbn,s) (__x, __n);                                 \
291 }                                                                         \
292                                                                           \
293 __m81_defun (float_type, __CONCAT(__nearbyint,s), (float_type __x))       \
294 {                                                                         \
295   float_type __result;                                                    \
296   unsigned long int __ctrl_reg;                                           \
297   __asm__ __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg));                  \
298   /* Temporarily disable the inexact exception.  */                       \
299   __asm__ __volatile__ ("fmove%.l %0, %!" : /* No outputs.  */            \
300                       : "dmi" (__ctrl_reg & ~0x200));                     \
301   __asm__ __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x));          \
302   __asm__ __volatile__ ("fmove%.l %0, %!" : /* No outputs.  */            \
303                       : "dmi" (__ctrl_reg));                              \
304   return __result;                                                        \
305 }                                                                         \
306                                                                           \
307 __m81_defun (long int, __CONCAT(__lrint,s), (float_type __x))             \
308 {                                                                         \
309   long int __result;                                                      \
310   __asm__ ("fmove%.l %1, %0" : "=dm" (__result) : "f" (__x));             \
311   return __result;                                                        \
312 }                                                                         \
313                                                                           \
314 __m81_inline float_type                                                   \
315 __m81_u(__CONCAT(__fma,s))(float_type __x, float_type __y,                \
316                            float_type __z)                                \
317 {                                                                         \
318   return (__x * __y) + __z;                                               \
319 }
320
321 __inline_functions (double,)
322 __inline_functions (float,f)
323 __inline_functions (long double,l)
324 # undef __inline_functions
325
326 #endif /* Use ISO C9x */
327
328 #ifdef __USE_GNU
329
330 # define __inline_functions(float_type, s)                              \
331 __m81_inline void                                                       \
332 __m81_u(__CONCAT(__sincos,s))(float_type __x, float_type *__sinx,       \
333                               float_type *__cosx)                       \
334 {                                                                       \
335   __asm__ ("fsincos%.x %2,%1:%0"                                                \
336          : "=f" (*__sinx), "=f" (*__cosx) : "f" (__x));                 \
337 }
338
339 __inline_functions (double,)
340 __inline_functions (float,f)
341 __inline_functions (long double,l)
342 # undef __inline_functions
343
344 #endif
345
346 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
347
348 /* Define inline versions of the user visible functions.  */
349
350 /* Note that there must be no whitespace before the argument passed for
351    NAME, to make token pasting work correctly with -traditional.  */
352 # define __inline_forward_c(rettype, name, args1, args2)        \
353 extern __inline rettype __attribute__((__const__))              \
354   name args1                                                    \
355 {                                                               \
356   return __CONCAT(__,name) args2;                               \
357 }
358
359 # define __inline_forward(rettype, name, args1, args2)  \
360 extern __inline rettype name args1                      \
361 {                                                       \
362   return __CONCAT(__,name) args2;                       \
363 }
364
365 __inline_forward_c(double,floor, (double __x), (__x))
366 __inline_forward_c(double,ceil, (double __x), (__x))
367 # ifdef __USE_MISC
368 #  ifndef __USE_ISOC99 /* Conflict with macro of same name.  */
369 __inline_forward_c(int,isinf, (double __value), (__value))
370 #  endif
371 __inline_forward_c(int,finite, (double __value), (__value))
372 __inline_forward_c(double,scalbn, (double __x, int __n), (__x, __n))
373 # endif
374 # if defined __USE_MISC || defined __USE_XOPEN
375 #  ifndef __USE_ISOC99 /* Conflict with macro of same name.  */
376 __inline_forward_c(int,isnan, (double __value), (__value))
377 #  endif
378 # endif
379 # ifdef __USE_ISOC99
380 __inline_forward_c(double,scalbln, (double __x, long int __n), (__x, __n))
381 __inline_forward_c(double,nearbyint, (double __value), (__value))
382 __inline_forward_c(long int,lrint, (double __value), (__value))
383 __inline_forward_c(double,fma, (double __x, double __y, double __z),
384                    (__x, __y, __z))
385 # endif
386 # ifdef __USE_GNU
387 __inline_forward(void,sincos, (double __x, double *__sinx, double *__cosx),
388                  (__x, __sinx, __cosx))
389 # endif
390
391 # if defined __USE_MISC || defined __USE_ISOC99
392
393 __inline_forward_c(float,floorf, (float __x), (__x))
394 __inline_forward_c(float,ceilf, (float __x), (__x))
395 #  ifdef __USE_MISC
396 __inline_forward_c(int,isinff, (float __value), (__value))
397 __inline_forward_c(int,finitef, (float __value), (__value))
398 __inline_forward_c(float,scalbnf, (float __x, int __n), (__x, __n))
399 __inline_forward_c(int,isnanf, (float __value), (__value))
400 #  endif
401 # ifdef __USE_ISOC99
402 __inline_forward_c(float,scalblnf, (float __x, long int __n), (__x, __n))
403 __inline_forward_c(float,nearbyintf, (float __value), (__value))
404 __inline_forward_c(long int,lrintf, (float __value), (__value))
405 __inline_forward_c(float,fmaf, (float __x, float __y, float __z),
406                    (__x, __y, __z))
407 # endif
408 # ifdef __USE_GNU
409 __inline_forward(void,sincosf, (float __x, float *__sinx, float *__cosx),
410                  (__x, __sinx, __cosx))
411 # endif
412
413 __inline_forward_c(long double,floorl, (long double __x), (__x))
414 __inline_forward_c(long double,ceill, (long double __x), (__x))
415 # ifdef __USE_MISC
416 __inline_forward_c(int,isinfl, (long double __value), (__value))
417 __inline_forward_c(int,finitel, (long double __value), (__value))
418 __inline_forward_c(long double,scalbnl, (long double __x, int __n), (__x, __n))
419 __inline_forward_c(int,isnanl, (long double __value), (__value))
420 # endif
421 # ifdef __USE_ISOC99
422 __inline_forward_c(long double,scalblnl, (long double __x, long int __n),
423                    (__x, __n))
424 __inline_forward_c(long double,nearbyintl, (long double __value), (__value))
425 __inline_forward_c(long int,lrintl, (long double __value), (__value))
426 __inline_forward_c(long double,fmal,
427                    (long double __x, long double __y, long double __z),
428                    (__x, __y, __z))
429 # endif
430 # ifdef __USE_GNU
431 __inline_forward(void,sincosl,
432                  (long double __x, long double *__sinx, long double *__cosx),
433                  (__x, __sinx, __cosx))
434 # endif
435
436 #endif /* Use misc or ISO C99 */
437
438 #undef __inline_forward
439 #undef __inline_forward_c
440
441 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
442
443 #endif
444 #endif  /* GCC.  */