mathinline.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /* Inline math functions for i387.
  2. Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by John C. Bowman <bowman@math.ualberta.ca>, 1995.
  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.
  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.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. Boston, MA 02111-1307, USA. */
  17. #ifndef _MATH_H
  18. # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
  19. #endif
  20. #ifdef __cplusplus
  21. # define __MATH_INLINE __inline
  22. #else
  23. # define __MATH_INLINE extern __inline
  24. #endif
  25. #if defined __USE_ISOC9X && defined __GNUC__ && __GNUC__ >= 2
  26. /* ISO C 9X defines some macros to perform unordered comparisons. The
  27. ix87 FPU supports this with special opcodes and we should use them.
  28. These must not be inline functions since we have to be able to handle
  29. all floating-point types. */
  30. # ifdef __i686__
  31. /* For the PentiumPro and more recent processors we can provide
  32. better code. */
  33. # define isgreater(x, y) \
  34. ({ register char __result; \
  35. __asm__ ("fucomip %%st(1), %%st; seta %%al" \
  36. : "=a" (__result) : "u" (y), "t" (x) : "cc", "st"); \
  37. __result; })
  38. # define isgreaterequal(x, y) \
  39. ({ register char __result; \
  40. __asm__ ("fucomip %%st(1), %%st; setae %%al" \
  41. : "=a" (__result) : "u" (y), "t" (x) : "cc", "st"); \
  42. __result; })
  43. # define isless(x, y) \
  44. ({ register char __result; \
  45. __asm__ ("fucomip %%st(1), %%st; seta %%al" \
  46. : "=a" (__result) : "u" (x), "t" (y) : "cc", "st"); \
  47. __result; })
  48. # define islessequal(x, y) \
  49. ({ register char __result; \
  50. __asm__ ("fucomip %%st(1), %%st; setae %%al" \
  51. : "=a" (__result) : "u" (x), "t" (y) : "cc", "st"); \
  52. __result; })
  53. # define islessgreater(x, y) \
  54. ({ register char __result; \
  55. __asm__ ("fucomip %%st(1), %%st; setne %%al" \
  56. : "=a" (__result) : "u" (y), "t" (x) : "cc", "st"); \
  57. __result; })
  58. # define isunordered(x, y) \
  59. ({ register char __result; \
  60. __asm__ ("fucomip %%st(1), %%st; setp %%al" \
  61. : "=a" (__result) : "u" (y), "t" (x) : "cc", "st"); \
  62. __result; })
  63. # else
  64. /* This is the dumb, portable code for i386 and above. */
  65. # define isgreater(x, y) \
  66. ({ register char __result; \
  67. __asm__ ("fucompp; fnstsw; testb $0x45, %%ah; setz %%al" \
  68. : "=a" (__result) : "u" (y), "t" (x) : "cc", "st", "st(1)"); \
  69. __result; })
  70. # define isgreaterequal(x, y) \
  71. ({ register char __result; \
  72. __asm__ ("fucompp; fnstsw; testb $0x05, %%ah; setz %%al" \
  73. : "=a" (__result) : "u" (y), "t" (x) : "cc", "st", "st(1)"); \
  74. __result; })
  75. # define isless(x, y) \
  76. ({ register char __result; \
  77. __asm__ ("fucompp; fnstsw; testb $0x45, %%ah; setz %%al" \
  78. : "=a" (__result) : "u" (x), "t" (y) : "cc", "st", "st(1)"); \
  79. __result; })
  80. # define islessequal(x, y) \
  81. ({ register char __result; \
  82. __asm__ ("fucompp; fnstsw; testb $0x05, %%ah; setz %%al" \
  83. : "=a" (__result) : "u" (x), "t" (y) : "cc", "st", "st(1)"); \
  84. __result; })
  85. # define islessgreater(x, y) \
  86. ({ register char __result; \
  87. __asm__ ("fucompp; fnstsw; testb $0x44, %%ah; setz %%al" \
  88. : "=a" (__result) : "u" (y), "t" (x) : "cc", "st", "st(1)"); \
  89. __result; })
  90. # define isunordered(x, y) \
  91. ({ register char __result; \
  92. __asm__ ("fucompp; fnstsw; sahf; setp %%al" \
  93. : "=a" (__result) : "u" (y), "t" (x) : "cc", "st", "st(1)"); \
  94. __result; })
  95. # endif /* __i686__ */
  96. /* The gcc, version 2.7 or below, has problems with all this inlining
  97. code. So disable it for this version of the compiler. */
  98. # if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 7))
  99. /* Test for negative number. Used in the signbit() macro. */
  100. __MATH_INLINE int
  101. __signbitf (float __x)
  102. {
  103. __extension__ union { float __f; int __i; } __u = { __f: __x };
  104. return __u.__i < 0;
  105. }
  106. __MATH_INLINE int
  107. __signbit (double __x)
  108. {
  109. __extension__ union { double __d; int __i[2]; } __u = { __d: __x };
  110. return __u.__i[1] < 0;
  111. }
  112. __MATH_INLINE int
  113. __signbitl (long double __x)
  114. {
  115. __extension__ union { long double __l; int __i[3]; } __u = { __l: __x };
  116. return (__u.__i[2] & 0x8000) != 0;
  117. }
  118. # endif
  119. #endif
  120. /* The gcc, version 2.7 or below, has problems with all this inlining
  121. code. So disable it for this version of the compiler. */
  122. #if defined __GNUC__ && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 7))
  123. #if ((!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) \
  124. && defined __OPTIMIZE__)
  125. /* A macro to define float, double, and long double versions of various
  126. math functions for the ix87 FPU. FUNC is the function name (which will
  127. be suffixed with f and l for the float and long double version,
  128. respectively). OP is the name of the FPU operation. */
  129. #if defined __USE_MISC || defined __USE_ISOC9X
  130. # define __inline_mathop(func, op) \
  131. __inline_mathop_ (double, func, op) \
  132. __inline_mathop_ (float, __CONCAT(func,f), op) \
  133. __inline_mathop_ (long double, __CONCAT(func,l), op)
  134. #else
  135. # define __inline_mathop(func, op) \
  136. __inline_mathop_ (double, func, op)
  137. #endif
  138. #define __inline_mathop_(float_type, func, op) \
  139. __inline_mathop_decl_ (float_type, func, op, "0" (__x))
  140. #if defined __USE_MISC || defined __USE_ISOC9X
  141. # define __inline_mathop_decl(func, op, params...) \
  142. __inline_mathop_decl_ (double, func, op, params) \
  143. __inline_mathop_decl_ (float, __CONCAT(func,f), op, params) \
  144. __inline_mathop_decl_ (long double, __CONCAT(func,l), op, params)
  145. #else
  146. # define __inline_mathop_decl(func, op, params...) \
  147. __inline_mathop_decl_ (double, func, op, params)
  148. #endif
  149. #define __inline_mathop_decl_(float_type, func, op, params...) \
  150. __MATH_INLINE float_type func (float_type); \
  151. __MATH_INLINE float_type func (float_type __x) \
  152. { \
  153. register float_type __result; \
  154. __asm __volatile__ (op : "=t" (__result) : params); \
  155. return __result; \
  156. }
  157. #if defined __USE_MISC || defined __USE_ISOC9X
  158. # define __inline_mathcode(func, arg, code) \
  159. __inline_mathcode_ (double, func, arg, code) \
  160. __inline_mathcode_ (float, __CONCAT(func,f), arg, code) \
  161. __inline_mathcode_ (long double, __CONCAT(func,l), arg, code)
  162. # define __inline_mathcode2(func, arg1, arg2, code) \
  163. __inline_mathcode2_ (double, func, arg1, arg2, code) \
  164. __inline_mathcode2_ (float, __CONCAT(func,f), arg1, arg2, code) \
  165. __inline_mathcode2_ (long double, __CONCAT(func,l), arg1, arg2, code)
  166. # define __inline_mathcode3(func, arg1, arg2, arg3, code) \
  167. __inline_mathcode3_ (double, func, arg1, arg2, arg3, code) \
  168. __inline_mathcode3_ (float, __CONCAT(func,f), arg1, arg2, arg3, code) \
  169. __inline_mathcode3_ (long double, __CONCAT(func,l), arg1, arg2, arg3, code)
  170. #else
  171. # define __inline_mathcode(func, arg, code) \
  172. __inline_mathcode_ (double, func, (arg), code)
  173. # define __inline_mathcode2(func, arg1, arg2, code) \
  174. __inline_mathcode2_ (double, func, arg1, arg2, code)
  175. # define __inline_mathcode3(func, arg1, arg2, arg3, code) \
  176. __inline_mathcode3_ (double, func, arg1, arg2, arg3, code)
  177. #endif
  178. #define __inline_mathcode_(float_type, func, arg, code) \
  179. __MATH_INLINE float_type func (float_type); \
  180. __MATH_INLINE float_type func (float_type arg) \
  181. { \
  182. code; \
  183. }
  184. #define __inline_mathcode2_(float_type, func, arg1, arg2, code) \
  185. __MATH_INLINE float_type func (float_type, float_type); \
  186. __MATH_INLINE float_type func (float_type arg1, float_type arg2) \
  187. { \
  188. code; \
  189. }
  190. #define __inline_mathcode3_(float_type, func, arg1, arg2, arg3, code) \
  191. __MATH_INLINE float_type func (float_type, float_type, float_type); \
  192. __MATH_INLINE float_type func (float_type arg1, float_type arg2, \
  193. float_type arg3) \
  194. { \
  195. code; \
  196. }
  197. #endif
  198. #if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
  199. /* Miscellaneous functions */
  200. __inline_mathcode (__sgn, __x, \
  201. return __x == 0.0 ? 0.0 : (__x > 0.0 ? 1.0 : -1.0))
  202. __inline_mathcode (__pow2, __x, \
  203. register long double __value; \
  204. register long double __exponent; \
  205. __extension__ long long int __p = (long long int) __x; \
  206. if (__x == (long double) __p) \
  207. { \
  208. __asm __volatile__ \
  209. ("fscale" \
  210. : "=t" (__value) : "0" (1.0), "u" (__x)); \
  211. return __value; \
  212. } \
  213. __asm __volatile__ \
  214. ("fld %%st(0)\n\t" \
  215. "frndint # int(x)\n\t" \
  216. "fxch\n\t" \
  217. "fsub %%st(1) # fract(x)\n\t" \
  218. "f2xm1 # 2^(fract(x)) - 1\n\t" \
  219. : "=t" (__value), "=u" (__exponent) : "0" (__x)); \
  220. __value += 1.0; \
  221. __asm __volatile__ \
  222. ("fscale" \
  223. : "=t" (__value) : "0" (__value), "u" (__exponent)); \
  224. return __value)
  225. #define __sincos_code \
  226. register long double __cosr; \
  227. register long double __sinr; \
  228. __asm __volatile__ \
  229. ("fsincos\n\t" \
  230. "fnstsw %%ax\n\t" \
  231. "testl $0x400, %%eax\n\t" \
  232. "jz 1f\n\t" \
  233. "fldpi\n\t" \
  234. "fadd %%st(0)\n\t" \
  235. "fxch %%st(1)\n\t" \
  236. "2: fprem1\n\t" \
  237. "fnstsw %%ax\n\t" \
  238. "testl $0x400, %%eax\n\t" \
  239. "jnz 2b\n\t" \
  240. "fstp %%st(1)\n\t" \
  241. "fsincos\n\t" \
  242. "1:" \
  243. : "=t" (__cosr), "=u" (__sinr) : "0" (__x)); \
  244. *__sinx = __sinr; \
  245. *__cosx = __cosr
  246. __MATH_INLINE void __sincos (double __x, double *__sinx, double *__cosx);
  247. __MATH_INLINE void
  248. __sincos (double __x, double *__sinx, double *__cosx)
  249. {
  250. __sincos_code;
  251. }
  252. __MATH_INLINE void __sincosf (float __x, float *__sinx, float *__cosx);
  253. __MATH_INLINE void
  254. __sincosf (float __x, float *__sinx, float *__cosx)
  255. {
  256. __sincos_code;
  257. }
  258. __MATH_INLINE void __sincosl (long double __x, long double *__sinx,
  259. long double *__cosx);
  260. __MATH_INLINE void
  261. __sincosl (long double __x, long double *__sinx, long double *__cosx)
  262. {
  263. __sincos_code;
  264. }
  265. /* Optimized inline implementation, sometimes with reduced precision
  266. and/or argument range. */
  267. #define __expm1_code \
  268. register long double __value; \
  269. register long double __exponent; \
  270. register long double __temp; \
  271. __asm __volatile__ \
  272. ("fldl2e # e^x - 1 = 2^(x * log2(e)) - 1\n\t" \
  273. "fmul %%st(1) # x * log2(e)\n\t" \
  274. "fst %%st(1)\n\t" \
  275. "frndint # int(x * log2(e))\n\t" \
  276. "fxch\n\t" \
  277. "fsub %%st(1) # fract(x * log2(e))\n\t" \
  278. "f2xm1 # 2^(fract(x * log2(e))) - 1\n\t" \
  279. "fscale # 2^(x * log2(e)) - 2^(int(x * log2(e)))\n\t" \
  280. : "=t" (__value), "=u" (__exponent) : "0" (__x)); \
  281. __asm __volatile__ \
  282. ("fscale # 2^int(x * log2(e))\n\t" \
  283. : "=t" (__temp) : "0" (1.0), "u" (__exponent)); \
  284. __temp -= 1.0; \
  285. return __temp + __value
  286. __inline_mathcode_ (long double, __expm1l, __x, __expm1_code)
  287. #define __exp_code \
  288. register long double __value; \
  289. register long double __exponent; \
  290. __asm __volatile__ \
  291. ("fldl2e # e^x = 2^(x * log2(e))\n\t" \
  292. "fmul %%st(1) # x * log2(e)\n\t" \
  293. "fst %%st(1)\n\t" \
  294. "frndint # int(x * log2(e))\n\t" \
  295. "fxch\n\t" \
  296. "fsub %%st(1) # fract(x * log2(e))\n\t" \
  297. "f2xm1 # 2^(fract(x * log2(e))) - 1\n\t" \
  298. : "=t" (__value), "=u" (__exponent) : "0" (__x)); \
  299. __value += 1.0; \
  300. __asm __volatile__ \
  301. ("fscale" \
  302. : "=t" (__value) : "0" (__value), "u" (__exponent)); \
  303. return __value
  304. __inline_mathcode (exp, __x, __exp_code)
  305. __inline_mathcode_ (long double, __expl, __x, __exp_code)
  306. __inline_mathcode (tan, __x, \
  307. register long double __value; \
  308. register long double __value2 __attribute__ ((__unused__)); \
  309. __asm __volatile__ \
  310. ("fptan" \
  311. : "=t" (__value2), "=u" (__value) : "0" (__x)); \
  312. return __value)
  313. #define __atan2_code \
  314. register long double __value; \
  315. __asm __volatile__ \
  316. ("fpatan" \
  317. : "=t" (__value) : "0" (__x), "u" (__y) : "st(1)"); \
  318. return __value
  319. __inline_mathcode2 (atan2, __y, __x, __atan2_code)
  320. __inline_mathcode2_ (long double, __atan2l, __y, __x, __atan2_code)
  321. __inline_mathcode2 (fmod, __x, __y, \
  322. register long double __value; \
  323. __asm __volatile__ \
  324. ("1: fprem\n\t" \
  325. "fnstsw %%ax\n\t" \
  326. "sahf\n\t" \
  327. "jp 1b" \
  328. : "=t" (__value) : "0" (__x), "u" (__y) : "ax", "cc"); \
  329. return __value)
  330. __inline_mathcode2 (pow, __x, __y, \
  331. register long double __value; \
  332. register long double __exponent; \
  333. __extension__ long long int __p = (long long int) __y; \
  334. if (__x == 0.0 && __y > 0.0) \
  335. return 0.0; \
  336. if (__y == (double) __p) \
  337. { \
  338. long double __r = 1.0; \
  339. if (__p == 0) \
  340. return 1.0; \
  341. if (__p < 0) \
  342. { \
  343. __p = -__p; \
  344. __x = 1.0 / __x; \
  345. } \
  346. while (1) \
  347. { \
  348. if (__p & 1) \
  349. __r *= __x; \
  350. __p >>= 1; \
  351. if (__p == 0) \
  352. return __r; \
  353. __x *= __x; \
  354. } \
  355. /* NOTREACHED */ \
  356. } \
  357. __asm __volatile__ \
  358. ("fyl2x" : "=t" (__value) : "0" (__x), "u" (1.0) : "st(1)"); \
  359. __asm __volatile__ \
  360. ("fmul %%st(1) # y * log2(x)\n\t" \
  361. "fst %%st(1)\n\t" \
  362. "frndint # int(y * log2(x))\n\t" \
  363. "fxch\n\t" \
  364. "fsub %%st(1) # fract(y * log2(x))\n\t" \
  365. "f2xm1 # 2^(fract(y * log2(x))) - 1\n\t" \
  366. : "=t" (__value), "=u" (__exponent) : "0" (__y), "1" (__value)); \
  367. __value += 1.0; \
  368. __asm __volatile__ \
  369. ("fscale" \
  370. : "=t" (__value) : "0" (__value), "u" (__exponent)); \
  371. return __value)
  372. __inline_mathop (sqrt, "fsqrt")
  373. __inline_mathop_ (long double, __sqrtl, "fsqrt")
  374. #if defined __GNUC__ && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 8)
  375. __inline_mathcode_ (double, fabs, __x, return __builtin_fabs (__x))
  376. __inline_mathcode_ (float, fabsf, __x, return __builtin_fabsf (__x))
  377. __inline_mathcode_ (long double, fabsl, __x, return __builtin_fabsl (__x))
  378. __inline_mathcode_ (long double, __fabsl, __x, return __builtin_fabsl (__x))
  379. #else
  380. __inline_mathop (fabs, "fabs")
  381. __inline_mathop_ (long double, __fabsl, "fabs")
  382. #endif
  383. /* The argument range of this inline version is reduced. */
  384. __inline_mathop (sin, "fsin")
  385. /* The argument range of this inline version is reduced. */
  386. __inline_mathop (cos, "fcos")
  387. __inline_mathop_decl (atan, "fld1; fpatan", "0" (__x) : "st(1)")
  388. __inline_mathop_decl (log, "fldln2; fxch; fyl2x", "0" (__x) : "st(1)")
  389. __inline_mathop_decl (log10, "fldlg2; fxch; fyl2x", "0" (__x) : "st(1)")
  390. __inline_mathcode (asin, __x, return __atan2l (__x, __sqrtl (1.0 - __x * __x)))
  391. __inline_mathcode (acos, __x, return __atan2l (__sqrtl (1.0 - __x * __x), __x))
  392. __inline_mathcode_ (long double, __sgn1l, __x, return __x >= 0.0 ? 1.0 : -1.0)
  393. /* The argument range of the inline version of sinhl is slightly reduced. */
  394. __inline_mathcode (sinh, __x, \
  395. register long double __exm1 = __expm1l (__fabsl (__x)); \
  396. return 0.5 * (__exm1 / (__exm1 + 1.0) + __exm1) * __sgn1l (__x))
  397. __inline_mathcode (cosh, __x, \
  398. register long double __ex = __expl (__x); \
  399. return 0.5 * (__ex + 1.0 / __ex))
  400. __inline_mathcode (tanh, __x, \
  401. register long double __exm1 = __expm1l (-__fabsl (__x + __x)); \
  402. return __exm1 / (__exm1 + 2.0) * __sgn1l (-__x))
  403. __inline_mathcode (floor, __x, \
  404. register long double __value; \
  405. __volatile unsigned short int __cw; \
  406. __volatile unsigned short int __cwtmp; \
  407. __asm __volatile ("fnstcw %0" : "=m" (__cw)); \
  408. __cwtmp = (__cw & 0xf3ff) | 0x0400; /* rounding down */ \
  409. __asm __volatile ("fldcw %0" : : "m" (__cwtmp)); \
  410. __asm __volatile ("frndint" : "=t" (__value) : "0" (__x)); \
  411. __asm __volatile ("fldcw %0" : : "m" (__cw)); \
  412. return __value)
  413. __inline_mathcode (ceil, __x, \
  414. register long double __value; \
  415. __volatile unsigned short int __cw; \
  416. __volatile unsigned short int __cwtmp; \
  417. __asm __volatile ("fnstcw %0" : "=m" (__cw)); \
  418. __cwtmp = (__cw & 0xf3ff) | 0x0800; /* rounding up */ \
  419. __asm __volatile ("fldcw %0" : : "m" (__cwtmp)); \
  420. __asm __volatile ("frndint" : "=t" (__value) : "0" (__x)); \
  421. __asm __volatile ("fldcw %0" : : "m" (__cw)); \
  422. return __value)
  423. #define __ldexp_code \
  424. register long double __value; \
  425. __asm __volatile__ \
  426. ("fscale" \
  427. : "=t" (__value) : "0" (__x), "u" ((long double) __y)); \
  428. return __value
  429. __MATH_INLINE double ldexp (double __x, int __y);
  430. __MATH_INLINE double
  431. ldexp (double __x, int __y)
  432. {
  433. __ldexp_code;
  434. }
  435. /* Optimized versions for some non-standardized functions. */
  436. #if defined __USE_ISOC9X || defined __USE_MISC
  437. __inline_mathcode (expm1, __x, __expm1_code)
  438. /* We cannot rely on M_SQRT being defined. So we do it for ourself
  439. here. */
  440. # define __M_SQRT2 1.41421356237309504880L /* sqrt(2) */
  441. __inline_mathcode (log1p, __x, \
  442. register long double __value; \
  443. if (__fabsl (__x) >= 1.0 - 0.5 * __M_SQRT2) \
  444. __value = logl (1.0 + __x); \
  445. else \
  446. __asm __volatile__ \
  447. ("fldln2\n\t" \
  448. "fxch\n\t" \
  449. "fyl2xp1" \
  450. : "=t" (__value) : "0" (__x) : "st(1)"); \
  451. return __value)
  452. /* The argument range of the inline version of asinhl is slightly reduced. */
  453. __inline_mathcode (asinh, __x, \
  454. register long double __y = __fabsl (__x); \
  455. return (log1pl (__y * __y / (__sqrtl (__y * __y + 1.0) + 1.0) + __y) \
  456. * __sgn1l (__x)))
  457. __inline_mathcode (acosh, __x, \
  458. return logl (__x + __sqrtl (__x - 1.0) * __sqrtl (__x + 1.0)))
  459. __inline_mathcode (atanh, __x, \
  460. register long double __y = __fabsl (__x); \
  461. return -0.5 * log1pl (-(__y + __y) / (1.0 + __y)) * __sgn1l (__x))
  462. /* The argument range of the inline version of hypotl is slightly reduced. */
  463. __inline_mathcode2 (hypot, __x, __y, return __sqrtl (__x * __x + __y * __y))
  464. __inline_mathcode(logb, __x, \
  465. register long double __value; \
  466. register long double __junk; \
  467. __asm __volatile__ \
  468. ("fxtract\n\t" \
  469. : "=t" (__junk), "=u" (__value) : "0" (__x)); \
  470. return __value)
  471. #endif
  472. #ifdef __USE_ISOC9X
  473. __inline_mathop_decl (log2, "fld1; fxch; fyl2x", "0" (__x) : "st(1)")
  474. __MATH_INLINE float ldexpf (float __x, int __y);
  475. __MATH_INLINE float
  476. ldexpf (float __x, int __y)
  477. {
  478. __ldexp_code;
  479. }
  480. __MATH_INLINE long double ldexpl (long double __x, int __y);
  481. __MATH_INLINE long double
  482. ldexpl (long double __x, int __y)
  483. {
  484. __ldexp_code;
  485. }
  486. __inline_mathcode3 (fma, __x, __y, __z, return (__x * __y) + __z)
  487. __inline_mathop(rint, "frndint")
  488. #define __lrint_code \
  489. long int __lrintres; \
  490. __asm__ __volatile__ \
  491. ("fistpl %0" \
  492. : "=m" (__lrintres) : "t" (__x) : "st"); \
  493. return __lrintres
  494. __MATH_INLINE long int
  495. lrintf (float __x)
  496. {
  497. __lrint_code;
  498. }
  499. __MATH_INLINE long int
  500. lrint (double __x)
  501. {
  502. __lrint_code;
  503. }
  504. __MATH_INLINE long int
  505. lrintl (long double __x)
  506. {
  507. __lrint_code;
  508. }
  509. #undef __lrint_code
  510. #define __llrint_code \
  511. long long int __llrintres; \
  512. __asm__ __volatile__ \
  513. ("fistpll %0" \
  514. : "=m" (__llrintres) : "t" (__x) : "st"); \
  515. return __llrintres
  516. __MATH_INLINE long long int
  517. llrintf (float __x)
  518. {
  519. __llrint_code;
  520. }
  521. __MATH_INLINE long long int
  522. llrint (double __x)
  523. {
  524. __llrint_code;
  525. }
  526. __MATH_INLINE long long int
  527. llrintl (long double __x)
  528. {
  529. __llrint_code;
  530. }
  531. #undef __llrint_code
  532. #endif
  533. #ifdef __USE_MISC
  534. __inline_mathcode2 (drem, __x, __y, \
  535. register double __value; \
  536. register int __clobbered; \
  537. __asm __volatile__ \
  538. ("1: fprem1\n\t" \
  539. "fstsw %%ax\n\t" \
  540. "sahf\n\t" \
  541. "jp 1b" \
  542. : "=t" (__value), "=&a" (__clobbered) : "0" (__x), "u" (__y) : "cc"); \
  543. return __value)
  544. /* This function is used in the `isfinite' macro. */
  545. __MATH_INLINE int __finite (double __x) __attribute__ ((__const__));
  546. __MATH_INLINE int
  547. __finite (double __x)
  548. {
  549. return (__extension__
  550. (((((union { double __d; int __i[2]; }) {__d: __x}).__i[1]
  551. | 0x800fffffu) + 1) >> 31));
  552. }
  553. /* Miscellaneous functions */
  554. __inline_mathcode (__coshm1, __x, \
  555. register long double __exm1 = __expm1l (__fabsl (__x)); \
  556. return 0.5 * (__exm1 / (__exm1 + 1.0)) * __exm1)
  557. __inline_mathcode (__acosh1p, __x, \
  558. return log1pl (__x + __sqrtl (__x) * __sqrtl (__x + 2.0)))
  559. #endif /* __USE_MISC */
  560. /* Undefine some of the large macros which are not used anymore. */
  561. #undef __expm1_code
  562. #undef __exp_code
  563. #undef __atan2_code
  564. #undef __sincos_code
  565. #endif /* __NO_MATH_INLINES */
  566. /* This code is used internally in the GNU libc. */
  567. #ifdef __LIBC_INTERNAL_MATH_INLINES
  568. __inline_mathop (__ieee754_sqrt, "fsqrt")
  569. __inline_mathcode2 (__ieee754_atan2, __y, __x,
  570. register long double __value;
  571. __asm __volatile__ ("fpatan\n\t"
  572. : "=t" (__value)
  573. : "0" (__x), "u" (__y) : "st(1)");
  574. return __value;)
  575. #endif
  576. #endif /* __GNUC__ */