diff --git a/src/libc/gen/Makefile b/src/libc/gen/Makefile index 933e2af..254fd60 100755 --- a/src/libc/gen/Makefile +++ b/src/libc/gen/Makefile @@ -36,7 +36,7 @@ STDOBJ = abort.o alarm.o atof.o atoi.o atol.o calloc.o closedir.o crypt.o \ getpass.o getpwent.o getloadavg.o getmntinfo.o \ getttyent.o getttynam.o getusershell.o getwd.o \ initgroups.o isatty.o isinff.o isnanf.o ldexp.o malloc.o mktemp.o \ - modff.o modf.c ndbm.o nlist.o knlist.o opendir.o perror.o popen.o \ + modff.o modf.o ndbm.o nlist.o knlist.o opendir.o perror.o popen.o \ psignal.o qsort.o random.o readdir.o regex.o scandir.o \ seekdir.o setmode.o sethostname.o setenv.o siglist.o \ signal.o siginterrupt.o sigsetops.o \ diff --git a/src/libc/gen/isinff.c b/src/libc/gen/isinff.c index 1755a65..8bba21f 100644 --- a/src/libc/gen/isinff.c +++ b/src/libc/gen/isinff.c @@ -27,4 +27,4 @@ int isinff (float x) /* * For PIC32, double is the same as float. */ -int isinf (double x) __attribute__((alias ("isinff"))); +//int isinf (double x) __attribute__((alias ("isinff"))); diff --git a/src/libc/gen/isnanf.c b/src/libc/gen/isnanf.c index dda3938..c54ba7c 100644 --- a/src/libc/gen/isnanf.c +++ b/src/libc/gen/isnanf.c @@ -27,4 +27,4 @@ int isnanf (float x) /* * For PIC32, double is the same as float. */ -int isnan (double x) __attribute__((alias ("isnanf"))); +//int isnan (double x) __attribute__((alias ("isnanf"))); diff --git a/src/libc/gen/modf.c b/src/libc/gen/modf.c index a331a26..a9ee6f3 100644 --- a/src/libc/gen/modf.c +++ b/src/libc/gen/modf.c @@ -8,12 +8,20 @@ */ #include +// IM: dereferencing type-punned pointer will break strict-aliasing rules +// TODO check Endiannes + union { + double d64; + struct { long i32h; + long i32l; + }; + } ew; + /* Get two 32 bit ints from a double. */ -#define EXTRACT_WORDS(high,low,d) \ - high = *(unsigned long long*) &d; \ - low = (*(unsigned long long*) &d) >> 32 - +//#define EXTRACT_WORDS(high,low,d) +// high = *(unsigned long long*) &d; +// low = (*(unsigned long long*) &d) >> 32 /* Set a double from two 32 bit ints. */ @@ -36,22 +44,30 @@ double modf (double x, double *iptr) long i0, i1, j0; unsigned long i; - EXTRACT_WORDS (i0, i1, x); + //EXTRACT_WORDS (i0, i1, x); + ew.d64 = x; i0 = ew.i32h; i1 = ew.i32l; + // j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; /* exponent of x */ if (j0 < 20) { /* integer part in high x */ if (j0 < 0) { /* |x|<1 */ - INSERT_WORDS (*iptr, i0 & 0x80000000, 0); + //INSERT_WORDS (*iptr, i0 & 0x80000000, 0); + ew.i32h = i0 & 0x80000000; ew.i32l = 0; *iptr = ew.d64; + // /* *iptr = +-0 */ return x; } else { i = (0x000fffff) >> j0; if (((i0 & i) | i1) == 0) { /* x is integral */ *iptr = x; - INSERT_WORDS (x, i0 & 0x80000000, 0); + //INSERT_WORDS (x, i0 & 0x80000000, 0); + ew.i32h = i0 & 0x80000000; ew.i32l = 0; x = ew.d64; + // /* return +-0 */ return x; } else { - INSERT_WORDS (*iptr, i0 & (~i), 0); + //INSERT_WORDS (*iptr, i0 & (~i), 0); + ew.i32h = i0 & (~i); ew.i32l = 0; *iptr = ew.d64; + // return x - *iptr; } } @@ -61,18 +77,24 @@ double modf (double x, double *iptr) if (j0 == 0x400 && ((i0 & 0xfffff) | i1)) return x * one; - INSERT_WORDS (x, i0 & 0x80000000, 0); + //INSERT_WORDS (x, i0 & 0x80000000, 0); + ew.i32h = i0 & 0x80000000; ew.i32l = 0; x = ew.d64; + // /* return +-0 */ return x; } else { /* fraction part in low x */ i = ((unsigned long) (0xffffffff)) >> (j0 - 20); if ((i1 & i) == 0) { /* x is integral */ *iptr = x; - INSERT_WORDS (x, i0 & 0x80000000, 0); + //INSERT_WORDS (x, i0 & 0x80000000, 0); + ew.i32h = i0 & 0x80000000; ew.i32l = 0; x = ew.d64; + // /* return +-0 */ return x; } else { - INSERT_WORDS (*iptr, i0, i1 & (~i)); + //INSERT_WORDS (*iptr, i0, i1 & (~i)); + ew.i32h = i0; ew.i32l = i1 & (~i); *iptr = ew.d64; + // return x - *iptr; } } diff --git a/src/libc/gen/modff.c b/src/libc/gen/modff.c index 7eeac60..41a5d94 100644 --- a/src/libc/gen/modff.c +++ b/src/libc/gen/modff.c @@ -52,4 +52,4 @@ float modff (float fx, float *iptr) /* * For PIC32, double is the same as float. */ -double modf (double x, double *iptr) __attribute__((alias ("modff"))); +//double modf (double x, double *iptr) __attribute__((alias ("modff")));