From 462b4f35652098e26c677f89df6990428a4aad6a Mon Sep 17 00:00:00 2001 From: nsz Date: Sun, 7 Oct 2012 17:15:03 +0200 Subject: [PATCH] new test framework (one main per test) --- Makefile | 6 +- Makefile.inc | 75 +++------- common/b.c | 171 ---------------------- common/t.c | 123 ---------------- common/test.h | 8 -- src/env/Makefile | 3 +- src/env/env.c | 11 +- src/env/test.h | 20 +++ src/malloc/Makefile | 2 - src/malloc/bench.c | 163 --------------------- src/math/Makefile | 4 - src/math/acos.c | 12 -- src/math/classify.c | 105 -------------- src/math/fenv.c | 60 -------- src/math/fenvutil.c | 59 -------- src/math/fenvutil.h | 2 - src/math/fma.c | 212 ---------------------------- src/math/lrint.c | 167 ---------------------- src/math/modf.c | 151 -------------------- src/math/nextafter.c | 81 ----------- src/math/nextafterl.c | 88 ------------ src/math/sanity.c | 257 ---------------------------------- src/math/scalbn.c | 72 ---------- src/math/sqrt.c | 92 ------------ src/misc/Makefile | 3 +- src/misc/basename.c | 30 ++-- src/misc/dirname.c | 34 ++--- src/misc/test.h | 20 +++ src/multibyte/Makefile | 3 +- src/multibyte/mbc.c | 106 +++++++------- src/multibyte/test.h | 20 +++ src/multibyte/utf8bench.c | 65 --------- src/process/spawn.c | 33 +++-- src/process/test.h | 20 +++ src/regex/Makefile | 3 +- src/regex/bench.c | 41 ------ src/regex/fnmatch.c | 27 ++-- src/regex/test.h | 20 +++ src/stdio/Makefile | 3 +- src/stdio/bench.c | 50 ------- src/stdio/fdopen.c | 13 +- src/stdio/fscanf.c | 48 +++---- src/stdio/memstream.c | 3 +- src/stdio/popen.c | 4 +- src/stdio/snprintf.c | 5 +- src/stdio/sscanf.c | 4 +- src/stdio/sscanf_long.c | 51 +++++++ src/stdio/swprintf.c | 9 +- src/stdio/test.h | 20 +++ src/stdio/ungetc.c | 6 +- src/stdlib/Makefile | 5 +- src/stdlib/qsort.c | 33 +---- src/stdlib/strtod.c | 125 +---------------- src/stdlib/strtod_long.c | 19 +++ src/stdlib/strtod_simple.c | 32 +++++ src/stdlib/strtof.c | 42 ++++++ src/stdlib/strtol.c | 4 +- src/stdlib/strtold.c | 94 +++++++++++++ src/stdlib/test.h | 20 +++ src/stdlib/wcstol.c | 4 +- src/string/Makefile | 4 +- src/string/bench.c | 85 ----------- src/string/string.c | 4 +- src/string/test.h | 20 +++ src/thread/Makefile | 10 +- src/thread/bench.c | 106 -------------- src/thread/pthread.c | 4 +- src/thread/sem.c | 3 +- src/thread/test.h | 20 +++ src/thread/tls_align.c | 23 +++ src/thread/tls_align_dlopen.c | 31 ++++ src/thread/tls_align_dso.c | 32 +++++ src/thread/tls_init.c | 42 ++++++ src/time/Makefile | 3 +- src/time/test.h | 20 +++ src/time/time.c | 6 +- src/udiv/Makefile | 3 +- src/udiv/test.h | 20 +++ src/udiv/udiv.c | 33 +---- 79 files changed, 835 insertions(+), 2597 deletions(-) delete mode 100644 common/b.c delete mode 100644 common/t.c delete mode 100644 common/test.h create mode 100644 src/env/test.h delete mode 100644 src/malloc/Makefile delete mode 100644 src/malloc/bench.c delete mode 100644 src/math/Makefile delete mode 100644 src/math/acos.c delete mode 100644 src/math/classify.c delete mode 100644 src/math/fenv.c delete mode 100644 src/math/fenvutil.c delete mode 100644 src/math/fenvutil.h delete mode 100644 src/math/fma.c delete mode 100644 src/math/lrint.c delete mode 100644 src/math/modf.c delete mode 100644 src/math/nextafter.c delete mode 100644 src/math/nextafterl.c delete mode 100644 src/math/sanity.c delete mode 100644 src/math/scalbn.c delete mode 100644 src/math/sqrt.c create mode 100644 src/misc/test.h create mode 100644 src/multibyte/test.h delete mode 100644 src/multibyte/utf8bench.c create mode 100644 src/process/test.h delete mode 100644 src/regex/bench.c create mode 100644 src/regex/test.h delete mode 100644 src/stdio/bench.c create mode 100644 src/stdio/sscanf_long.c create mode 100644 src/stdio/test.h create mode 100644 src/stdlib/strtod_long.c create mode 100644 src/stdlib/strtod_simple.c create mode 100644 src/stdlib/strtof.c create mode 100644 src/stdlib/strtold.c create mode 100644 src/stdlib/test.h delete mode 100644 src/string/bench.c create mode 100644 src/string/test.h delete mode 100644 src/thread/bench.c create mode 100644 src/thread/test.h create mode 100644 src/thread/tls_align.c create mode 100644 src/thread/tls_align_dlopen.c create mode 100644 src/thread/tls_align_dso.c create mode 100644 src/thread/tls_init.c create mode 100644 src/time/test.h create mode 100644 src/udiv/test.h diff --git a/Makefile b/Makefile index 0c86cef..a4726fb 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,7 @@ DIRS = $(sort $(wildcard src/*)) all: for i in $(DIRS); do printf "%-20s" $$i; make -s -C $$i; done -t: - @for i in $(DIRS); do printf "%-20s" $$i; make -s -C $$i t 2>/dev/null || echo 'BUILD FAIL'; $$i/t; done -b: t - @for i in $(DIRS); do echo $$i; $$i/b; done +run: + for i in $(DIRS); do printf "%-20s" $$i; make -s -C $$i run; done clean: for i in $(DIRS); do make -s -C $$i clean; done diff --git a/Makefile.inc b/Makefile.inc index 05d8689..26b41c6 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -1,55 +1,22 @@ -# gnu makefile -# when included in a Makefile it builds *.c unless SRCS are overridden - -# default TROOT works from src/*/Makefile -TROOT ?= ../.. -SRCS ?= $(sort $(wildcard *.c)) -OBJS = $(SRCS:.c=.o) - -AR=ar -RANLIB=ranlib - -CFLAGS += -g -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE -std=c99 -pipe -Wall -Wno-unused-function -Wno-missing-braces -LDFLAGS += -g -lpthread -lrt -lm - -include $(TROOT)/config.mak - -CFLAGS += -I$(TROOT)/common - -all: test - -test: t b - ./t - +CFLAGS+=-g -pipe -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wno-unused-function -Wno-missing-braces +LDFLAGS+=-g + +SRC=$(sort $(wildcard *.c)) +OBJ=$(SRC:.c=.o) +DSOOBJ=$(filter %_dso.o,$(OBJ)) +BINOBJ=$(filter-out %_dso.o,$(OBJ)) +DSO=$(DSOOBJ:.o=.so) +BIN=$(BINOBJ:.o=) + +all: $(BIN) $(DSO) +run: all + @N=0; for i in $(BIN);do ./$$i || N=$$((N+1)); done; [ "$$N" = 0 ] && echo PASS || echo FAILS: $$N clean: - rm -f $(OBJS) t t_.o b b_.o tests.a tests.h - -.c.o: - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJS): $(TROOT)/common/test.h $(TROOT)/config.mak - -tests.h: $(OBJS) - nm -f posix $+ |awk ' \ - /^test/ && $$2=="T"{print "T(" $$1 ")"} \ - /^bench/ && $$2=="T"{print "B(" $$1 ")"} \ - ' >tests.h - -tests.a: $(OBJS) - $(AR) rc $@ $+ - $(RANLIB) $@ - -# TODO: /tmp/t.o ? -t_.o: $(TROOT)/common/t.c $(TROOT)/common/test.h tests.h - $(CC) $(CFLAGS) -I. -c -o $@ $< - -t: t_.o tests.a - $(CC) $+ $(LDFLAGS) -o $@ - -b_.o: $(TROOT)/common/b.c $(TROOT)/common/test.h tests.h - $(CC) $(CFLAGS) -I. -c -o $@ $< - -b: b_.o tests.a - $(CC) $+ $(LDFLAGS) -lrt -o $@ - -.PHONY: all clean test + rm -f $(OBJ) $(DSO) $(BIN) + +$(OBJ): test.h +$(DSOOBJ): CFLAGS += -fPIC +%.so: %.o + $(CC) $(LDFLAGS) -shared -o $@ $< +%: %.o + $(CC) $(LDFLAGS) -o $@ $(patsubst %.so,./%.so,$+) diff --git a/common/b.c b/common/b.c deleted file mode 100644 index ac0159c..0000000 --- a/common/b.c +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "test.h" - -#define T(f) -#define B(f) void f(int); -#include "tests.h" -#undef B - -static int verbose = 1; - -void error__(const char *n, int l, const char *s, ...) { - dprintf(1, "use error in tests only\n"); -} - -static int N; -static unsigned long long start; -static unsigned long long dt; -//static unsigned long long bytes; - -#define SEC 1000000000ULL -#define MAXN 500000000 -#define MINT (SEC/5) - -static unsigned long long tic() { - struct timespec ts; - - if (clock_gettime(CLOCK_REALTIME, &ts) < 0) { - dprintf(1, "bench: clock_gettime failed: %s\n", strerror(errno)); - return 0; - } - return ts.tv_sec*SEC + ts.tv_nsec; -} - -void start_timer() { - if (!start) - start = tic(); -} - -void stop_timer() { - if (start) - dt += tic() - start; - start = 0; -} - -void reset_timer() { - if (start) - start = tic(); - dt = 0; -} - -static int nextN() { - unsigned long long n = dt/N; - unsigned long long i; - - if (n) - n = MINT/n; - else - n = MINT; - n += n/2; - if (n > N*100ULL) - n = N*100ULL; - else if (n <= N) - n = N+1; - if (n > MAXN) - n = MAXN; - - /* round up to a nice number */ - for (i = 1; i < n; i *= 10); - if (i/2 >= n) - i /= 2; - if (i/2 >= n) - i /= 2; - return i; -} - -void vmstats() { - FILE *f; - char buf[256]; - int maj, min, in_heap=0; - unsigned long l; - size_t vm_size=0, vm_rss=0, vm_priv_dirty=0; - - f = fopen("/proc/self/smaps", "rb"); - if (f) while (fgets(buf, sizeof buf, f)) { - if (sscanf(buf, "%*x-%*x %*s %*x %x:%x %*u %*s", &maj, &min)==2) - in_heap = (!maj && !min && !strstr(buf, "---p") && (strstr(buf, "[heap]") || !strchr(buf, '['))); - if (in_heap) { - if (sscanf(buf, "Size: %lu", &l)==1) vm_size += l; - else if (sscanf(buf, "Rss: %lu", &l)==1) vm_rss += l; - else if (sscanf(buf, "Private_Dirty: %lu", &l)==1) vm_priv_dirty += l; - } - } - if (f) fclose(f); - dprintf(1, " %7zu virt %7zu res %7zu dirty", vm_size, vm_rss, vm_priv_dirty); -} - -void stats() { - if (dt/N >= 100) - dprintf(1, "%10d N %10llu ns/op ", N, dt/N); - else - dprintf(1, "%10d N %13.2f ns/op", N, (double)dt/N); - if (verbose) - vmstats(); - dprintf(1, "\n"); -} - -static char *pattern; - -static void run(const char *name, void (*f)(int)) { - int p; - - if (pattern && !strstr(name, pattern)) - return; - p = fork(); - if (p) { - int s; - if (p<0 || wait(&s)<0 || !WIFEXITED(s) || WEXITSTATUS(s)) - dprintf(1, "benchmark %s failed\n", name); - return; - } - dprintf(1, "%-32s", name); - for (N=1; ; N=nextN()) { - // TODO: fork at each iteration and pass N,dt..? - reset_timer(); - start_timer(); - f(N); - stop_timer(); -// dprintf(1, "%10d%12llu next: %d\n", N, dt, nextN()); - if (dt >= SEC/2 || N >= MAXN) { - stats(); - exit(0); - } - if (N <= 0) { - dprintf(1, "bench: fatal: N <= 0\n"); - exit(1); - } - } -} - -static void usage() { - fprintf(stderr, "usage: ./b [-vq] [pat]\n"); - exit(1); -} - -int main(int argc, char *argv[]) { - int c; - - while((c = getopt(argc, argv, "vq")) != -1) - switch(c) { - case 'v': - verbose = 1; - break; - case 'q': - verbose = 0; - break; - default: - usage(); - } - if (optind != argc) - pattern = argv[optind]; -#define B(t) run(#t, t); -#include "tests.h" - return 0; -} diff --git a/common/t.c b/common/t.c deleted file mode 100644 index 3e9c95e..0000000 --- a/common/t.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "test.h" - -#define B(f) -#define T(f) void f(); -#include "tests.h" -#undef T - -static int failed; -static const char *name; - -static int slow; -static int verbose; -static int count; -static int nfailed; - -static void errtimer() { error("use *_timer in benchmarks only\n"); } -void start_timer() { errtimer(); } -void stop_timer() { errtimer(); } -void reset_timer() { errtimer(); } - -void error__(const char *n, int l, const char *s, ...) { - va_list ap; - - if (failed == 0 && nfailed == 0) - dprintf(1, "FAIL\n"); - failed = 1; - dprintf(1, " ERROR %s %s:%d: ", name, n, l); - va_start(ap, s); - vdprintf(1, s, ap); - va_end(ap); -} - -static void setrl(int r, long lim) { - struct rlimit rl; - - if (getrlimit(r, &rl)) - error("getrlimit %d: %s\n", r, strerror(errno)); - rl.rlim_cur = lim; - if (setrlimit(r, &rl)) - error("setrlimit %d: %s\n", r, strerror(errno)); -} - -static void run(const char *n, void (*f)()) { - pid_t pid; - int s; - - count++; - failed = 0; - name = n; - if (verbose) - dprintf(1, "running %s:\n", name); - - pid = fork(); - if (pid == 0) { - /* run test in a child process */ - setrl(RLIMIT_STACK, 1<<16); - setrl(RLIMIT_CPU, 2); - f(); - exit(failed); - } - - if (pid == -1) - error("fork failed: %s\n", strerror(errno)); - else { - if (waitpid(pid, &s, 0) == -1) - error("waitpid failed: %s\n", strerror(errno)); - else if (!WIFEXITED(s)) - error("abnormal exit: %s\n", WIFSIGNALED(s) ? strsignal(WTERMSIG(s)) : "(unknown)"); - else - failed = !!WEXITSTATUS(s); - } - - if (failed) { - nfailed++; - dprintf(1, "FAILED %s\n", name); - } else if (verbose) - dprintf(1, "PASSED %s\n", name); -} - -static int summary() { - if (nfailed) - dprintf(1, "FAIL (%d out of %d tests)\n", nfailed, count); - else - dprintf(1, "ok (%d tests)\n", count); - return !!nfailed; -} - -static void usage() { - dprintf(1, "usage: ./t [-vs]\n"); - exit(1); -} - -int main(int argc, char *argv[]) { - int c; - - while((c = getopt(argc, argv, "vs")) != -1) - switch(c) { - case 'v': - verbose = 1; - break; - case 's': - slow = 1; /* TODO */ - break; - default: - usage(); - } - if (optind != argc) - usage(); - -#define T(t) run(#t, t); -#include "tests.h" - return summary(); -} diff --git a/common/test.h b/common/test.h deleted file mode 100644 index f1abf56..0000000 --- a/common/test.h +++ /dev/null @@ -1,8 +0,0 @@ -/* use it in test_ functions */ -#define error(...) error__(__FILE__, __LINE__, __VA_ARGS__) -void error__(const char *n, int l, const char *s, ...); - -/* use it in bench_ functions */ -void start_timer(void); -void stop_timer(void); -void reset_timer(void); diff --git a/src/env/Makefile b/src/env/Makefile index 278e884..ee4552b 100644 --- a/src/env/Makefile +++ b/src/env/Makefile @@ -1,2 +1 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc diff --git a/src/env/env.c b/src/env/env.c index 640303f..7962bf5 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -1,14 +1,16 @@ -#define _XOPEN_SOURCE 700 -#include "test.h" +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif #include #include #include #include +#include "test.h" extern char **environ; -int clearenv(void); -void test_env() { +int main() +{ char *s; int r; @@ -45,4 +47,5 @@ void test_env() { error("setenv(\"\",\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL); if ((r=setenv(0,"",0)) != -1 || errno != EINVAL) error("setenv(0,\"\",0): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL); + return test_status; } diff --git a/src/env/test.h b/src/env/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/env/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/malloc/Makefile b/src/malloc/Makefile deleted file mode 100644 index 278e884..0000000 --- a/src/malloc/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc diff --git a/src/malloc/bench.c b/src/malloc/bench.c deleted file mode 100644 index 030e5ee..0000000 --- a/src/malloc/bench.c +++ /dev/null @@ -1,163 +0,0 @@ -#include -#include -#include -#include -#include "test.h" - -enum { Len = 1000 }; - -void bench_malloc_sparse(int N) { - void *p[Len]; - int i,j; - - for (j = 0; j < N; j++) { - for (i=0; i - -void bench_acos(int N) -{ - int i; - volatile double y; - - for (i = 0; i < N; i++) { - y = acos(0.3456); - } -} diff --git a/src/math/classify.c b/src/math/classify.c deleted file mode 100644 index 82745dc..0000000 --- a/src/math/classify.c +++ /dev/null @@ -1,105 +0,0 @@ -#include -#include -#include "test.h" - -static struct { - float f; - int class; -} tf[] = { - 0.0/0.0, FP_NAN, - -0.0/0.0, FP_NAN, - 1/0.0, FP_INFINITE, - -1/0.0, FP_INFINITE, - 0x1.ffffp127, FP_NORMAL, - -0x1.ffffp127, FP_NORMAL, - 0x1p-127, FP_SUBNORMAL, - -0x1p-127, FP_SUBNORMAL, - 0.0, FP_ZERO, - -0.0, FP_ZERO, - 3.14, FP_NORMAL, - -42, FP_NORMAL, -}; -static int ntf = sizeof tf / sizeof *tf; - -static struct { - double f; - int class; -} td[] = { - 0.0/0.0, FP_NAN, - -0.0/0.0, FP_NAN, - 1/0.0, FP_INFINITE, - -1/0.0, FP_INFINITE, - 0x1.ffffp1023, FP_NORMAL, - -0x1.ffffp1023, FP_NORMAL, - 0x1p-1023, FP_SUBNORMAL, - -0x1p-1023, FP_SUBNORMAL, - 0.0, FP_ZERO, - -0.0, FP_ZERO, - 3.14, FP_NORMAL, - -42, FP_NORMAL, -}; -static int ntd = sizeof td / sizeof *td; - -static struct { - long double f; - int class; -} tl[] = { - 0.0/0.0, FP_NAN, - -0.0/0.0, FP_NAN, - 1/0.0, FP_INFINITE, - -1/0.0, FP_INFINITE, - 0x1.ffffp16383L, FP_NORMAL, - -0x1.ffffp16383L, FP_NORMAL, - 0x1p-16383L, FP_SUBNORMAL, - -0x1p-16383L, FP_SUBNORMAL, - 0.0, FP_ZERO, - -0.0, FP_ZERO, - 3.14, FP_NORMAL, - -42, FP_NORMAL, -}; -static int ntl = sizeof tl / sizeof *tl; - - -void test_fpclassify() -{ - int i; - - for (i = 0; i < ntf; i++) { - if (fpclassify(tf[i].f) != tf[i].class) - error("%a want class %d got %d\n", tf[i].f, tf[i].class, fpclassify(tf[i].f)); - if (!!isinf(tf[i].f) != (tf[i].class == FP_INFINITE)) - error("%a want class %d got isinf %d\n", tf[i].f, tf[i].class, isinf(tf[i].f)); - if (!!isnan(tf[i].f) != (tf[i].class == FP_NAN)) - error("%a want class %d got isnan %d\n", tf[i].f, tf[i].class, isnan(tf[i].f)); - if (!!isnormal(tf[i].f) != (tf[i].class == FP_NORMAL)) - error("%a want class %d got isnormal %d\n", tf[i].f, tf[i].class, isnormal(tf[i].f)); - if (!!isfinite(tf[i].f) != (tf[i].class > FP_INFINITE)) - error("%a want class %d got isfinite %d\n", tf[i].f, tf[i].class, isfinite(tf[i].f)); - } - - for (i = 0; i < ntd; i++) { - if (fpclassify(td[i].f) != td[i].class) - error("%a want class %d got %d\n", td[i].f, td[i].class, fpclassify(td[i].f)); - if (!!isinf(td[i].f) != (td[i].class == FP_INFINITE)) - error("%a want class %d got isinf %d\n", td[i].f, td[i].class, isinf(td[i].f)); - if (!!isnan(td[i].f) != (td[i].class == FP_NAN)) - error("%a want class %d got isnan %d\n", td[i].f, td[i].class, isnan(td[i].f)); - if (!!isnormal(td[i].f) != (td[i].class == FP_NORMAL)) - error("%a want class %d got isnormal %d\n", td[i].f, td[i].class, isnormal(td[i].f)); - if (!!isfinite(td[i].f) != (td[i].class > FP_INFINITE)) - error("%a want class %d got isfinite %d\n", td[i].f, td[i].class, isfinite(td[i].f)); - } - - for (i = 0; i < ntl; i++) { - if (fpclassify(tl[i].f) != tl[i].class) - error("%La want class %d got %d\n", tl[i].f, tl[i].class, fpclassify(tl[i].f)); - if (!!isinf(tl[i].f) != (tl[i].class == FP_INFINITE)) - error("%La want class %d got isinf %d\n", tl[i].f, tl[i].class, isinf(tl[i].f)); - if (!!isnan(tl[i].f) != (tl[i].class == FP_NAN)) - error("%La want class %d got isnan %d\n", tl[i].f, tl[i].class, isnan(tl[i].f)); - if (!!isnormal(tl[i].f) != (tl[i].class == FP_NORMAL)) - error("%La want class %d got isnormal %d\n", tl[i].f, tl[i].class, isnormal(tl[i].f)); - if (!!isfinite(tl[i].f) != (tl[i].class > FP_INFINITE)) - error("%La want class %d got isfinite %d\n", tl[i].f, tl[i].class, isfinite(tl[i].f)); - } -} diff --git a/src/math/fenv.c b/src/math/fenv.c deleted file mode 100644 index ae1f897..0000000 --- a/src/math/fenv.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "test.h" -#include -#include -#include -#include -#include - - -void test_fenv() -{ - int r; - - r = fesetround(FE_UPWARD); - if (r != 0) - error("fesetround %d\n", r); - r = fegetround(); - if (r != FE_UPWARD) - error("fegetround %x wanted %x\n", r, FE_UPWARD); - r = fesetround(FE_TONEAREST); - if (r != 0) - error("fesetround %d\n", r); - r = fegetround(); - if (r != FE_TONEAREST) - error("fegetround %x wanted %x\n", r, FE_TONEAREST); -} - -void test_fenv_except() -{ - int i,r; - - for (i = 0; i < 64; i++) { - feclearexcept(FE_ALL_EXCEPT); - - r = feraiseexcept(i); - if (r) - error("feraise %d returned %d\n", i, r); - r = fetestexcept(FE_ALL_EXCEPT); - if (r != i) - error("feraise want %d got %d\n", i, r); - } -} - -void bench_feraiseexcept(int N) -{ - int i; - for (i = 0; i < N; i++) { - feraiseexcept(i&63); - } -} - -void bench_fesetround(int N) -{ - int i; - int r = 0; - - for (i = 0; i < N; i++) { - r ^= 0x400; - fesetround(r); - } -} diff --git a/src/math/fenvutil.c b/src/math/fenvutil.c deleted file mode 100644 index ee3e7a3..0000000 --- a/src/math/fenvutil.c +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include "fenvutil.h" - -static struct { - int flag; - char *s; -} eflags[] = { - {FE_INVALID, "FE_INVALID"}, - {FE_DIVBYZERO, "FE_DIVBYZERO"}, - {FE_OVERFLOW, "FE_OVERFLOW"}, - {FE_UNDERFLOW, "FE_UNDERFLOW"}, - {FE_INEXACT, "FE_INEXACT"}, -}; -static int ne = sizeof eflags / sizeof *eflags; - -static struct { - int flag; - char *s; -} rflags[] = { - {FE_TONEAREST,"FE_TONEAREST"}, - {FE_DOWNWARD,"FE_DOWNWARD"}, - {FE_UPWARD,"FE_UPWARD"}, - {FE_TOWARDZERO,"FE_TOWARDZERO"}, -}; -static int nr = sizeof rflags / sizeof *rflags; - -char *strexcept(int f) { - static char buf[256]; - char *p; - int i, all=0; - - p = buf; - for (i = 0; i < ne; i++) - if (f & eflags[i].flag) { - p += sprintf(p, "%s%s", all ? "|" : "", eflags[i].s); - all |= eflags[i].flag; - } - if (all != f) { - p += sprintf(p, "%s%d", all ? "|" : "", f & ~all); - all = f; - } - p += sprintf(p, "%s", all ? "" : "0"); - return buf; -} - -char *strround(int f) { - static char buf[256]; - int i; - - for (i = 0; i < nr; i++) - if (f == rflags[i].flag) { - sprintf(buf, "%s", rflags[i].s); - return buf; - } - sprintf(buf, "%d", f); - return buf; -} - diff --git a/src/math/fenvutil.h b/src/math/fenvutil.h deleted file mode 100644 index c77d341..0000000 --- a/src/math/fenvutil.h +++ /dev/null @@ -1,2 +0,0 @@ -char *strexcept(int f); -char *strround(int f); diff --git a/src/math/fma.c b/src/math/fma.c deleted file mode 100644 index 6baa635..0000000 --- a/src/math/fma.c +++ /dev/null @@ -1,212 +0,0 @@ -#include "test.h" -#include -#include -#include -#include -#include -#include - -static struct { - double x, y, z, r; -} testdata[] = { --0x1p+0, 0x0p0, -0x0p+0, -0x0p+0, --0x1p+0, 0x1p+0, 0x1p+0, 0x0p+0, -0x1p+0, 0x1p+0, -0x1p+0, 0x0p+0, --0x1p+0, -0x1p+0, -0x1p+0, 0x0p+0, -0x1.0000000000001p+0, 0x1p+0, 0x1p+53, 0x1.0000000000001p+53, -0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1p+53, 0x1.0000000000001p+53, -0x1p+0, 0x1.fffffffffffffp-1, 0x1.fffffffffffffp+53, 0x1.fffffffffffffp+53, -0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.ffffffffffffep+53, 0x1.fffffffffffffp+53, -0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1p-52, 0x1.0000000000001p+0, -0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.fffffffffffffp-53, 0x1.0000000000001p+0, -0x1.0000000000005p+0, 0x1.ffffffffffffbp-1, 0x1p-52, 0x1.0000000000003p+0, -0x1.0000000000006p+0, 0x1.ffffffffffffdp-1, 0x1p-52, 0x1.0000000000005p+0, -0x1.0000000000001p+0, 0x1.fffffffffffffp-1, -0x1p+0, 0x1.ffffffffffffep-54, -0x1.0000000000001p+0, 0x1.fffffffffffffp-1, -0x1.fffffffffffffp-1, 0x1.fffffffffffffp-53, -0x1.0000000000001p+0, 0x1.ffffffffffffep-1, -0x1p+0, -0x1p-104, -0x1.0000000000001p+0, 0x1.ffffffffffffep-1, -0x1.fffffffffffffp-1, 0x1.ffffffffffffcp-54, -0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, -0x1p+0, -0x1.0000000000003p-53, -0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, -0x1.fffffffffffffp-1, -0x1.8p-104, -0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, -0x1.ffffffffffffep-1, 0x1.ffffffffffffap-54, -0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, -0x1p+0, -0x1.0000000000002p-52, -0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, -0x1.fffffffffffffp-1, -0x1.0000000000004p-53, -0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, -0x1.ffffffffffffep-1, -0x1p-103, -0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, -0x1.ffffffffffffdp-1, 0x1.ffffffffffff8p-54, -0x1.fffffffffffffp-1, 0x1.fffffffffffffp-1, -0x1.fffffffffffffp-1, -0x1.fffffffffffffp-54, -0x1.fffffffffffffp-1, 0x1.fffffffffffffp-1, -0x1.ffffffffffffep-1, 0x1p-106, -0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, -0x1.fffffffffffffp-1, -0x1.fffffffffffffp-53, -0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, -0x1.ffffffffffffep-1, -0x1.ffffffffffffep-54, -0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, -0x1.ffffffffffffdp-1, 0x1p-105, -0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, -0x1.ffffffffffffcp-1, 0x1.0000000000001p-53, -0x1.fffffffffffffp-1, 0x1.ffffffffffffdp-1, -0x1p+0, -0x1.fffffffffffffp-52, -0x1.ffffffffffff7p-1, 0x1.ffffffffffffbp-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffff5p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffffap-1, 0x1p+0, 0x1.ffffffffffff9p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffffcp-1, 0x1.ffffffffffff7p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffff8p-1, 0x1.ffffffffffff5p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffff9p-1, 0x1.ffffffffffffdp-1, 0x1.ffffffffffff7p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffff9p-1, 0x1.ffffffffffff9p-1, 0x1.ffffffffffff5p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffff8p-1, 0x1.ffffffffffffep-1, 0x1.ffffffffffff7p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffff8p-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffff5p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffff7p-1, 0x1.fffffffffffffp-1, 0x1.ffffffffffff7p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffffbp-1, 0x1.ffffffffffff5p+0, -0x1.ffffffffffff7p-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffff3p+0, -0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, 0x1.fffffffffffffp+0, -0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffffdp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffep-1, 0x1.fffffffffffffp-1, 0x1.fffffffffffffp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffep-1, 0x1.ffffffffffffbp-1, 0x1.ffffffffffffdp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffep-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffffbp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, 0x1p+0, 0x1.fffffffffffffp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, 0x1.ffffffffffffcp-1, 0x1.ffffffffffffdp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, 0x1.ffffffffffff8p-1, 0x1.ffffffffffffbp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, 0x1.ffffffffffffdp-1, 0x1.ffffffffffffdp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, 0x1.ffffffffffff9p-1, 0x1.ffffffffffffbp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffbp-1, 0x1.ffffffffffffep-1, 0x1.ffffffffffffdp+0, -0x1.0000000000001p+0, 0x1.ffffffffffffbp-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffffbp+0, -0x1.5872449b765b9p+0, 0x1.c9acf91f8de2bp+0, 0x1.9265607e4d168p+0, 0x1.fd190c77c2a67p+1, -0x1.81d010b146d0ep+0, 0x1.2d3c680dc9071p+0, 0x1.a80b69538754cp+0, 0x1.b7040b44973a7p+1, -0x1.6a44f2252b6a2p+0, 0x1.da452a378b832p+0, 0x1.1fe2ce329104p+0, 0x1.df842b6f48b13p+1, -0x1.096b1d26463eep+0, 0x1.d846d3e34333p+0, 0x1.721e3480922b8p+0, 0x1.ade2909c0269fp+1, -0x1.99bd3434c454bp+0, 0x1.03cb8e4115bdep+0, 0x1.109f107188b08p+0, 0x1.5837a47d37fafp+1, -0x1.ba930a0a78ed2p+0, 0x1.8c24e8d67f636p+0, 0x1.ac49dbfbf8affp+0, 0x1.164947ae6a5d9p+2, -0x1.be224ad773191p+0, 0x1.d96b77169731fp+0, 0x1.662cfb75d8edep+0, 0x1.27cd67e720f79p+2, -0x1.59e7a1b0bdb3cp+0, 0x1.2decba4d46421p+0, 0x1.88f4062e96df5p+0, 0x1.90749e4794f79p+1, -0x1.22edf4b4da9a7p+0, 0x1.dfa8d65f506cdp+0, 0x1.2799208da2fbap+0, 0x1.a45a1e99ed7a9p+1, -0x1.ad5b991a2a279p+0, 0x1.f02fd26706024p+0, 0x1.831cdd5c8797cp+0, 0x1.30d3a2ac90a61p+2, -0x1.531f9620e764ap+0, 0x1.cad61b54d4425p+0, 0x1.df817cae8a9afp+0, 0x1.0fd4e7f8671ddp+2, -0x1.629a5ad79494fp+0, 0x1.049e58693f4c4p+0, 0x1.45b0109e4d00cp+0, 0x1.5758154e14965p+1, -0x1.2f52b53f9240ap+0, 0x1.1d5c686dbb0dap+0, 0x1.6da3e392a4fd4p+0, 0x1.5fe03a6795913p+1, -0x1.058667552b49ep+0, 0x1.23307bacc1c42p+0, 0x1.5b059b47cd8f5p+0, 0x1.423f752486d13p+1, -0x1.a717d95337ed8p+0, 0x1.2b1c37846aaadp+0, 0x1.be65672f885b1p+0, 0x1.d65e72303c075p+1, -0x1.deb79287b3d32p+0, 0x1.62776b829babap+0, 0x1.67daf18bd2eb1p+0, 0x1.ff5a0d45c69d7p+1, -0x1.fbf12d3a6de91p+0, 0x1.879fe6124f11p+0, 0x1.9f3f1247a8641p+0, 0x1.2a126c6980019p+2, -0x1.c589628460e01p+0, 0x1.e1bec1c797533p+0, 0x1.349f30cdb84bbp+0, 0x1.2286118b6f6e5p+2, -0x1.46fd6c2c924ebp+0, 0x1.65e2f02e730a1p+0, 0x1.37739d2751098p+0, 0x1.804a71c1f1273p+1, -0x1.f99e595ae11fdp+0, 0x1.bd33d9a1d81bp+0, 0x1.932a2a2e244c1p+0, 0x1.409e34f8f2f89p+2, -0x1.59ea1e56bfe55p+0, 0x1.6f46b7d412a44p+0, 0x1.80f2bc9a32cc3p+0, 0x1.b89c7640e32ffp+1, -0x1.61490fcb44129p+0, 0x1.0038ec4fc35c2p+0, 0x1.df7436ed7a7b7p+0, 0x1.a085ea68d05cfp+1, -0x1.d41b98788502bp+0, 0x1.1a7b77843aca6p+0, 0x1.05be891837d36p+0, 0x1.8523596ceced9p+1, -0x1.3153cf6f69af9p+0, 0x1.aaa947e38e57ap+0, 0x1.8519f9b590645p+0, 0x1.c0fcab7b46369p+1, -0x1.c25a1f73581aap+0, 0x1.0a51ffca372ap+0, 0x1.0c77e3ebac5f3p+0, 0x1.707ce48c7d72dp+1, -0x1.829c2cde44b7p+0, 0x1.f692e86d8cb36p+0, 0x1.455e72d264bfp+0, 0x1.0f16a3b8b3f97p+2, -0x1.94729588dcc69p+0, 0x1.c3bb794c6edf8p+0, 0x1.9da4e94d262d2p+0, 0x1.19d4bd84d9fd3p+2, -0x1.e6a5e7e39c3d5p+0, 0x1.1b69af2bdd978p+0, 0x1.e7ef1eafa119cp+0, 0x1.00ac5b44c9f31p+2, -0x1.bc9ba1320700cp-1022, 0x1.981f2e1a451a8p-2, 0x1.046144efc0ceap-1022, 0x1.b594d0e4368efp-1022, -0x1.022db53c98d14p-1022, 0x1.21157eef74848p-2, 0x1.2f880432b1bc1p-1022, 0x1.786ad60a02b3dp-1022, -0x1.805a491fa9597p-1022, 0x1.e0f49d782ff87p-2, 0x1.172a62346206p-1022, 0x1.cbb085199a3f5p-1022, -0x1.adbc3a9d816dep-1022, 0x1.e039d4431e3cdp-2, 0x1.93ceef6fe18a2p-1022, 0x1.2eabb7dc0e2f1p-1021, -0x1.645aa5c2df3afp-1022, 0x1.649edfcad854fp-2, 0x1.8b43e0bbaeb01p-1022, 0x1.03af571d2b505p-1021, -0x1.133474a2c0fb1p-1022, 0x1.72442bcbfa01dp-2, 0x1.4a1a21971c5dbp-1022, 0x1.ad9ce7fcefa3fp-1022, -0x1.8ee3feb00c3e7p-1022, 0x1.53bd9353313bcp-2, 0x1.5501b57dc3b6fp-1022, 0x1.d9598906f0bb3p-1022, -0x1.161225cfa61e2p-1022, 0x1.b6dd69a0af5bp-2, 0x1.924ffc3ead5c3p-1022, 0x1.04be6fc25367bp-1021, -0x1.820f7faf219afp-1022, 0x1.06717ae771f6dp-2, 0x1.0dc5035f5e2afp-1022, 0x1.70b6c3169f043p-1022, -0x1.ce0e2ea55040ep-1022, 0x1.ce5a55fa3828dp-2, 0x1.f2f444d50ce59p-1022, 0x1.61ca36f5a8a79p-1021, -0x1.a7a271c67cdcfp-1022, 0x1.1e979090e218p-2, 0x1.b1f10b6e2177ap-1022, 0x1.1440cf1c105ebp-1021, -0x1.76df065829dc6p-1022, 0x1.fb22ab1b86b8bp-2, 0x1.6966267f317cp-1022, 0x1.1186e1f77012dp-1021, -0x1.8b004a28b70dbp-1022, 0x1.48e5805a8b453p-2, 0x1.0ea791f716557p-1022, 0x1.8d86310bad175p-1022, -0x1.fb3391a4b1d23p-1022, 0x1.4d8705b057caep-2, 0x1.d026cb6dae73bp-1022, 0x1.3aad18b424c67p-1021, -0x1.a5ba39730e197p-1022, 0x1.794df89b1cc49p-2, 0x1.24a0a388d0b6bp-1022, 0x1.c0048fd33a417p-1022, -0x1.aa9eff070281cp-1022, 0x1.fab05661b48ebp-2, 0x1.cbe2af6c69c6ep-1022, 0x1.4f7ddbe122765p-1021, -0x1.758bbff0ec4bap-1022, 0x1.a4a197f3fa424p-2, 0x1.47761e8d142ddp-1022, 0x1.e0e762ee2e7c5p-1022, -0x1.4dab43918a9a8p-1022, 0x1.ed667442b4751p-2, 0x1.3f25f82e02e3ep-1022, 0x1.dfec0ee732dcbp-1022, -0x1.7943735951931p-1022, 0x1.fa6a357c5c9ddp-2, 0x1.0bed44b0b71b4p-1022, 0x1.c6803a6059abfp-1022, -0x1.66c26bc29a5e8p-1022, 0x1.3faed079f761ap-2, 0x1.163ff906dd651p-1022, 0x1.8640492c45959p-1022, -0x1.f52172c56bdf5p-1022, 0x1.672b2de422734p-2, 0x1.7bc5d708e5a34p-1022, 0x1.15c5b95145cc7p-1021, -0x1.2f94e89aa7558p-1022, 0x1.dfa6d30835f5ep-2, 0x1.59c6b0d504cf9p-1022, 0x1.e7fa0dd76fbefp-1022, -0x1.6159897ae533cp-1022, 0x1.f3b8892e3a3c8p-2, 0x1.09ca702b7759p-1022, 0x1.b63a7f56fce1fp-1022, -0x1.f73d5f4e81fd8p-1022, 0x1.7ccff2642124ap-2, 0x1.e7d836a0c8308p-1022, 0x1.517f1763126d3p-1021, -0x1.b4328925969fbp-1022, 0x1.8fa02832a22d5p-2, 0x1.2084598e2f8c6p-1022, 0x1.cabf43838dc51p-1022, -0x1.66ee60a92676fp-1022, 0x1.eddd2e7681ce4p-2, 0x1.b81d57daeb3a7p-1022, 0x1.329c918ffb683p-1021, -0x1.ff2737585895dp-1022, 0x1.fb4bf3828ae4ap-2, 0x1.4a866847740fp-1022, 0x1.23e07e4dbbeabp-1021, -0x1.5e2008d269a86p-1022, 0x1.507bbbe4d78eep-2, 0x1.6220c6f83f636p-1022, 0x1.d52d9874f1c75p-1022, -0x1.ce7e2e5812d86p-1022, 0x1.0e6689d092e5fp-2, 0x1.1e43fd55c3458p-1022, 0x1.9864925e2fb0fp-1022, -0x1.7b353b81e793dp-1022, 0x1.82b426f874c6dp-2, 0x1.d92b19d21fd5cp-1022, 0x1.342fb0c544a79p-1021, -0x1.5be667823370ap-1022, 0x1.a8a99b163869bp-2, 0x1.95456b68dc3bcp-1022, 0x1.12c638de03c71p-1021, -0x1.17b0fc6c850e5p-1022, 0x1.d1d0a4853c315p-2, 0x1.36b79f7c0c24p-1022, 0x1.b5f2baff5635dp-1022, -0x1.bd97819bacfd8p-1022, 0x1.2c25f267ba4eep-2, 0x1.804b5204a3f3ap-1022, 0x1.01739c190fd97p-1021, -0x1.596577053873dp-1022, 0x1.3562ab2d29949p-2, 0x1.b3f1ee75db6e7p-1022, 0x1.0e268a498009bp-1021, -0x1.3c7a68cf0f7b3p-1022, 0x1.9a55c15b167bdp-2, 0x1.7635b7b163c07p-1022, 0x1.f5073b93b7b81p-1022, -0x1.5825164bc4068p-1022, 0x1.dcbb6e5ff3245p-2, 0x1.52fc3be0e84dap-1022, 0x1.f334771c2dcfbp-1022, -0x1.139ea77b760ecp+1022, 0x1.9b25f2fd017eap+2, -0x1.bc16788922b6fp+1023, 0x1.b93aac527380fp+1023, -0x1.0e6f9c1657d7cp+1022, 0x1.4d5c6b55ab5f1p+2, -0x1.e027dd5742e2cp+1023, 0x1.c0538372b4bbfp+1022, -0x1.1182524fa411cp+1022, 0x1.a3dba56842d19p+2, -0x1.c1ad59474d71fp+1023, 0x1.bf78969300a77p+1023, -0x1.1cbf4fb8ec82p+1022, 0x1.5e32019a84fbbp+2, -0x1.985af08f32edep+1023, 0x1.72af6bbad4a29p+1023, -0x1.311e25c6db346p+1022, 0x1.4e30db6c4b51dp+2, -0x1.7681f7a9786a7p+1023, 0x1.a61d29434fc13p+1023, -0x1.1201cf577052fp+1022, 0x1.59730b2db7a16p+2, -0x1.56f1a64a078d5p+1023, 0x1.8c8d801df34d9p+1023, -0x1.3e52335b76e81p+1022, 0x1.4dbd56f857479p+2, -0x1.509340c11bd2ep+1023, 0x1.ed6576837f653p+1023, -0x1.18566b4f843cbp+1022, 0x1.444fba10eaf29p+2, -0x1.f927beae57f0ap+1023, 0x1.9a433b9796559p+1022, -0x1.3fbe544fe1be8p+1022, 0x1.2d2a5fda03639p+2, -0x1.007407dbfd03cp+1023, 0x1.efdb644b613e5p+1023, -0x1.263a0d3bc2e4p+1022, 0x1.4cc198adbc651p+2, -0x1.734b1c1f7fdb8p+1023, 0x1.899878afc0fa3p+1023, -0x1.5bf4aec8efc8ep+1022, 0x1.555f0341516c9p+2, -0x1.c706408acd14cp+1023, 0x1.d8f5e18b868bdp+1023, -0x1.1e57f1af78279p+1022, 0x1.34bc0c7f082b3p+2, -0x1.497b92c1365edp+1023, 0x1.692cb7ec68a93p+1023, -0x1.1d9824cd73511p+1022, 0x1.1d557ddfe47ffp+2, -0x1.556cdb1d20a72p+1023, 0x1.2736a6b6e35f3p+1023, -0x1.1ff85a24aff31p+1022, 0x1.39ab374b2680dp+2, -0x1.35e6b07b651b8p+1023, 0x1.8bc7ce2087081p+1023, -0x1.0449b3965227ep+1022, 0x1.4430d4441f9f2p+2, -0x1.a6966c96307ep+1023, 0x1.d94eda8c81771p+1022, -0x1.3c91fa00fd0c7p+1022, 0x1.1b6661c0b0303p+2, -0x1.f1f2846b64483p+1023, 0x1.95eae0d2644d3p+1022, -0x1.0979b36d46534p+1022, 0x1.12fa205f41f7fp+2, -0x1.a83ecf4544a63p+1023, 0x1.2420f34e2aa3dp+1022, -0x1.4c89df582a599p+1022, 0x1.55f3dc473ea8fp+2, -0x1.e35037292ddfp+1023, 0x1.95109fdbc3771p+1023, -0x1.35ee0a669c4fbp+1022, 0x1.2263cb63f386ap+2, -0x1.449218ae35ac7p+1023, 0x1.7a8ed977d817bp+1023, -0x1.117cc860f61bcp+1022, 0x1.440985b25d994p+2, -0x1.d7a7d82000449p+1023, 0x1.b960b7088e74fp+1022, -0x1.1e78a37be320fp+1022, 0x1.0db0fce62287bp+2, -0x1.376337da5eb53p+1023, 0x1.24326b9956dfbp+1023, -0x1.0c79b5c8331c2p+1022, 0x1.0aba6ea746b5p+2, -0x1.c86f1fcaf0741p+1023, 0x1.9c135bb2cff85p+1021, -0x1.556c4c072f272p+1022, 0x1.347758d7d4eb5p+2, -0x1.c6fe4f24b248dp+1023, 0x1.6fcc9f756df6dp+1023, --0x1.e8349b891b2fp-1, 0x1.4a6dec9b72578p-1, 0x1.3b6151ce809ddp-1, 0x1.3a62fe330b355p-11, -0x1.2996632ac7d74p-1, -0x1.bb3c58b654d94p-1, 0x1.01a6660e64a31p-1, 0x1.ed045bb956a8ep-15, --0x1.c602e894c1df8p-1, 0x1.a1c980e7d3f94p-1, 0x1.7271244b43386p-1, -0x1.ba251fe026e5bp-15, --0x1.c84baf47e85cp-1, 0x1.770b5149ef2ep-1, 0x1.4d80f139320bap-1, -0x1.79277433b9e23p-10, --0x1.36e667dcf9c6p-1, 0x1.2591f82556b88p-1, 0x1.2452a0f795f95p-1, 0x1.c83c8e63c159fp-3, -0x1.88b2cede61e4cp-1, -0x1.71dcab5ad9e9p-3, 0x1.32b27fea2ae97p-3, 0x1.70461909b25e2p-7, -0x1.8d1e44002c98p-3, -0x1.af9fdfb347834p-1, 0x1.e280942fb4146p-4, -0x1.761ac23896dfdp-5, -0x1.236e8cb9492c8p-1, -0x1.d37443a57f1c4p-1, 0x1.ca10df801aabcp-4, -0x1.a1a2cdf0138f9p-2, --0x1.6ad943e610fb8p-1, -0x1.cef92a7bb18bcp-1, 0x1.f28587d8fb0ep-4, 0x1.866b5204b9aecp-1, --0x1.60a8569a5d894p-1, -0x1.ca07e29dd171cp-1, 0x1.b6c475ace09ecp-4, 0x1.72549291e2f7ap-1, -0x1.d1962720d678cp-1, -0x1.4548ee45c4084p-1, 0x1.f416ab193d75cp-4, -0x1.d2929879dc853p-2, --0x1.9ddcb295a7d64p-1, 0x1.67fb3a2068a78p-1, 0x1.da9cd4597fe0ap-4, -0x1.cf4f6eb4fc5d8p-2, -0x1.c00d16ed45b88p+0, 0x1.c787eddda3664p+0, 0x1.1e3e6f0cc1802p-5, 0x1.931b8f379dcc3p+1, -0x1.19c2a2372c184p+0, -0x1.cb506961c19fp+0, 0x1.db1abf3f7ba3ap-6, -0x1.f21c0eab0bc18p+0, --0x1.3a263218ccd1cp+0, -0x1.e818d390df27cp+0, 0x1.2a81ed71785f5p-5, 0x1.3025ab0f63925p+1, -0x1.b0b041fbaca58p+0, -0x1.9d5f76d178e6p+0, 0x1.0215c7bb84cf9p-6, -0x1.5b52aec7ef4p+1, --0x1.377549d9a87f4p+0, -0x1.a13d4a03dd6d8p+0, 0x1.f190388bc5cc6p-7, 0x1.ff83bebbd6fe4p+0, -0x1.6a726c0762ac8p-1, -0x1.d32f2d30e483cp+0, 0x1.f953eb70fbde6p-7, -0x1.46c61b3070332p+0, -0x1.94cf2509d40cp-1, 0x1.721976af6dfbp+0, 0x1.f51a456921c3ep-7, 0x1.28880842acc6p+0, -0x1.b128eb0ad8728p-1, 0x1.7682566a54268p+0, 0x1.bd4122a074cafp-8, 0x1.3e9469530e762p+0, -0x1.c4ae75976e35cp+0, -0x1.11c329dd1160cp+0, 0x1.9993f5e13c9bdp-8, -0x1.e27d925b07cf1p+0, --0x1.85f81f88fa3c4p+0, -0x1.17648a494fa18p-1, 0x1.37d305113b48p-10, 0x1.aa367b7490e57p-1, --0x1.311f2b4319efcp+0, 0x1.abbb5272e3d18p-1, 0x1.35841b7bdbcfep-10, -0x1.fd337f24b39ep-1, -0x1.ab94369a9a0dp-1, 0x1.9d1e0e0aa3bacp+0, 0x1.0a63ca87cfa78p-11, 0x1.592173ee296b6p+0, -}; - -void bench_fma(int N) -{ - int i; - double x, y, z; - volatile double r; - - x = 0x1.629a5ad79494fp+0; - y = 0x1.049e58693f4c4p+0; - z = 0x1.45b0109e4d00cp+0; - for (i = 0; i < N; i++) { - r = fma(x, y, z); - x += 0.00001; - } -} - -void test_fma() -{ - int j, c; - double x, y, z, r, r0; - - c = 0; - for (j = 0; j < sizeof testdata / sizeof *testdata; j++) { - x = testdata[j].x; - y = testdata[j].y; - z = testdata[j].z; - r0 = testdata[j].r; - r = fma(x, y, z); - if (r != r0 || signbit(r) != signbit(r0)) { - c++; - error("fma(%a,%a,%a): wanted %a got %a\n", x, y, z, r0, r); - } - } - if (c) - printf("errors: %d\n", c); -} diff --git a/src/math/lrint.c b/src/math/lrint.c deleted file mode 100644 index b7d14a7..0000000 --- a/src/math/lrint.c +++ /dev/null @@ -1,167 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "fenvutil.h" -#include "test.h" - -static struct { - int round; - double x; - long n; - int except; -} t[] = { -FE_TONEAREST, 0x0p+0, 0, 0, -FE_DOWNWARD, 0x0p+0, 0, 0, -FE_UPWARD, 0x0p+0, 0, 0, -FE_TOWARDZERO, 0x0p+0, 0, 0, -FE_TONEAREST, 0x1p-2, 0, FE_INEXACT, -FE_DOWNWARD, 0x1p-2, 0, FE_INEXACT, -FE_UPWARD, 0x1p-2, 1, FE_INEXACT, -FE_TOWARDZERO, 0x1p-2, 0, FE_INEXACT, -FE_TONEAREST, -0x1p-2, 0, FE_INEXACT, -FE_DOWNWARD, -0x1p-2, -1, FE_INEXACT, -FE_UPWARD, -0x1p-2, 0, FE_INEXACT, -FE_TOWARDZERO, -0x1p-2, 0, FE_INEXACT, -FE_TONEAREST, 0x1p-1, 0, FE_INEXACT, -FE_DOWNWARD, 0x1p-1, 0, FE_INEXACT, -FE_UPWARD, 0x1p-1, 1, FE_INEXACT, -FE_TOWARDZERO, 0x1p-1, 0, FE_INEXACT, -FE_TONEAREST, -0x1p-1, 0, FE_INEXACT, -FE_DOWNWARD, -0x1p-1, -1, FE_INEXACT, -FE_UPWARD, -0x1p-1, 0, FE_INEXACT, -FE_TOWARDZERO, -0x1p-1, 0, FE_INEXACT, -FE_TONEAREST, 0x1.8p-1, 1, FE_INEXACT, -FE_DOWNWARD, 0x1.8p-1, 0, FE_INEXACT, -FE_UPWARD, 0x1.8p-1, 1, FE_INEXACT, -FE_TOWARDZERO, 0x1.8p-1, 0, FE_INEXACT, -FE_TONEAREST, -0x1.8p-1, -1, FE_INEXACT, -FE_DOWNWARD, -0x1.8p-1, -1, FE_INEXACT, -FE_UPWARD, -0x1.8p-1, 0, FE_INEXACT, -FE_TOWARDZERO, -0x1.8p-1, 0, FE_INEXACT, -FE_TONEAREST, 0x1p+0, 1, 0, -FE_DOWNWARD, 0x1p+0, 1, 0, -FE_UPWARD, 0x1p+0, 1, 0, -FE_TOWARDZERO, 0x1p+0, 1, 0, -FE_TONEAREST, -0x1p+0, -1, 0, -FE_DOWNWARD, -0x1p+0, -1, 0, -FE_UPWARD, -0x1p+0, -1, 0, -FE_TOWARDZERO, -0x1p+0, -1, 0, -FE_TONEAREST, 0x1.4p+0, 1, FE_INEXACT, -FE_DOWNWARD, 0x1.4p+0, 1, FE_INEXACT, -FE_UPWARD, 0x1.4p+0, 2, FE_INEXACT, -FE_TOWARDZERO, 0x1.4p+0, 1, FE_INEXACT, -FE_TONEAREST, -0x1.4p+0, -1, FE_INEXACT, -FE_DOWNWARD, -0x1.4p+0, -2, FE_INEXACT, -FE_UPWARD, -0x1.4p+0, -1, FE_INEXACT, -FE_TOWARDZERO, -0x1.4p+0, -1, FE_INEXACT, -FE_TONEAREST, 0x1p+30, 1073741824, 0, -FE_DOWNWARD, 0x1p+30, 1073741824, 0, -FE_UPWARD, 0x1p+30, 1073741824, 0, -FE_TOWARDZERO, 0x1p+30, 1073741824, 0, -FE_TONEAREST, -0x1p+30, -1073741824, 0, -FE_DOWNWARD, -0x1p+30, -1073741824, 0, -FE_UPWARD, -0x1p+30, -1073741824, 0, -FE_TOWARDZERO, -0x1p+30, -1073741824, 0, -FE_TONEAREST, 0x1.fffffffcp+30, 2147483647, 0, -FE_DOWNWARD, 0x1.fffffffcp+30, 2147483647, 0, -FE_UPWARD, 0x1.fffffffcp+30, 2147483647, 0, -FE_TOWARDZERO, 0x1.fffffffcp+30, 2147483647, 0, -FE_TONEAREST, -0x1.fffffffcp+30, -2147483647, 0, -FE_DOWNWARD, -0x1.fffffffcp+30, -2147483647, 0, -FE_UPWARD, -0x1.fffffffcp+30, -2147483647, 0, -FE_TOWARDZERO, -0x1.fffffffcp+30, -2147483647, 0, -FE_TONEAREST, 0x1p+31, 0, FE_INVALID, -FE_DOWNWARD, 0x1p+31, 0, FE_INVALID, -FE_UPWARD, 0x1p+31, 0, FE_INVALID, -FE_TOWARDZERO, 0x1p+31, 0, FE_INVALID, -FE_TONEAREST, -0x1p+31, -2147483648, 0, -FE_DOWNWARD, -0x1p+31, -2147483648, 0, -FE_UPWARD, -0x1p+31, -2147483648, 0, -FE_TOWARDZERO, -0x1p+31, -2147483648, 0, -FE_TONEAREST, 0x1.00000002p+31, 0, FE_INVALID, -FE_DOWNWARD, 0x1.00000002p+31, 0, FE_INVALID, -FE_UPWARD, 0x1.00000002p+31, 0, FE_INVALID, -FE_TOWARDZERO, 0x1.00000002p+31, 0, FE_INVALID, -FE_TONEAREST, -0x1.00000002p+31, 0, FE_INVALID, -FE_DOWNWARD, -0x1.00000002p+31, 0, FE_INVALID, -FE_UPWARD, -0x1.00000002p+31, 0, FE_INVALID, -FE_TOWARDZERO, -0x1.00000002p+31, 0, FE_INVALID, -FE_TONEAREST, 0x1.fffffffep+30, 0, FE_INVALID, -FE_DOWNWARD, 0x1.fffffffep+30, 2147483647, FE_INEXACT, -FE_UPWARD, 0x1.fffffffep+30, 0, FE_INVALID, -FE_TOWARDZERO, 0x1.fffffffep+30, 2147483647, FE_INEXACT, -FE_TONEAREST, -0x1.fffffffep+30, -2147483648, FE_INEXACT, -FE_DOWNWARD, -0x1.fffffffep+30, -2147483648, FE_INEXACT, -FE_UPWARD, -0x1.fffffffep+30, -2147483647, FE_INEXACT, -FE_TOWARDZERO, -0x1.fffffffep+30, -2147483647, FE_INEXACT, -FE_TONEAREST, 0x1.00000001p+31, 0, FE_INVALID, -FE_DOWNWARD, 0x1.00000001p+31, 0, FE_INVALID, -FE_UPWARD, 0x1.00000001p+31, 0, FE_INVALID, -FE_TOWARDZERO, 0x1.00000001p+31, 0, FE_INVALID, -FE_TONEAREST, -0x1.00000001p+31, -2147483648, FE_INEXACT, -FE_DOWNWARD, -0x1.00000001p+31, 0, FE_INVALID, -FE_UPWARD, -0x1.00000001p+31, -2147483648, FE_INEXACT, -FE_TOWARDZERO, -0x1.00000001p+31, -2147483648, FE_INEXACT, -FE_TONEAREST, 0x1p+32, 0, FE_INVALID, -FE_DOWNWARD, 0x1p+32, 0, FE_INVALID, -FE_UPWARD, 0x1p+32, 0, FE_INVALID, -FE_TOWARDZERO, 0x1p+32, 0, FE_INVALID, -FE_TONEAREST, -0x1p+32, 0, FE_INVALID, -FE_DOWNWARD, -0x1p+32, 0, FE_INVALID, -FE_UPWARD, -0x1p+32, 0, FE_INVALID, -FE_TOWARDZERO, -0x1p+32, 0, FE_INVALID, -FE_TONEAREST, 0x1.ffffffffp+31, 0, FE_INVALID, -FE_DOWNWARD, 0x1.ffffffffp+31, 0, FE_INVALID, -FE_UPWARD, 0x1.ffffffffp+31, 0, FE_INVALID, -FE_TOWARDZERO, 0x1.ffffffffp+31, 0, FE_INVALID, -FE_TONEAREST, -0x1.ffffffffp+31, 0, FE_INVALID, -FE_DOWNWARD, -0x1.ffffffffp+31, 0, FE_INVALID, -FE_UPWARD, -0x1.ffffffffp+31, 0, FE_INVALID, -FE_TOWARDZERO, -0x1.ffffffffp+31, 0, FE_INVALID, -}; - -void test_lrint() -{ - int f, i; - long n; - - for (i = 0; i < sizeof t/sizeof *t; i++) { - fesetround(t[i].round); - feclearexcept(FE_ALL_EXCEPT); - n = lrint(t[i].x); - f = fetestexcept(FE_ALL_EXCEPT); - - if (t[i].except != FE_INVALID && n != t[i].n) - error("round=%s, lrint(%a) want %ld got %ld\n", strround(t[i].round), t[i].x, t[i].n, n); - if (f != t[i].except) - error("round=%s, lrint(%a)==%ld want except=%s, got except=%s\n", - strround(t[i].round), t[i].x, t[i].n, strdup(strexcept(t[i].except)), strdup(strexcept(f))); - } -} - -void bench_lrint_simple(int N) -{ - int i; - volatile int n; - - for (i = 0; i < N; i++) { - n = lrint(1.25); - } -} - -void bench_lrint_hard(int N) -{ - int i; - volatile int n; - - for (i = 0; i < N; i++) { -// feclearexcept(FE_ALL_EXCEPT); -// n = lrint(1.5); -// n = lrint(0x1p32); -// n = lrint(-0x1p31); - n = lrint(0x1p31+0.5); - } -} diff --git a/src/math/modf.c b/src/math/modf.c deleted file mode 100644 index 77c044c..0000000 --- a/src/math/modf.c +++ /dev/null @@ -1,151 +0,0 @@ -#include -#include -#include "test.h" - -static struct { - double x; - double yf; - double yi; -} t[] = { - 0.7, 0x1.6666666666666p-1, 0.0, - -0.7, -0x1.6666666666666p-1, -0.0, - 1.7, 0x1.6666666666666p-1, 1.0, - -1.7, -0x1.6666666666666p-1, -1.0, - 2.0, 0.0, 2.0, - -2.0, -0.0, -2.0, - -0x1p99, -0.0, -0x1p99, - -0.0, -0.0, -0.0, - INFINITY, 0.0, INFINITY, - -INFINITY, -0.0, -INFINITY, - NAN, NAN, NAN, -}; - -static struct { - float x; - float yf; - float yi; -} tf[] = { - 0.7, 0x1.666666p-1, 0.0, - -0.7, -0x1.666666p-1, -0.0, - 1.7, 0x1.666668p-1, 1.0, - -1.7, -0x1.666668p-1, -1.0, - 2.0, 0.0, 2.0, - -2.0, -0.0, -2.0, - -0x1p99, -0.0, -0x1p99, - -0.0, -0.0, -0.0, - INFINITY, 0.0, INFINITY, - -INFINITY, -0.0, -INFINITY, - NAN, NAN, NAN, -}; - -static struct { - long double x; - long double yf; - long double yi; -} tl[] = { - 0.7L, 0x1.6666666666666666p-1L, 0.0, - -0.7L, -0x1.6666666666666666p-1L, -0.0, - 1.7L, 0x1.6666666666666668p-1L, 1.0, - -1.7L, -0x1.6666666666666668p-1L, -1.0, - 2.0, 0, 2.0, - -2.0, -0.0, -2.0, - -0x1p99, -0.0, -0x1p99, - -0.0, -0.0, -0.0, - INFINITY, 0.0, INFINITY, - -INFINITY, -0.0, -INFINITY, - NAN, NAN, NAN, -}; - -#define eq(a, b) ((isnan(a) && isnan(b)) || ((a) == (b) && signbit(a) == signbit(b))) - -void test_modf() -{ - double yf, yi; - int i; - for (i = 0; i < sizeof t/sizeof *t; i++) { - yf = modf(t[i].x, &yi); - if (!eq(yf,t[i].yf) || !eq(yi,t[i].yi)) - error("modf(%a) want %a %a got %a %a\n", t[i].x, t[i].yf, t[i].yi, yf, yi); - } -} -void test_modff() -{ - float yf, yi; - int i; - for (i = 0; i < sizeof tf/sizeof *tf; i++) { - yf = modff(tf[i].x, &yi); - if (!eq(yf,tf[i].yf) || !eq(yi,tf[i].yi)) - error("modff(%a) want %a %a got %a %a\n", tf[i].x, tf[i].yf, tf[i].yi, yf, yi); - } -} -void test_modfl() -{ - long double yf, yi; - int i; - for (i = 0; i < sizeof tl/sizeof *tl; i++) { - yf = modfl(tl[i].x, &yi); - if (!eq(yf,tl[i].yf) || !eq(yi,tl[i].yi)) - error("modfl(%La) want %La %La got %La %La\n", tl[i].x, tl[i].yf, tl[i].yi, yf, yi); - } -} - -void bench_modf_small(int N) -{ - int i; - double yi; - volatile double yf; - - for (i = 0; i < N; i++) - yf = modf(1234.5678, &yi); -} - -void bench_modf_negint(int N) -{ - int i; - double yi; - volatile double yf; - - for (i = 0; i < N; i++) - yf = modf(-1234.0, &yi); -} - -void bench_modf_large(int N) -{ - int i; - double yi; - volatile double yf; - - for (i = 0; i < N; i++) - yf = modf(1.2345678e300, &yi); -} - - -void bench_modff_small(int N) -{ - int i; - float yi; - volatile float yf; - - for (i = 0; i < N; i++) - yf = modff(1234.5678, &yi); -} - -void bench_modff_negint(int N) -{ - int i; - float yi; - volatile float yf; - - for (i = 0; i < N; i++) - yf = modff(-1234.0, &yi); -} - -void bench_modff_large(int N) -{ - int i; - float yi; - volatile float yf; - - for (i = 0; i < N; i++) - yf = modff(1.2345678e100, &yi); -} diff --git a/src/math/nextafter.c b/src/math/nextafter.c deleted file mode 100644 index 78cb3d1..0000000 --- a/src/math/nextafter.c +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "fenvutil.h" -#include "test.h" - -static struct { - double x; - double y; - double z; - int except; -} t[] = { - 0, 0, 0, 0, - 0, -0.0, -0.0, 0, - -0.0, 0, 0, 0, - 0, 1, 0x1p-1074, FE_INEXACT|FE_UNDERFLOW, - 0, -1, -0x1p-1074, FE_INEXACT|FE_UNDERFLOW, - -0.0, 1, 0x1p-1074, FE_INEXACT|FE_UNDERFLOW, - -0.0, -1, -0x1p-1074, FE_INEXACT|FE_UNDERFLOW, - 0x1p-1074, INFINITY, 0x1p-1073, FE_INEXACT|FE_UNDERFLOW, - 0x1p-1074, -INFINITY, 0, FE_INEXACT|FE_UNDERFLOW, --0x1p-1074, INFINITY, -0.0, FE_INEXACT|FE_UNDERFLOW, --0x1p-1074, -INFINITY, -0x1p-1073, FE_INEXACT|FE_UNDERFLOW, - DBL_MIN, 0, 0x0.fffffffffffffp-1022, FE_INEXACT|FE_UNDERFLOW, - -DBL_MIN, 0, -0x0.fffffffffffffp-1022, FE_INEXACT|FE_UNDERFLOW, - 1, 2, 0x1.0000000000001p+0, 0, - 1, -2, 0x1.fffffffffffffp-1, 0, - 1, 0.5, 0x1.fffffffffffffp-1, 0, - 0x1p1023, 0x1p1000, 0x1.fffffffffffffp+1022, 0, - 0x1p1023, INFINITY, 0x1.0000000000001p+1023, 0, - -1.5, -2.5, -0x1.8000000000001p+0, 0, - -1.5, 2.5, -0x1.7ffffffffffffp+0, 0, - 1.5, -2.5, 0x1.7ffffffffffffp+0, 0, - DBL_MAX, INFINITY, INFINITY, FE_INEXACT|FE_OVERFLOW, - INFINITY, INFINITY, INFINITY, 0, - -DBL_MAX, -INFINITY, -INFINITY, FE_INEXACT|FE_OVERFLOW, - -INFINITY, -INFINITY, -INFINITY, 0, - NAN, 1, NAN, 0, - 1, NAN, NAN, 0, -}; - -void test_nextafter() -{ - int f, i; - double z; - - for (i = 0; i < sizeof t/sizeof *t; i++) { - feclearexcept(FE_ALL_EXCEPT); - z = nextafter(t[i].x, t[i].y); - f = fetestexcept(FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT); - - if (z != t[i].z && !(isnan(z) && isnan(t[i].z))) - error("nextafter(%a, %a) want %a got %a\n", t[i].x, t[i].y, t[i].z, z); - if (f != t[i].except) - error("nextafter(%a, %a)==%a want except=%s got except=%s\n", - t[i].x, t[i].y, t[i].z, strdup(strexcept(t[i].except)), strdup(strexcept(f))); - } -} - -void bench_nextafter_normal(int N) -{ - int i; - volatile double z; - - for (i = 0; i < N; i++) { - z = nextafter(1.25, 4); - } -} - -void bench_nextafter_subnormal(int N) -{ - int i; - volatile double z; - - for (i = 0; i < N; i++) { - z = nextafter(0x1p-1070, -0x1p-1071); - } -} diff --git a/src/math/nextafterl.c b/src/math/nextafterl.c deleted file mode 100644 index d5eb6cf..0000000 --- a/src/math/nextafterl.c +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "fenvutil.h" -#include "test.h" - -/* ld80 only */ - -static struct { - long double x; - long double y; - long double z; - int except; -} t[] = { - 0, 0, 0, 0, - 0, -0.0, -0.0, 0, - -0.0, 0, 0, 0, - 0, 1, 0x1p-16445L, FE_INEXACT|FE_UNDERFLOW, - 0, -1, -0x1p-16445L, FE_INEXACT|FE_UNDERFLOW, - -0.0, 1, 0x1p-16445L, FE_INEXACT|FE_UNDERFLOW, - -0.0, -1, -0x1p-16445L, FE_INEXACT|FE_UNDERFLOW, - 0x1p-16445L, INFINITY, 0x1p-16444L, FE_INEXACT|FE_UNDERFLOW, - 0x1p-16445L, -INFINITY, 0, FE_INEXACT|FE_UNDERFLOW, --0x1p-16445L, INFINITY, -0.0, FE_INEXACT|FE_UNDERFLOW, --0x1p-16445L, -INFINITY, -0x1p-16444L, FE_INEXACT|FE_UNDERFLOW, - 0x1p-16440L, -0x1p-16444L, 0x1.fp-16441L, FE_INEXACT|FE_UNDERFLOW, - 0x1p-16440L, 0x1p-16444L, 0x1.fp-16441L, FE_INEXACT|FE_UNDERFLOW, - 0x1p-16440L, 0x1p-16430L, 0x1.08p-16440L, FE_INEXACT|FE_UNDERFLOW, - LDBL_MIN, 0, 0x1.fffffffffffffffcp-16383L, FE_INEXACT|FE_UNDERFLOW, - -LDBL_MIN, 0,-0x1.fffffffffffffffcp-16383L, FE_INEXACT|FE_UNDERFLOW, - 0x1.fffffffffffffffcp-16383L, 1, LDBL_MIN, 0, --0x1.fffffffffffffffcp-16383L, -1, -LDBL_MIN, 0, - 1, 2, 0x1.0000000000000002p+0L, 0, - 1, -2, 0x1.fffffffffffffffep-1L, 0, - 1, 0.5, 0x1.fffffffffffffffep-1L, 0, - 0x1p1023, 0x1p1000, 0x1.fffffffffffffffep+1022L, 0, - 0x1p1023, INFINITY, 0x1.0000000000000002p+1023L, 0, - -1.5, -2.5, -0x1.8000000000000002p+0L, 0, - -1.5, 2.5, -0x1.7ffffffffffffffep+0L, 0, - 1.5, -2.5, 0x1.7ffffffffffffffep+0L, 0, - LDBL_MAX, INFINITY, INFINITY, FE_INEXACT|FE_OVERFLOW, - INFINITY, INFINITY, INFINITY, 0, - -LDBL_MAX, -INFINITY, -INFINITY, FE_INEXACT|FE_OVERFLOW, - -INFINITY, -INFINITY, -INFINITY, 0, - NAN, 1, NAN, 0, - 1, NAN, NAN, 0, -}; - -void test_nextafterl() -{ - int f, i; - long double z; - - for (i = 0; i < sizeof t/sizeof *t; i++) { - feclearexcept(FE_ALL_EXCEPT); - z = nextafterl(t[i].x, t[i].y); - f = fetestexcept(FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT); - - if (z != t[i].z && !(isnan(z) && isnan(t[i].z))) - error("%d nextafterl(%La, %La) want %La got %La\n", i, t[i].x, t[i].y, t[i].z, z); - if (f != t[i].except) - error("%d nextafterl(%La, %La)==%La want except=%s got except=%s\n", - i, t[i].x, t[i].y, t[i].z, strdup(strexcept(t[i].except)), strdup(strexcept(f))); - } -} - -void bench_nextafterl_normal(int N) -{ - int i; - volatile long double z; - - for (i = 0; i < N; i++) { - z = nextafterl(1.25, 4); - } -} - -void bench_nextafterl_subnormal(int N) -{ - int i; - volatile long double z; - - for (i = 0; i < N; i++) { - z = nextafterl(0x1p-16440L, -0x1p-16444L); - } -} diff --git a/src/math/sanity.c b/src/math/sanity.c deleted file mode 100644 index 9550a70..0000000 --- a/src/math/sanity.c +++ /dev/null @@ -1,257 +0,0 @@ -#include -#include -#include "test.h" - -static int check(double a, double b) -{ - double d = a - b; - return fabs(d) <= 0x1p-52*fabs(a); -} - -static int checkf(float a, float b) -{ - float d = a - b; - return fabsf(d) <= 0x1p-23*fabsf(a); -} - -static int checkl(long double a, long double b) -{ - long double d = a - b; - return fabsl(d) <= 0x1p-63L*fabsl(a); -} - -#define D(fx, y) do{ \ - volatile double yy = fx; \ - volatile long double yl = fx; \ - if (!check(yy, y)) \ - error("%s got %a = %.21e want %a = %.21e\n", #fx, yy, yy, y, y); \ - if (yy != yl) \ - error("float-store issue: (double)%s = %a (long double)%s = %La\n", #fx, yy, #fx, yl); \ -}while(0) - -#define F(fx, y) do{ \ - volatile float yy = fx; \ - volatile long double yl = fx; \ - if (!checkf(yy, y)) \ - error("%s got %a = %.21e want %a = %.21e\n", #fx, yy, yy, y, y); \ - if (yy != yl) \ - error("float-store issue: (float)%s = %a (long double)%s = %La\n", #fx, yy, #fx, yl); \ -}while(0) - -#define L(fx, y) do{ \ - long double yy = fx; \ - if (!checkl(yy, y)) \ - error("%s got %La = %.21Le want %La = %.21Le\n", #fx, yy, yy, y, y); \ -}while(0) - -#define I(fx, y) do{ \ - int yy = fx; \ - if (yy != y) \ - error("%s got %d want %d\n", #fx, yy, y); \ -}while(0) - -#define IL(fx, y) do{ \ - long yy = fx; \ - if (yy != y) \ - error("%s got %ld want %ld\n", #fx, yy, y); \ -}while(0) - -#define ILL(fx, y) do{ \ - long long yy = fx; \ - if (yy != y) \ - error("%s got %lld want %lld\n", #fx, yy, y); \ -}while(0) - -void test_math_sanity() -{ - int i; - double q; - float qf; - long double ql; - -D(acos(0.7), 0x1.973e83f5d5c9bp-1); -F(acosf(0.7f), 0x1.973e84p-1); -L(acosl(0.7L), 0x1.973e83f5d5c9aaf8p-1L); -D(acosh(1.7), 0x1.1f8c10d010fe6p+0); -F(acoshf(1.7f), 0x1.1f8c12p+0); -L(acoshl(1.7L), 0x1.1f8c10d010fe5d96p+0L); -D(asin(0.7), 0x1.8d00e692afd95p-1); -F(asinf(0.7f), 0x1.8d00e6p-1); -L(asinl(0.7L), 0x1.8d00e692afd95ddap-1L); -D(asinh(0.7), 0x1.4e2a4fe9085ddp-1); -F(asinhf(0.7f), 0x1.4e2a5p-1); -L(asinhl(0.7L), 0x1.4e2a4fe9085dd732p-1L); -D(atan(0.7), 0x1.38b112d7bd4adp-1); -F(atanf(0.7f), 0x1.38b112p-1); -L(atanl(0.7L), 0x1.38b112d7bd4ad786p-1L); -D(atan2(0.7, 1.0), 0x1.38b112d7bd4adp-1); -F(atan2f(0.7f, 1.0f), 0x1.38b112p-1); -L(atan2l(0.7L, 1.0L), 0x1.38b112d7bd4ad786p-1L); -D(atanh(0.7), 0x1.bc0ed0947fbe8p-1); -F(atanhf(0.7f), 0x1.bc0edp-1); -L(atanhl(0.7L), 0x1.bc0ed0947fbe9068p-1L); -D(cbrt(0.7), 0x1.c69b5a72f1a99p-1); -F(cbrtf(0.7f), 0x1.c69b5ap-1); -L(cbrtl(0.7L), 0x1.c69b5a72f1a99902p-1L); -D(ceil(0.7), 0x1p+0); -F(ceilf(0.7f), 0x1p+0); -L(ceill(0.7L), 0x1p+0L); -D(copysign(0.7, -1.0), -0x1.6666666666666p-1); -F(copysignf(0.7f, -1.0f), -0x1.666666p-1); -L(copysignl(0.7L, -1.0L), -0x1.6666666666666666p-1L); -D(cos(0.7), 0x1.87996529f9d93p-1); -F(cosf(0.7f), 0x1.879966p-1); -L(cosl(0.7L), 0x1.87996529f9d92618p-1L); -D(cosh(0.7), 0x1.4152c1862342fp+0); -F(coshf(0.7f), 0x1.4152c2p+0); -L(coshl(0.7L), 0x1.4152c1862342ef8ep+0L); -D(erf(0.7), 0x1.5b08c21171646p-1); -F(erff(0.7f), 0x1.5b08c2p-1); -L(erfl(0.7L), 0x1.5b08c21171646544p-1L); -D(erfc(0.7), 0x1.49ee7bdd1d374p-2); -F(erfcf(0.7f), 0x1.49ee7cp-2); -L(erfcl(0.7L), 0x1.49ee7bdd1d373576p-2L); -D(exp(0.7), 0x1.01c2a61268987p+1); -F(expf(0.7f), 0x1.01c2a6p+1); -L(expl(0.7L), 0x1.01c2a61268986bfep+1L); -D(exp2(0.7), 0x1.9fdf8bcce533dp+0); -F(exp2f(0.7f), 0x1.9fdf8cp+0); -L(exp2l(0.7L), 0x1.9fdf8bcce533d72p+0L); -D(expm1(0.7), 0x1.03854c24d130dp+0); -F(expm1f(0.7f), 0x1.03854cp+0); -L(expm1l(0.7L), 0x1.03854c24d130d7fep+0L); -D(fabs(-0.7), 0x1.6666666666666p-1); -F(fabsf(-0.7f), 0x1.666666p-1); -L(fabsl(-0.7L), 0x1.6666666666666666p-1L); -D(fdim(0.7, 0.5), 0x1.9999999999998p-3); -F(fdimf(0.7f, 0.5f), 0x1.999998p-3); -L(fdiml(0.7L, 0.5L), 0x1.9999999999999998p-3L); -D(floor(0.7), 0x0p+0); -F(floorf(0.7f), 0x0p+0); -L(floorl(0.7L), 0x0p+0L); -D(fma(0.7, 2.0, 0.1), 0x1.8p+0); -F(fmaf(0.7f, 2.0f, 0.1f), 0x1.8p+0); -L(fmal(0.7L, 2.0L, 0.1L), 0x1.8p+0L); -D(fmax(0.7, 0.5), 0x1.6666666666666p-1); -F(fmaxf(0.7f, 0.5), 0x1.666666p-1); -L(fmaxl(0.7L, 0.5), 0x1.6666666666666666p-1L); -D(fmin(0.7, 0.5), 0x1p-1); -F(fminf(0.7f, 0.5f), 0x1p-1); -L(fminl(0.7L, 0.5L), 0x1p-1L); -D(fmod(0.7, 0.5), 0x1.9999999999998p-3); -F(fmodf(0.7f, 0.5f), 0x1.999998p-3); -L(fmodl(0.7L, 0.5L), 0x1.9999999999999998p-3L); -D(frexp(0.7, &i), 0x1.6666666666666p-1); -F(frexpf(0.7f, &i), 0x1.666666p-1); -L(frexpl(0.7L, &i), 0x1.6666666666666666p-1L); -D(hypot(0.7, 1.0), 0x1.387ce204a35d2p+0); -F(hypotf(0.7f, 1.0f), 0x1.387ce2p+0); -L(hypotl(0.7L, 1.0L), 0x1.387ce204a35d1ff6p+0L); -I(ilogb(0.7), -1); -I(ilogbf(0.7f), -1); -I(ilogbl(0.7L), -1); -D(j0(0.7), 0x1.c32cc34b8cc59p-1); -F(j0f(0.7f), 0x1.c32cc4p-1); -D(j1(0.7), 0x1.50e44279c0546p-2); -F(j1f(0.7f), 0x1.50e442p-2); -D(jn(2, 0.7), 0x1.e195286f3b2fbp-5); -F(jnf(2, 0.7f), 0x1.e19528p-5); -D(ldexp(0.7, 3), 0x1.6666666666666p+2); -F(ldexpf(0.7f, 3), 0x1.666666p+2); -L(ldexpl(0.7L, 3), 0x1.6666666666666666p+2L); -D(lgamma(0.7), 0x1.0b20c891cde73p-2); -F(lgammaf(0.7f), 0x1.0b20cap-2); -L(lgammal(0.7L), 0x1.0b20c891cde72846p-2L); -D(lgamma_r(0.7, &i), 0x1.0b20c891cde73p-2); -F(lgammaf_r(0.7f, &i), 0x1.0b20cap-2); -L(lgammal_r(0.7L, &i), 0x1.0b20c891cde72846p-2L); -ILL(llrint(0.7), 1); -ILL(llrintf(0.7f), 1); -ILL(llrintl(0.7l), 1); -ILL(llround(0.7), 1); -ILL(llroundf(0.7f), 1); -ILL(llroundl(0.7L), 1); -D(log(0.7), -0x1.6d3c324e13f5p-2); -F(logf(0.7f), -0x1.6d3c34p-2); -L(logl(0.7L), -0x1.6d3c324e13f4ec54p-2L); -D(log10(0.7), -0x1.3d3d3d21ccf04p-3); -F(log10f(0.7f), -0x1.3d3d3ep-3); -L(log10l(0.7L), -0x1.3d3d3d21ccf035a6p-3L); -D(log1p(0.7), 0x1.0fae81914a991p-1); -F(log1pf(0.7f), 0x1.0fae82p-1); -L(log1pl(0.7L), 0x1.0fae81914a991308p-1L); -D(log2(0.7), -0x1.0776228967d13p-1); -F(log2f(0.7f), -0x1.077624p-1); -L(log2l(0.7L), -0x1.0776228967d1218cp-1L); -D(logb(0.7), -0x1p+0); -F(logbf(0.7f), -0x1p+0); -L(logbl(0.7L), -0x1p+0L); -IL(lrint(0.7), 1); -IL(lrintf(0.7f), 1); -IL(lrintl(0.7l), 1); -IL(lround(0.7), 1); -IL(lroundf(0.7f), 1); -IL(lroundl(0.7L), 1); -D(modf(0.7, &q), 0x1.6666666666666p-1); -F(modff(0.7f, &qf), 0x1.666666p-1); -L(modfl(0.7L, &ql), 0x1.6666666666666666p-1L); -D(nearbyint(0.7), 0x1p+0); -F(nearbyintf(0.7f), 0x1p+0); -L(nearbyintl(0.7L), 0x1p+0L); -D(nextafter(0.7, 1.0), 0x1.6666666666667p-1); -F(nextafterf(0.7f, 1.0f), 0x1.666668p-1); -L(nextafterl(0.7L, 1.0L), 0x1.6666666666666667p-1L); -D(nexttoward(0.7, 1.0L), 0x1.6666666666667p-1); -F(nexttowardf(0.7f, 1.0L), 0x1.666668p-1); -L(nexttowardl(0.7L, 1.0L), 0x1.6666666666666667p-1L); -D(pow(0.7, 1.5), 0x1.2bdbe460916ep-1); -F(powf(0.7f, 1.5f), 0x1.2bdbe4p-1); -L(powl(0.7L, 1.5L), 0x1.2bdbe460916e0b5p-1L); -D(remainder(0.7, 0.5), 0x1.9999999999998p-3); -F(remainderf(0.7f, 0.5f), 0x1.999998p-3); -L(remainderl(0.7L, 0.5L), 0x1.9999999999999998p-3L); -D(remquo(0.7, 0.5, &i), 0x1.9999999999998p-3); -F(remquof(0.7f, 0.5f, &i), 0x1.999998p-3); -L(remquol(0.7L, 0.5L, &i), 0x1.9999999999999998p-3L); -D(rint(0.7), 0x1p+0); -F(rintf(0.7f), 0x1p+0); -L(rintl(0.7L), 0x1p+0L); -D(round(0.7), 0x1p+0); -F(roundf(0.7f), 0x1p+0); -L(roundl(0.7L), 0x1p+0L); -D(scalb(0.7, 3), 0x1.6666666666666p+2); -F(scalbf(0.7f, 3), 0x1.666666p+2); -D(scalbln(0.7, 3), 0x1.6666666666666p+2); -F(scalblnf(0.7f, 3), 0x1.666666p+2); -L(scalblnl(0.7L, 3), 0x1.6666666666666666p+2L); -D(scalbn(0.7, 3), 0x1.6666666666666p+2); -F(scalbnf(0.7f, 3), 0x1.666666p+2); -L(scalbnl(0.7L, 3), 0x1.6666666666666666p+2L); -D(sin(0.7), 0x1.49d6e694619b8p-1); -F(sinf(0.7f), 0x1.49d6e6p-1); -L(sinl(0.7L), 0x1.49d6e694619b854ep-1L); -D(sinh(0.7), 0x1.8465153d5bdbdp-1); -F(sinhf(0.7f), 0x1.846514p-1); -L(sinhl(0.7L), 0x1.8465153d5bdbd0dep-1L); -D(sqrt(0.7), 0x1.ac5eb3f7ab2f8p-1); -F(sqrtf(0.7f), 0x1.ac5eb4p-1); -L(sqrtl(0.7L), 0x1.ac5eb3f7ab2f7de2p-1L); -D(tan(0.7), 0x1.af406c2fc78aep-1); -F(tanf(0.7f), 0x1.af406cp-1); -L(tanl(0.7L), 0x1.af406c2fc78ae54cp-1L); -D(tanh(0.7), 0x1.356fb17af2e91p-1); -F(tanhf(0.7f), 0x1.356fb2p-1); -L(tanhl(0.7L), 0x1.356fb17af2e9100ap-1L); -D(tgamma(0.7), 0x1.4c4d5ab21ea23p+0); -F(tgammaf(0.7f), 0x1.4c4d5cp+0); -L(tgammal(0.7L), 0x1.4c4d5ab21ea22798p+0L); -D(trunc(0.7), 0x0p+0); -F(truncf(0.7f), 0x0p+0); -L(truncl(0.7L), 0x0p+0L); -D(y0(0.7), -0x1.867b559ffc715p-3); -F(y0f(0.7f), -0x1.867b58p-3); -D(y1(0.7), -0x1.1a6e956728d35p+0); -F(y1f(0.7f), -0x1.1a6e96p+0); -D(yn(2, 0.7), -0x1.7b11b25df166ep+1); -F(ynf(2, 0.7f), -0x1.7b11b4p+1); -} diff --git a/src/math/scalbn.c b/src/math/scalbn.c deleted file mode 100644 index b4a56be..0000000 --- a/src/math/scalbn.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "test.h" -#include -#include -#include -#include -#include - -static struct { - double x; - int n; - double y; -} t[] = { - 0.0, 0, 0.0, - -0.0, 0, -0.0, - 0.0, -1234567, 0.0, - -0.0, 1234567, -0.0, - 0x1.234p0, 13, 0x1.234p13, - 0x1.234p0, -13, 0x1.234p-13, - -0x1.234p1, 137, -0x1.234p138, - -0x1.234p1, -137, -0x1.234p-136, - 0x1.234p1023, 1, INFINITY, - 0x1.234p1023, -1022, 0x1.234p1, - 0x1.234p1023, -1023, 0x1.234p0, - 0x1.234p1023, -1024, 0x1.234p-1, - 0x1.234p1023, -2023, 0x1.234p-1000, - 0x1.234p1023, -2045, 0x1.234p-1022, - 0x1.234p1023, -2046, 0x1.234p-1023, - 0x1.234p1023, -2048, 0x1.234p-1025, - 0x1.234p1023, -2049, 0x1.234p-1026, - 0x1p1023, -2096, 0x1p-1073, - 0x1p1023, -2097, 0x1p-1074, - 0x1p1023, -2098, 0, - 0x1.234p-1022, 1022, 0x1.234p0, - 0x1.234p-1022, 2045, 0x1.234p1023, - 0x1p-1074, 2097, 0x1p1023, - 0x1p-1074, 2098, INFINITY, - 0x1p-1074, 1, 0x1p-1073, - 0x1p-1073, -1, 0x1p-1074, - 0x1p-1074, -1, 0, -}; - -void test_scalbn() -{ - int i; - double y; - - for (i = 0; i < sizeof t/sizeof *t; i++) { - y = scalbn(t[i].x, t[i].n); - if (y != t[i].y) - error("scalbn(%a,%d) want %a got %a\n", t[i].x, t[i].n, t[i].y, y); - } -} - -void bench_scalbn_simple(int N) -{ - int i; - volatile double y; - - for (i = 0; i < N; i++) { - y = scalbn(1.25, 73); - } -} - -void bench_scalbn_hard(int N) -{ - int i; - volatile double y; - - for (i = 0; i < N; i++) { - y = scalbn(0x1.23p-1050, 2070); - } -} diff --git a/src/math/sqrt.c b/src/math/sqrt.c deleted file mode 100644 index 3dce651..0000000 --- a/src/math/sqrt.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "test.h" -#include -#include - -static struct { - double x,y; -} testdata[] = { -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+511, -0x1.ffffffffffffbp+1023, 0x1.ffffffffffffdp+511, -0x1.ffffffffffff7p+1023, 0x1.ffffffffffffbp+511, -0x1.ffffffffffff3p+1023, 0x1.ffffffffffff9p+511, -0x1.fffffffffffefp+1023, 0x1.ffffffffffff7p+511, -0x1.fffffffffffebp+1023, 0x1.ffffffffffff5p+511, -0x1.fffffffffffe7p+1023, 0x1.ffffffffffff3p+511, -0x1.fffffffffffe3p+1023, 0x1.ffffffffffff1p+511, -0x1.fffffffffffdfp+1023, 0x1.fffffffffffefp+511, -0x1.fffffffffffdbp+1023, 0x1.fffffffffffedp+511, -0x1.fffffffffffd7p+1023, 0x1.fffffffffffebp+511, -0x1.0000000000003p-1022, 0x1.0000000000001p-511, -0x1.0000000000007p-1022, 0x1.0000000000003p-511, -0x1.000000000000bp-1022, 0x1.0000000000005p-511, -0x1.000000000000fp-1022, 0x1.0000000000007p-511, -0x1.0000000000013p-1022, 0x1.0000000000009p-511, -0x1.0000000000017p-1022, 0x1.000000000000bp-511, -0x1.000000000001bp-1022, 0x1.000000000000dp-511, -0x1.000000000001fp-1022, 0x1.000000000000fp-511, -0x1.0000000000023p-1022, 0x1.0000000000011p-511, -0x1.0000000000027p-1022, 0x1.0000000000013p-511, -0x1.000000000002bp-1022, 0x1.0000000000015p-511, -0x1.000000000002fp-1022, 0x1.0000000000017p-511, -0x1.0000000000033p-1022, 0x1.0000000000019p-511, -0x1.0000000000037p-1022, 0x1.000000000001bp-511, -0x1.7167bc36eaa3bp+6, 0x1.3384c7db650cdp+3, -0x1.7570994273ad7p+6, 0x1.353186e89b8ffp+3, -0x1.7dae969442fe6p+6, 0x1.389640fb18b75p+3, -0x1.7f8444fcf67e5p+6, 0x1.395659e94669fp+3, -0x1.8364650e63a54p+6, 0x1.3aea9efe1a3d7p+3, -0x1.85bedd274edd8p+6, 0x1.3bdf20c867057p+3, -0x1.8609cf496ab77p+6, 0x1.3bfd7e14b5eabp+3, -0x1.873849c70a375p+6, 0x1.3c77ed341d27fp+3, -0x1.8919c962cbaaep+6, 0x1.3d3a7113ee82fp+3, -0x1.8de4493e22dc6p+6, 0x1.3f27d448220c3p+3, -0x1.924829a17a288p+6, 0x1.40e9552eec28fp+3, -0x1.92702cd992f12p+6, 0x1.40f94a6fdfddfp+3, -0x1.92b763a8311fdp+6, 0x1.4115af614695fp+3, -0x1.947da013c7293p+6, 0x1.41ca91102940fp+3, -0x1.9536091c494d2p+6, 0x1.4213e334c77adp+3, -0x1.61b04c6p-1019, 0x1.a98b88f18b46dp-510, -0x1.93789f1p-1018, 0x1.4162ae43d5821p-509, -0x1.a1989b4p-1018, 0x1.46f6736eb44bbp-509, -0x1.f93bc9p-1018, 0x1.67a36ec403bafp-509, -0x1.2f675e3p-1017, 0x1.8a22ab6dcfee1p-509, -0x1.a158508p-1017, 0x1.ce418a96cf589p-509, -0x1.cd31f078p-1017, 0x1.e5ef1c65dccebp-509, -0x1.33b43b08p-1016, 0x1.18a9f607e1701p-508, -0x1.6e66a858p-1016, 0x1.324402a00b45fp-508, -0x1.8661cbf8p-1016, 0x1.3c212046bfdffp-508, -0x1.bbb221b4p-1016, 0x1.510681b939931p-508, -0x1.c4942f3cp-1016, 0x1.5461e59227ab5p-508, -0x1.dbb258c8p-1016, 0x1.5cf7b0f78d3afp-508, -0x1.57103ea4p-1015, 0x1.a31ab946d340bp-508, -0x1.9b294f88p-1015, 0x1.cad197e28e85bp-508, -0x1.0000000000001p+0, 0x1p+0, -0x1.fffffffffffffp-1, 0x1.fffffffffffffp-1, -}; - -void test_sqrt(void) -{ - int j; - double x, y, y0; - - for (j = 0; j < sizeof testdata / sizeof *testdata; j++) { - x = testdata[j].x; - y = testdata[j].y; - y0 = sqrt(x); - if (y != y0) - error("sqrt(%a): wanted %a got %a\n", x, y, y0); - } -} - -void bench_sqrt(int N) -{ - int i; - double x; - volatile double y; - - x = 0x1.23456p7; - for (i = 0; i < N; i++) { - y = sqrt(x); - x += 0.0000001; - } -} diff --git a/src/misc/Makefile b/src/misc/Makefile index 278e884..ee4552b 100644 --- a/src/misc/Makefile +++ b/src/misc/Makefile @@ -1,2 +1 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc diff --git a/src/misc/basename.c b/src/misc/basename.c index 95e0d36..071966a 100644 --- a/src/misc/basename.c +++ b/src/misc/basename.c @@ -3,22 +3,24 @@ #include #include "test.h" -static void t(char *p, char *b) { - char *tmp = strdup(p); - char *s = basename(tmp); - - if (strcmp(b,s) != 0) - error("basename(\"%s\") returned \"%s\"; expected \"%s\"\n", p, s, b); - free(tmp); +#define T(path, want) \ +{ \ + char tmp[1000]; \ + char *got = basename(strcpy(tmp, path)); \ + if (strcmp(want, got) != 0) \ + error("basename(\"%s\") got \"%s\" want \"%s\"\n", path, got, want); \ } -void test_basename() { +int main() +{ if (strcmp(".", basename(0)) != 0) error("basename(0) returned \"%s\"; expected \".\"\n", basename(0)); - t("", "."); - t("/usr/lib", "lib"); - t("/usr/", "usr"); - t("/", "/"); - t("///", "/"); - t("//usr//lib//", "lib"); + T("", "."); + T("/usr/lib", "lib"); + T("/usr/", "usr"); + T("usr/", "usr"); + T("/", "/"); + T("///", "/"); + T("//usr//lib//", "lib"); + return test_status; } diff --git a/src/misc/dirname.c b/src/misc/dirname.c index b4a1c48..ae8b67b 100644 --- a/src/misc/dirname.c +++ b/src/misc/dirname.c @@ -3,24 +3,26 @@ #include #include "test.h" -static void t(char *p, char *b) { - char *tmp = strdup(p); - char *s = dirname(tmp); - - if (strcmp(b,s) != 0) - error("dirname(\"%s\") returned \"%s\"; expected \"%s\"\n", p, s, b); - free(tmp); +#define T(path, want) \ +{ \ + char tmp[1000]; \ + char *got = dirname(strcpy(tmp, path)); \ + if (strcmp(want, got) != 0) \ + error("dirname(\"%s\") got \"%s\" want \"%s\"\n", path, got, want); \ } -void test_dirname() { +int main() +{ if (strcmp(dirname(0), ".") != 0) error("dirname(0) returned \"%s\"; expected \".\"\n", dirname(0)); - t("", "."); - t("/usr/lib", "/usr"); - t("/usr/", "/"); - t("usr", "."); - t("/", "/"); - t("///", "/"); - t(".", "."); - t("..", "."); + T("", "."); + T("/usr/lib", "/usr"); + T("/usr/", "/"); + T("usr", "."); + T("usr/", "."); + T("/", "/"); + T("///", "/"); + T(".", "."); + T("..", "."); + return test_status; } diff --git a/src/misc/test.h b/src/misc/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/misc/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/multibyte/Makefile b/src/multibyte/Makefile index 278e884..ee4552b 100644 --- a/src/multibyte/Makefile +++ b/src/multibyte/Makefile @@ -1,2 +1 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc diff --git a/src/multibyte/mbc.c b/src/multibyte/mbc.c index 6b61806..56c546b 100644 --- a/src/multibyte/mbc.c +++ b/src/multibyte/mbc.c @@ -6,80 +6,80 @@ #include #include "test.h" -/* r = place to store result +/* * f = function call to test (or any expression) * x = expected result - * m = message to print on failure (with formats for r & x) -**/ - -#define TEST(r, f, x, m) ( \ + * m = message to print on failure + */ +#define T(f, x, m) (void)( \ memset(&st, 0, sizeof st), \ - ((r) = (f)) == (x) || \ - (error("%s failed (" m ")\n", #f, r, x), 0) ) - -#define TEST_S(s, x, m) ( \ - !strcmp((s),(x)) || \ - (error("[%s] != [%s] (%s)\n", s, x, m), 0) ) + (i = (f)) == (x) || \ + error("%s failed (%s) got %d want %d\n", #f, m, i, x) ) +#define TCHAR(f, x, m) (void)( \ + memset(&st, 0, sizeof st), \ + (i = (f)) == (x) || \ + error("%s failed (%s) got 0x%04x want 0x%04x\n", #f, m, i, x) ) -void test_mbc(void) { +int main(void) +{ const char *cs; int i; mbstate_t st, st2; wchar_t wc, wcs[32]; - + + (void)( setlocale(LC_CTYPE, "en_US.UTF-8") || setlocale(LC_CTYPE, "en_GB.UTF-8") || setlocale(LC_CTYPE, "en.UTF-8") || setlocale(LC_CTYPE, "POSIX.UTF-8") || setlocale(LC_CTYPE, "C.UTF-8") || setlocale(LC_CTYPE, "UTF-8") || - setlocale(LC_CTYPE, ""); + setlocale(LC_CTYPE, "") ); + + T(mbsrtowcs(wcs, (cs="abcdef",&cs), 3, &st), 3, "wrong semantics for wcs buf len"); + T(mbsrtowcs(wcs, (cs="abcdef",&cs), 8, &st), 6, "wrong semantics for wcs buf len"); + T(mbsrtowcs(NULL, (cs="abcdef",&cs), 2, &st), 6, "wrong semantics for NULL wcs"); - TEST(i, mbsrtowcs(wcs, (cs="abcdef",&cs), 3, &st), 3, "wrong semantics for wcs buf len, %d != %d"); - TEST(i, mbsrtowcs(wcs, (cs="abcdef",&cs), 8, &st), 6, "wrong semantics for wcs buf len, %d != %d"); - TEST(i, mbsrtowcs(NULL, (cs="abcdef",&cs), 2, &st), 6, "wrong semantics for NULL wcs, %d != %d"); + if (strcmp(nl_langinfo(CODESET), "UTF-8")) + return error("cannot set UTF-8 locale for test (codeset=%s)\n", nl_langinfo(CODESET)); - if (strcmp(nl_langinfo(CODESET), "UTF-8")) { - error("cannot set UTF-8 locale for test (codeset=%s)\n", nl_langinfo(CODESET)); - return; - } - - TEST(i, mbrtowc(&wc, "\x80", 1, &st), -1, "failed to catch error %d != %d"); - TEST(i, mbrtowc(&wc, "\xc0", 1, &st), -1, "failed to catch illegal initial, %d != %d"); + T(mbrtowc(&wc, "\x80", 1, &st), -1, "failed to catch error"); + T(mbrtowc(&wc, "\xc0", 1, &st), -1, "failed to catch illegal initial"); - TEST(i, mbrtowc(&wc, "\xc0\x80", 2, &st), -1, "aliasing nul %d != %d"); - TEST(i, mbrtowc(&wc, "\xc0\xaf", 2, &st), -1, "aliasing slash %d != %d"); - TEST(i, mbrtowc(&wc, "\xe0\x80\xaf", 3, &st), -1, "aliasing slash %d != %d"); - TEST(i, mbrtowc(&wc, "\xf0\x80\x80\xaf", 4, &st), -1, "aliasing slash %d != %d"); - TEST(i, mbrtowc(&wc, "\xf8\x80\x80\x80\xaf", 5, &st), -1, "aliasing slash %d != %d"); - TEST(i, mbrtowc(&wc, "\xfc\x80\x80\x80\x80\xaf", 6, &st), -1, "aliasing slash %d != %d"); - TEST(i, mbrtowc(&wc, "\xe0\x82\x80", 3, &st), -1, "aliasing U+0080 %d != %d"); - TEST(i, mbrtowc(&wc, "\xe0\x9f\xbf", 3, &st), -1, "aliasing U+07FF %d != %d"); - TEST(i, mbrtowc(&wc, "\xf0\x80\xa0\x80", 4, &st), -1, "aliasing U+0800 %d != %d"); - TEST(i, mbrtowc(&wc, "\xf0\x8f\xbf\xbd", 4, &st), -1, "aliasing U+FFFD %d != %d"); + T(mbrtowc(&wc, "\xc0\x80", 2, &st), -1, "aliasing nul"); + T(mbrtowc(&wc, "\xc0\xaf", 2, &st), -1, "aliasing slash"); + T(mbrtowc(&wc, "\xe0\x80\xaf", 3, &st), -1, "aliasing slash"); + T(mbrtowc(&wc, "\xf0\x80\x80\xaf", 4, &st), -1, "aliasing slash"); + T(mbrtowc(&wc, "\xf8\x80\x80\x80\xaf", 5, &st), -1, "aliasing slash"); + T(mbrtowc(&wc, "\xfc\x80\x80\x80\x80\xaf", 6, &st), -1, "aliasing slash"); + T(mbrtowc(&wc, "\xe0\x82\x80", 3, &st), -1, "aliasing U+0080"); + T(mbrtowc(&wc, "\xe0\x9f\xbf", 3, &st), -1, "aliasing U+07FF"); + T(mbrtowc(&wc, "\xf0\x80\xa0\x80", 4, &st), -1, "aliasing U+0800"); + T(mbrtowc(&wc, "\xf0\x8f\xbf\xbd", 4, &st), -1, "aliasing U+FFFD"); - TEST(i, mbrtowc(&wc, "\xed\xa0\x80", 3, &st), -1, "failed to catch surrogate, %d != %d"); - TEST(i, mbrtowc(&wc, "\xef\xbf\xbe", 3, &st), 3, "failed to accept U+FFFE, %d != %d"); - TEST(i, mbrtowc(&wc, "\xef\xbf\xbf", 3, &st), 3, "failed to accept U+FFFF, %d != %d"); - TEST(i, mbrtowc(&wc, "\xf4\x8f\xbf\xbe", 4, &st), 4, "failed to accept U+10FFFE, %d != %d"); - TEST(i, mbrtowc(&wc, "\xf4\x8f\xbf\xbf", 4, &st), 4, "failed to accept U+10FFFF, %d != %d"); + T(mbrtowc(&wc, "\xed\xa0\x80", 3, &st), -1, "failed to catch surrogate"); + T(mbrtowc(&wc, "\xef\xbf\xbe", 3, &st), 3, "failed to accept U+FFFE"); + T(mbrtowc(&wc, "\xef\xbf\xbf", 3, &st), 3, "failed to accept U+FFFF"); + T(mbrtowc(&wc, "\xf4\x8f\xbf\xbe", 4, &st), 4, "failed to accept U+10FFFE"); + T(mbrtowc(&wc, "\xf4\x8f\xbf\xbf", 4, &st), 4, "failed to accept U+10FFFF"); - TEST(i, mbrtowc(&wc, "\xc2\x80", 2, &st), 2, "wrong length %d != %d"); - TEST(i, (mbrtowc(&wc, "\xc2\x80", 2, &st),wc), 0x80, "wrong char %04x != %04x"); - TEST(i, mbrtowc(&wc, "\xe0\xa0\x80", 3, &st), 3, "wrong length %d != %d"); - TEST(i, (mbrtowc(&wc, "\xe0\xa0\x80", 3, &st),wc), 0x800, "wrong char %04x != %04x"); - TEST(i, mbrtowc(&wc, "\xf0\x90\x80\x80", 4, &st), 4, "wrong length %d != %d"); - TEST(i, (mbrtowc(&wc, "\xf0\x90\x80\x80", 4, &st),wc), 0x10000, "wrong char %04x != %04x"); + T(mbrtowc(&wc, "\xc2\x80", 2, &st), 2, "wrong length"); + TCHAR((mbrtowc(&wc, "\xc2\x80", 2, &st),wc), 0x80, "wrong char"); + T(mbrtowc(&wc, "\xe0\xa0\x80", 3, &st), 3, "wrong length"); + TCHAR((mbrtowc(&wc, "\xe0\xa0\x80", 3, &st),wc), 0x800, "wrong char"); + T(mbrtowc(&wc, "\xf0\x90\x80\x80", 4, &st), 4, "wrong length"); + TCHAR((mbrtowc(&wc, "\xf0\x90\x80\x80", 4, &st),wc), 0x10000, "wrong char"); memset(&st2, 0, sizeof st2); - TEST(i, mbrtowc(&wc, "\xc2", 1, &st2), -2, "failed to accept initial byte, %d != %d"); - TEST(i, mbrtowc(&wc, "\x80", 1, &st2), 1, "failed to resume, %d != %d"); - TEST(i, wc, 0x80, "wrong char %04x != %04x"); + T(mbrtowc(&wc, "\xc2", 1, &st2), -2, "failed to accept initial byte"); + T(mbrtowc(&wc, "\x80", 1, &st2), 1, "failed to resume"); + TCHAR(wc, 0x80, "wrong char"); memset(&st2, 0, sizeof st2); - TEST(i, mbrtowc(&wc, "\xc2", 1, &st2), -2, "failed to accept initial byte, %d != %d"); - TEST(i, mbsrtowcs(wcs, (cs="\xa0""abc",&cs), 32, &st2), 4, "failed to resume, %d != %d"); - TEST(i, wcs[0], 0xa0, "wrong char %04x != %04x"); - TEST(i, wcs[1], 'a', "wrong char %04x != %04x"); - TEST(i, !cs, 1, "wrong final position %d != %d"); + T(mbrtowc(&wc, "\xc2", 1, &st2), -2, "failed to accept initial byte"); + T(mbsrtowcs(wcs, (cs="\xa0""abc",&cs), 32, &st2), 4, "failed to resume"); + TCHAR(wcs[0], 0xa0, "wrong char"); + TCHAR(wcs[1], 'a', "wrong char"); + T(!cs, 1, "wrong final position"); + return test_status; } diff --git a/src/multibyte/test.h b/src/multibyte/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/multibyte/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/multibyte/utf8bench.c b/src/multibyte/utf8bench.c deleted file mode 100644 index 5233549..0000000 --- a/src/multibyte/utf8bench.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#define LEN 500000 - -static char *initbuf() { - char *buf; - int i, j, k, l; - - setlocale(LC_CTYPE, "C.UTF-8") - || setlocale(LC_CTYPE, "en_US.UTF-8") - || setlocale(LC_CTYPE, "en_GB.UTF-8") - || setlocale(LC_CTYPE, "en.UTF-8") - || setlocale(LC_CTYPE, "de_DE-8") - || setlocale(LC_CTYPE, "fr_FR-8"); - if (strcmp(nl_langinfo(CODESET), "UTF-8")) exit(1); - - buf = malloc(LEN); - l = 0; - for (i=0xc3; i<0xe0; i++) - for (j=0x80; j<0xc0; j++) - buf[l++] = i, buf[l++] = j; - for (i=0xe1; i<0xed; i++) - for (j=0x80; j<0xc0; j++) - for (k=0x80; k<0xc0; k++) - buf[l++] = i, buf[l++] = j, buf[l++] = k; - for (i=0xf1; i<0xf4; i++) - for (j=0x80; j<0xc0; j++) - for (k=0x80; k<0xc0; k++) - buf[l++] = i, buf[l++] = j, buf[l++] = 0x80, buf[l++] = k; - buf[l++] = 0; - return buf; -} - -void bench_utf8_bigbuf(int N) { - char *buf; - wchar_t *wbuf; - int i; - int cs; - - buf = initbuf(); - wbuf = malloc(LEN*sizeof(wchar_t)); - for (i=0; i #include #include @@ -8,14 +10,16 @@ #include #include "test.h" -#define TEST(r, f, x, m) ( \ - ((r) = (f)) == (x) || \ - (error("%s failed (" m ")\n", #f, r, x), 0) ) +#define TEST(f, x) (void)( \ + (r = (f)) == (x) || \ + error("%s failed, got %d want %d\n", #f, r, x) ) -#define TEST_E(f) ( (errno = 0), (f) || \ - (error("%s failed (errno = %d \"%s\")\n", #f, errno, strerror(errno)), 0) ) +#define TEST_E(f) (void)( \ + (errno = 0), (f) || \ + error("%s failed (errno = %d \"%s\")\n", #f, errno, strerror(errno)) ) -void test_spawn(void) { +int main(void) +{ int r; char foo[10]; int p[2]; @@ -24,14 +28,15 @@ void test_spawn(void) { posix_spawn_file_actions_t fa; TEST_E(!pipe(p)); - TEST(r, posix_spawn_file_actions_init(&fa), 0, "%d != %d"); - TEST(r, posix_spawn_file_actions_addclose(&fa, p[0]), 0, "%d != %d"); - TEST(r, posix_spawn_file_actions_adddup2(&fa, p[1], 1), 0, "%d != %d"); - TEST(r, posix_spawn_file_actions_addclose(&fa, p[1]), 0, "%d != %d"); - TEST(r, posix_spawnp(&pid, "echo", &fa, 0, (char *[]){"echo","hello",0}, 0), 0, "%d != %d"); + TEST(posix_spawn_file_actions_init(&fa), 0); + TEST(posix_spawn_file_actions_addclose(&fa, p[0]), 0); + TEST(posix_spawn_file_actions_adddup2(&fa, p[1], 1), 0); + TEST(posix_spawn_file_actions_addclose(&fa, p[1]), 0); + TEST(posix_spawnp(&pid, "echo", &fa, 0, (char *[]){"echo","hello",0}, 0), 0); close(p[1]); - TEST(r, waitpid(pid, &status, 0), pid, "%d != %d"); - TEST(r, read(p[0], foo, sizeof foo), 6, "%d != %d"); + TEST(waitpid(pid, &status, 0), pid); + TEST(read(p[0], foo, sizeof foo), 6); close(p[0]); - TEST(r, posix_spawn_file_actions_destroy(&fa), 0, "%d != %d"); + TEST(posix_spawn_file_actions_destroy(&fa), 0); + return test_status; } diff --git a/src/process/test.h b/src/process/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/process/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/regex/Makefile b/src/regex/Makefile index 278e884..ee4552b 100644 --- a/src/regex/Makefile +++ b/src/regex/Makefile @@ -1,2 +1 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc diff --git a/src/regex/bench.c b/src/regex/bench.c deleted file mode 100644 index 526662b..0000000 --- a/src/regex/bench.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include -#include "test.h" - - -void bench_regex_compile(int N) { - regex_t re; - int i; - - setlocale(LC_CTYPE, ""); - for (i=0; istr; map++) { if (map->val && (flags & map->val) == map->val) { - fprintf(stderr, "%s%s", sep, map->str); + sprintf(buf, "%s%s", sep, map->str); sep = "|"; flags &= ~(map->val); } } - if (flags) fprintf(stderr, "%sunknown=%#x", sep, flags); + if (flags) + sprintf(buf, "%sunknown=%#x", sep, flags); + return buf; } /* tests harness adapted from glibc testfnm.c */ @@ -114,7 +118,8 @@ struct { { "a[.]b", "a.b", FNM_PATHNAME|FNM_PERIOD, 0 }, }; -void test_fnmatch(void) { +int main(void) +{ int i; for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) { @@ -123,11 +128,11 @@ void test_fnmatch(void) { r = fnmatch(tests[i].pattern, tests[i].string, tests[i].flags); x = tests[i].expected; if (r != x && (r != FNM_NOMATCH || x != -FNM_NOMATCH)) { - error("fail - fnmatch(\"%s\", \"%s\", ", - tests[i].pattern, tests[i].string); - printflags(fnmatch_flags, tests[i].flags); - fprintf(stderr, ") => %d (expected %d)\n", - r, tests[i].expected); + error("fnmatch(\"%s\", \"%s\", %s) failed, got %d want %d\n", + tests[i].pattern, tests[i].string, + flagstr(fnmatch_flags, tests[i].flags), + r, x); } } + return test_status; } diff --git a/src/regex/test.h b/src/regex/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/regex/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/stdio/Makefile b/src/stdio/Makefile index 278e884..ee4552b 100644 --- a/src/stdio/Makefile +++ b/src/stdio/Makefile @@ -1,2 +1 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc diff --git a/src/stdio/bench.c b/src/stdio/bench.c deleted file mode 100644 index 0e87845..0000000 --- a/src/stdio/bench.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include "test.h" - -void bench_stdio_getc_unlocked(int N) { - FILE *f = tmpfile(); - size_t i; - size_t cs = 0; - - for (i=0; i -#include -#include +#endif #include +#include +#include #include +#include +#include "test.h" #define TEST(c) do { \ errno = 0; \ @@ -12,7 +14,7 @@ error("%s failed (errno = %d)\n", #c, errno); \ } while(0) -void test_fdopen(void) +int main(void) { char tmp[] = "/tmp/testsuite-XXXXXX"; char foo[6]; @@ -32,4 +34,5 @@ void test_fdopen(void) } if (fd > 2) TEST(unlink(tmp) != -1); + return test_status; } diff --git a/src/stdio/fscanf.c b/src/stdio/fscanf.c index d5da238..62627b7 100644 --- a/src/stdio/fscanf.c +++ b/src/stdio/fscanf.c @@ -6,7 +6,7 @@ #include #include "test.h" -#define T(r, f, x, m) do { \ +#define T(f, x, m) do { \ r = (f); \ if (r != (x)) \ error("%s failed (got %d, expected %d, errno \"%s\") (%s)\n", \ @@ -14,48 +14,38 @@ errno = 0; \ } while (0) -static void S(const char *s, const char *x, const char *m) { - if (strcmp(s, x) != 0) - error("got [%s], expected [%s] (%s)\n", s, x, m); -} - -void test_scanf_long(void) { - enum {n = 1<<21}; - char *s = malloc(n+1); - int i; - int r; - - for (i = 0; i < n; i++) s[i] = '1'; - s[n] = 0; - r = sscanf(s, "%d", &i); - free(s); -} +#define S(s, x, m) do { \ + if (strcmp(s, x) != 0) \ + error("got [%s] want [%s] (%s)\n", s, x, m); \ +} while(0) -void test_fscanf(void) { - int i, x, y; +int main(void) +{ + int r, x, y; char a[100], b[100]; int p[2]; FILE *f; - T(i, pipe(p), 0, "open pipe"); - T(i, !(f = fdopen(p[0], "rb")), 0, "fdopen pipe"); + T(pipe(p), 0, "open pipe"); + T(!(f = fdopen(p[0], "rb")), 0, "fdopen pipe"); if (!f) { close(p[0]); close(p[1]); - return; + return test_status; } - T(i, write(p[1], "hello, world\n", 13), 13, "write to pipe"); - T(i, fscanf(f, "%s %[own]", a, b), 2, ""); + T(write(p[1], "hello, world\n", 13), 13, "write to pipe"); + T(fscanf(f, "%s %[own]", a, b), 2, ""); S(a, "hello,", "wrong result for %s"); S(b, "wo", "wrong result for %[own]"); - T(i, fgetc(f), 'r', "fgetc 'r'"); + T(fgetc(f), 'r', "fgetc 'r'"); - T(i, write(p[1], " 0x12 0x34", 10), 10, ""); - T(i, fscanf(f, "ld %5i%2i", &x, &y), 1, ""); - T(i, x, 0x12, ""); - T(i, fgetc(f), '3', "fgetc '3'"); + T(write(p[1], " 0x12 0x34", 10), 10, ""); + T(fscanf(f, "ld %5i%2i", &x, &y), 1, ""); + T(x, 0x12, ""); + T(fgetc(f), '3', "fgetc '3'"); fclose(f); close(p[1]); + return test_status; } diff --git a/src/stdio/memstream.c b/src/stdio/memstream.c index baca42b..749c664 100644 --- a/src/stdio/memstream.c +++ b/src/stdio/memstream.c @@ -20,7 +20,7 @@ !memcmp((s),(x),(n)) || \ (error("[%s] != [%s] (%s)\n", s, x, m), 0) ) -void test_memstream(void) +int main(void) { FILE *f; char *s; @@ -91,4 +91,5 @@ void test_memstream(void) TEST(i, ftell(f), 8, "%d != %d"); TEST_S(buf, "hello104", ""); fclose(f); + return test_status; } diff --git a/src/stdio/popen.c b/src/stdio/popen.c index f647bf4..f5cf05a 100644 --- a/src/stdio/popen.c +++ b/src/stdio/popen.c @@ -22,7 +22,8 @@ static void handler(int sig) { got_sig = 1; } -void test_popen(void) { +int main(void) +{ int i; char foo[6]; char cmd[64]; @@ -44,4 +45,5 @@ void test_popen(void) { TEST(i, got_sig, 1, "child process did not send signal"); } signal(SIGUSR1, SIG_DFL); + return test_status; } diff --git a/src/stdio/snprintf.c b/src/stdio/snprintf.c index 3f28237..1187fd7 100644 --- a/src/stdio/snprintf.c +++ b/src/stdio/snprintf.c @@ -1,4 +1,6 @@ +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 700 +#endif #include #include #include @@ -123,7 +125,7 @@ static const struct { { NULL, 0.0, NULL } }; -void test_snprintf(void) +int main(void) { int i, j, k; char b[2000]; @@ -168,4 +170,5 @@ void test_snprintf(void) } TEST(i, snprintf(0, 0, "%.4a", 1.0), 11, "%d != %d"); + return test_status; } diff --git a/src/stdio/sscanf.c b/src/stdio/sscanf.c index 0d49431..a087c21 100644 --- a/src/stdio/sscanf.c +++ b/src/stdio/sscanf.c @@ -15,7 +15,8 @@ TEST(i, sscanf(# x, "%lf", &d), 1, "got %d fields, expected %d"), \ TEST(t, d, (double)x, "%g != %g") ) -void test_sscanf(void) { +int main(void) +{ int i; char a[100], b[100]; int x, y, z, u, v; @@ -81,4 +82,5 @@ void test_sscanf(void) { TEST(i, sscanf("10e", "%lf", &d), 0, "got %d fields, expected no match (%d)"); TEST(i, sscanf("", "%lf\n", &d), -1, "got %d fields, expected input failure (%d)"); + return test_status; } diff --git a/src/stdio/sscanf_long.c b/src/stdio/sscanf_long.c new file mode 100644 index 0000000..a26999d --- /dev/null +++ b/src/stdio/sscanf_long.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include +#include "test.h" + +static void setrl(int r, long lim) +{ + struct rlimit rl; + + if (getrlimit(r, &rl)) + error("getrlimit %d: %s\n", r, strerror(errno)); + rl.rlim_cur = lim; + if (setrlimit(r, &rl)) + error("setrlimit %d: %s\n", r, strerror(errno)); +} + +int main(void) +{ + enum {n = 8*1024*1024}; + char *s = malloc(n); + int i; + float f; + char c; + + if (!s) + return error("out of memory"); + setrl(RLIMIT_STACK, 128*1024); + + for (i = 0; i < n; i++) s[i] = '1'; + s[n-3] = ' '; + s[n-1] = 0; + + /* + * stack overflow if scanf copies s on the stack (glibc) + * same issue with %d except then storing the conversion + * result is undefined behaviour + */ + i = sscanf(s, "%f %c", &f, &c); + + if (i != 2) + error("sscanf returned %d, want 2\n", i); + if (f != INFINITY) + error("sscanf(longnum, \"%%f\") read %f, want inf\n", f); + if (c != '1') + error("sscanf(\"1\", %%c) read '%c', want '1'\n", c); + free(s); + return test_status; +} diff --git a/src/stdio/swprintf.c b/src/stdio/swprintf.c index 14c53d6..189de33 100644 --- a/src/stdio/swprintf.c +++ b/src/stdio/swprintf.c @@ -1,4 +1,6 @@ +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 700 +#endif #include #include #include @@ -94,17 +96,19 @@ static const struct { { NULL, 0.0, NULL } }; -void test_swprintf(void) { +int main(void) +{ int i, j; wchar_t b[500]; + (void)( setlocale(LC_CTYPE, "en_US.UTF-8") || setlocale(LC_CTYPE, "en_GB.UTF-8") || setlocale(LC_CTYPE, "en.UTF-8") || setlocale(LC_CTYPE, "POSIX.UTF-8") || setlocale(LC_CTYPE, "C.UTF-8") || setlocale(LC_CTYPE, "UTF-8") || - setlocale(LC_CTYPE, ""); + setlocale(LC_CTYPE, "") ); TEST(i, strcmp(nl_langinfo(CODESET), "UTF-8"), 0, "no UTF-8 locale; tests might fail"); @@ -133,4 +137,5 @@ void test_swprintf(void) { TEST(i, swprintf(b, sizeof b/sizeof *b, fp_tests[j].fmt, fp_tests[j].f), wcslen(b), "%d != %d"); TEST_S(b, fp_tests[j].expect, "bad floating point conversion"); } + return test_status; } diff --git a/src/stdio/test.h b/src/stdio/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/stdio/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/stdio/ungetc.c b/src/stdio/ungetc.c index 230b327..9003a1c 100644 --- a/src/stdio/ungetc.c +++ b/src/stdio/ungetc.c @@ -13,14 +13,15 @@ !strcmp((s),(x)) || \ (error("[%s] != [%s] (%s)\n", s, x, m), 0) ) -void test_ungetc(void) { +int main(void) +{ int i; char a[100]; FILE *f; TEST(i, !(f = tmpfile()), 0, "failed to create temp file %d!=%d (%s)"); - if (!f) return; + if (!f) return test_status; TEST(i, fprintf(f, "hello, world\n"), 13, "%d != %d (%m)"); TEST(i, fseek(f, 0, SEEK_SET), 0, "%d != %d (%m)"); @@ -48,4 +49,5 @@ void test_ungetc(void) { TEST(i, fgetc(f), 'h', "'%c' != '%c'"); fclose(f); + return test_status; } diff --git a/src/stdlib/Makefile b/src/stdlib/Makefile index 278e884..645640b 100644 --- a/src/stdlib/Makefile +++ b/src/stdlib/Makefile @@ -1,2 +1,3 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc +LDFLAGS+=-lm + diff --git a/src/stdlib/qsort.c b/src/stdlib/qsort.c index 6edbc17..b45c080 100644 --- a/src/stdlib/qsort.c +++ b/src/stdlib/qsort.c @@ -30,7 +30,8 @@ static int n[] = { 848405, 3434, 3434344, 3535, 93994, 2230404, 4334 }; -void test_qsort(void) { +int main(void) +{ int i; qsort(s, sizeof(s)/sizeof(char *), sizeof(char *), scmp); @@ -38,7 +39,7 @@ void test_qsort(void) { if (strcmp(s[i], s[i+1]) > 0) { error("string sort failed at index %d\n", i); for (i=0; i n[i+1]) { error("integer sort failed at index %d\n", i); for (i=0; i #include -#include #include #include "test.h" -/* r = place to store result - * f = function call to test (or any expression) - * x = expected result - * m = message to print on failure (with formats for r & x) -**/ +#define length(x) (sizeof(x) / sizeof *(x)) -#define TEST(r, f, x, m) ( \ - ((r) = (f)) == (x) || \ - (error("%s failed (" m ")\n", #f, r, x, r-x), 0) ) - -void test_strtod_simple(void) { - int i; - double d, d2; - char buf[1000]; - - for (i=0; i<100; i++) { - d = sin(i); - snprintf(buf, sizeof buf, "%.300f", d); - TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)"); - } - - TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a"); - TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a"); -} - -#define length(x) (sizeof(x) / sizeof(*(x))) - -/* TODO: float exceptions, rounding mode, endptr check */ - -static struct { - char *s; - long double f; -} tl[] = { - {"12.345", 12.345L}, - {"1.2345e1", 12.345L}, - // 2^-16445 * 0.5 - eps - {".1822599765941237301264202966809709908199525407846781671860490243514185844316698e-4950", 0}, - // 2^-16445 * 0.5 + eps - {".1822599765941237301264202966809709908199525407846781671860490243514185844316699e-4950", 0x1p-16445L}, - // 2^-16445 * 1.5 - eps - {".5467799297823711903792608900429129724598576223540345015581470730542557532950096e-4950", 0x1p-16445L}, - // 2^-16445 * 1.5 + eps - {".5467799297823711903792608900429129724598576223540345015581470730542557532950097e-4950", 0x1p-16444L}, - // 2^-16382 + 2^-16446 - eps - {".3362103143112093506444937793915876332724499641527442230928779770593420866576777e-4931", 0x1p-16382L}, - // 2^-16382 + 2^-16446 + eps - {".3362103143112093506444937793915876332724499641527442230928779770593420866576778e-4931", 0x1.0000000000000002p-16382L}, - // 2^16384 - 2^16319 - eps - {"118973149535723176505351158982948.86679662540046955672e4900", 0x1.fffffffffffffffep16383L}, - // 2^16384 - 2^16319 + eps - {"118973149535723176505351158982948.86679662540046955673e4900", INFINITY}, -}; static struct { char *s; double f; @@ -109,43 +58,8 @@ static struct { {"0.9709481716420048341897258980454298205278e8", 97094817.164200485}, // 0x1.7263284a8242cp+26 {"0.4996908522051874110779982354932499499602e9", 499690852.20518744}, // 0x1.dc8ad6434872ap+28 }; -static struct { - char *s; - float f; -} tf[] = { - // 2^-149 * 0.5 - eps - {".7006492321624085354618647916449580656401309709382578858785341419448955413429303e-45", 0}, - // 2^-149 * 0.5 + eps - {".7006492321624085354618647916449580656401309709382578858785341419448955413429304e-45", 0x1p-149}, - // 2^-149 * 0.5 - eps - {".2101947696487225606385594374934874196920392912814773657635602425834686624028790e-44", 0x1p-149}, - // 2^-149 * 0.5 + eps - {".2101947696487225606385594374934874196920392912814773657635602425834686624028791e-44", 0x1p-148}, - // 2^-126 + 2^-150 - eps - {".1175494420887210724209590083408724842314472120785184615334540294131831453944281e-37", 0x1p-126}, - // 2^-126 + 2^-150 + eps - {".1175494420887210724209590083408724842314472120785184615334540294131831453944282e-37", 0x1.000002p-126}, - // 2^128 - 2^103 - eps - {"340282356779733661637539395458142568447.9999999999999999999", 0x1.fffffep127}, - // 2^128 - 2^103 - {"340282356779733661637539395458142568448", INFINITY}, -}; - -void test_strtold() -{ - int i; - long double x; - char *p; - - for (i = 0; i < length(tl); i++) { - x = strtold(tl[i].s, &p); - if (x != tl[i].f) - error("strtold(\"%s\") want %La got %La\n", tl[i].s, tl[i].f, x); - } -} - -void test_strtod() +int main(void) { int i; double x; @@ -156,39 +70,6 @@ void test_strtod() if (x != t[i].f) error("strtod(\"%s\") want %a got %a\n", t[i].s, t[i].f, x); } -} - -void test_strtof() -{ - int i; - float x; - char *p; - - for (i = 0; i < length(tf); i++) { - x = strtof(tf[i].s, &p); - if (x != tf[i].f) - error("strtof(\"%s\") want %a got %a\n", tf[i].s, tf[i].f, x); - } -} - -void bench_strtod(int N) -{ - volatile double y; - char *p; - int i; - - for (i = 0; i < N; i++) - y = strtod("2740037.230228005325852424697698331177377e-7", &p); -} - - -void bench_strtold_big(int N) -{ - volatile long double y; - char *p; - int i; - - for (i = 0; i < N; i++) - y = strtold("118973149535723176505351158982948.86679662540046955672e4900", &p); + return test_status; } diff --git a/src/stdlib/strtod_long.c b/src/stdlib/strtod_long.c new file mode 100644 index 0000000..d2db2e8 --- /dev/null +++ b/src/stdlib/strtod_long.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include "test.h" + +int main(void) +{ + double x, want = .1111111111111111111111; + char buf[40000]; + + memset(buf, '1', sizeof buf); + buf[0] = '.'; + buf[sizeof buf - 1] = 0; + + if ((x=strtod(buf, 0)) != want) + error("strtod(.11[...]1) got %a want %a\n", x, want); + return test_status; +} + diff --git a/src/stdlib/strtod_simple.c b/src/stdlib/strtod_simple.c new file mode 100644 index 0000000..c95dc9e --- /dev/null +++ b/src/stdlib/strtod_simple.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include "test.h" + +/* r = place to store result + * f = function call to test (or any expression) + * x = expected result + * m = message to print on failure (with formats for r & x) +**/ + +#define TEST(r, f, x, m) ( \ + ((r) = (f)) == (x) || \ + (error("%s failed (" m ")\n", #f, r, x, r-x), 0) ) + +int main(void) +{ + int i; + double d, d2; + char buf[1000]; + + for (i=0; i<100; i++) { + d = sin(i); + snprintf(buf, sizeof buf, "%.300f", d); + TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)"); + } + + TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a"); + TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a"); + return test_status; +} + diff --git a/src/stdlib/strtof.c b/src/stdlib/strtof.c new file mode 100644 index 0000000..29876bc --- /dev/null +++ b/src/stdlib/strtof.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include "test.h" + +#define length(x) (sizeof(x) / sizeof *(x)) + +static struct { + char *s; + float f; +} t[] = { + // 2^-149 * 0.5 - eps + {".7006492321624085354618647916449580656401309709382578858785341419448955413429303e-45", 0}, + // 2^-149 * 0.5 + eps + {".7006492321624085354618647916449580656401309709382578858785341419448955413429304e-45", 0x1p-149}, + // 2^-149 * 0.5 - eps + {".2101947696487225606385594374934874196920392912814773657635602425834686624028790e-44", 0x1p-149}, + // 2^-149 * 0.5 + eps + {".2101947696487225606385594374934874196920392912814773657635602425834686624028791e-44", 0x1p-148}, + // 2^-126 + 2^-150 - eps + {".1175494420887210724209590083408724842314472120785184615334540294131831453944281e-37", 0x1p-126}, + // 2^-126 + 2^-150 + eps + {".1175494420887210724209590083408724842314472120785184615334540294131831453944282e-37", 0x1.000002p-126}, + // 2^128 - 2^103 - eps + {"340282356779733661637539395458142568447.9999999999999999999", 0x1.fffffep127}, + // 2^128 - 2^103 + {"340282356779733661637539395458142568448", INFINITY}, +}; + +int main(void) +{ + int i; + float x; + char *p; + + for (i = 0; i < length(t); i++) { + x = strtof(t[i].s, &p); + if (x != t[i].f) + error("strtof(\"%s\") want %a got %a\n", t[i].s, t[i].f, x); + } + return test_status; +} diff --git a/src/stdlib/strtol.c b/src/stdlib/strtol.c index 7d15542..81df887 100644 --- a/src/stdlib/strtol.c +++ b/src/stdlib/strtol.c @@ -18,7 +18,8 @@ ((r) = (f)) == (x) || \ (error("%s failed (" m ")\n", msg, r, x), 0) ) -void test_strtol(void) { +int main(void) +{ int i; long l; unsigned long ul; @@ -69,4 +70,5 @@ void test_strtol(void) { TEST(l, strtol(s="123", &c, 37), 0, "%ld != %ld"); TEST2(i, c-s, 0, "wrong final position %d != %d"); TEST2(i, errno, EINVAL, "%d != %d"); + return test_status; } diff --git a/src/stdlib/strtold.c b/src/stdlib/strtold.c new file mode 100644 index 0000000..e37f7f0 --- /dev/null +++ b/src/stdlib/strtold.c @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include "test.h" + +#define length(x) (sizeof(x) / sizeof *(x)) + +static struct { + char *s; + long double f; +} t[] = { + {"0", 0.0}, + {"12.345", 12.345L}, + {"1.2345e1", 12.345L}, + {"1e+1000000", INFINITY}, + {"1e-1000000", 0}, +#if LDBL_MANT_DIG == 53 + // 2^-1074 * 0.5 - eps + {".2470328229206232720882843964341106861825299013071623822127928412503377536351043e-323", 0}, + // 2^-1074 * 0.5 + eps + {".2470328229206232720882843964341106861825299013071623822127928412503377536351044e-323", 0x1p-1074}, + // 2^-1074 * 1.5 - eps + {".7410984687618698162648531893023320585475897039214871466383785237510132609053131e-323", 0x1p-1074}, + // 2^-1074 * 1.5 + eps + {".7410984687618698162648531893023320585475897039214871466383785237510132609053132e-323", 0x1p-1073}, + // 2^-1022 + 2^-1075 - eps + {".2225073858507201630123055637955676152503612414573018013083228724049586647606759e-307", 0x1p-1022}, + // 2^-1022 + 2^-1075 + eps + {".2225073858507201630123055637955676152503612414573018013083228724049586647606760e-307", 0x1.0000000000001p-1022}, + // 2^1024 - 2^970 - eps + {"17976931348623158079372897140530341507993413271003782693617377898044" + "49682927647509466490179775872070963302864166928879109465555478519404" + "02630657488671505820681908902000708383676273854845817711531764475730" + "27006985557136695962284291481986083493647529271907416844436551070434" + "2711559699508093042880177904174497791.999999999999999999999999999999", 0x1.fffffffffffffp1023}, + // 2^1024 - 2^970 + {"17976931348623158079372897140530341507993413271003782693617377898044" + "49682927647509466490179775872070963302864166928879109465555478519404" + "02630657488671505820681908902000708383676273854845817711531764475730" + "27006985557136695962284291481986083493647529271907416844436551070434" + "2711559699508093042880177904174497792", INFINITY}, + // some random numbers + {".5961860348131807091861002266453941950428e00", 0.59618603481318067}, // 0x1.313f4bc3b584cp-1 + {"1.815013169218038729887460898733526957442e-1", 0.18150131692180388}, // 0x1.73b6f662e1712p-3 + {"42.07082357534453600681618685682257590772e-2", 0.42070823575344535}, // 0x1.aece23c6e028dp-2 + {"665.4686306516261456328973225579833470816e-3", 0.66546863065162609}, // 0x1.54b84dea53453p-1 + {"6101.852922970868621786690495485449831753e-4", 0.61018529229708685}, // 0x1.386a34e5d516bp-1 + {"76966.95208236968077849464348875471158549e-5", 0.76966952082369677}, // 0x1.8a121f9954dfap-1 + {"250506.5322228682496132604807222923702304e-6", 0.25050653222286823}, // 0x1.0084c8cd538c2p-2 + {"2740037.230228005325852424697698331177377e-7", 0.27400372302280052}, // 0x1.18946e9575ef4p-2 + {"20723093.50049742645941529268715428324490e-8", 0.20723093500497428}, // 0x1.a868b14486e4dp-3 + {"0.7900280238081604956226011047460238748912e1", 7.9002802380816046}, // 0x1.f99e3100f2eaep+2 + {"0.9822860653737296848190558448760465863597e2", 98.228606537372968}, // 0x1.88ea17d506accp+6 + {"0.7468949723190370809405570560160405324869e3", 746.89497231903704}, // 0x1.75728e73f48b7p+9 + {"0.1630268320282728475980459844271031751665e4", 1630.2683202827284}, // 0x1.97912c28d5cbp+10 + {"0.4637168629719170695109918769645492022088e5", 46371.686297191707}, // 0x1.6a475f6258737p+15 + {"0.6537805944497711554209461686415872067523e6", 653780.59444977110}, // 0x1.3f3a9305bb86cp+19 + {"0.2346324356502437045212230713960457676531e6", 234632.43565024371}, // 0x1.ca4437c3631eap+17 + {"0.9709481716420048341897258980454298205278e8", 97094817.164200485}, // 0x1.7263284a8242cp+26 + {"0.4996908522051874110779982354932499499602e9", 499690852.20518744}, // 0x1.dc8ad6434872ap+28 +#elif LDBL_MANT_DIG == 64 + // 2^-16445 * 0.5 - eps + {".1822599765941237301264202966809709908199525407846781671860490243514185844316698e-4950", 0}, + // 2^-16445 * 0.5 + eps + {".1822599765941237301264202966809709908199525407846781671860490243514185844316699e-4950", 0x1p-16445L}, + // 2^-16445 * 1.5 - eps + {".5467799297823711903792608900429129724598576223540345015581470730542557532950096e-4950", 0x1p-16445L}, + // 2^-16445 * 1.5 + eps + {".5467799297823711903792608900429129724598576223540345015581470730542557532950097e-4950", 0x1p-16444L}, + // 2^-16382 + 2^-16446 - eps + {".3362103143112093506444937793915876332724499641527442230928779770593420866576777e-4931", 0x1p-16382L}, + // 2^-16382 + 2^-16446 + eps + {".3362103143112093506444937793915876332724499641527442230928779770593420866576778e-4931", 0x1.0000000000000002p-16382L}, + // 2^16384 - 2^16319 - eps + {"118973149535723176505351158982948.86679662540046955672e4900", 0x1.fffffffffffffffep16383L}, + // 2^16384 - 2^16319 + eps + {"118973149535723176505351158982948.86679662540046955673e4900", INFINITY}, +#endif +}; + +int main(void) +{ + int i; + long double x; + char *p; + + for (i = 0; i < length(t); i++) { + x = strtold(t[i].s, &p); + if (x != t[i].f) + error("strtold(\"%s\") want %La got %La\n", t[i].s, t[i].f, x); + } + return test_status; +} diff --git a/src/stdlib/test.h b/src/stdlib/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/stdlib/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/stdlib/wcstol.c b/src/stdlib/wcstol.c index c92fa2d..abd76af 100644 --- a/src/stdlib/wcstol.c +++ b/src/stdlib/wcstol.c @@ -13,7 +13,8 @@ ((r) = (f)) == (x) || \ (error("%s failed (" m ")\n", msg, r, x), 0) ) -void test_wcstol(void) { +int main(void) +{ int i; long l; unsigned long ul; @@ -62,4 +63,5 @@ void test_wcstol(void) { TEST(l, wcstol(s=L"123", &c, 37), 0, "%ld != %ld"); TEST2(i, c-s, 0, "wrong final position %d != %d"); TEST2(i, errno, EINVAL, "%d != %d"); + return test_status; } diff --git a/src/string/Makefile b/src/string/Makefile index 278e884..4105e2a 100644 --- a/src/string/Makefile +++ b/src/string/Makefile @@ -1,2 +1,2 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc + diff --git a/src/string/bench.c b/src/string/bench.c deleted file mode 100644 index 9f0a7f5..0000000 --- a/src/string/bench.c +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include -#include "test.h" - -#define LEN 200000 - -static int bstrstr(int N, const char *needle) { - size_t l = strlen(needle); - size_t cnt = 10000; - int i; - int cs = 0; - char *haystack = malloc(l * cnt + 1); - - for (i=0; i +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/thread/Makefile b/src/thread/Makefile index 278e884..c799ad6 100644 --- a/src/thread/Makefile +++ b/src/thread/Makefile @@ -1,2 +1,8 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc +LDFLAGS+=-lpthread + +sem: LDFLAGS += -lrt +tls_align_dlopen: LDFLAGS += -ldl + +tls_align: tls_align_dso.so + diff --git a/src/thread/bench.c b/src/thread/bench.c deleted file mode 100644 index 10937aa..0000000 --- a/src/thread/bench.c +++ /dev/null @@ -1,106 +0,0 @@ -#define _XOPEN_SOURCE 700 -#include -#include -#include -#include -#include -#include "test.h" - -void *emptyfunc(void *dummy) { - return 0; -} - -void bench_pthread_createjoin_serial1(int N) { - int i; - pthread_t td; - void *dummy; - - for (i=0; i +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/thread/tls_align.c b/src/thread/tls_align.c new file mode 100644 index 0000000..7607833 --- /dev/null +++ b/src/thread/tls_align.c @@ -0,0 +1,23 @@ +#include +#include "test.h" + +extern struct { + char *name; + size_t size; + size_t align; + size_t addr; +} t[4]; + +int main() +{ + int i; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + if (!t[i].name) + error("name is not set for t[%d]\n", i); + if (t[i].addr & (t[i].align-1)) + error("bad alignment: %s, size: %u, align: %u, addr: 0x%lx\n", + t[i].name, (unsigned)t[i].size, (unsigned)t[i].align, (unsigned long)t[i].addr); + } + return test_status; +} diff --git a/src/thread/tls_align_dlopen.c b/src/thread/tls_align_dlopen.c new file mode 100644 index 0000000..33c8ae6 --- /dev/null +++ b/src/thread/tls_align_dlopen.c @@ -0,0 +1,31 @@ +#include +#include +#include "test.h" + +int main() +{ + int i; + void *h; + struct { + char *name; + size_t size; + size_t align; + size_t addr; + } *t; + + h = dlopen("./tls_align_dso.so", RTLD_LAZY); + if (!h) + error("dlopen failed\n"); + t = dlsym(h, "t"); + if (!t) + error("dlsym failed\n"); + + for (i = 0; i < 4; i++) { + if (!t[i].name) + error("name is not set for t[%d]\n", i); + if (t[i].addr & (t[i].align-1)) + error("bad alignment: %s, size: %lu, align: %lu, addr: 0x%lx\n", + t[i].name, (unsigned long)t[i].size, (unsigned long)t[i].align, (unsigned long)t[i].addr); + } + return test_status; +} diff --git a/src/thread/tls_align_dso.c b/src/thread/tls_align_dso.c new file mode 100644 index 0000000..c78e929 --- /dev/null +++ b/src/thread/tls_align_dso.c @@ -0,0 +1,32 @@ +#include + +__thread char c1 = 1; +__thread char xchar = 2; +__thread char c2 = 3; +__thread short xshort = 4; +__thread char c3 = 5; +__thread int xint = 6; +__thread char c4 = 7; +__thread long long xllong = 8; + +struct { + char *name; + size_t size; + size_t align; + size_t addr; +} t[4]; + +#define entry(i,x) \ + t[i].name = #x; \ + t[i].size = sizeof x; \ + t[i].align = __alignof__(x); \ + t[i].addr = (size_t)&x; + +__attribute__((constructor)) static void init(void) +{ + entry(0, xchar) + entry(1, xshort) + entry(2, xint) + entry(3, xllong) +} + diff --git a/src/thread/tls_init.c b/src/thread/tls_init.c new file mode 100644 index 0000000..8a43829 --- /dev/null +++ b/src/thread/tls_init.c @@ -0,0 +1,42 @@ +#include +#include "test.h" + +__thread int tls_fix = 23; +__thread int tls_zero; + +static void *f(void *arg) +{ + if (tls_fix != 23) + error("fixed init failed: want 23 got %d\n", tls_fix); + if (tls_zero != 0) + error("zero init failed: want 0 got %d\n", tls_zero); + tls_fix++; + tls_zero++; + return 0; +} + +#define CHECK(f) do{ if(f) error("%s failed.\n", #f); }while(0) +#define length(a) (sizeof(a)/sizeof*(a)) + +int main() +{ + pthread_t t[5]; + int i, j; + + if (tls_fix != 23) + error("fixed init failed: want 23 got %d\n", tls_fix); + if (tls_zero != 0) + error("zero init failed: want 0 got %d\n", tls_zero); + + for (j = 0; j < 2; j++) { + for (i = 0; i < length(t); i++) { + CHECK(pthread_create(t+i, 0, f, 0)); + tls_fix++; + tls_zero++; + } + for (i = 0; i < length(t); i++) + CHECK(pthread_join(t[i], 0)); + } + + return test_status; +} diff --git a/src/time/Makefile b/src/time/Makefile index 278e884..ee4552b 100644 --- a/src/time/Makefile +++ b/src/time/Makefile @@ -1,2 +1 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc diff --git a/src/time/test.h b/src/time/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/time/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/time/time.c b/src/time/time.c index a06aac7..27598b8 100644 --- a/src/time/time.c +++ b/src/time/time.c @@ -6,7 +6,7 @@ /* We use this instead of memcmp because some broken C libraries * add additional nonstandard fields to struct tm... */ - + int tm_cmp(struct tm tm1, struct tm tm2) { return tm1.tm_sec != tm2.tm_sec || @@ -50,7 +50,8 @@ char *tm_str(struct tm tm) ((r) = (f)) == (x) || \ (error("%s failed (" m ")\n", #f, r, x), 0) ) -void test_time(void) { +int main(void) +{ struct tm tm, *tm_p; time_t t; @@ -71,4 +72,5 @@ void test_time(void) { TEST_TM(*tm_p, TM_Y2038, "mktime/gmtime(Y2038)"); /* FIXME: set a TZ var and check DST boundary conditions */ + return test_status; } diff --git a/src/udiv/Makefile b/src/udiv/Makefile index 278e884..ee4552b 100644 --- a/src/udiv/Makefile +++ b/src/udiv/Makefile @@ -1,2 +1 @@ -TROOT=../.. -include $(TROOT)/Makefile.inc +include ../../Makefile.inc diff --git a/src/udiv/test.h b/src/udiv/test.h new file mode 100644 index 0000000..a6a7706 --- /dev/null +++ b/src/udiv/test.h @@ -0,0 +1,20 @@ +#include +#include +#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) + +static int test_status; + +static int test_error(const char *n, int l, const char *s, ...) +{ + va_list ap; + + if (test_status == 0) + printf("FAIL\n"); + test_status = 1; + printf(" ERROR %s:%d: ", n, l); + va_start(ap, s); + vprintf(s, ap); + va_end(ap); + return -1; +} + diff --git a/src/udiv/udiv.c b/src/udiv/udiv.c index 42010ee..e5b6d2c 100644 --- a/src/udiv/udiv.c +++ b/src/udiv/udiv.c @@ -149,7 +149,7 @@ static struct { 0x4b21d01617167e39ull, 0x2ull, 0x2590e80b0b8b3f1cull, 0x1ull, }; -void test_udiv() +int main(void) { uint64_t x, y, div, mod; int i; @@ -164,34 +164,5 @@ void test_udiv() if (mod != t[i].mod) error("umod %llu%%%llu want %llu got %llu\n", x, y, t[i].mod, mod); } -} - -void bench_udiv(int N) -{ - int i; - volatile uint64_t r = 0; - uint64_t d = 111222333444ull; - - for (i = 0; i < N; i++) - r += ((uint64_t)i<<32) / d; -} - -void bench_umod(int N) -{ - int i; - volatile uint64_t r = 0; - uint64_t d = 111222333444ull; - - for (i = 0; i < N; i++) - r += ((uint64_t)i<<32) % d; -} - -void bench_fdiv(int N) -{ - int i; - volatile double r = 0; - double d = 111222333444.0; - - for (i = 0; i < N; i++) - r += i / d; + return test_status; } -- 2.20.1