Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

405 lines
13 KiB

  1. /***
  2. *trans.h - definitions for computing transcendentals
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Define constants and macros that are used for computing
  8. * transcendentals. Some of the definitions are machine dependent.
  9. * Double is assumed to conform to the IEEE 754 std format.
  10. *
  11. *Revision History:
  12. * 08-14-91 GDP written
  13. * 10-29-91 GDP removed unused prototypes, added _frnd
  14. * 01-20-92 GDP significant changes -- IEEE exc. support
  15. * 03-27-92 GDP put IEEE definitions in fpieee.h
  16. * 03-31-92 GDP add internal constants for _ctrlfp, _statfp
  17. * 05-08-92 PLM added M68K switch
  18. * 05-18-92 XY added exception macro under M68K switch
  19. * 06-23-92 GDP added macro for negative zero
  20. * 09-06-92 GDP include cruntime.h, calling convention macros
  21. * 07-16-93 SRW ALPHA Merge
  22. * 11-17-93 GJF Merged in NT SDK version. Replaced MIPS with
  23. * _M_MRX000, _ALPHA_ with _M_ALPHA, deleted old M68K
  24. * stuff (obsolete).
  25. * 01-13-94 RDL Added #ifndef _LANGUAGE_ASSEMBLY for asm includes.
  26. * 01-25-94 GJF Merged in 01-13 change above from Roger Lanser (from
  27. * fp32 tree on \\orville\razzle).
  28. * 03-11-94 GJF Picked up latest changes from Dec (from fp32 tree
  29. * on \\orville\razzle for Alpha build).
  30. * 10-02-94 BWT PPC merge
  31. * 02-06-95 JWM Mac merge
  32. * 02-07-95 JWM powhlp() prototype restored to Intel version.
  33. * 10-07-97 RDL Added IA64.
  34. * 05-13-99 PML Remove _CRTAPI1
  35. * 05-17-99 PML Remove all Macintosh support.
  36. * 10-06-99 PML Add _W64 modifier to types which are 32 bits in Win32,
  37. * 64 bits in Win64.
  38. * 04-30-01 BWT AMD64 change from DaveC
  39. * 07-15-01 PML Remove all ALPHA, MIPS, and PPC code
  40. *
  41. *******************************************************************************/
  42. #ifndef _INC_TRANS
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. #ifndef __assembler /* MIPS ONLY: Protect from assembler */
  47. #include <cruntime.h>
  48. /* Define __cdecl for non-Microsoft compilers */
  49. #if ( !defined(_MSC_VER) && !defined(__cdecl) )
  50. #define __cdecl
  51. #endif
  52. #if !defined(_W64)
  53. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
  54. #define _W64 __w64
  55. #else
  56. #define _W64
  57. #endif
  58. #endif
  59. #ifndef _INTPTR_T_DEFINED
  60. #ifdef _WIN64
  61. typedef __int64 intptr_t;
  62. #else
  63. typedef _W64 int intptr_t;
  64. #endif
  65. #define _INTPTR_T_DEFINED
  66. #endif
  67. #ifndef _UINTPTR_T_DEFINED
  68. #ifdef _WIN64
  69. typedef unsigned __int64 uintptr_t;
  70. #else
  71. typedef _W64 unsigned int uintptr_t;
  72. #endif
  73. #define _UINTPTR_T_DEFINED
  74. #endif
  75. #include <fpieee.h>
  76. #define D_BIASM1 0x3fe /* off by one to compensate for the implied bit */
  77. #ifdef B_END
  78. /* big endian */
  79. #define D_EXP(x) ((unsigned short *)&(x))
  80. #define D_HI(x) ((unsigned long *)&(x))
  81. #define D_LO(x) ((unsigned long *)&(x)+1)
  82. #else
  83. #define D_EXP(x) ((unsigned short *)&(x)+3)
  84. #define D_HI(x) ((unsigned long *)&(x)+1)
  85. #define D_LO(x) ((unsigned long *)&(x))
  86. #endif
  87. /* return the int representation of the exponent
  88. * if x = .f * 2^n, 0.5<=f<1, return n (unbiased)
  89. * e.g. INTEXP(3.0) == 2
  90. */
  91. #define INTEXP(x) ((signed short)((*D_EXP(x) & 0x7ff0) >> 4) - D_BIASM1)
  92. /* check for infinity, NAN */
  93. #define D_ISINF(x) ((*D_HI(x) & 0x7fffffff) == 0x7ff00000 && *D_LO(x) == 0)
  94. #define IS_D_SPECIAL(x) ((*D_EXP(x) & 0x7ff0) == 0x7ff0)
  95. #define IS_D_NAN(x) (IS_D_SPECIAL(x) && !D_ISINF(x))
  96. #define IS_D_QNAN(x) ((*D_EXP(x) & 0x7ff8) == 0x7ff8)
  97. #define IS_D_SNAN(x) ((*D_EXP(x) & 0x7ff8) == 0x7ff0 && \
  98. (*D_HI(x) << 13 || *D_LO(x)))
  99. #define IS_D_DENORM(x) ((*D_EXP(x) & 0x7ff0) == 0 && \
  100. (*D_HI(x) << 12 || *D_LO(x)))
  101. #define IS_D_INF(x) (*D_HI(x) == 0x7ff00000 && *D_LO(x) == 0)
  102. #define IS_D_MINF(x) (*D_HI(x) == 0xfff00000 && *D_LO(x) == 0)
  103. #define D_IND_HI 0xfff80000
  104. #define D_IND_LO 0x0
  105. typedef union {
  106. long lng[2];
  107. double dbl;
  108. } _dbl;
  109. extern _dbl _d_inf;
  110. extern _dbl _d_ind;
  111. extern _dbl _d_max;
  112. extern _dbl _d_min;
  113. extern _dbl _d_mzero;
  114. #define D_INF (_d_inf.dbl)
  115. #define D_IND (_d_ind.dbl)
  116. #define D_MAX (_d_max.dbl)
  117. #define D_MIN (_d_min.dbl)
  118. #define D_MZERO (_d_mzero.dbl) /* minus zero */
  119. /* min and max exponents for normalized numbers in the
  120. * form: 0.xxxxx... * 2^exp (NOT 1.xxxx * 2^exp !)
  121. */
  122. #define MAXEXP 1024
  123. #define MINEXP -1021
  124. #endif /* #ifndef __assembler */
  125. #if defined(_M_IX86)
  126. /* Control word for computation of transcendentals */
  127. #define ICW 0x133f
  128. #define IMCW 0xffff
  129. #define IMCW_EM 0x003f /* interrupt Exception Masks */
  130. #define IEM_INVALID 0x0001 /* invalid */
  131. #define IEM_DENORMAL 0x0002 /* denormal */
  132. #define IEM_ZERODIVIDE 0x0004 /* zero divide */
  133. #define IEM_OVERFLOW 0x0008 /* overflow */
  134. #define IEM_UNDERFLOW 0x0010 /* underflow */
  135. #define IEM_INEXACT 0x0020 /* inexact (precision) */
  136. #define IMCW_RC 0x0c00 /* Rounding Control */
  137. #define IRC_CHOP 0x0c00 /* chop */
  138. #define IRC_UP 0x0800 /* up */
  139. #define IRC_DOWN 0x0400 /* down */
  140. #define IRC_NEAR 0x0000 /* near */
  141. #define ISW_INVALID 0x0001 /* invalid */
  142. #define ISW_DENORMAL 0x0002 /* denormal */
  143. #define ISW_ZERODIVIDE 0x0004 /* zero divide */
  144. #define ISW_OVERFLOW 0x0008 /* overflow */
  145. #define ISW_UNDERFLOW 0x0010 /* underflow */
  146. #define ISW_INEXACT 0x0020 /* inexact (precision) */
  147. #define IMCW_PC 0x0300 /* Precision Control */
  148. #define IPC_24 0x0000 /* 24 bits */
  149. #define IPC_53 0x0200 /* 53 bits */
  150. #define IPC_64 0x0300 /* 64 bits */
  151. #define IMCW_IC 0x1000 /* Infinity Control */
  152. #define IIC_AFFINE 0x1000 /* affine */
  153. #define IIC_PROJECTIVE 0x0000 /* projective */
  154. #elif defined(_M_AMD64)
  155. /* Control word for computation of transcendentals */
  156. #define ICW (IEM_INVALID| IEM_DENORMAL | IEM_ZERODIVIDE | IEM_OVERFLOW | IEM_UNDERFLOW | IEM_INEXACT | IRC_NEAR)
  157. #define ISW (ISW_INEXACT | ISW_UNDERFLOW | ISW_OVERFLOW | ISW_ZERODIVIDE | ISW_INVALID | ISW_DENORMAL)
  158. #define IMCW (0xffff ^ ISW)
  159. #define IMCW_EM 0x1f80 /* interrupt Exception Masks */
  160. #define IEM_INVALID 0x0080 /* invalid */
  161. #define IEM_DENORMAL 0x0100 /* denormal */
  162. #define IEM_ZERODIVIDE 0x0200 /* zero divide */
  163. #define IEM_OVERFLOW 0x0400 /* overflow */
  164. #define IEM_UNDERFLOW 0x0800 /* underflow */
  165. #define IEM_INEXACT 0x1000 /* inexact (precision) */
  166. #define IMCW_RC 0x6000 /* Rounding Control */
  167. #define IRC_CHOP 0x6000 /* chop */
  168. #define IRC_UP 0x4000 /* up */
  169. #define IRC_DOWN 0x2000 /* down */
  170. #define IRC_NEAR 0x0000 /* near */
  171. #define ISW_INVALID 0x0001 /* invalid */
  172. #define ISW_DENORMAL 0x0002 /* denormal */
  173. #define ISW_ZERODIVIDE 0x0004 /* zero divide */
  174. #define ISW_OVERFLOW 0x0008 /* overflow */
  175. #define ISW_UNDERFLOW 0x0010 /* underflow */
  176. #define ISW_INEXACT 0x0020 /* inexact (precision) */
  177. #elif defined(_M_IA64)
  178. /* Control word for computation of transcendentals */
  179. #define ICW (IMCW_EM | IRC_NEAR | IPC_64)
  180. #define ISW (ISW_INEXACT | ISW_UNDERFLOW | ISW_OVERFLOW | ISW_ZERODIVIDE | ISW_INVALID | ISW_DENORMAL)
  181. #define IMCW (0xffffffff ^ ISW)
  182. #define IMCW_EM 0x003f /* interrupt Exception Masks */
  183. #define IEM_INVALID 0x0001 /* invalid */
  184. #define IEM_DENORMAL 0x0002 /* denormal */
  185. #define IEM_ZERODIVIDE 0x0004 /* zero divide */
  186. #define IEM_OVERFLOW 0x0008 /* overflow */
  187. #define IEM_UNDERFLOW 0x0010 /* underflow */
  188. #define IEM_INEXACT 0x0020 /* inexact (precision) */
  189. #define IMCW_RC 0x0c00 /* Rounding Control */
  190. #define IRC_CHOP 0x0c00 /* chop */
  191. #define IRC_UP 0x0800 /* up */
  192. #define IRC_DOWN 0x0400 /* down */
  193. #define IRC_NEAR 0x0000 /* near */
  194. #define ISW_INVALID 0x02000 /* invalid */
  195. #define ISW_DENORMAL 0x04000 /* denormal */
  196. #define ISW_ZERODIVIDE 0x08000 /* zero divide */
  197. #define ISW_OVERFLOW 0x10000 /* overflow */
  198. #define ISW_UNDERFLOW 0x20000 /* underflow */
  199. #define ISW_INEXACT 0x40000 /* inexact (precision) */
  200. #define IMCW_PC 0x0300 /* Precision Control */
  201. #define IPC_24 0x0000 /* 24 bits */
  202. #define IPC_53 0x0200 /* 53 bits */
  203. #define IPC_64 0x0300 /* 64 bits */
  204. #endif
  205. #ifndef __assembler /* MIPS ONLY: Protect from assembler */
  206. #define RETURN(fpcw,result) return _rstorfp(fpcw),(result)
  207. #define RETURN_INEXACT1(op,arg1,res,cw) \
  208. if (cw & IEM_INEXACT) { \
  209. _rstorfp(cw); \
  210. return res; \
  211. } \
  212. else { \
  213. return _except1(FP_P, op, arg1, res, cw); \
  214. }
  215. #define RETURN_INEXACT2(op,arg1,arg2,res,cw) \
  216. if (cw & IEM_INEXACT) { \
  217. _rstorfp(cw); \
  218. return res; \
  219. } \
  220. else { \
  221. return _except2(FP_P, op, arg1, arg2, res, cw); \
  222. }
  223. //handle NaN propagation
  224. #define _d_snan2(x,y) ((x)+(y))
  225. #define _s2qnan(x) ((x)+1.0)
  226. #define _maskfp() _ctrlfp(ICW, IMCW)
  227. #define _rstorfp(cw) _ctrlfp(cw, IMCW)
  228. #define ABS(x) ((x)<0 ? -(x) : (x) )
  229. int _d_inttype(double);
  230. #endif /* #ifndef __assembler */
  231. #define _D_NOINT 0
  232. #define _D_ODD 1
  233. #define _D_EVEN 2
  234. // IEEE exceptions
  235. #define FP_O 0x01
  236. #define FP_U 0x02
  237. #define FP_Z 0x04
  238. #define FP_I 0x08
  239. #define FP_P 0x10
  240. // An extra flag for matherr support
  241. // Set together with FP_I from trig functions when the argument is too large
  242. #define FP_TLOSS 0x20
  243. #ifndef __assembler /* MIPS ONLY: Protect from assembler */
  244. #ifdef B_END
  245. #define SET_DBL(msw, lsw) msw, lsw
  246. #else
  247. #define SET_DBL(msw, lsw) lsw, msw
  248. #endif
  249. #endif /* #ifndef __assembler */
  250. // special types
  251. #define T_PINF 1
  252. #define T_NINF 2
  253. #define T_QNAN 3
  254. #define T_SNAN 4
  255. // exponent adjustment for IEEE overflow/underflow exceptions
  256. // used before passing the result to the trap handler
  257. #define IEEE_ADJUST 1536
  258. // QNAN values
  259. #define INT_NAN (~0)
  260. #define QNAN_SQRT D_IND
  261. #define QNAN_LOG D_IND
  262. #define QNAN_LOG10 D_IND
  263. #define QNAN_POW D_IND
  264. #define QNAN_SINH D_IND
  265. #define QNAN_COSH D_IND
  266. #define QNAN_TANH D_IND
  267. #define QNAN_SIN1 D_IND
  268. #define QNAN_SIN2 D_IND
  269. #define QNAN_COS1 D_IND
  270. #define QNAN_COS2 D_IND
  271. #define QNAN_TAN1 D_IND
  272. #define QNAN_TAN2 D_IND
  273. #define QNAN_ACOS D_IND
  274. #define QNAN_ASIN D_IND
  275. #define QNAN_ATAN2 D_IND
  276. #define QNAN_CEIL D_IND
  277. #define QNAN_FLOOR D_IND
  278. #define QNAN_MODF D_IND
  279. #define QNAN_LDEXP D_IND
  280. #define QNAN_FMOD D_IND
  281. #define QNAN_FREXP D_IND
  282. /*
  283. * Function prototypes
  284. */
  285. #ifndef __assembler /* MIPS ONLY: Protect from assembler */
  286. double _set_exp(double x, int exp);
  287. double _set_bexp(double x, int exp);
  288. double _add_exp(double x, int exp);
  289. double _frnd(double);
  290. double _fsqrt(double);
  291. double _except1(int flags, int opcode, double arg, double res, uintptr_t cw);
  292. double _except2(int flags, int opcode, double arg1, double arg2, double res, uintptr_t cw);
  293. int _sptype(double);
  294. int _get_exp(double);
  295. double _decomp(double, int *);
  296. int _powhlp(double x, double y, double * result);
  297. extern unsigned int _fpstatus;
  298. double _frnd(double);
  299. double _exphlp(double, int *);
  300. double _handle_qnan1(unsigned int op, double arg, uintptr_t cw);
  301. double _handle_qnan2(unsigned int op,double arg1,double arg2,uintptr_t cw);
  302. unsigned int _clhwfp(void);
  303. unsigned int _setfpcw(uintptr_t);
  304. int _errcode(unsigned int flags);
  305. void _set_errno(int matherrtype);
  306. int _handle_exc(unsigned int flags, double * presult, uintptr_t cw);
  307. uintptr_t _clrfp(void);
  308. uintptr_t _ctrlfp(uintptr_t,uintptr_t);
  309. uintptr_t _statfp(void);
  310. void _set_statfp(uintptr_t);
  311. #endif /* #ifndef __assembler */
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. #define _INC_TRANS
  316. #endif /* _INC_TRANS */