⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mathinline.h

📁 它通过提供glibc兼容使得应用程序移植到较小的c 库时相当得容易. 它能够应用到带虚拟存储的Linux和uClinux上.在大多数带MMU部件的平台上为使它更加紧凑,它也能够编译成共享库.uClib
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Inline math functions for i387.   Copyright (C) 1995,96,97,98,99,2000,2001 Free Software Foundation, Inc.   This file is part of the GNU C Library.   Contributed by John C. Bowman <bowman@math.ualberta.ca>, 1995.   The GNU C Library is free software; you can redistribute it and/or   modify it under the terms of the GNU Lesser General Public   License as published by the Free Software Foundation; either   version 2.1 of the License, or (at your option) any later version.   The GNU C Library is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   Lesser General Public License for more details.   You should have received a copy of the GNU Lesser General Public   License along with the GNU C Library; if not, write to the Free   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   02111-1307 USA.  */#ifndef _MATH_H# error "Never use <bits/mathinline.h> directly; include <math.h> instead."#endif#ifdef __cplusplus# define __MATH_INLINE __inline#else# define __MATH_INLINE extern __inline#endif#if defined __USE_ISOC99 && defined __GNUC__ && __GNUC__ >= 2# if __GNUC_PREREQ (2,97)/* GCC 2.97 and up have builtins that actually can be used.  */#  define isgreater(x, y) __builtin_isgreater (x, y)#  define isgreaterequal(x, y) __builtin_isgreaterequal (x, y)#  define isless(x, y) __builtin_isless (x, y)#  define islessequal(x, y) __builtin_islessequal (x, y)#  define islessgreater(x, y) __builtin_islessgreater (x, y)#  define isunordered(x, y) __builtin_isunordered (x, y)# else/* ISO C99 defines some macros to perform unordered comparisons.  The   ix87 FPU supports this with special opcodes and we should use them.   These must not be inline functions since we have to be able to handle   all floating-point types.  */#  ifdef __i686__/* For the PentiumPro and more recent processors we can provide   better code.  */#   define isgreater(x, y) \     ({ register char __result;						      \	__asm__ ("fucomip %%st(1), %%st; seta %%al"			      \		 : "=a" (__result) : "u" (y), "t" (x) : "cc", "st");	      \	__result; })#   define isgreaterequal(x, y) \     ({ register char __result;						      \	__asm__ ("fucomip %%st(1), %%st; setae %%al"			      \		 : "=a" (__result) : "u" (y), "t" (x) : "cc", "st");	      \	__result; })#   define isless(x, y) \     ({ register char __result;						      \	__asm__ ("fucomip %%st(1), %%st; seta %%al"			      \		 : "=a" (__result) : "u" (x), "t" (y) : "cc", "st");	      \	__result; })#   define islessequal(x, y) \     ({ register char __result;						      \	__asm__ ("fucomip %%st(1), %%st; setae %%al"			      \		 : "=a" (__result) : "u" (x), "t" (y) : "cc", "st");	      \	__result; })#   define islessgreater(x, y) \     ({ register char __result;						      \	__asm__ ("fucomip %%st(1), %%st; setne %%al"			      \		 : "=a" (__result) : "u" (y), "t" (x) : "cc", "st");	      \	__result; })#   define isunordered(x, y) \     ({ register char __result;						      \	__asm__ ("fucomip %%st(1), %%st; setp %%al"			      \		 : "=a" (__result) : "u" (y), "t" (x) : "cc", "st");	      \	__result; })#  else/* This is the dumb, portable code for i386 and above.  */#   define isgreater(x, y) \     ({ register char __result;						      \	__asm__ ("fucompp; fnstsw; testb $0x45, %%ah; setz %%al"	      \		 : "=a" (__result) : "u" (y), "t" (x) : "cc", "st", "st(1)"); \	__result; })#   define isgreaterequal(x, y) \     ({ register char __result;						      \	__asm__ ("fucompp; fnstsw; testb $0x05, %%ah; setz %%al"	      \		 : "=a" (__result) : "u" (y), "t" (x) : "cc", "st", "st(1)"); \	__result; })#   define isless(x, y) \     ({ register char __result;						      \	__asm__ ("fucompp; fnstsw; testb $0x45, %%ah; setz %%al"	      \		 : "=a" (__result) : "u" (x), "t" (y) : "cc", "st", "st(1)"); \	__result; })#   define islessequal(x, y) \     ({ register char __result;						      \	__asm__ ("fucompp; fnstsw; testb $0x05, %%ah; setz %%al"	      \		 : "=a" (__result) : "u" (x), "t" (y) : "cc", "st", "st(1)"); \	__result; })#   define islessgreater(x, y) \     ({ register char __result;						      \	__asm__ ("fucompp; fnstsw; testb $0x44, %%ah; setz %%al"	      \		 : "=a" (__result) : "u" (y), "t" (x) : "cc", "st", "st(1)"); \	__result; })#   define isunordered(x, y) \     ({ register char __result;						      \	__asm__ ("fucompp; fnstsw; sahf; setp %%al"			      \		 : "=a" (__result) : "u" (y), "t" (x) : "cc", "st", "st(1)"); \	__result; })#  endif /* __i686__ */# endif	/* GCC 2.97 *//* The gcc, version 2.7 or below, has problems with all this inlining   code.  So disable it for this version of the compiler.  */# if __GNUC_PREREQ (2, 8)/* Test for negative number.  Used in the signbit() macro.  */__MATH_INLINE int__signbitf (float __x) __THROW{  __extension__ union { float __f; int __i; } __u = { __f: __x };  return __u.__i < 0;}__MATH_INLINE int__signbit (double __x) __THROW{  __extension__ union { double __d; int __i[2]; } __u = { __d: __x };  return __u.__i[1] < 0;}__MATH_INLINE int__signbitl (long double __x) __THROW{  __extension__ union { long double __l; int __i[3]; } __u = { __l: __x };  return (__u.__i[2] & 0x8000) != 0;}# endif#endif/* The gcc, version 2.7 or below, has problems with all this inlining   code.  So disable it for this version of the compiler.  */#if __GNUC_PREREQ (2, 8)#if ((!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) \     && defined __OPTIMIZE__)/* A macro to define float, double, and long double versions of various   math functions for the ix87 FPU.  FUNC is the function name (which will   be suffixed with f and l for the float and long double version,   respectively).  OP is the name of the FPU operation.   We define two sets of macros.  The set with the additional NP   doesn't add a prototype declaration.  */#if defined __USE_MISC || defined __USE_ISOC99# define __inline_mathop(func, op) \  __inline_mathop_ (double, func, op)					      \  __inline_mathop_ (float, __CONCAT(func,f), op)			      \  __inline_mathop_ (long double, __CONCAT(func,l), op)# define __inline_mathopNP(func, op) \  __inline_mathopNP_ (double, func, op)					      \  __inline_mathopNP_ (float, __CONCAT(func,f), op)			      \  __inline_mathopNP_ (long double, __CONCAT(func,l), op)#else# define __inline_mathop(func, op) \  __inline_mathop_ (double, func, op)# define __inline_mathopNP(func, op) \  __inline_mathopNP_ (double, func, op)#endif#define __inline_mathop_(float_type, func, op) \  __inline_mathop_decl_ (float_type, func, op, "0" (__x))#define __inline_mathopNP_(float_type, func, op) \  __inline_mathop_declNP_ (float_type, func, op, "0" (__x))#if defined __USE_MISC || defined __USE_ISOC99# define __inline_mathop_decl(func, op, params...) \  __inline_mathop_decl_ (double, func, op, params)			      \  __inline_mathop_decl_ (float, __CONCAT(func,f), op, params)		      \  __inline_mathop_decl_ (long double, __CONCAT(func,l), op, params)# define __inline_mathop_declNP(func, op, params...) \  __inline_mathop_declNP_ (double, func, op, params)			      \  __inline_mathop_declNP_ (float, __CONCAT(func,f), op, params)		      \  __inline_mathop_declNP_ (long double, __CONCAT(func,l), op, params)#else# define __inline_mathop_decl(func, op, params...) \  __inline_mathop_decl_ (double, func, op, params)# define __inline_mathop_declNP(func, op, params...) \  __inline_mathop_declNP_ (double, func, op, params)#endif#define __inline_mathop_decl_(float_type, func, op, params...) \  __MATH_INLINE float_type func (float_type) __THROW;			      \  __inline_mathop_declNP_ (float_type, func, op, params)#define __inline_mathop_declNP_(float_type, func, op, params...) \  __MATH_INLINE float_type func (float_type __x) __THROW		      \  {									      \    register float_type __result;					      \    __asm __volatile__ (op : "=t" (__result) : params);			      \    return __result;							      \  }#if defined __USE_MISC || defined __USE_ISOC99# define __inline_mathcode(func, arg, code) \  __inline_mathcode_ (double, func, arg, code)				      \  __inline_mathcode_ (float, __CONCAT(func,f), arg, code)		      \  __inline_mathcode_ (long double, __CONCAT(func,l), arg, code)# define __inline_mathcodeNP(func, arg, code) \  __inline_mathcodeNP_ (double, func, arg, code)				      \  __inline_mathcodeNP_ (float, __CONCAT(func,f), arg, code)		      \  __inline_mathcodeNP_ (long double, __CONCAT(func,l), arg, code)# define __inline_mathcode2(func, arg1, arg2, code) \  __inline_mathcode2_ (double, func, arg1, arg2, code)			      \  __inline_mathcode2_ (float, __CONCAT(func,f), arg1, arg2, code)	      \  __inline_mathcode2_ (long double, __CONCAT(func,l), arg1, arg2, code)# define __inline_mathcodeNP2(func, arg1, arg2, code) \  __inline_mathcodeNP2_ (double, func, arg1, arg2, code)			      \  __inline_mathcodeNP2_ (float, __CONCAT(func,f), arg1, arg2, code)	      \  __inline_mathcodeNP2_ (long double, __CONCAT(func,l), arg1, arg2, code)# define __inline_mathcode3(func, arg1, arg2, arg3, code) \  __inline_mathcode3_ (double, func, arg1, arg2, arg3, code)		      \  __inline_mathcode3_ (float, __CONCAT(func,f), arg1, arg2, arg3, code)	      \  __inline_mathcode3_ (long double, __CONCAT(func,l), arg1, arg2, arg3, code)# define __inline_mathcodeNP3(func, arg1, arg2, arg3, code) \  __inline_mathcodeNP3_ (double, func, arg1, arg2, arg3, code)		      \  __inline_mathcodeNP3_ (float, __CONCAT(func,f), arg1, arg2, arg3, code)	      \  __inline_mathcodeNP3_ (long double, __CONCAT(func,l), arg1, arg2, arg3, code)#else# define __inline_mathcode(func, arg, code) \  __inline_mathcode_ (double, func, (arg), code)# define __inline_mathcodeNP(func, arg, code) \  __inline_mathcodeNP_ (double, func, (arg), code)# define __inline_mathcode2(func, arg1, arg2, code) \  __inline_mathcode2_ (double, func, arg1, arg2, code)# define __inline_mathcodeNP2(func, arg1, arg2, code) \  __inline_mathcodeNP2_ (double, func, arg1, arg2, code)# define __inline_mathcode3(func, arg1, arg2, arg3, code) \  __inline_mathcode3_ (double, func, arg1, arg2, arg3, code)# define __inline_mathcodeNP3(func, arg1, arg2, arg3, code) \  __inline_mathcodeNP3_ (double, func, arg1, arg2, arg3, code)#endif#define __inline_mathcode_(float_type, func, arg, code) \  __MATH_INLINE float_type func (float_type) __THROW;			      \  __inline_mathcodeNP_(float_type, func, arg, code)#define __inline_mathcodeNP_(float_type, func, arg, code) \  __MATH_INLINE float_type func (float_type arg) __THROW		      \  {									      \    code;								      \  }#define __inline_mathcode2_(float_type, func, arg1, arg2, code) \  __MATH_INLINE float_type func (float_type, float_type) __THROW;	      \  __inline_mathcodeNP2_ (float_type, func, arg1, arg2, code)#define __inline_mathcodeNP2_(float_type, func, arg1, arg2, code) \  __MATH_INLINE float_type func (float_type arg1, float_type arg2) __THROW    \  {									      \    code;								      \  }#define __inline_mathcode3_(float_type, func, arg1, arg2, arg3, code) \  __MATH_INLINE float_type func (float_type, float_type, float_type) __THROW; \  __inline_mathcodeNP3_(float_type, func, arg1, arg2, arg3, code)#define __inline_mathcodeNP3_(float_type, func, arg1, arg2, arg3, code) \  __MATH_INLINE float_type func (float_type arg1, float_type arg2,	      \				 float_type arg3) __THROW		      \  {									      \    code;								      \  }#endif#if !defined __NO_MATH_INLINES && defined __OPTIMIZE__/* Miscellaneous functions */__inline_mathcode (__sgn, __x, \  return __x == 0.0 ? 0.0 : (__x > 0.0 ? 1.0 : -1.0))/* __FAST_MATH__ is defined by gcc -ffast-math.  */#ifdef __FAST_MATH____inline_mathcode (__pow2, __x, \  register long double __value;						      \  register long double __exponent;					      \  __extension__ long long int __p = (long long int) __x;		      \  if (__x == (long double) __p)						      \    {									      \      __asm __volatile__						      \	("fscale"							      \	 : "=t" (__value) : "0" (1.0), "u" (__x));			      \      return __value;							      \    }									      \  __asm __volatile__							      \    ("fld	%%st(0)\n\t"						      \     "frndint			# int(x)\n\t"				      \     "fxch\n\t"								      \     "fsub	%%st(1)		# fract(x)\n\t"				      \     "f2xm1			# 2^(fract(x)) - 1\n\t"			      \     : "=t" (__value), "=u" (__exponent) : "0" (__x));			      \  __value += 1.0;							      \  __asm __volatile__							      \    ("fscale"								      \     : "=t" (__value) : "0" (__value), "u" (__exponent));		      \  return __value)# ifdef __USE_GNU#  define __sincos_code \  register long double __cosr;						      \  register long double __sinr;						      \  __asm __volatile__							      \    ("fsincos\n\t"							      \     "fnstsw	%%ax\n\t"						      \     "testl	$0x400, %%eax\n\t"					      \     "jz	1f\n\t"							      \     "fldpi\n\t"							      \     "fadd	%%st(0)\n\t"						      \     "fxch	%%st(1)\n\t"						      \     "2: fprem1\n\t"							      \     "fnstsw	%%ax\n\t"						      \     "testl	$0x400, %%eax\n\t"					      \     "jnz	2b\n\t"							      \     "fstp	%%st(1)\n\t"						      \     "fsincos\n\t"							      \     "1:"								      \     : "=t" (__cosr), "=u" (__sinr) : "0" (__x));			      \  *__sinx = __sinr;							      \  *__cosx = __cosr__MATH_INLINE void__sincos (double __x, double *__sinx, double *__cosx) __THROW{  __sincos_code;}__MATH_INLINE void__sincosf (float __x, float *__sinx, float *__cosx) __THROW{  __sincos_code;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -