1 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
21 #include <sys/cdefs.h>
23 #ifdef __NO_MATH_INLINES
24 #define __m81_u(x) __CONCAT(__,x)
27 #define __MATH_INLINES 1
30 #define __inline_mathop2(func, op) \
31 extern __inline __const double \
32 __m81_u(func)(double __mathop_x) \
35 __asm("f" __STRING(op) "%.x %1, %0" : "=f" (__result) : "f" (__mathop_x));\
38 #define __inline_mathop(op) __inline_mathop2(op, op)
49 __inline_mathop2(exp, etox)
50 __inline_mathop2(fabs, abs)
51 __inline_mathop(log10)
52 __inline_mathop2(log, logn)
53 __inline_mathop2(floor, intrz)
56 __inline_mathop2(__rint, intr)
59 __inline_mathop2(rint, intr)
60 __inline_mathop2(expm1, etoxm1)
61 __inline_mathop2(log1p, lognp1)
62 __inline_mathop(atanh)
65 extern __inline __const double
66 __m81_u(__drem)(double __x, double __y)
69 __asm("frem%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
73 extern __inline __const double
74 __m81_u(ldexp)(double __x, int __e)
77 double __double_e = (double) __e;
78 __asm("fscale%.x %1, %0" : "=f" (__result) : "f" (__double_e), "0" (__x));
82 extern __inline __const double
83 __m81_u(fmod)(double __x, double __y)
86 __asm("fmod%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
90 extern __inline double
91 __m81_u(frexp)(double __value, int *__expptr)
93 double __mantissa, __exponent;
94 __asm("fgetexp%.x %1, %0" : "=f" (__exponent) : "f" (__value));
95 __asm("fgetman%.x %1, %0" : "=f" (__mantissa) : "f" (__value));
96 *__expptr = (int) __exponent;
100 extern __inline __const double
101 __m81_u(pow)(double __x, double __y)
104 if (__y == 0.0 || __x == 1.0)
109 __result = __x * __x;
110 else if (__x == 10.0)
111 __asm("ftentox%.x %1, %0" : "=f" (__result) : "f" (__y));
113 __asm("ftwotox%.x %1, %0" : "=f" (__result) : "f" (__y));
115 __result = __m81_u(exp)(__y * __m81_u(log)(__x));
119 extern __inline __const double
120 __m81_u(ceil)(double __x)
123 unsigned long int __ctrl_reg;
124 __asm("fmove%.l fpcr, %0" : "=g" (__ctrl_reg));
125 /* Set rounding towards positive infinity. */
126 __asm("fmove%.l %0, fpcr" : /* No outputs. */ : "g" (__ctrl_reg | 0x30));
127 /* Convert X to an integer, using +Inf rounding. */
128 __asm("fint%.x %1, %0" : "=f" (__result) : "f" (__x));
129 /* Restore the previous rounding mode. */
130 __asm("fmove%.l %0, fpcr" : /* No outputs. */ : "g" (__ctrl_reg));
134 extern __inline double
135 __m81_u(modf)(double __value, double *__iptr)
137 double __modf_int = __m81_u(floor)(__value);
138 *__iptr = __modf_int;
139 return __value - __modf_int;
143 __m81_u(__isinf)(double __value)
145 /* There is no branch-condition for infinity,
146 so we must extract and examine the condition codes manually. */
147 unsigned long int __fpsr;
149 "fmove%.l fpsr, %0" : "=g" (__fpsr) : "f" (__value));
150 return (__fpsr & (2 << (3 * 8))) ? (__value < 0 ? -1 : 1) : 0;
154 __m81_u(__isnan)(double __value)
158 "fsun %0" : "=g" (__result) : "f" (__value));