aboutsummaryrefslogtreecommitdiffstats
path: root/bench
diff options
context:
space:
mode:
Diffstat (limited to 'bench')
-rw-r--r--bench/benchmark-func.c6
-rw-r--r--bench/benchmark.c3
-rw-r--r--bench/libgmp.h2
-rw-r--r--bench/libhebimath.h4
-rw-r--r--bench/libtfm.h2
-rw-r--r--bench/libtommath.h2
6 files changed, 11 insertions, 8 deletions
diff --git a/bench/benchmark-func.c b/bench/benchmark-func.c
index e5fb08b..82368a7 100644
--- a/bench/benchmark-func.c
+++ b/bench/benchmark-func.c
@@ -164,7 +164,8 @@ FUNCTION_2D(bench_zcmp, zcmp(temp2, *a),)
FUNCTION_2D(bench_sqr_zmul, zmul(temp, *a, temp2),)
FUNCTION_2D(bench_zsqr, zsqr(temp, *a),)
FUNCTION_2D(bench_zstr_length, zstr_length(*a, 10),)
-FUNCTION_2D(bench_zstr, zstr(*a, buf),)
+FUNCTION_2D(bench_zstr, zstr(*a, buf, sizeof(buf) - 1),)
+FUNCTION_2D(bench_auto_zstr, zstr(*a, buf, 0),)
FUNCTION_2D(bench_zsave, zsave(*a, buf),)
FUNCTION_2D(bench_zload, zload(temp, buf), zsave(*a, buf))
FUNCTION_2D(bench_zbset_set, zbset(temp, *a, 2, 1),)
@@ -175,7 +176,7 @@ FUNCTION_2D(bench_self_zbset_clear, zbset(temp2, temp2, 2, 0),)
FUNCTION_2D(bench_self_zbset_flip, zbset(temp2, temp2, 2, -1),)
FUNCTION_2D(bench_zbtest, zbtest(*a, 2),)
FUNCTION_2D(bench_zptest, zptest(temp, *a, 5),)
-FUNCTION_2D(bench_zsets, zsets(temp, buf), zstr(*a, buf))
+FUNCTION_2D(bench_zsets, zsets(temp, buf), zstr(*a, buf, sizeof(buf) - 1))
FUNCTION_2D(bench_zlsh, zlsh(temp, *a, 1),)
FUNCTION_2D(bench_zrsh, zrsh(temp, *a, 1),)
FUNCTION_2D(bench_ztrunc, ztrunc(temp, *a, i / 2),)
@@ -231,6 +232,7 @@ struct function functions[] = {
{F(zsqr), 1, 4097, 64, FULL, 0, 0, 0, 0, 10, 20},
{F(zstr_length), 1, 4097, 64, FULL, 0, 0, 0, 0, 10, 20},
{F(zstr), 1, 4097, 64, FULL, 0, 0, 0, 0, 10, 20},
+ {F(auto_zstr), 1, 4097, 64, FULL, 0, 0, 0, 0, 10, 20},
{F(zsave), 1, 4097, 64, FULL, 0, 0, 0, 0, 1000, M_MAX},
{F(zload), 1, 4097, 64, FULL, 0, 0, 0, 0, 1000, M_MAX},
diff --git a/bench/benchmark.c b/bench/benchmark.c
index 27efee1..2c3f464 100644
--- a/bench/benchmark.c
+++ b/bench/benchmark.c
@@ -117,7 +117,8 @@ main(int argc, char *argv[])
BENCHMARK(zmodpowu(c, a, 12, b), 0);
BENCHMARK(zsets(c, "5495468234592964023447280368442884381000481887"), 0);
BENCHMARK(zstr_length(a, 10), 0);
- BENCHMARK(zstr(a, buf), 0);
+ BENCHMARK(zstr(a, buf, 0), 0);
+ BENCHMARK(zstr(a, buf, sizeof(buf) - 1), 0);
BENCHMARK(zrand(c, DEFAULT_RANDOM, QUASIUNIFORM, a), 0);
BENCHMARK(zrand(c, DEFAULT_RANDOM, UNIFORM, a), 0);
BENCHMARK(zptest(d, a, 5), 0);
diff --git a/bench/libgmp.h b/bench/libgmp.h
index 95a518d..42b2d1e 100644
--- a/bench/libgmp.h
+++ b/bench/libgmp.h
@@ -91,7 +91,7 @@ zunsetup(void)
#define zmodpowu mpz_powm_ui
#define zsets(a, s) mpz_set_str(a, s, 10)
#define zstr_length(a, b) (mpz_sizeinbase(a, 10) + (zsignum(a) < 0))
-#define zstr(a, s) mpz_get_str(s, 10, a)
+#define zstr(a, s, n) ((void)n, mpz_get_str(s, 10, a))
#define zptest(w, a, t) mpz_probab_prime_p(a, t) /* Note, the witness is not returned. */
#define zdiv mpz_tdiv_q
#define zmod mpz_tdiv_r
diff --git a/bench/libhebimath.h b/bench/libhebimath.h
index e2ef936..7ddd6d6 100644
--- a/bench/libhebimath.h
+++ b/bench/libhebimath.h
@@ -79,11 +79,11 @@ zunsetup(void)
#define zpow(r, a, b) zpowu(r, a, hebi_get_u(b))
#define zmodpow(r, a, b, m) zmodpowu(r, a, hebi_get_u(b), m)
#define zsets(a, s) hebi_set_str(a, s, 0, 10)
-#define zstr(a, s) hebi_get_str(s, sizeof(s), a, 10) /* Assumes s is [], not * */
+#define zstr(a, s, n) hebi_get_str(s, n ? n : zstr_length(a, 10) + 1, a, 10)
#define zdiv(q, a, b) hebi_div(q, 0, a, b)
#define zmod(r, a, b) hebi_div(_a, r, a, b)
#define zdivmod(q, r, a, b) hebi_div(q, r, a, b)
-#define zsave(a, s) zstr(a, s)
+#define zsave(a, s) zstr(a, s, sizeof(s) - 1)
#define zload(a, s) zsets(a, s)
static size_t
diff --git a/bench/libtfm.h b/bench/libtfm.h
index 00e175f..1d8ade3 100644
--- a/bench/libtfm.h
+++ b/bench/libtfm.h
@@ -83,7 +83,7 @@ zunsetup(void)
#define zmodpowu(r, a, b, m) (fp_set_int(_b, b), fp_exptmod(a, _b, m, r))
#define zsets(a, s) fp_read_radix(a, s, 10)
#define zstr_length(a, b) (fp_radix_size(a, b, &_tmp), _tmp)
-#define zstr(a, s) fp_toradix(a, s, 10)
+#define zstr(a, s, n) ((void)n, fp_toradix(a, s, 10))
#define zptest(w, a, t) fp_isprime_ex(a, t) /* Note, the witness is not returned. */
#define zload(a, s) fp_read_signed_bin(a, (unsigned char *)s, _tmp)
#define zdiv(r, a, b) fp_div(a, b, r, 0)
diff --git a/bench/libtommath.h b/bench/libtommath.h
index 1867bdb..ac7c95d 100644
--- a/bench/libtommath.h
+++ b/bench/libtommath.h
@@ -83,7 +83,7 @@ zunsetup(void)
#define zmodpowu(r, a, b, m) (mp_set_int(_b, b), mp_exptmod(a, _b, m, r))
#define zsets(a, s) mp_read_radix(a, s, 10)
#define zstr_length(a, b) (mp_radix_size(a, b, &_tmp), _tmp)
-#define zstr(a, s) mp_toradix(a, s, 10)
+#define zstr(a, s, n) ((void)n, 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 zload(a, s) mp_read_signed_bin(a, (unsigned char *)s, _tmp)
#define zdiv(r, a, b) mp_div(a, b, r, 0)