commit 52f91804ff67246deab3d98c790f8b6b845afcde
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Fri Apr 8 15:53:31 2016 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Fri Apr 8 15:53:31 2016 +0200
Some improvements:
- Improve .gitignore
- Improve portability of the makefile
- Bring the translations, for gmp and tommath,
used by the benchmark up to date
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/.gitignore b/.gitignore
index 98a13ba..618db63 100644
--- a/.gitignore
+++ b/.gitignore
_AT_@ -1,5 +1,10 @@
-_/
*~
+\#*\#
+.\#*
+*.swo
+*.swp
+*.orig
+*.bak
*.o
*.su
*.a
diff --git a/Makefile b/Makefile
index ad98cf1..aae0a80 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -67,14 +67,42 @@ INLINE_FUN =\
zcmpu\
zbtest
-HDR = $(HDR_PUBLIC) $(HDR_PRIVATE)
-OBJ = $(FUN:=.o) allocator.o
+HDR = $(HDR_PUBLIC) $(HDR_PRIVATE)
+OBJ = $(FUN:=.o) allocator.o
MAN3 = $(FUN:=.3) $(INLINE_FUN:=.3)
MAN7 = libzahl.7
+VPATH = src
+
+BENCHMARK_LIB_ = libzahl.a
+BENCHMARK_LIB_zahl = libzahl.a
+BENCHMARK_LIB_libzahl = libzahl.a
+BENCHMARK_LIB_tommath = -ltommath
+BENCHMARK_LIB_libtommath = -ltommath
+BENCHMARK_LIB_gmp = -lgmp
+BENCHMARK_LIB_libgmp = -lgmp
+
+BENCHMARK_DEP_ = libzahl.a
+BENCHMARK_DEP_zahl = libzahl.a
+BENCHMARK_DEP_libzahl = libzahl.a
+BENCHMARK_DEP_tommath = bench/libtommath.h
+BENCHMARK_DEP_libtommath = bench/libtommath.h
+BENCHMARK_DEP_gmp = bench/libgmp.h
+BENCHMARK_DEP_libgmp = bench/libgmp.h
+
+BENCHMARK_CPP_tommath = '-DBENCHMARK_LIB="libtommath.h"'
+BENCHMARK_CPP_libtommath = '-DBENCHMARK_LIB="libtommath.h"'
+BENCHMARK_CPP_gmp = '-DBENCHMARK_LIB="libgmp.h"'
+BENCHMARK_CPP_libgmp = '-DBENCHMARK_LIB="libgmp.h"'
+
+CPPFLAGS += $(BENCHMARK_CPP_$(BENCHMARK_LIB))
+
+CFLAGS_WITHOUT_O = $$(printf '%s\n' $(CFLAGS) | sed '/^-O.*$$/d')
+
+
all: libzahl.a
-%.o: src/%.c $(HDR) config.mk
+.o: .c $(HDR) config.mk
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $_AT_ $<
libzahl.a: $(OBJ)
_AT_@ -85,19 +113,10 @@ test-random.c: test-generate.py
./test-generate.py > test-random.c
test: test.c libzahl.a test-random.c
- $(CC) $(LDFLAGS) $(CFLAGS:--O*) -O0 $(CPPFLAGS) -o $_AT_ test.c libzahl.a
+ $(CC) $(LDFLAGS) $(CFLAGS_WITHOUT_O) -O0 $(CPPFLAGS) -o $_AT_ test.c libzahl.a
-ifndef BENCHMARK_LIB
-benchmark: bench/benchmark.c libzahl.a
- $(CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS) -o $_AT_ $^
-endif
-ifdef BENCHMARK_LIB
-CPPFLAGS += -DBENCHMARK_LIB='"$(BENCHMARK_LIB).h"'
-BENCHMARK_libtommath = -ltommath
-BENCHMARK_libgmp = -lgmp
-benchmark: bench/benchmark.c bench/$(BENCHMARK_LIB).h
- $(CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS) -o $_AT_ bench/benchmark.c $(BENCHMARK_$(BENCHMARK_LIB))
-endif
+benchmark: bench/benchmark.c $(BENCHMARK_DEP_$(BENCHMARK_LIB))
+ $(CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS) -o $_AT_ bench/benchmark.c $(BENCHMARK_LIB_$(BENCHMARK_LIB))
benchmark-zrand: bench/benchmark-zrand.c libzahl.a
$(CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS) -o $_AT_ $^
_AT_@ -110,10 +129,14 @@ install: libzahl.a
mkdir -p -- "$(DESTDIR)$(PREFIX)/include"
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3"
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7"
+ _AT_if test -n "$(DESTDIR)"; then \
+ cd man && test -d "$(DESTDIR)$(MANPREFIX)/man7" || \
+ (printf '\n\n!! DESTDIR must be an absolute path. !!\n\n\n' ; exit 1) \
+ fi
cp -- libzahl.a "$(DESTDIR)$(EXECPREFIX)/lib"
cp -- $(HDR_PUBLIC) "$(DESTDIR)$(PREFIX)/include"
- cp -- $(foreach M,$(MAN3),man/$(M)) "$(DESTDIR)$(MANPREFIX)/man3"
- cp -- $(foreach M,$(MAN7),man/$(M)) "$(DESTDIR)$(MANPREFIX)/man7"
+ cd man && cp -- $(MAN3) "$(DESTDIR)$(MANPREFIX)/man3"
+ cd man && cp -- $(MAN7) "$(DESTDIR)$(MANPREFIX)/man7"
uninstall:
-rm -- "$(DESTDIR)$(EXECPREFIX)/lib/libzahl.a"
diff --git a/bench/benchmark.c b/bench/benchmark.c
index 68084f2..6649958 100644
--- a/bench/benchmark.c
+++ b/bench/benchmark.c
_AT_@ -18,7 +18,7 @@
i = FAST ? 1000000L : 1000L;\
clock_gettime(CLOCK_MONOTONIC_RAW, &start);\
while (i--) {\
- INSTRUCTION;\
+ (void)INSTRUCTION;\
}\
clock_gettime(CLOCK_MONOTONIC_RAW, &end);\
end.tv_sec -= start.tv_sec;\
diff --git a/bench/libgmp.h b/bench/libgmp.h
index 7dc74e2..1ea6dcb 100644
--- a/bench/libgmp.h
+++ b/bench/libgmp.h
_AT_@ -37,8 +37,15 @@ zunsetup(void)
}
#define FAST_RANDOM 0
+#define SECURE_RANDOM 0
+#define DEFAULT_RANDOM 0
+#define FASTEST_RANDOM 0
+#define LIBC_RAND_RANDOM 0
+#define LIBC_RANDOM_RANDOM 0
+#define LIBC_RAND48_RANDOM 0
#define QUASIUNIFORM 0
#define UNIFORM 1
+#define MODUNIFORM 2
#define zperror(x) ((void)0)
#define zinit mpz_init
_AT_@ -197,6 +204,13 @@ zrand(z_t r, int dev, int dist, z_t n)
mpz_urandomm(r, _randstate, n);
break;
+ case MODUNIFORM:
+ bits = zbits(n);
+ mpz_urandomb(r, _randstate, bits);
+ if (zcmp(r, n) > 0)
+ zsub(r, r, n);
+ break;
+
default:
abort();
}
diff --git a/bench/libtommath.h b/bench/libtommath.h
index 4a81373..25da3ff 100644
--- a/bench/libtommath.h
+++ b/bench/libtommath.h
_AT_@ -30,8 +30,15 @@ zunsetup(void)
}
#define FAST_RANDOM 0
+#define SECURE_RANDOM 0
+#define DEFAULT_RANDOM 0
+#define FASTEST_RANDOM 0
+#define LIBC_RAND_RANDOM 0
+#define LIBC_RANDOM_RANDOM 0
+#define LIBC_RAND48_RANDOM 0
#define QUASIUNIFORM 0
#define UNIFORM 1
+#define MODUNIFORM 2
#define zperror(x) ((void)0)
#define zinit(a) mp_init(a)
_AT_@ -76,12 +83,18 @@ zunsetup(void)
#define zstr_length(a, b) (mp_radix_size(a, b, &_tmp), _tmp)
#define zstr(a, s) mp_toradix(a, s, 10)
#define zptest(w, a, t) (mp_prime_is_prime(a, t, &_tmp), _tmp) /* Note, the witness is not returned. */
-#define zsave(a, s) ((_tmp = ((s) ? mp_signed_bin_size(a) : mp_to_signed_bin(a, s))))
-#define zload(a, s) mp_read_signed_bin(a, s, _tmp)
+#define zload(a, s) mp_read_signed_bin(a, (unsigned char *)s, _tmp)
#define zdiv(r, a, b) mp_div(a, b, r, 0)
#define zmod(r, a, b) mp_mod(a, b, r)
#define zdivmod(q, r, a, b) mp_div(a, b, q, r)
+static int
+zsave(z_t a, char *buf)
+{
+ _tmp = buf ? mp_signed_bin_size(a) : mp_to_signed_bin(a, (unsigned char *)buf);
+ return _tmp;
+}
+
static void
zsetu(z_t r, unsigned long long int val)
{
_AT_@ -183,6 +196,12 @@ zrand(z_t r, int dev, int dist, z_t n)
}
break;
+ case MODUNIFORM:
+ mp_rand(r, bits);
+ if (zcmp(r, n) > 0)
+ zsub(r, r, n);
+ break;
+
default:
abort();
}
Received on Fri Apr 08 2016 - 15:55:06 CEST
This archive was generated by hypermail 2.3.0
: Fri Apr 08 2016 - 16:00:17 CEST