Author: jgardou
Date: Mon Jul 30 12:55:13 2012
New Revision: 56995
URL:
http://svn.reactos.org/svn/reactos?rev=56995&view=rev
Log:
[INCLUDE]
- Add some more C99 math functions
- Fix definition of __forceinline and FORCEINLINE for C99
- Fix and add definition of _aligned_malloc and _aligned_free
- Fix definition of is(w)blank, as a C99 function, it is not in msvcrt.dll and has to be
implemented in msvcrtex
All of this taken from the mingw-w64 project
Modified:
trunk/reactos/include/crt/_mingw.h
trunk/reactos/include/crt/ctype.h
trunk/reactos/include/crt/malloc.h
trunk/reactos/include/crt/math.h
trunk/reactos/include/crt/stdlib.h
trunk/reactos/include/psdk/intsafe.h
trunk/reactos/include/psdk/ntdef.h
trunk/reactos/include/psdk/winnt.h
Modified: trunk/reactos/include/crt/_mingw.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/_mingw.h?rev=5…
==============================================================================
--- trunk/reactos/include/crt/_mingw.h [iso-8859-1] (original)
+++ trunk/reactos/include/crt/_mingw.h [iso-8859-1] Mon Jul 30 12:55:13 2012
@@ -172,7 +172,11 @@
# endif
# define __ptr32
# define __ptr64
-# define __forceinline extern __inline __attribute((always_inline))
+# if ( __MINGW_GNUC_PREREQ(4, 3) && __STDC_VERSION__ >= 199901L)
+# define __forceinline extern inline __attribute__((__always_inline__,__gnu_inline__))
+# else
+# define __forceinline extern __inline__ __attribute__((__always_inline__))
+# endif
#endif
#ifdef __cplusplus
Modified: trunk/reactos/include/crt/ctype.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/ctype.h?rev=56…
==============================================================================
--- trunk/reactos/include/crt/ctype.h [iso-8859-1] (original)
+++ trunk/reactos/include/crt/ctype.h [iso-8859-1] Mon Jul 30 12:55:13 2012
@@ -112,7 +112,7 @@
_CRTIMP int __cdecl __iscsymf(int _C);
_CRTIMP int __cdecl __iscsym(int _C);
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined
(NO_OLDNAMES)
- _CRTIMP int __cdecl isblank(int _C);
+ int __cdecl isblank(int _C);
#endif
#endif /* !_CTYPE_DEFINED */
@@ -156,7 +156,7 @@
_CRTIMP int __cdecl is_wctype(wint_t _C,wctype_t _Type);
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined
(NO_OLDNAMES)
- _CRTIMP int __cdecl iswblank(wint_t _C);
+ int __cdecl iswblank(wint_t _C);
#endif
#endif
Modified: trunk/reactos/include/crt/malloc.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/malloc.h?rev=5…
==============================================================================
--- trunk/reactos/include/crt/malloc.h [iso-8859-1] (original)
+++ trunk/reactos/include/crt/malloc.h [iso-8859-1] Mon Jul 30 12:55:13 2012
@@ -52,6 +52,18 @@
extern unsigned int _amblksiz;
+/* Make sure that X86intrin.h doesn't produce here collisions. */
+#if (!defined (_XMMINTRIN_H_INCLUDED) && !defined (_MM_MALLOC_H_INCLUDED)) ||
defined(_aligned_malloc)
+#define __DO_ALIGN_DEFINES
+#endif
+
+#ifdef __DO_ALIGN_DEFINES
+#pragma push_macro("_aligned_free")
+#pragma push_macro("_aligned_malloc")
+#undef _aligned_free
+#undef _aligned_malloc
+#endif
+
#define _mm_free(a) _aligned_free(a)
#define _mm_malloc(a,b) _aligned_malloc(a,b)
@@ -62,13 +74,25 @@
void *__cdecl malloc(size_t _Size);
void *__cdecl realloc(void *_Memory,size_t _NewSize);
_CRTIMP void *__cdecl _recalloc(void *_Memory,size_t _Count,size_t _Size);
- /* _CRTIMP void __cdecl _aligned_free(void *_Memory);
- _CRTIMP void *__cdecl _aligned_malloc(size_t _Size,size_t _Alignment); */
+
+#ifdef __DO_ALIGN_DEFINES
+ _CRTIMP void __cdecl _aligned_free(void *_Memory);
+ _CRTIMP void *__cdecl _aligned_malloc(size_t _Size,size_t _Alignment);
+#endif
+
_CRTIMP void *__cdecl _aligned_offset_malloc(size_t _Size,size_t _Alignment,size_t
_Offset);
_CRTIMP void *__cdecl _aligned_realloc(void *_Memory,size_t _Size,size_t _Alignment);
_CRTIMP void *__cdecl _aligned_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t
_Alignment);
_CRTIMP void *__cdecl _aligned_offset_realloc(void *_Memory,size_t _Size,size_t
_Alignment,size_t _Offset);
_CRTIMP void *__cdecl _aligned_offset_recalloc(void *_Memory,size_t _Count,size_t
_Size,size_t _Alignment,size_t _Offset);
+#endif
+
+#ifdef __DO_ALIGN_DEFINES
+#undef __DO_ALIGN_DEFINES
+
+#pragma pop_macro("_aligned_malloc")
+#pragma pop_macro("_aligned_free")
+
#endif
#define _MAX_WAIT_MALLOC_CRT 60000
Modified: trunk/reactos/include/crt/math.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/math.h?rev=569…
==============================================================================
--- trunk/reactos/include/crt/math.h [iso-8859-1] (original)
+++ trunk/reactos/include/crt/math.h [iso-8859-1] Mon Jul 30 12:55:13 2012
@@ -240,8 +240,6 @@
#pragma pack(pop)
-#endif /* !_INC_MATH */
-
#if defined(_USE_MATH_DEFINES) && !defined(_MATH_DEFINES_DEFINED)
#define _MATH_DEFINES_DEFINED
@@ -261,41 +259,141 @@
#endif /* _USE_MATH_DEFINES */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifndef __NO_ISOCEXT
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
|| !defined __STRICT_ANSI__ || defined __GLIBCPP__
- /* Inverse hyperbolic trig functions */
- /* 7.12.5.1 */
+/* 7.12.3.1 */
+/*
+ Return values for fpclassify.
+ These are based on Intel x87 fpu condition codes
+ in the high byte of status word and differ from
+ the return values for MS IEEE 754 extension _fpclass()
+*/
+#define FP_NAN 0x0100
+#define FP_NORMAL 0x0400
+#define FP_INFINITE (FP_NAN | FP_NORMAL)
+#define FP_ZERO 0x4000
+#define FP_SUBNORMAL (FP_NORMAL | FP_ZERO)
+/* 0x0200 is signbit mask */
+
+/*
+ We can't inline float or double, because we want to ensure truncation
+ to semantic type before classification.
+ (A normal long double value might become subnormal when
+ converted to double, and zero when converted to float.)
+*/
+
+ extern int __cdecl __fpclassifyl (long double);
+ extern int __cdecl __fpclassifyf (float);
+ extern int __cdecl __fpclassify (double);
+
+#ifndef __CRT__NO_INLINE
+ __CRT_INLINE int __cdecl __fpclassifyl (long double x) {
+ unsigned short sw;
+ __asm__ __volatile__ ("fxam; fstsw %%ax;" : "=a" (sw):
"t" (x));
+ return sw & (FP_NAN | FP_NORMAL | FP_ZERO );
+ }
+ __CRT_INLINE int __cdecl __fpclassify (double x) {
+#ifdef __x86_64__
+ __mingw_dbl_type_t hlp;
+ unsigned int l, h;
+
+ hlp.x = x;
+ h = hlp.lh.high;
+ l = hlp.lh.low | (h & 0xfffff);
+ h &= 0x7ff00000;
+ if ((h | l) == 0)
+ return FP_ZERO;
+ if (!h)
+ return FP_SUBNORMAL;
+ if (h == 0x7ff00000)
+ return (l ? FP_NAN : FP_INFINITE);
+ return FP_NORMAL;
+#else
+ unsigned short sw;
+ __asm__ __volatile__ ("fxam; fstsw %%ax;" : "=a" (sw):
"t" (x));
+ return sw & (FP_NAN | FP_NORMAL | FP_ZERO );
+#endif
+ }
+ __CRT_INLINE int __cdecl __fpclassifyf (float x) {
+#ifdef __x86_64__
+ __mingw_flt_type_t hlp;
+
+ hlp.x = x;
+ hlp.val &= 0x7fffffff;
+ if (hlp.val == 0)
+ return FP_ZERO;
+ if (hlp.val < 0x800000)
+ return FP_SUBNORMAL;
+ if (hlp.val >= 0x7f800000)
+ return (hlp.val > 0x7f800000 ? FP_NAN : FP_INFINITE);
+ return FP_NORMAL;
+#else
+ unsigned short sw;
+ __asm__ __volatile__ ("fxam; fstsw %%ax;" : "=a" (sw):
"t" (x));
+ return sw & (FP_NAN | FP_NORMAL | FP_ZERO );
+#endif
+ }
+#endif
+
+#define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x) \
+ : sizeof (x) == sizeof (double) ? __fpclassify (x) \
+ : __fpclassifyl (x))
+
+/* 7.12.3.2 */
+#define isfinite(x) ((fpclassify(x) & FP_NAN) == 0)
+
+/* 7.12.3.3 */
+#define isinf(x) (fpclassify(x) == FP_INFINITE)
+
+/* Inverse hyperbolic trig functions */
+/* 7.12.5.1 */
extern double __cdecl acosh (double);
extern float __cdecl acoshf (float);
extern long double __cdecl acoshl (long double);
- /* 7.12.5.2 */
+/* 7.12.5.2 */
extern double __cdecl asinh (double);
extern float __cdecl asinhf (float);
extern long double __cdecl asinhl (long double);
- /* 7.12.5.3 */
+/* 7.12.5.3 */
extern double __cdecl atanh (double);
extern float __cdecl atanhf (float);
extern long double __cdecl atanhl (long double);
- /* 7.12.6.2 */
+/* 7.12.6.2 */
extern double __cdecl exp2(double);
extern float __cdecl exp2f(float);
extern long double __cdecl exp2l(long double);
- /* 7.12.6.10 */
+/* 7.12.6.10 */
extern double __cdecl log2 (double);
extern float __cdecl log2f (float);
extern long double __cdecl log2l (long double);
- /* 7.12.9.8 */
- /* round towards zero, regardless of fpu control word settings */
+/* 7.12.9.6 */
+/* round away from zero, regardless of fpu control word settings */
+ extern double __cdecl round (double);
+ extern float __cdecl roundf (float);
+ extern long double __cdecl roundl (long double);
+
+/* 7.12.9.8 */
+/* round towards zero, regardless of fpu control word settings */
extern double __cdecl trunc (double);
extern float __cdecl truncf (float);
extern long double __cdecl truncl (long double);
#endif /* __STDC_VERSION__ >= 199901L */
#endif /* __NO_ISOCEXT */
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* !_INC_MATH */
Modified: trunk/reactos/include/crt/stdlib.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/crt/stdlib.h?rev=5…
==============================================================================
--- trunk/reactos/include/crt/stdlib.h [iso-8859-1] (original)
+++ trunk/reactos/include/crt/stdlib.h [iso-8859-1] Mon Jul 30 12:55:13 2012
@@ -342,8 +342,17 @@
void *__cdecl malloc(size_t _Size);
void *__cdecl realloc(void *_Memory,size_t _NewSize);
_CRTIMP void *__cdecl _recalloc(void *_Memory,size_t _Count,size_t _Size);
- //_CRTIMP void __cdecl _aligned_free(void *_Memory);
- //_CRTIMP void *__cdecl _aligned_malloc(size_t _Size,size_t _Alignment);
+/* Make sure that X86intrin.h doesn't produce here collisions. */
+#if (!defined (_XMMINTRIN_H_INCLUDED) && !defined (_MM_MALLOC_H_INCLUDED)) ||
defined(_aligned_malloc)
+#pragma push_macro("_aligned_free")
+#pragma push_macro("_aligned_malloc")
+#undef _aligned_free
+#undef _aligned_malloc
+ _CRTIMP void __cdecl _aligned_free(void *_Memory);
+ _CRTIMP void *__cdecl _aligned_malloc(size_t _Size,size_t _Alignment);
+#pragma pop_macro("_aligned_free")
+#pragma pop_macro("_aligned_malloc")
+#endif
_CRTIMP void *__cdecl _aligned_offset_malloc(size_t _Size,size_t _Alignment,size_t
_Offset);
_CRTIMP void *__cdecl _aligned_realloc(void *_Memory,size_t _Size,size_t _Alignment);
_CRTIMP void *__cdecl _aligned_recalloc(void *_Memory,size_t _Count,size_t _Size,size_t
_Alignment);
Modified: trunk/reactos/include/psdk/intsafe.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/intsafe.h?rev…
==============================================================================
--- trunk/reactos/include/psdk/intsafe.h [iso-8859-1] (original)
+++ trunk/reactos/include/psdk/intsafe.h [iso-8859-1] Mon Jul 30 12:55:13 2012
@@ -31,7 +31,11 @@
#include <specstrings.h>
#if defined(__GNUC__) && !defined(__forceinline)
-#define __forceinline extern __inline __attribute((always_inline))
+# if ( __MINGW_GNUC_PREREQ(4, 3) && __STDC_VERSION__ >= 199901L)
+# define __forceinline extern inline __attribute__((__always_inline__,__gnu_inline__))
+# else
+# define __forceinline extern __inline__ __attribute__((__always_inline__))
+# endif
#endif
/* Handle ntintsafe here too */
Modified: trunk/reactos/include/psdk/ntdef.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/ntdef.h?rev=5…
==============================================================================
--- trunk/reactos/include/psdk/ntdef.h [iso-8859-1] (original)
+++ trunk/reactos/include/psdk/ntdef.h [iso-8859-1] Mon Jul 30 12:55:13 2012
@@ -264,7 +264,11 @@
#elif defined(_MSC_VER)
#define FORCEINLINE __inline
#else /* __GNUC__ */
-#define FORCEINLINE extern __inline__ __attribute__((always_inline))
+# if ( __MINGW_GNUC_PREREQ(4, 3) && __STDC_VERSION__ >= 199901L)
+# define FORCEINLINE extern inline __attribute__((__always_inline__,__gnu_inline__))
+# else
+# define FORCEINLINE extern __inline__ __attribute__((__always_inline__))
+# endif
#endif
#endif /* FORCEINLINE */
Modified: trunk/reactos/include/psdk/winnt.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/winnt.h?rev=5…
==============================================================================
--- trunk/reactos/include/psdk/winnt.h [iso-8859-1] (original)
+++ trunk/reactos/include/psdk/winnt.h [iso-8859-1] Mon Jul 30 12:55:13 2012
@@ -176,7 +176,11 @@
#elif (_MSC_VER)
#define FORCEINLINE __inline
#else
-#define FORCEINLINE extern __inline__ __attribute__((always_inline))
+# if ( __MINGW_GNUC_PREREQ(4, 3) && __STDC_VERSION__ >= 199901L)
+# define FORCEINLINE extern inline __attribute__((__always_inline__,__gnu_inline__))
+# else
+# define FORCEINLINE extern __inline__ __attribute__((__always_inline__))
+# endif
#endif
#endif