Compare commits
30 Commits
master
...
double_pre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5da189ad36 | ||
|
|
de9ae5c603 | ||
|
|
9cf1805a1d | ||
|
|
4e2777e9fb | ||
|
|
6316b05ec3 | ||
|
|
738874016f | ||
|
|
6ce8e28a85 | ||
|
|
4783836659 | ||
|
|
249b5716bb | ||
|
|
1d1151403b | ||
|
|
54a771c6f0 | ||
|
|
eddfd51e51 | ||
|
|
d9033fbf2d | ||
|
|
28aae2c427 | ||
|
|
6d689c335c | ||
|
|
bad98ad239 | ||
|
|
c04495837f | ||
|
|
297b14aa0c | ||
|
|
190aa1e633 | ||
|
|
0220852a66 | ||
|
|
2afff6f8aa | ||
|
|
5b1496e5c3 | ||
|
|
bcff791a3c | ||
|
|
98d034efe1 | ||
|
|
0f6e23c2fe | ||
|
|
af3db0bcd2 | ||
|
|
b73ccfb9dc | ||
|
|
c31e4fa1e8 | ||
|
|
16e7b63b48 | ||
|
|
16214d4557 |
47
include/ieee.h
Normal file
47
include/ieee.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
typedef union // LITTLE ENDIAN
|
||||||
|
{
|
||||||
|
double value;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
unsigned long lsw;
|
||||||
|
unsigned long msw;
|
||||||
|
} parts;
|
||||||
|
} ieee_double_shape_type;
|
||||||
|
|
||||||
|
/* Get two 32 bit ints from a double. */
|
||||||
|
|
||||||
|
#define EXTRACT_WORDS(ix0,ix1,d) \
|
||||||
|
do { \
|
||||||
|
ieee_double_shape_type ew_u; \
|
||||||
|
ew_u.value = (d); \
|
||||||
|
(ix0) = ew_u.parts.msw; \
|
||||||
|
(ix1) = ew_u.parts.lsw; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Get the more significant 32 bit int from a double. */
|
||||||
|
|
||||||
|
#define GET_HIGH_WORD(i,d) \
|
||||||
|
do { \
|
||||||
|
ieee_double_shape_type gh_u; \
|
||||||
|
gh_u.value = (d); \
|
||||||
|
(i) = gh_u.parts.msw; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Set a double from two 32 bit ints. */
|
||||||
|
|
||||||
|
#define INSERT_WORDS(d,ix0,ix1) \
|
||||||
|
do { \
|
||||||
|
ieee_double_shape_type iw_u; \
|
||||||
|
iw_u.parts.msw = (ix0); \
|
||||||
|
iw_u.parts.lsw = (ix1); \
|
||||||
|
(d) = iw_u.value; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define SET_HIGH_WORD(d,v) \
|
||||||
|
do { \
|
||||||
|
ieee_double_shape_type sh_u; \
|
||||||
|
sh_u.value = (d); \
|
||||||
|
sh_u.parts.msw = (v); \
|
||||||
|
(d) = sh_u.value; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
@@ -12,8 +12,9 @@ extern double sinh(), cosh(), tanh();
|
|||||||
extern double gamma();
|
extern double gamma();
|
||||||
extern double j0(), j1(), jn(), y0(), y1(), yn();
|
extern double j0(), j1(), jn(), y0(), y1(), yn();
|
||||||
|
|
||||||
#define HUGE 1.701411733192644270e38
|
// ###PITO #define HUGE 1.701411733192644270e38
|
||||||
#define LOGHUGE 39
|
#define HUGE 1.79769313486231570000e+308
|
||||||
|
#define LOGHUGE 307
|
||||||
|
|
||||||
int isnanf(float x);
|
int isnanf(float x);
|
||||||
int isnan(double x);
|
int isnan(double x);
|
||||||
|
|||||||
@@ -22,8 +22,8 @@
|
|||||||
#define va_copy(dest, src) __builtin_va_copy((dest), (src))
|
#define va_copy(dest, src) __builtin_va_copy((dest), (src))
|
||||||
|
|
||||||
|
|
||||||
#ifndef _VA_LIST_T
|
#ifndef _VA_LIST
|
||||||
#define _VA_LIST_T
|
#define _VA_LIST
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
typedef __builtin_va_list va_list;
|
typedef __builtin_va_list va_list;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
1
lib/.gitignore
vendored
1
lib/.gitignore
vendored
@@ -11,3 +11,4 @@ ranlib.h
|
|||||||
retroImage
|
retroImage
|
||||||
size
|
size
|
||||||
strip
|
strip
|
||||||
|
gccdump.s
|
||||||
|
|||||||
0
lib/Makefile
Normal file → Executable file
0
lib/Makefile
Normal file → Executable file
57
src/cmd/9degree/9degree.c
Normal file
57
src/cmd/9degree/9degree.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
void print64x( double x ) {
|
||||||
|
char* p;
|
||||||
|
int j;
|
||||||
|
p = (char *) &x;
|
||||||
|
for( j=0; j< sizeof(x); j++) {
|
||||||
|
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print32x( float x ) {
|
||||||
|
char* p;
|
||||||
|
int j;
|
||||||
|
p = (char *) &x;
|
||||||
|
for( j=0; j< sizeof(x); j++) {
|
||||||
|
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
struct timeval start, stop;
|
||||||
|
volatile double _p64, q64, r64, e64;
|
||||||
|
long i;
|
||||||
|
unsigned long elapsed;
|
||||||
|
|
||||||
|
_p64 = 3.1415926535897932384626433832795;
|
||||||
|
|
||||||
|
for(i=0;i<100;i++) {
|
||||||
|
// 64bit test
|
||||||
|
// 9 degree test input
|
||||||
|
q64 = i;
|
||||||
|
// Convert to radians
|
||||||
|
q64 = q64 * _p64 / 180.0;
|
||||||
|
// Make the test
|
||||||
|
|
||||||
|
gettimeofday(&start, NULL);
|
||||||
|
|
||||||
|
r64 = (asin(acos(atan(tan(cos(sin(q64)))))));
|
||||||
|
|
||||||
|
gettimeofday(&stop, NULL);
|
||||||
|
|
||||||
|
// Convert to degree
|
||||||
|
r64 = r64 * 180.0 / _p64;
|
||||||
|
|
||||||
|
elapsed = stop.tv_usec - start.tv_usec;
|
||||||
|
|
||||||
|
printf("%ld degree 64bit test result= %1.15e time= %lu " , i, r64, elapsed );
|
||||||
|
printf("= 0x");
|
||||||
|
print64x( r64 );
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
1
src/cmd/9degree/Makefile
Symbolic link
1
src/cmd/9degree/Makefile
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../generic.mk
|
||||||
@@ -17,7 +17,7 @@ SUBDIR = adb adc-demo ar as awk basic cc chflags chpass \
|
|||||||
rdprof ranlib re renice retroforth scm setty sl \
|
rdprof ranlib re renice retroforth scm setty sl \
|
||||||
sed sh smallc smlrc stty sysctl test uname wiznet xargs \
|
sed sh smallc smlrc stty sysctl test uname wiznet xargs \
|
||||||
zmodem gtest msec unixbench cron compress date2 tip \
|
zmodem gtest msec unixbench cron compress date2 tip \
|
||||||
talloc devupdate uucp smux
|
talloc devupdate uucp smux 9degree mathtest scantest
|
||||||
|
|
||||||
# /sbin
|
# /sbin
|
||||||
SUBDIR += chown chroot disktool fsck getty init \
|
SUBDIR += chown chroot disktool fsck getty init \
|
||||||
|
|||||||
@@ -522,7 +522,7 @@ void startup ()
|
|||||||
|
|
||||||
int fd = mkstemp (tfilename);
|
int fd = mkstemp (tfilename);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
uerror ("cannot create temporary file %2", tfilename);
|
uerror ("cannot create temporary file %s", tfilename);
|
||||||
} else {
|
} else {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|||||||
31
src/cmd/generic.mk
Normal file
31
src/cmd/generic.mk
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#==========================================
|
||||||
|
# Makefile: makefile for adc-demo
|
||||||
|
# Copyright 2012 Majenko Technolohies
|
||||||
|
# (matt@majenko.co.uk
|
||||||
|
# Last Modified: 29/01/2012
|
||||||
|
#==========================================
|
||||||
|
|
||||||
|
TOPSRC = $(shell cd ../../..; pwd)
|
||||||
|
include $(TOPSRC)/target.mk
|
||||||
|
|
||||||
|
PWD = $(shell pwd)
|
||||||
|
PROG = $(shell basename "$(PWD)")
|
||||||
|
|
||||||
|
OBJS = $(PROG).o
|
||||||
|
SRCS = $(PROG).c
|
||||||
|
|
||||||
|
all: $(PROG)
|
||||||
|
|
||||||
|
-include Makefile.app
|
||||||
|
|
||||||
|
$(PROG): ${OBJS}
|
||||||
|
${CC} ${LDFLAGS} -o $(PROG).elf ${OBJS} ${LIBS}
|
||||||
|
${OBJDUMP} -S $(PROG).elf > $(PROG).dis
|
||||||
|
${SIZE} $(PROG).elf
|
||||||
|
${ELF2AOUT} $(PROG).elf $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f $(PROG) ${OBJS} $(PROG).elf $(PROG).dis
|
||||||
|
|
||||||
|
install: all
|
||||||
|
install $(PROG) $(DESTDIR)/bin/
|
||||||
1
src/cmd/mathtest/Makefile
Symbolic link
1
src/cmd/mathtest/Makefile
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../generic.mk
|
||||||
49
src/cmd/mathtest/mathtest.c
Normal file
49
src/cmd/mathtest/mathtest.c
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
// Pito 12/2013
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// print out double (IEEE 64bit) variable in HEX
|
||||||
|
// ie. 9.0 is 4022000000000000
|
||||||
|
// more on http://babbage.cs.qc.cuny.edu/IEEE-754/
|
||||||
|
|
||||||
|
void print64x( double x ) {
|
||||||
|
const unsigned char* p;
|
||||||
|
int j;
|
||||||
|
p = (unsigned char *) &x;
|
||||||
|
printf("%02X", p[7]);
|
||||||
|
printf("%02X", p[6]);
|
||||||
|
printf("%02X", p[5]);
|
||||||
|
printf("%02X", p[4]);
|
||||||
|
printf("%02X", p[3]);
|
||||||
|
printf("%02X", p[2]);
|
||||||
|
printf("%02X", p[1]);
|
||||||
|
printf("%02X", p[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print32x( float x ) {
|
||||||
|
const char* p;
|
||||||
|
int j;
|
||||||
|
p = (char *) &x;
|
||||||
|
for( j=0; j< sizeof(x); j++) {
|
||||||
|
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
volatile double num1 = 1.2499999999999998193580478994e-10;
|
||||||
|
volatile double num2 = 2.16000000000000081281633984229e-10;
|
||||||
|
volatile double res = 0;
|
||||||
|
|
||||||
|
res = num1 + num2;
|
||||||
|
|
||||||
|
// print64x(num1);
|
||||||
|
// printf(" + ");
|
||||||
|
// print64x(num2);
|
||||||
|
// printf(" = ");
|
||||||
|
// print64x(res);
|
||||||
|
// printf("\n");
|
||||||
|
|
||||||
|
printf("%1.15e + %1.15e = %1.15e\n", num1, num2, res);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
1
src/cmd/scantest/Makefile
Symbolic link
1
src/cmd/scantest/Makefile
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../generic.mk
|
||||||
84
src/cmd/scantest/scantest.c
Normal file
84
src/cmd/scantest/scantest.c
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
// Pito 12/2013
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// print out double (IEEE 64bit) variable in HEX
|
||||||
|
// ie. 9.0 is 4022000000000000
|
||||||
|
// more on http://babbage.cs.qc.cuny.edu/IEEE-754/
|
||||||
|
|
||||||
|
void print64x( double x ) {
|
||||||
|
const unsigned char* p;
|
||||||
|
int j;
|
||||||
|
p = (unsigned char *) &x;
|
||||||
|
printf("%02X", p[7]);
|
||||||
|
printf("%02X", p[6]);
|
||||||
|
printf("%02X", p[5]);
|
||||||
|
printf("%02X", p[4]);
|
||||||
|
printf("%02X", p[3]);
|
||||||
|
printf("%02X", p[2]);
|
||||||
|
printf("%02X", p[1]);
|
||||||
|
printf("%02X", p[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print32x( float x ) {
|
||||||
|
const char* p;
|
||||||
|
int j;
|
||||||
|
p = (char *) &x;
|
||||||
|
for( j=0; j< sizeof(x); j++) {
|
||||||
|
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
double num;
|
||||||
|
int i;
|
||||||
|
double sum;
|
||||||
|
FILE *InFile, *OutFile;
|
||||||
|
char str[100];
|
||||||
|
double backup;
|
||||||
|
double result;
|
||||||
|
|
||||||
|
if ((OutFile = fopen("num.dat","w")) == 0) {
|
||||||
|
printf("num.dat not found\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<=10000; i++) {
|
||||||
|
num = 0.0001L * (double)(i);
|
||||||
|
num = num * num * num;
|
||||||
|
fprintf(OutFile, "%1.15e\n", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(OutFile);
|
||||||
|
|
||||||
|
if ((InFile = fopen("num.dat","r")) == 0) {
|
||||||
|
printf("num.dat not found\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sum = 0;
|
||||||
|
num = 0;
|
||||||
|
|
||||||
|
for (i=0; i<=10000; i++) {
|
||||||
|
backup = sum;
|
||||||
|
fgets (str, 80, InFile);
|
||||||
|
sscanf (str,"%le",&num);
|
||||||
|
result = sum + num;
|
||||||
|
|
||||||
|
if (sum != backup) {
|
||||||
|
printf("*** SUM CHANGED: %1.15e => %1.15e ***\n", backup, sum);
|
||||||
|
}
|
||||||
|
sum = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Sum test result = %1.15e\n", sum);
|
||||||
|
printf("Shall be result = 2.500500025000002e+03\n");
|
||||||
|
printf("Sum test result (HEX) = ");
|
||||||
|
print64x( sum );
|
||||||
|
printf("\n");
|
||||||
|
printf("Shall be result (HEX) = 40A389000346DC62\n");
|
||||||
|
|
||||||
|
fclose(InFile);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
0
src/libc/compat/Makefile
Normal file → Executable file
0
src/libc/compat/Makefile
Normal file → Executable file
4
src/libc/gen/Makefile
Normal file → Executable file
4
src/libc/gen/Makefile
Normal file → Executable file
@@ -19,7 +19,7 @@ STDSRC = abort.c alarm.c atof.c atoi.c atol.c calloc.c closedir.c crypt.c \
|
|||||||
getpass.c getpwent.c getloadavg.c getmntinfo.c \
|
getpass.c getpwent.c getloadavg.c getmntinfo.c \
|
||||||
getttyent.c getttynam.c getusershell.c getwd.c \
|
getttyent.c getttynam.c getusershell.c getwd.c \
|
||||||
initgroups.c isatty.c isinff.c isnanf.c ldexp.c malloc.c mktemp.c \
|
initgroups.c isatty.c isinff.c isnanf.c ldexp.c malloc.c mktemp.c \
|
||||||
modff.c ndbm.c nlist.c knlist.c opendir.c perror.c popen.c \
|
modff.c modf.c ndbm.c nlist.c knlist.c opendir.c perror.c popen.c \
|
||||||
psignal.c qsort.c random.c readdir.c regex.c scandir.c \
|
psignal.c qsort.c random.c readdir.c regex.c scandir.c \
|
||||||
seekdir.c setmode.c sethostname.c setenv.c siglist.c \
|
seekdir.c setmode.c sethostname.c setenv.c siglist.c \
|
||||||
signal.c siginterrupt.c sigsetops.c \
|
signal.c siginterrupt.c sigsetops.c \
|
||||||
@@ -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 \
|
getpass.o getpwent.o getloadavg.o getmntinfo.o \
|
||||||
getttyent.o getttynam.o getusershell.o getwd.o \
|
getttyent.o getttynam.o getusershell.o getwd.o \
|
||||||
initgroups.o isatty.o isinff.o isnanf.o ldexp.o malloc.o mktemp.o \
|
initgroups.o isatty.o isinff.o isnanf.o ldexp.o malloc.o mktemp.o \
|
||||||
modff.o 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 \
|
psignal.o qsort.o random.o readdir.o regex.o scandir.o \
|
||||||
seekdir.o setmode.o sethostname.o setenv.o siglist.o \
|
seekdir.o setmode.o sethostname.o setenv.o siglist.o \
|
||||||
signal.o siginterrupt.o sigsetops.o \
|
signal.o siginterrupt.o sigsetops.o \
|
||||||
|
|||||||
@@ -27,4 +27,4 @@ int isinff (float x)
|
|||||||
/*
|
/*
|
||||||
* For PIC32, double is the same as float.
|
* For PIC32, double is the same as float.
|
||||||
*/
|
*/
|
||||||
int isinf (double x) __attribute__((alias ("isinff")));
|
//int isinf (double x) __attribute__((alias ("isinff")));
|
||||||
|
|||||||
@@ -27,4 +27,4 @@ int isnanf (float x)
|
|||||||
/*
|
/*
|
||||||
* For PIC32, double is the same as float.
|
* For PIC32, double is the same as float.
|
||||||
*/
|
*/
|
||||||
int isnan (double x) __attribute__((alias ("isnanf")));
|
//int isnan (double x) __attribute__((alias ("isnanf")));
|
||||||
|
|||||||
@@ -1,46 +1,46 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <ieee.h>
|
||||||
|
|
||||||
|
static const double
|
||||||
|
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
|
||||||
|
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
|
||||||
|
huge = 1.0e+308,
|
||||||
|
tiny = 1.0e-307;
|
||||||
|
|
||||||
|
static double
|
||||||
|
_copysign(double x, double y)
|
||||||
|
{
|
||||||
|
unsigned long hx,hy;
|
||||||
|
GET_HIGH_WORD(hx,x);
|
||||||
|
GET_HIGH_WORD(hy,y);
|
||||||
|
SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
ldexp(fr, exp)
|
ldexp(double x, int n)
|
||||||
double fr;
|
|
||||||
int exp;
|
|
||||||
{
|
{
|
||||||
double huge = 1.701411834604692293e38;
|
unsigned long k,hx,lx;
|
||||||
int neg;
|
EXTRACT_WORDS(hx,lx,x);
|
||||||
int i;
|
k = (hx&0x7ff00000)>>20; /* extract exponent */
|
||||||
|
if (k==0) { /* 0 or subnormal x */
|
||||||
neg = 0;
|
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
|
||||||
if (fr < 0) {
|
x *= two54;
|
||||||
fr = -fr;
|
GET_HIGH_WORD(hx,x);
|
||||||
neg = 1;
|
k = ((hx&0x7ff00000)>>20) - 54;
|
||||||
|
if (n< -50000) return tiny*x; /*underflow*/
|
||||||
|
}
|
||||||
|
if (k==0x7ff) return x+x; /* NaN or Inf */
|
||||||
|
k = k+n;
|
||||||
|
if (k > 0x7fe) return huge*_copysign(huge,x); /* overflow */
|
||||||
|
if (k > 0) /* normal result */
|
||||||
|
{SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
|
||||||
|
if (k <= -54) {
|
||||||
|
if (n > 50000) /* in case integer overflow in n+k */
|
||||||
|
return huge*_copysign(huge,x); /*overflow*/
|
||||||
|
else return tiny*_copysign(tiny,x); /*underflow*/
|
||||||
}
|
}
|
||||||
fr = frexp(fr, &i);
|
k += 54; /* subnormal result */
|
||||||
while (fr < 0.5) {
|
SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
|
||||||
fr = 2*fr;
|
return x*twom54;
|
||||||
i = i-1;
|
|
||||||
}
|
|
||||||
exp = exp+i;
|
|
||||||
if (exp > 127) {
|
|
||||||
if (neg)
|
|
||||||
return(-huge);
|
|
||||||
else
|
|
||||||
return(huge);
|
|
||||||
}
|
|
||||||
if (exp < -127)
|
|
||||||
return(0);
|
|
||||||
while (exp > 30) {
|
|
||||||
fr = fr*(1L<<30);
|
|
||||||
exp = exp-30;
|
|
||||||
}
|
|
||||||
while (exp < -30) {
|
|
||||||
fr = fr/(1L<<30);
|
|
||||||
exp = exp+30;
|
|
||||||
}
|
|
||||||
if (exp > 0)
|
|
||||||
fr = fr*(1L<<exp);
|
|
||||||
if (exp < 0)
|
|
||||||
fr = fr/(1L<<-exp);
|
|
||||||
if (neg)
|
|
||||||
fr = -fr;
|
|
||||||
return(fr);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,18 +7,7 @@
|
|||||||
* is preserved.
|
* is preserved.
|
||||||
*/
|
*/
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <ieee.h>
|
||||||
/* 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
|
|
||||||
|
|
||||||
|
|
||||||
/* Set a double from two 32 bit ints. */
|
|
||||||
|
|
||||||
#define INSERT_WORDS(d,high,low) \
|
|
||||||
*(unsigned long long*) &(x) = (unsigned long long) (high) << 32 | (low)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* modf(double x, double *iptr)
|
* modf(double x, double *iptr)
|
||||||
@@ -37,10 +26,12 @@ double modf (double x, double *iptr)
|
|||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
|
||||||
EXTRACT_WORDS (i0, i1, x);
|
EXTRACT_WORDS (i0, i1, x);
|
||||||
|
//
|
||||||
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; /* exponent of x */
|
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; /* exponent of x */
|
||||||
if (j0 < 20) { /* integer part in high x */
|
if (j0 < 20) { /* integer part in high x */
|
||||||
if (j0 < 0) { /* |x|<1 */
|
if (j0 < 0) { /* |x|<1 */
|
||||||
INSERT_WORDS (*iptr, i0 & 0x80000000, 0);
|
INSERT_WORDS (*iptr, i0 & 0x80000000, 0);
|
||||||
|
//
|
||||||
/* *iptr = +-0 */
|
/* *iptr = +-0 */
|
||||||
return x;
|
return x;
|
||||||
} else {
|
} else {
|
||||||
@@ -48,10 +39,12 @@ double modf (double x, double *iptr)
|
|||||||
if (((i0 & i) | i1) == 0) { /* x is integral */
|
if (((i0 & i) | i1) == 0) { /* x is integral */
|
||||||
*iptr = x;
|
*iptr = x;
|
||||||
INSERT_WORDS (x, i0 & 0x80000000, 0);
|
INSERT_WORDS (x, i0 & 0x80000000, 0);
|
||||||
|
//
|
||||||
/* return +-0 */
|
/* return +-0 */
|
||||||
return x;
|
return x;
|
||||||
} else {
|
} else {
|
||||||
INSERT_WORDS (*iptr, i0 & (~i), 0);
|
INSERT_WORDS (*iptr, i0 & (~i), 0);
|
||||||
|
//
|
||||||
return x - *iptr;
|
return x - *iptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,6 +55,7 @@ double modf (double x, double *iptr)
|
|||||||
return x * one;
|
return x * one;
|
||||||
|
|
||||||
INSERT_WORDS (x, i0 & 0x80000000, 0);
|
INSERT_WORDS (x, i0 & 0x80000000, 0);
|
||||||
|
//
|
||||||
/* return +-0 */
|
/* return +-0 */
|
||||||
return x;
|
return x;
|
||||||
} else { /* fraction part in low x */
|
} else { /* fraction part in low x */
|
||||||
@@ -69,10 +63,12 @@ double modf (double x, double *iptr)
|
|||||||
if ((i1 & i) == 0) { /* x is integral */
|
if ((i1 & i) == 0) { /* x is integral */
|
||||||
*iptr = x;
|
*iptr = x;
|
||||||
INSERT_WORDS (x, i0 & 0x80000000, 0);
|
INSERT_WORDS (x, i0 & 0x80000000, 0);
|
||||||
|
//
|
||||||
/* return +-0 */
|
/* return +-0 */
|
||||||
return x;
|
return x;
|
||||||
} else {
|
} else {
|
||||||
INSERT_WORDS (*iptr, i0, i1 & (~i));
|
INSERT_WORDS (*iptr, i0, i1 & (~i));
|
||||||
|
//
|
||||||
return x - *iptr;
|
return x - *iptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,4 +52,4 @@ float modff (float fx, float *iptr)
|
|||||||
/*
|
/*
|
||||||
* For PIC32, double is the same as float.
|
* 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")));
|
||||||
|
|||||||
0
src/libc/gen/ndbm.c
Normal file → Executable file
0
src/libc/gen/ndbm.c
Normal file → Executable file
0
src/libc/mips/sys/Makefile
Normal file → Executable file
0
src/libc/mips/sys/Makefile
Normal file → Executable file
0
src/libc/stdio/Makefile
Normal file → Executable file
0
src/libc/stdio/Makefile
Normal file → Executable file
@@ -42,7 +42,9 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
/* Max number conversion buffer length: a long in base 2, plus NUL byte. */
|
/* Max number conversion buffer length: a long in base 2, plus NUL byte. */
|
||||||
#define MAXNBUF (sizeof(long) * 8 + 1)
|
//#define MAXNBUF (sizeof(long) * 8 + 1)
|
||||||
|
/* Max number conversion buffer length: MAXEXP(308) + MAXFRACTION(15) + 2 */
|
||||||
|
#define MAXNBUF 308+15+2
|
||||||
|
|
||||||
static unsigned char *ksprintn (unsigned char *buf, unsigned long v, unsigned char base,
|
static unsigned char *ksprintn (unsigned char *buf, unsigned long v, unsigned char base,
|
||||||
int width, unsigned char *lp);
|
int width, unsigned char *lp);
|
||||||
@@ -61,6 +63,8 @@ _doprnt (char const *fmt, va_list ap, FILE *stream)
|
|||||||
int n, width, dwidth, retval, uppercase, extrazeros, sign;
|
int n, width, dwidth, retval, uppercase, extrazeros, sign;
|
||||||
unsigned long ul;
|
unsigned long ul;
|
||||||
|
|
||||||
|
double d;
|
||||||
|
|
||||||
if (! stream)
|
if (! stream)
|
||||||
return 0;
|
return 0;
|
||||||
if (! fmt)
|
if (! fmt)
|
||||||
@@ -361,7 +365,11 @@ number: if (sign && ((long) ul != 0L)) {
|
|||||||
case 'F':
|
case 'F':
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G': {
|
case 'G': {
|
||||||
double d = va_arg (ap, double);
|
|
||||||
|
// ---va_arg alignment fix
|
||||||
|
d = va_arg(ap, double);
|
||||||
|
// ---
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* don't do unrealistic precision; just pad it with
|
* don't do unrealistic precision; just pad it with
|
||||||
* zeroes later, so buffer size stays rational.
|
* zeroes later, so buffer size stays rational.
|
||||||
@@ -583,10 +591,11 @@ cvt (double number, int prec, int sharpflag, unsigned char *negp, unsigned char
|
|||||||
* get integer portion of number; put into the end of the buffer; the
|
* get integer portion of number; put into the end of the buffer; the
|
||||||
* .01 is added for modf (356.0 / 10, &integer) returning .59999999...
|
* .01 is added for modf (356.0 / 10, &integer) returning .59999999...
|
||||||
*/
|
*/
|
||||||
for (p = endp - 1; integer; ++expcnt) {
|
p = endp - 1;
|
||||||
tmp = modf (integer / 10, &integer);
|
for (; integer && p >= startp; ++expcnt) {
|
||||||
*p-- = (int) ((tmp + .01) * 10) + '0';
|
tmp = modf(integer * 0.1L , &integer);
|
||||||
}
|
*p-- = (int)((tmp + .01L) * 10) + '0';
|
||||||
|
}
|
||||||
switch (fmtch) {
|
switch (fmtch) {
|
||||||
case 'f':
|
case 'f':
|
||||||
/* reverse integer into beginning of buffer */
|
/* reverse integer into beginning of buffer */
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define HAVE_FLOAT 1
|
||||||
|
|
||||||
#define SPC 01
|
#define SPC 01
|
||||||
#define STP 02
|
#define STP 02
|
||||||
|
|||||||
0
src/libc/stdlib/Makefile
Normal file → Executable file
0
src/libc/stdlib/Makefile
Normal file → Executable file
@@ -7,7 +7,7 @@ TOPSRC = $(shell cd ../../..; pwd)
|
|||||||
include $(TOPSRC)/target.mk
|
include $(TOPSRC)/target.mk
|
||||||
|
|
||||||
DEFS =
|
DEFS =
|
||||||
CFLAGS += ${DEFS} -Os
|
CFLAGS += ${DEFS}
|
||||||
|
|
||||||
SRCS = strcspn.c strpbrk.c strerror.c strsep.c strspn.c strstr.c strtok.c strtok_r.c
|
SRCS = strcspn.c strpbrk.c strerror.c strsep.c strspn.c strstr.c strtok.c strtok_r.c
|
||||||
OBJS = strcspn.o strpbrk.o strerror.o strsep.o strspn.o strstr.o strtok.o strtok_r.o
|
OBJS = strcspn.o strpbrk.o strerror.o strsep.o strspn.o strstr.o strtok.o strtok_r.o
|
||||||
|
|||||||
@@ -39,15 +39,17 @@ asin(arg)
|
|||||||
|
|
||||||
double
|
double
|
||||||
acos(arg)
|
acos(arg)
|
||||||
double arg;
|
double arg;
|
||||||
{
|
{
|
||||||
if(arg < 0)
|
double sign = 1.0;
|
||||||
arg = -arg;
|
if(arg < 0.0){
|
||||||
|
arg = -arg;
|
||||||
|
sign = -1.0;
|
||||||
|
}
|
||||||
|
if(arg > 1.0){
|
||||||
|
errno = EDOM;
|
||||||
|
return(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
if(arg > 1.){
|
return(pio2 - sign*asin(arg));
|
||||||
errno = EDOM;
|
}
|
||||||
return(0.);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(pio2 - asin(arg));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
double static sq2p1 =2.414213562373095048802e0;
|
static double sq2p1 =2.414213562373095048802e0;
|
||||||
static double sq2m1 = .414213562373095048802e0;
|
static double sq2m1 = .414213562373095048802e0;
|
||||||
static double pio2 =1.570796326794896619231e0;
|
static double pio2 =1.570796326794896619231e0;
|
||||||
static double pio4 = .785398163397448309615e0;
|
static double pio4 = .785398163397448309615e0;
|
||||||
|
|||||||
@@ -1,23 +1,47 @@
|
|||||||
/* Get two 32 bit ints from a double. */
|
typedef union // LITTLE ENDIAN
|
||||||
|
|
||||||
#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. */
|
|
||||||
|
|
||||||
#define INSERT_WORDS(d,high,low) \
|
|
||||||
*(unsigned long long*) &(x) = (unsigned long long) (high) << 32 | (low)
|
|
||||||
|
|
||||||
|
|
||||||
typedef union
|
|
||||||
{
|
{
|
||||||
double value;
|
double value;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32_t lsw;
|
unsigned long lsw;
|
||||||
uint32_t msw;
|
unsigned long msw;
|
||||||
} parts;
|
} parts;
|
||||||
} ieee_double_shape_type;
|
} ieee_double_shape_type;
|
||||||
|
|
||||||
|
/* Get two 32 bit ints from a double. */
|
||||||
|
|
||||||
|
#define EXTRACT_WORDS(ix0,ix1,d) \
|
||||||
|
do { \
|
||||||
|
ieee_double_shape_type ew_u; \
|
||||||
|
ew_u.value = (d); \
|
||||||
|
(ix0) = ew_u.parts.msw; \
|
||||||
|
(ix1) = ew_u.parts.lsw; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Get the more significant 32 bit int from a double. */
|
||||||
|
|
||||||
|
#define GET_HIGH_WORD(i,d) \
|
||||||
|
do { \
|
||||||
|
ieee_double_shape_type gh_u; \
|
||||||
|
gh_u.value = (d); \
|
||||||
|
(i) = gh_u.parts.msw; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Set a double from two 32 bit ints. */
|
||||||
|
|
||||||
|
#define INSERT_WORDS(d,ix0,ix1) \
|
||||||
|
do { \
|
||||||
|
ieee_double_shape_type iw_u; \
|
||||||
|
iw_u.parts.msw = (ix0); \
|
||||||
|
iw_u.parts.lsw = (ix1); \
|
||||||
|
(d) = iw_u.value; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define SET_HIGH_WORD(d,v) \
|
||||||
|
do { \
|
||||||
|
ieee_double_shape_type sh_u; \
|
||||||
|
sh_u.value = (d); \
|
||||||
|
sh_u.parts.msw = (v); \
|
||||||
|
(d) = sh_u.value; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ struct sigstack {
|
|||||||
struct sigcontext {
|
struct sigcontext {
|
||||||
int sc_onstack; /* sigstack state to restore */
|
int sc_onstack; /* sigstack state to restore */
|
||||||
long sc_mask; /* signal mask to restore */
|
long sc_mask; /* signal mask to restore */
|
||||||
|
int sc_align[2]; /* align to 16 bytes */
|
||||||
int sc_r1; /* r1 to restore */
|
int sc_r1; /* r1 to restore */
|
||||||
int sc_r2; /* and other registers */
|
int sc_r2; /* and other registers */
|
||||||
int sc_r3;
|
int sc_r3;
|
||||||
|
|||||||
2
sys/kernel/kern_exec.c
Normal file → Executable file
2
sys/kernel/kern_exec.c
Normal file → Executable file
@@ -432,7 +432,7 @@ badarg:
|
|||||||
*/
|
*/
|
||||||
ucp = USER_DATA_END - nc - NBPW;
|
ucp = USER_DATA_END - nc - NBPW;
|
||||||
ap = ucp - na*NBPW - 2*NBPW;
|
ap = ucp - na*NBPW - 2*NBPW;
|
||||||
u.u_frame [FRAME_SP] = ap - 16;
|
u.u_frame [FRAME_SP] = (ap - 16) & ~0xf; /* align to 16 bytes */
|
||||||
u.u_frame [FRAME_R4] = na - ne; /* $a0 := argc */
|
u.u_frame [FRAME_R4] = na - ne; /* $a0 := argc */
|
||||||
u.u_frame [FRAME_R5] = ap; /* $a1 := argv */
|
u.u_frame [FRAME_R5] = ap; /* $a1 := argv */
|
||||||
u.u_frame [FRAME_R6] = ap + (na-ne+1)*NBPW; /* $a2 := env */
|
u.u_frame [FRAME_R6] = ap + (na-ne+1)*NBPW; /* $a2 := env */
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ SUBDIR = baremetal dip duinomite duinomite-uart duinomite-e \
|
|||||||
duinomite-e-uart explorer16 max32 max32-eth maximite \
|
duinomite-e-uart explorer16 max32 max32-eth maximite \
|
||||||
meb pinguino-micro starter-kit ubw32 ubw32-uart \
|
meb pinguino-micro starter-kit ubw32 ubw32-uart \
|
||||||
ubw32-uart-sdram baremetal fubarino fubarino-uart \
|
ubw32-uart-sdram baremetal fubarino fubarino-uart \
|
||||||
fubarino-uart-sramc mmb-mx7 maximite-color \
|
fubarino-uart-sramc mmb-mx7 maximite-color 32mxsdram-uart
|
||||||
32mxsdram-uart
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
|||||||
@@ -24,19 +24,29 @@
|
|||||||
* The values are dependant upon the presence of the -fno-short-double
|
* The values are dependant upon the presence of the -fno-short-double
|
||||||
* compiler option.
|
* compiler option.
|
||||||
*/
|
*/
|
||||||
#define DBL_EPSILON FLT_EPSILON
|
//#define DBL_EPSILON FLT_EPSILON
|
||||||
#define DBL_MAX FLT_MAX
|
//#define DBL_MAX FLT_MAX
|
||||||
#define DBL_MIN FLT_MIN
|
//#define DBL_MIN FLT_MIN
|
||||||
#define DBL_DIG FLT_DIG
|
//#define DBL_DIG FLT_DIG
|
||||||
#define DBL_MANT_DIG FLT_MANT_DIG
|
//#define DBL_MANT_DIG FLT_MANT_DIG
|
||||||
#define DBL_MAX_10_EXP FLT_MAX_10_EXP
|
//#define DBL_MAX_10_EXP FLT_MAX_10_EXP
|
||||||
#define DBL_MAX_EXP FLT_MAX_EXP
|
//#define DBL_MAX_EXP FLT_MAX_EXP
|
||||||
#define DBL_MIN_10_EXP FLT_MIN_10_EXP
|
//#define DBL_MIN_10_EXP FLT_MIN_10_EXP
|
||||||
#define DBL_MIN_EXP FLT_MIN_EXP
|
//#define DBL_MIN_EXP FLT_MIN_EXP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These values provide information pertaining to the long double type.
|
* These values provide information pertaining to the long double type.
|
||||||
*/
|
*/
|
||||||
|
#define DBL_EPSILON 2.2204460492503131E-16
|
||||||
|
#define DBL_MAX 1.7976931348623157E+308
|
||||||
|
#define DBL_MIN 2.2250738585072014E-308
|
||||||
|
#define DBL_DIG 15
|
||||||
|
#define DBL_MANT_DIG 53
|
||||||
|
#define DBL_MAX_10_EXP 308
|
||||||
|
#define DBL_MAX_EXP 1024
|
||||||
|
#define DBL_MIN_10_EXP (-307)
|
||||||
|
#define DBL_MIN_EXP (-1021)
|
||||||
|
|
||||||
#define LDBL_EPSILON 2.2204460492503131E-16
|
#define LDBL_EPSILON 2.2204460492503131E-16
|
||||||
#define LDBL_MAX 1.7976931348623157E+308
|
#define LDBL_MAX 1.7976931348623157E+308
|
||||||
#define LDBL_MIN 2.2250738585072014E-308
|
#define LDBL_MIN 2.2250738585072014E-308
|
||||||
|
|||||||
0
sys/pic32/gcc-config.mk
Normal file → Executable file
0
sys/pic32/gcc-config.mk
Normal file → Executable file
0
sys/pic32/kernel-post.mk
Normal file → Executable file
0
sys/pic32/kernel-post.mk
Normal file → Executable file
6
target.mk
Normal file → Executable file
6
target.mk
Normal file → Executable file
@@ -34,8 +34,8 @@ ifndef GCCPREFIX
|
|||||||
INCLUDES =
|
INCLUDES =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CC = $(GCCPREFIX)gcc -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES)
|
CC = $(GCCPREFIX)gcc -mips32r2 -EL -msoft-float -fno-short-double -nostdinc -I$(TOPSRC)/include $(INCLUDES)
|
||||||
CXX = $(GCCPREFIX)g++ -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES)
|
CXX = $(GCCPREFIX)g++ -mips32r2 -EL -msoft-float -fno-short-double -nostdinc -I$(TOPSRC)/include $(INCLUDES)
|
||||||
LD = $(GCCPREFIX)ld
|
LD = $(GCCPREFIX)ld
|
||||||
AR = $(GCCPREFIX)ar
|
AR = $(GCCPREFIX)ar
|
||||||
RANLIB = $(GCCPREFIX)ranlib
|
RANLIB = $(GCCPREFIX)ranlib
|
||||||
@@ -50,7 +50,7 @@ TAGSFILE = tags
|
|||||||
MANROFF = nroff -man -h -Tascii
|
MANROFF = nroff -man -h -Tascii
|
||||||
ELF2AOUT = $(TOPSRC)/tools/elf2aout/elf2aout
|
ELF2AOUT = $(TOPSRC)/tools/elf2aout/elf2aout
|
||||||
|
|
||||||
CFLAGS = -O
|
CFLAGS = -O
|
||||||
|
|
||||||
LDFLAGS += -N -nostartfiles -fno-dwarf2-cfi-asm -T$(TOPSRC)/src/elf32-mips.ld \
|
LDFLAGS += -N -nostartfiles -fno-dwarf2-cfi-asm -T$(TOPSRC)/src/elf32-mips.ld \
|
||||||
$(TOPSRC)/src/crt0.o -L$(TOPSRC)/src
|
$(TOPSRC)/src/crt0.o -L$(TOPSRC)/src
|
||||||
|
|||||||
Reference in New Issue
Block a user