summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile162
-rw-r--r--math.c56
-rwxr-xr-xtest.sh16
3 files changed, 234 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..339da87
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,162 @@
+CC=gcc
+CFLAGS=-O3 -mcpu=ev67 -mieee -funroll-loops
+
+TESTS= sin_glibc sin_cpml cos_glibc cos_cpml tan_glibc tan_cpml \
+ sinh_glibc sinh_cpml cosh_glibc cosh_cpml tanh_glibc tanh_cpml \
+ asin_glibc asin_cpml acos_glibc acos_cpml atan_glibc atan_cpml \
+ asinh_glibc asinh_cpml acosh_glibc acosh_cpml atanh_glibc atanh_cpml \
+ floor_glibc floor_cpml ceil_glibc ceil_cpml \
+ round_glibc round_cpml trunc_glibc trunc_cpml \
+ log_glibc log_cpml log10_glibc log10_cpml log2_glibc log2_cpml log1p_glibc log1p_cpml \
+ exp_glibc exp_cpml expm1_glibc expm1_cpml exp2_glibc exp2_cpml
+
+
+all: $(TESTS)
+
+test: $(TESTS)
+ ./test.sh $(TESTS) > results.csv
+
+clean:
+ rm -f $(TESTS) results.csv
+
+rebuild: clean all
+remake: rebuild
+
+sin_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=sin -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lm
+
+sin_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=sin -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lcpml
+
+cos_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=cos -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lm
+
+cos_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=cos -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lcpml
+
+tan_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=tan -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lm
+
+tan_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=tan -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lcpml
+
+sinh_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=sinh -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lm
+
+sinh_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=sinh -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lcpml
+
+cosh_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=cosh -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lm
+
+cosh_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=cosh -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lcpml
+
+tanh_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=tanh -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lm
+
+tanh_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=tanh -DDOMAIN_START="-2.0*M_PI" -DDOMAIN_END="2.0*M_PI" $< -o $@ -lcpml
+
+asin_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=asin -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lm
+
+asin_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=asin -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lcpml
+
+acos_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=acos -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lm
+
+acos_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=acos -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lcpml
+
+atan_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=atan -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lm
+
+atan_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=atan -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lcpml
+
+asinh_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=asinh -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lm
+
+asinh_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=asinh -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lcpml
+
+acosh_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=acosh -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lm
+
+acosh_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=acosh -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lcpml
+
+atanh_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=atanh -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lm
+
+atanh_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=atanh -DDOMAIN_START="-1.0" -DDOMAIN_END="1.0" $< -o $@ -lcpml
+
+floor_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=floor -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+floor_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=floor -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+ceil_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=ceil -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+ceil_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=ceil -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+round_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=round -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+round_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=round -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+trunc_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=trunc -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+trunc_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=trunc -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+log_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=log -DDOMAIN_START="0.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+log_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=log -DDOMAIN_START="0.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+log10_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=log10 -DDOMAIN_START="0.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+log10_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=log10 -DDOMAIN_START="0.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+log2_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=log2 -DDOMAIN_START="0.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+log2_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=log2 -DDOMAIN_START="0.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+log1p_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=log1p -DDOMAIN_START="-0.75" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+log1p_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=log1p -DDOMAIN_START="-0.75" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+exp_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=exp -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+exp_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=exp -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+expm1_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=expm1 -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+expm1_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=expm1 -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
+exp2_glibc: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=exp2 -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lm
+
+exp2_cpml: math.c
+ ${CC} ${CFLAGS} -DFUNCTION=exp2 -DDOMAIN_START="-10.0" -DDOMAIN_END="10.0" -DINCREMENT="0.25" $< -o $@ -lcpml
+
diff --git a/math.c b/math.c
new file mode 100644
index 0000000..d6fc798
--- /dev/null
+++ b/math.c
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#include <math.h>
+#include <stdint.h>
+
+#define __rpcc __builtin_alpha_rpcc
+
+#define CPML "cpml"
+#define GLIBC "glibc"
+
+#ifndef FUNCTION
+#error Must define FUNCTION
+#else
+double FUNCTION(double);
+#endif
+
+#ifndef DOMAIN_START
+#error Must define RANGE_START
+#endif
+
+#ifndef DOMAIN_END
+#error Must define DOMAIN_END
+#endif
+
+#ifndef INCREMENT
+#define INCREMENT 0.1
+#endif
+
+int main(int argc, char * argv[]) {
+ double x;
+ double results[100];
+ int i;
+ int iterations;
+
+ uint64_t start, end;
+
+ start = __rpcc();
+
+ for (i = 0, x = DOMAIN_START; x < DOMAIN_END; i++, x += INCREMENT) {
+ results[i] = FUNCTION(x);
+ }
+
+ end = __rpcc();
+
+ iterations = i;
+
+ if (argc != 1) {
+ for (i = 0; i < iterations; i++) {
+ printf("%f\n", results[i]);
+ }
+ }
+
+/* printf("%5s\t%5s\t%lu\n", LIB_NAME, FUNCTION_NAME, (end - start) / 30);*/
+ printf("%lu,", (end - start) / iterations);
+
+ return 0;
+}
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..78dbf4c
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+for x in $@ ; do
+ echo -en `expr match "$x" '\(.*\)_'`,`expr match "$x" '.*_\(.*\)'`,
+
+ # warm up the cache
+ for i in 1 2 3 ; do
+ ./$x &> /dev/null ;
+ done
+
+ # real benchmarking
+ for i in `seq 1 10`; do
+ ./$x ;
+ done
+ echo;
+done