aboutsummaryrefslogtreecommitdiff
path: root/win32/include/math.h
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2015-11-01 18:47:03 +0200
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2015-11-07 22:18:46 +0200
commit9c52ba48b347998abfe0ef544961bbaf88daee11 (patch)
treed3d2f7a4d2a1fbcd401b5e8049fdfd9634611e77 /win32/include/math.h
parent6e261a107cf92a62817e81c78b52470d81218e4a (diff)
downloadtinycc-9c52ba48b347998abfe0ef544961bbaf88daee11.tar.gz
tinycc-9c52ba48b347998abfe0ef544961bbaf88daee11.tar.bz2
win: math.h: fix fpclassify/signbit/etc - use C instead of broken asm
The asm code cannot currently be used with tcc since tcc doesn't support 't' constraint. Use inline C implementation instead, place it win32/include/tcc/tcc_libm.h, and include it from win32/include/math.h. Since fpclassify now works, it also fixes few other macros which depend on it. Implicitly fixed: isfinite, isinf, isnan, isnormal. The implementations were taken from musl-libc rs-1.0 (MIT license). musl-libc: http://git.musl-libc.org/cgit/musl/tree/src/math?h=rs-1.0 license: http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT?h=rs-1.0
Diffstat (limited to 'win32/include/math.h')
-rw-r--r--win32/include/math.h31
1 files changed, 9 insertions, 22 deletions
diff --git a/win32/include/math.h b/win32/include/math.h
index d923f17..297184f 100644
--- a/win32/include/math.h
+++ b/win32/include/math.h
@@ -313,13 +313,9 @@ extern "C" {
extern int __cdecl __fpclassifyf (float);
extern int __cdecl __fpclassify (double);
+ extern int __cdecl __fpclassifyl (long double);
- __CRT_INLINE int __cdecl __fpclassifyl (long double x){
- unsigned short sw;
- __asm__ ("fxam; fstsw %%ax;" : "=a" (sw): "t" (x));
- return sw & (FP_NAN | FP_NORMAL | FP_ZERO );
- }
-
+/* Implemented at tcc/tcc_libm.h */
#define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x) \
: sizeof (x) == sizeof (double) ? __fpclassify (x) \
: __fpclassifyl (x))
@@ -339,24 +335,12 @@ extern "C" {
#define isnormal(x) (fpclassify(x) == FP_NORMAL)
/* 7.12.3.6 The signbit macro */
- __CRT_INLINE int __cdecl __signbit (double x) {
- unsigned short stw;
- __asm__ ( "fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
- return stw & 0x0200;
- }
- __CRT_INLINE int __cdecl __signbitf (float x) {
- unsigned short stw;
- __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
- return stw & 0x0200;
- }
-
- __CRT_INLINE int __cdecl __signbitl (long double x) {
- unsigned short stw;
- __asm__ ("fxam; fstsw %%ax;": "=a" (stw) : "t" (x));
- return stw & 0x0200;
- }
+ extern int __cdecl __signbitf (float);
+ extern int __cdecl __signbit (double);
+ extern int __cdecl __signbitl (long double);
+/* Implemented at tcc/tcc_libm.h */
#define signbit(x) (sizeof (x) == sizeof (float) ? __signbitf (x) \
: sizeof (x) == sizeof (double) ? __signbit (x) \
: __signbitl (x))
@@ -746,5 +730,8 @@ extern "C++" {
* which always returns true: yes, (NaN != NaN) is true).
*/
+/* Mini libm (inline __fpclassify*, __signbit* and variants) */
+#include "tcc/tcc_libm.h"
+
#endif /* End _MATH_H_ */