1 /* Copyright (C) 1991 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. */
25 #define __m81_ul(x) __ ## x
29 #define __m81_s(x) "x"
30 #define __m81_ul(x) __/**/x
35 #ifdef __NO_MATH_INLINES
36 #define __m81_u(x) __m81_ul(x)
39 #define __MATH_INLINES 1
42 #define __inline_mathop2(func, op) \
43 extern __inline __const double \
44 __m81_u(func)(double __mathop_x) \
47 __asm("f" __m81_s(op) "%.x %1, %0" : "=f" (__result) : "f" (__mathop_x)); \
50 #define __inline_mathop(op) __inline_mathop2(op, op)
61 __inline_mathop2(exp, etox)
62 __inline_mathop2(fabs, abs)
63 __inline_mathop(log10)
64 __inline_mathop2(log, logn)
65 __inline_mathop2(floor, intrz)
69 __inline_mathop2(rint, int)
70 __inline_mathop2(expm1, etoxm1)
71 __inline_mathop2(log1p, lognp1)
72 __inline_mathop(atanh)
75 extern __inline __const double
76 __m81_u(__drem)(double __x, double __y)
79 __asm("frem%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
83 extern __inline __const double
84 __m81_u(__scalb)(double __x, int __n)
90 __asm("fscale%.l %1, %0" : "=f" (__result) : "g" (__n), "0" (__x));
94 extern __inline __const double
95 __m81_u(ldexp)(double __x, int __e)
98 double __double_e = (double) __e;
99 __asm("fscale%.x %1, %0" : "=f" (__result) : "f" (__double_e), "0" (__x));
103 extern __inline __const double
104 __m81_u(fmod)(double __x, double __y)
107 __asm("fmod%.x %1, %0" : "=f" (__result) : "f" (__y), "0" (__x));
111 extern __inline double
112 __m81_u(frexp)(double __value, int *__expptr)
114 double __mantissa, __exponent;
115 __asm("fgetexp%.x %1, %0" : "=f" (__exponent) : "f" (__value));
116 __asm("fgetman%.x %1, %0" : "=f" (__mantissa) : "f" (__value));
117 *__expptr = (int) __exponent;
121 extern __inline __const double
122 __m81_u(pow)(double __x, double __y)
125 if (__y == 0.0 || __x == 1.0)
130 __result = __x * __x;
131 else if (__x == 10.0)
132 __asm("ftentox%.x %1, %0" : "=f" (__result) : "f" (__y));
134 __asm("ftwotox%.x %1, %0" : "=f" (__result) : "f" (__y));
136 __result = __m81_u(exp)(__y * __m81_u(log)(__x));
140 extern __inline __const double
141 __m81_u(ceil)(double __x)
144 unsigned long int __ctrl_reg;
145 __asm("fmove%.l fpcr, %0" : "=g" (__ctrl_reg));
146 /* Set rounding towards positive infinity. */
147 __asm("fmove%.l %0, fpcr" : /* No outputs. */ : "g" (__ctrl_reg | 0x30));
148 /* Convert X to an integer, using +Inf rounding. */
149 __asm("fint%.x %1, %0" : "=f" (__result) : "f" (__x));
150 /* Restore the previous rounding mode. */
151 __asm("fmove%.l %0, fpcr" : /* No outputs. */ : "g" (__ctrl_reg));
155 extern __inline double
156 __m81_u(modf)(double __value, double *__iptr)
158 double __modf_int = __m81_u(floor)(__value);
159 *__iptr = __modf_int;
160 return __value - __modf_int;
164 __m81_u(__isinf)(double __value)
166 /* There is no branch-condition for infinity,
167 so we must extract and examine the condition codes manually. */
168 unsigned long int __fpsr;
170 "fmove%.l fpsr, %0" : "=g" (__fpsr) : "f" (__value));
171 return (__fpsr & (2 << (3 * 8))) ? (__value < 0 ? -1 : 1) : 0;
175 __m81_u(__isnan)(double __value)
179 "fsun %0" : "=g" (__result) : "f" (__value));