* sysdeps/m68k/fpu/bits/mathinline.h: Don't define log2 as inline.
[glibc.git] / sysdeps / m68k / fpu / bits / mathinline.h
blobcb59773f1662917964458702c2c33f64b3241008
1 /* Definitions of inline math functions implemented by the m68881/2.
2 Copyright (C) 1991,92,93,94,96,97,98,99,2000 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #ifdef __GNUC__
22 #ifdef __USE_ISOC99
24 /* ISO C99 defines some macros to perform unordered comparisons. The
25 m68k FPU supports this with special opcodes and we should use them.
26 These must not be inline functions since we have to be able to handle
27 all floating-point types. */
28 # define isgreater(x, y) \
29 __extension__ \
30 ({ char __result; \
31 __asm__ ("fcmp%.x %2,%1; fsogt %0" \
32 : "=dm" (__result) : "f" (x), "f" (y)); \
33 __result != 0; })
35 # define isgreaterequal(x, y) \
36 __extension__ \
37 ({ char __result; \
38 __asm__ ("fcmp%.x %2,%1; fsoge %0" \
39 : "=dm" (__result) : "f" (x), "f" (y)); \
40 __result != 0; })
42 # define isless(x, y) \
43 __extension__ \
44 ({ char __result; \
45 __asm__ ("fcmp%.x %2,%1; fsolt %0" \
46 : "=dm" (__result) : "f" (x), "f" (y)); \
47 __result != 0; })
49 # define islessequal(x, y) \
50 __extension__ \
51 ({ char __result; \
52 __asm__ ("fcmp%.x %2,%1; fsole %0" \
53 : "=dm" (__result) : "f" (x), "f" (y)); \
54 __result != 0; })
56 # define islessgreater(x, y) \
57 __extension__ \
58 ({ char __result; \
59 __asm__ ("fcmp%.x %2,%1; fsogl %0" \
60 : "=dm" (__result) : "f" (x), "f" (y)); \
61 __result != 0; })
63 # define isunordered(x, y) \
64 __extension__ \
65 ({ char __result; \
66 __asm__ ("fcmp%.x %2,%1; fsun %0" \
67 : "=dm" (__result) : "f" (x), "f" (y)); \
68 __result != 0; })
69 #endif
72 #if (!defined __NO_MATH_INLINES && defined __OPTIMIZE__) \
73 || defined __LIBC_INTERNAL_MATH_INLINES
75 #ifdef __LIBC_INTERNAL_MATH_INLINES
76 /* This is used when defining the functions themselves. Define them with
77 __ names, and with `static inline' instead of `extern inline' so the
78 bodies will always be used, never an external function call. */
79 # define __m81_u(x) __CONCAT(__,x)
80 # define __m81_inline static __inline
81 #else
82 # define __m81_u(x) x
83 # ifdef __cplusplus
84 # define __m81_inline __inline
85 # else
86 # define __m81_inline extern __inline
87 # endif
88 # define __M81_MATH_INLINES 1
89 #endif
91 /* Define a const math function. */
92 #define __m81_defun(rettype, func, args) \
93 __m81_inline rettype __attribute__((__const__)) \
94 __m81_u(func) args
96 /* Define the three variants of a math function that has a direct
97 implementation in the m68k fpu. FUNC is the name for C (which will be
98 suffixed with f and l for the float and long double version, resp). OP
99 is the name of the fpu operation (without leading f). */
101 #if defined __USE_MISC || defined __USE_ISOC99
102 # define __inline_mathop(func, op) \
103 __inline_mathop1(double, func, op) \
104 __inline_mathop1(float, __CONCAT(func,f), op) \
105 __inline_mathop1(long double, __CONCAT(func,l), op)
106 #else
107 # define __inline_mathop(func, op) \
108 __inline_mathop1(double, func, op)
109 #endif
111 #define __inline_mathop1(float_type,func, op) \
112 __m81_defun (float_type, func, (float_type __mathop_x)) __THROW \
114 float_type __result; \
115 __asm("f" __STRING(op) "%.x %1, %0" : "=f" (__result) : "f" (__mathop_x));\
116 return __result; \
119 __inline_mathop(__atan, atan)
120 __inline_mathop(__cos, cos)
121 __inline_mathop(__sin, sin)
122 __inline_mathop(__tan, tan)
123 __inline_mathop(__tanh, tanh)
124 __inline_mathop(__fabs, abs)
126 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
127 __inline_mathop(__rint, int)
128 __inline_mathop(__expm1, etoxm1)
129 __inline_mathop(__log1p, lognp1)
130 #endif
132 #ifdef __USE_MISC
133 __inline_mathop(__significand, getman)
134 #endif
136 #ifdef __USE_ISOC99
137 __inline_mathop(__trunc, intrz)
138 #endif
140 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
142 __inline_mathop(atan, atan)
143 __inline_mathop(cos, cos)
144 __inline_mathop(sin, sin)
145 __inline_mathop(tan, tan)
146 __inline_mathop(tanh, tanh)
148 # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
149 __inline_mathop(rint, int)
150 __inline_mathop(expm1, etoxm1)
151 __inline_mathop(log1p, lognp1)
152 # endif
154 # ifdef __USE_MISC
155 __inline_mathop(significand, getman)
156 # endif
158 # ifdef __USE_ISOC99
159 __inline_mathop(trunc, intrz)
160 # endif
162 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
164 /* This macro contains the definition for the rest of the inline
165 functions, using FLOAT_TYPE as the domain type and S as the suffix
166 for the function names. */
168 #define __inline_functions(float_type, s) \
169 __m81_inline float_type \
170 __m81_u(__CONCAT(__frexp,s))(float_type __value, int *__expptr) __THROW \
172 float_type __mantissa, __exponent; \
173 int __iexponent; \
174 unsigned long __fpsr; \
175 __asm("ftst%.x %1\n" \
176 "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value)); \
177 if (__fpsr & (7 << 24)) \
179 /* Not finite or zero. */ \
180 *__expptr = 0; \
181 return __value; \
183 __asm("fgetexp%.x %1, %0" : "=f" (__exponent) : "f" (__value)); \
184 __iexponent = (int) __exponent + 1; \
185 *__expptr = __iexponent; \
186 __asm("fscale%.l %2, %0" : "=f" (__mantissa) \
187 : "0" (__value), "dmi" (-__iexponent)); \
188 return __mantissa; \
191 __m81_defun (float_type, __CONCAT(__floor,s), (float_type __x)) __THROW \
193 float_type __result; \
194 unsigned long int __ctrl_reg; \
195 __asm __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg)); \
196 /* Set rounding towards negative infinity. */ \
197 __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
198 : "dmi" ((__ctrl_reg & ~0x10) | 0x20)); \
199 /* Convert X to an integer, using -Inf rounding. */ \
200 __asm __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x)); \
201 /* Restore the previous rounding mode. */ \
202 __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
203 : "dmi" (__ctrl_reg)); \
204 return __result; \
207 __m81_defun (float_type, __CONCAT(__ceil,s), (float_type __x)) __THROW \
209 float_type __result; \
210 unsigned long int __ctrl_reg; \
211 __asm __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg)); \
212 /* Set rounding towards positive infinity. */ \
213 __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
214 : "dmi" (__ctrl_reg | 0x30)); \
215 /* Convert X to an integer, using +Inf rounding. */ \
216 __asm __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x)); \
217 /* Restore the previous rounding mode. */ \
218 __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
219 : "dmi" (__ctrl_reg)); \
220 return __result; \
223 __inline_functions(double,)
224 #if defined __USE_MISC || defined __USE_ISOC99
225 __inline_functions(float,f)
226 __inline_functions(long double,l)
227 #endif
228 #undef __inline_functions
230 #ifdef __USE_MISC
232 # define __inline_functions(float_type, s) \
233 __m81_defun (int, __CONCAT(__isinf,s), (float_type __value)) __THROW \
235 /* There is no branch-condition for infinity, \
236 so we must extract and examine the condition codes manually. */ \
237 unsigned long int __fpsr; \
238 __asm("ftst%.x %1\n" \
239 "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value)); \
240 return (__fpsr & (2 << 24)) ? (__fpsr & (8 << 24) ? -1 : 1) : 0; \
243 __m81_defun (int, __CONCAT(__finite,s), (float_type __value)) __THROW \
245 /* There is no branch-condition for infinity, so we must extract and \
246 examine the condition codes manually. */ \
247 unsigned long int __fpsr; \
248 __asm ("ftst%.x %1\n" \
249 "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value)); \
250 return (__fpsr & (3 << 24)) == 0; \
253 __m81_defun (float_type, __CONCAT(__scalbn,s), \
254 (float_type __x, int __n)) __THROW \
256 float_type __result; \
257 __asm ("fscale%.l %1, %0" : "=f" (__result) : "dmi" (__n), "0" (__x)); \
258 return __result; \
261 __inline_functions(double,)
262 __inline_functions(float,f)
263 __inline_functions(long double,l)
264 # undef __inline_functions
266 #endif /* Use misc. */
268 #if defined __USE_MISC || defined __USE_XOPEN
270 # define __inline_functions(float_type, s) \
271 __m81_defun (int, __CONCAT(__isnan,s), (float_type __value)) __THROW \
273 char __result; \
274 __asm("ftst%.x %1\n" \
275 "fsun %0" : "=dm" (__result) : "f" (__value)); \
276 return __result; \
279 __inline_functions(double,)
280 # ifdef __USE_MISC
281 __inline_functions(float,f)
282 __inline_functions(long double,l)
283 # endif
284 # undef __inline_functions
286 #endif
288 #ifdef __USE_ISOC99
290 # define __inline_functions(float_type, s) \
291 __m81_defun (int, __CONCAT(__signbit,s), (float_type __value)) __THROW \
293 /* There is no branch-condition for the sign bit, so we must extract \
294 and examine the condition codes manually. */ \
295 unsigned long int __fpsr; \
296 __asm ("ftst%.x %1\n" \
297 "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value)); \
298 return (__fpsr >> 27) & 1; \
301 __m81_defun (float_type, __CONCAT(__scalbln,s), \
302 (float_type __x, long int __n)) __THROW \
304 return __CONCAT(__scalbn,s) (__x, __n); \
307 __m81_defun (float_type, __CONCAT(__nearbyint,s), (float_type __x)) __THROW \
309 float_type __result; \
310 unsigned long int __ctrl_reg; \
311 __asm __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg)); \
312 /* Temporarily disable the inexact exception. */ \
313 __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
314 : "dmi" (__ctrl_reg & ~0x200)); \
315 __asm __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x)); \
316 __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
317 : "dmi" (__ctrl_reg)); \
318 return __result; \
321 __m81_defun (long int, __CONCAT(__lrint,s), (float_type __x)) __THROW \
323 long int __result; \
324 __asm ("fmove%.l %1, %0" : "=dm" (__result) : "f" (__x)); \
325 return __result; \
328 __m81_inline float_type \
329 __m81_u(__CONCAT(__fma,s))(float_type __x, float_type __y, \
330 float_type __z) __THROW \
332 return (__x * __y) + __z; \
335 __inline_functions (double,)
336 __inline_functions (float,f)
337 __inline_functions (long double,l)
338 # undef __inline_functions
340 #endif /* Use ISO C9x */
342 #ifdef __USE_GNU
344 # define __inline_functions(float_type, s) \
345 __m81_inline void \
346 __m81_u(__CONCAT(__sincos,s))(float_type __x, float_type *__sinx, \
347 float_type *__cosx) __THROW \
349 __asm ("fsincos%.x %2,%1:%0" \
350 : "=f" (*__sinx), "=f" (*__cosx) : "f" (__x)); \
353 __inline_functions (double,)
354 __inline_functions (float,f)
355 __inline_functions (long double,l)
356 # undef __inline_functions
358 #endif
360 #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
362 /* Define inline versions of the user visible functions. */
364 /* Note that there must be no whitespace before the argument passed for
365 NAME, to make token pasting work correctly with -traditional. */
366 # define __inline_forward_c(rettype, name, args1, args2) \
367 extern __inline rettype __attribute__((__const__)) \
368 name args1 __THROW \
370 return __CONCAT(__,name) args2; \
373 # define __inline_forward(rettype, name, args1, args2) \
374 extern __inline rettype name args1 __THROW \
376 return __CONCAT(__,name) args2; \
379 __inline_forward(double,frexp, (double __value, int *__expptr),
380 (__value, __expptr))
381 __inline_forward_c(double,floor, (double __x), (__x))
382 __inline_forward_c(double,ceil, (double __x), (__x))
383 # ifdef __USE_MISC
384 # ifndef __USE_ISOC99 /* Conflict with macro of same name. */
385 __inline_forward_c(int,isinf, (double __value), (__value))
386 # endif
387 __inline_forward_c(int,finite, (double __value), (__value))
388 __inline_forward_c(double,scalbn, (double __x, int __n), (__x, __n))
389 # endif
390 # if defined __USE_MISC || defined __USE_XOPEN
391 # ifndef __USE_ISOC99 /* Conflict with macro of same name. */
392 __inline_forward_c(int,isnan, (double __value), (__value))
393 # endif
394 # endif
395 # ifdef __USE_ISOC99
396 __inline_forward_c(double,scalbln, (double __x, long int __n), (__x, __n))
397 __inline_forward_c(double,nearbyint, (double __value), (__value))
398 __inline_forward_c(long int,lrint, (double __value), (__value))
399 __inline_forward_c(double,fma, (double __x, double __y, double __z),
400 (__x, __y, __z))
401 # endif
402 # ifdef __USE_GNU
403 __inline_forward(void,sincos, (double __x, double *__sinx, double *__cosx),
404 (__x, __sinx, __cosx))
405 # endif
407 # if defined __USE_MISC || defined __USE_ISOC99
409 __inline_forward(float,frexpf, (float __value, int *__expptr),
410 (__value, __expptr))
411 __inline_forward_c(float,floorf, (float __x), (__x))
412 __inline_forward_c(float,ceilf, (float __x), (__x))
413 # ifdef __USE_MISC
414 __inline_forward_c(int,isinff, (float __value), (__value))
415 __inline_forward_c(int,finitef, (float __value), (__value))
416 __inline_forward_c(float,scalbnf, (float __x, int __n), (__x, __n))
417 __inline_forward_c(int,isnanf, (float __value), (__value))
418 # endif
419 # ifdef __USE_ISOC99
420 __inline_forward_c(float,scalblnf, (float __x, long int __n), (__x, __n))
421 __inline_forward_c(float,nearbyintf, (float __value), (__value))
422 __inline_forward_c(long int,lrintf, (float __value), (__value))
423 __inline_forward_c(float,fmaf, (float __x, float __y, float __z),
424 (__x, __y, __z))
425 # endif
426 # ifdef __USE_GNU
427 __inline_forward(void,sincosf, (float __x, float *__sinx, float *__cosx),
428 (__x, __sinx, __cosx))
429 # endif
431 __inline_forward(long double,frexpl, (long double __value, int *__expptr),
432 (__value, __expptr))
433 __inline_forward_c(long double,floorl, (long double __x), (__x))
434 __inline_forward_c(long double,ceill, (long double __x), (__x))
435 # ifdef __USE_MISC
436 __inline_forward_c(int,isinfl, (long double __value), (__value))
437 __inline_forward_c(int,finitel, (long double __value), (__value))
438 __inline_forward_c(long double,scalbnl, (long double __x, int __n), (__x, __n))
439 __inline_forward_c(int,isnanl, (long double __value), (__value))
440 # endif
441 # ifdef __USE_ISOC99
442 __inline_forward_c(long double,scalblnl, (long double __x, long int __n),
443 (__x, __n))
444 __inline_forward_c(long double,nearbyintl, (long double __value), (__value))
445 __inline_forward_c(long int,lrintl, (long double __value), (__value))
446 __inline_forward_c(long double,fmal,
447 (long double __x, long double __y, long double __z),
448 (__x, __y, __z))
449 # endif
450 # ifdef __USE_GNU
451 __inline_forward(void,sincosl,
452 (long double __x, long double *__sinx, long double *__cosx),
453 (__x, __sinx, __cosx))
454 # endif
456 #endif /* Use misc or ISO C99 */
458 #undef __inline_forward
459 #undef __inline_forward_c
461 #endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
463 #endif
464 #endif /* GCC. */