Skip to content

Commit 5167f6c

Browse files
authored
Merge pull request #490 from libtom/fix-488
Follow-up of #489
2 parents c18817c + 5d744e4 commit 5167f6c

21 files changed

+312
-208
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*.gcda
66
*.gcno
77
*.gcov
8+
*.dll
9+
*.exp
10+
*.pdb
811
*.lib
912
*.tmp
1013
[Dd]ebug/

.travis.yml

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# #
66
#############################################################################
77

8-
# Run the tests based on Ubuntu 16.04
9-
dist: xenial
8+
# The Ubuntu version we're going to use to run the tests
9+
dist: bionic
1010

1111
# Compilation failures are in gcc_errors_*.log
1212
# Failed tests in test_*.log
@@ -72,15 +72,26 @@ matrix:
7272
packages:
7373
- astyle
7474

75+
# Check public symbols of dynamic libraries
76+
- env: BUILDOPTIONS='--symbols'
77+
addons:
78+
apt:
79+
packages:
80+
- libtool-bin
81+
7582
# Run always with valgrind (no sanitizer, but debug info)
76-
- env: COMPILE_DEBUG=1 BUILDOPTIONS='--with-cc=gcc-4.9 --with-m64 --with-valgrind'
83+
- env: COMPILE_DEBUG=1 BUILDOPTIONS='--with-cc=gcc --with-m64 --with-valgrind'
84+
85+
# Shared library build
86+
- env: COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc --make-option=-f --make-option=makefile.shared'
7787
addons:
7888
apt:
7989
packages:
80-
- gcc-4.9
90+
- gcc-8
91+
- libtool-bin
8192

8293
# GCC for the 32-bit architecture (no valgrind)
83-
- env: BUILDOPTIONS='--with-cc=gcc-5 --with-m32'
94+
- env: BUILDOPTIONS='--with-cc=gcc --with-m32'
8495
addons:
8596
apt:
8697
packages:
@@ -108,9 +119,9 @@ matrix:
108119

109120
# GCC for the x86-64 architecture testing against a different Bigint-implementation
110121
# with 333333 different inputs.
111-
#- env: BUILDOPTIONS='--with-cc=gcc-5 --test-vs-mtest=333333 --with-travis-valgrind'
122+
#- env: BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --with-travis-valgrind'
112123
# ... and a better random source.
113-
- env: BUILDOPTIONS='--with-cc=gcc-5 --test-vs-mtest=333333 --mtest-real-rand --with-travis-valgrind'
124+
- env: BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --mtest-real-rand --with-travis-valgrind'
114125

115126
# clang for the x86-64 architecture testing against a different Bigint-implementation
116127
# with 333333 different inputs
@@ -121,20 +132,20 @@ matrix:
121132
# GCC for the x64_32 architecture (32-bit longs and 32-bit pointers)
122133
# TODO: Probably not possible to run anything in x32 in Travis
123134
# but needs to be checked to be sure.
124-
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --with-mx32'
135+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc --with-mx32'
125136
addons:
126137
apt:
127138
packages:
128139
- libc6-dev-x32
129140
- gcc-multilib
130141

131142
# GCC for the x86-64 architecture (64-bit longs and 64-bit pointers)
132-
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-travis-valgrind'
133-
- env: BUILDOPTIONS='--with-cc=gcc-4.7 --with-m64 --with-travis-valgrind'
143+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc --with-m64 --with-travis-valgrind'
144+
- env: BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-travis-valgrind'
134145
addons:
135146
apt:
136147
packages:
137-
- gcc-4.7
148+
- gcc-5
138149
- env: BUILDOPTIONS='--with-cc=gcc-4.8 --with-m64 --with-travis-valgrind'
139150
addons:
140151
apt:
@@ -147,6 +158,21 @@ matrix:
147158
- env: SANITIZER=1 CONV_WARNINGS=strict BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_USE_MEMOPS --with-m64 --with-travis-valgrind'
148159
- env: SANITIZER=1 CONV_WARNINGS=strict BUILDOPTIONS='--with-cc=clang-7 --c89 --with-m64 --with-travis-valgrind'
149160
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-travis-valgrind --cflags=-DMP_PREC=MP_MIN_PREC'
161+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-10 --with-m64 --with-travis-valgrind'
162+
addons:
163+
apt:
164+
packages:
165+
- clang-10
166+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-9 --with-m64 --with-travis-valgrind'
167+
addons:
168+
apt:
169+
packages:
170+
- clang-9
171+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-8 --with-m64 --with-travis-valgrind'
172+
addons:
173+
apt:
174+
packages:
175+
- clang-8
150176
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-6.0 --with-m64 --with-travis-valgrind'
151177
addons:
152178
apt:
@@ -164,18 +190,18 @@ matrix:
164190
- clang-4.0
165191

166192
# Link time optimization
167-
- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-travis-valgrind'
193+
- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc --with-m64 --with-travis-valgrind'
168194
#- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-travis-valgrind'
169195

170196
# GCC for the x86-64 architecture with restricted limb sizes
171197
# formerly started with the option "--with-low-mp" to testme.sh
172198
# but testing all three in one run took to long and timed out.
173-
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_16BIT --with-travis-valgrind'
174-
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_32BIT --with-travis-valgrind'
199+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_16BIT --with-travis-valgrind'
200+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_32BIT --with-travis-valgrind'
175201

176202
# clang for the x86-64 architecture with restricted limb sizes
177-
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_16BIT --with-travis-valgrind'
178-
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_32BIT --with-travis-valgrind'
203+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang --cflags=-DMP_16BIT --with-travis-valgrind'
204+
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang --cflags=-DMP_32BIT --with-travis-valgrind'
179205

180206
# Notifications go to
181207
# An email address is also possible.

appveyor.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ build_script:
1616
if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
1717
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
1818
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
19-
nmake -f makefile.msvc all
19+
nmake -f makefile.msvc test.exe
20+
nmake -f makefile.msvc clean-obj
21+
nmake -f makefile.msvc test_dll.exe CFLAGS="/Ox /MD /DLTM_TEST_DYNAMIC"
2022
test_script:
2123
- cmd: test.exe
24+
- cmd: test_dll.exe

s_mp_rand_jenkins.c renamed to demo/s_mp_rand_jenkins.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
/* Bob Jenkins' http://burtleburtle.net/bob/rand/smallprng.html */
77
/* Chosen for speed and a good "mix" */
8+
9+
/* TODO: jenkins prng is not thread safe as of now */
10+
811
typedef struct {
912
uint64_t a;
1013
uint64_t b;
@@ -25,7 +28,7 @@ static uint64_t s_rand_jenkins_val(void)
2528
return jenkins_x.d;
2629
}
2730

28-
void s_mp_rand_jenkins_init(uint64_t seed)
31+
static void s_mp_rand_jenkins_init(uint64_t seed)
2932
{
3033
int i;
3134
jenkins_x.a = 0xF1EA5EEDuL;
@@ -35,7 +38,7 @@ void s_mp_rand_jenkins_init(uint64_t seed)
3538
}
3639
}
3740

38-
mp_err s_mp_rand_jenkins(void *p, size_t n)
41+
static mp_err s_mp_rand_jenkins(void *p, size_t n)
3942
{
4043
char *q = (char *)p;
4144
while (n > 0u) {

demo/test.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include <inttypes.h>
22
#include "shared.h"
33

4+
#define S_MP_RAND_JENKINS_C
5+
#include "s_mp_rand_jenkins.c"
6+
47
static long rand_long(void)
58
{
69
long x;
7-
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
10+
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
811
fprintf(stderr, "s_mp_rand_source failed\n");
912
exit(EXIT_FAILURE);
1013
}
@@ -14,7 +17,7 @@ static long rand_long(void)
1417
static int rand_int(void)
1518
{
1619
int x;
17-
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
20+
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
1821
fprintf(stderr, "s_mp_rand_source failed\n");
1922
exit(EXIT_FAILURE);
2023
}
@@ -24,7 +27,7 @@ static int rand_int(void)
2427
static int32_t rand_int32(void)
2528
{
2629
int32_t x;
27-
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
30+
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
2831
fprintf(stderr, "s_mp_rand_source failed\n");
2932
exit(EXIT_FAILURE);
3033
}
@@ -34,7 +37,7 @@ static int32_t rand_int32(void)
3437
static int64_t rand_int64(void)
3538
{
3639
int64_t x;
37-
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
40+
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
3841
fprintf(stderr, "s_mp_rand_source failed\n");
3942
exit(EXIT_FAILURE);
4043
}
@@ -2134,15 +2137,20 @@ static int test_mp_pack_unpack(void)
21342137
return EXIT_FAILURE;
21352138
}
21362139

2140+
#ifndef LTM_TEST_DYNAMIC
2141+
#define ONLY_PUBLIC_API_C
2142+
#endif
2143+
21372144
static int unit_tests(int argc, char **argv)
21382145
{
21392146
static const struct {
21402147
const char *name;
21412148
int (*fn)(void);
21422149
} test[] = {
2143-
#define T0(n) { #n, test_##n }
2144-
#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
2145-
#define T2(n, o1, o2) { #n, (MP_HAS(o1) && MP_HAS(o2)) ? test_##n : NULL }
2150+
#define T0(n) { #n, test_##n }
2151+
#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
2152+
#define T2(n, o1, o2) { #n, (MP_HAS(o1) && MP_HAS(o2)) ? test_##n : NULL }
2153+
#define T3(n, o1, o2, o3) { #n, (MP_HAS(o1) && MP_HAS(o2) && MP_HAS(o3)) ? test_##n : NULL }
21462154
T0(feature_detection),
21472155
T0(trivial_stuff),
21482156
T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
@@ -2151,7 +2159,7 @@ static int unit_tests(int argc, char **argv)
21512159
T1(mp_cnt_lsb, MP_CNT_LSB),
21522160
T1(mp_complement, MP_COMPLEMENT),
21532161
T1(mp_decr, MP_SUB_D),
2154-
T1(s_mp_div_3, S_MP_DIV_3),
2162+
T2(s_mp_div_3, ONLY_PUBLIC_API, S_MP_DIV_3),
21552163
T1(mp_dr_reduce, MP_DR_REDUCE),
21562164
T2(mp_pack_unpack,MP_PACK, MP_UNPACK),
21572165
T2(mp_fread_fwrite, MP_FREAD, MP_FWRITE),
@@ -2176,21 +2184,22 @@ static int unit_tests(int argc, char **argv)
21762184
T1(mp_reduce_2k, MP_REDUCE_2K),
21772185
T1(mp_reduce_2k_l, MP_REDUCE_2K_L),
21782186
T1(mp_radix_size, MP_RADIX_SIZE),
2179-
T1(s_mp_radix_size_overestimate, S_MP_RADIX_SIZE_OVERESTIMATE),
2187+
T2(s_mp_radix_size_overestimate, ONLY_PUBLIC_API, S_MP_RADIX_SIZE_OVERESTIMATE),
21802188
#if defined(MP_HAS_SET_DOUBLE)
21812189
T1(mp_set_double, MP_SET_DOUBLE),
21822190
#endif
21832191
T1(mp_signed_rsh, MP_SIGNED_RSH),
21842192
T2(mp_sqrt, MP_SQRT, MP_ROOT_N),
21852193
T1(mp_sqrtmod_prime, MP_SQRTMOD_PRIME),
21862194
T1(mp_xor, MP_XOR),
2187-
T2(s_mp_div_recursive, S_MP_DIV_RECURSIVE, S_MP_DIV_SCHOOL),
2188-
T2(s_mp_div_small, S_MP_DIV_SMALL, S_MP_DIV_SCHOOL),
2189-
T1(s_mp_mul_balance, S_MP_MUL_BALANCE),
2190-
T1(s_mp_mul_karatsuba, S_MP_MUL_KARATSUBA),
2191-
T1(s_mp_sqr_karatsuba, S_MP_SQR_KARATSUBA),
2192-
T1(s_mp_mul_toom, S_MP_MUL_TOOM),
2193-
T1(s_mp_sqr_toom, S_MP_SQR_TOOM)
2195+
T3(s_mp_div_recursive, ONLY_PUBLIC_API, S_MP_DIV_RECURSIVE, S_MP_DIV_SCHOOL),
2196+
T3(s_mp_div_small, ONLY_PUBLIC_API, S_MP_DIV_SMALL, S_MP_DIV_SCHOOL),
2197+
T2(s_mp_mul_balance, ONLY_PUBLIC_API, S_MP_MUL_BALANCE),
2198+
T2(s_mp_mul_karatsuba, ONLY_PUBLIC_API, S_MP_MUL_KARATSUBA),
2199+
T2(s_mp_sqr_karatsuba, ONLY_PUBLIC_API, S_MP_SQR_KARATSUBA),
2200+
T2(s_mp_mul_toom, ONLY_PUBLIC_API, S_MP_MUL_TOOM),
2201+
T2(s_mp_sqr_toom, ONLY_PUBLIC_API, S_MP_SQR_TOOM)
2202+
#undef T3
21942203
#undef T2
21952204
#undef T1
21962205
};

etc/makefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
LTM_CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
2-
LTM_CFLAGS += $(CFLAGS)
1+
LTM_TUNE_CFLAGS = $(CFLAGS) $(LTM_CFLAGS) -Wall -W -Wextra -Wshadow -O3 -I../
32

43
# default lib name (requires install with root)
54
# LIBNAME=-ltommath
@@ -9,31 +8,31 @@ LIBNAME=../libtommath.a
98

109
#provable primes
1110
pprime: pprime.o
12-
$(CC) $(LTM_CFLAGS) pprime.o $(LIBNAME) -o pprime
11+
$(CC) $(LTM_TUNE_CFLAGS) pprime.o $(LIBNAME) -o pprime
1312

1413
# portable [well requires clock()] tuning app
1514
tune: tune.o
16-
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o tune
15+
$(CC) $(LTM_TUNE_CFLAGS) tune.o $(LIBNAME) -o tune
1716
./tune_it.sh
1817

1918
test_standalone: tune.o
2019
# The benchmark program works as a testtool, too
21-
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o test
20+
$(CC) $(LTM_TUNE_CFLAGS) tune.o $(LIBNAME) -o test
2221

2322
# spits out mersenne primes
2423
mersenne: mersenne.o
25-
$(CC) $(LTM_CFLAGS) mersenne.o $(LIBNAME) -o mersenne
24+
$(CC) $(LTM_TUNE_CFLAGS) mersenne.o $(LIBNAME) -o mersenne
2625

2726
# finds DR safe primes for the given config
2827
drprime: drprime.o
29-
$(CC) $(LTM_CFLAGS) drprime.o $(LIBNAME) -o drprime
28+
$(CC) $(LTM_TUNE_CFLAGS) drprime.o $(LIBNAME) -o drprime
3029

3130
# finds 2k safe primes for the given config
3231
2kprime: 2kprime.o
33-
$(CC) $(LTM_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
32+
$(CC) $(LTM_TUNE_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
3433

3534
mont: mont.o
36-
$(CC) $(LTM_CFLAGS) mont.o $(LIBNAME) -o mont
35+
$(CC) $(LTM_TUNE_CFLAGS) mont.o $(LIBNAME) -o mont
3736

3837

3938
clean:

etc/tune.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
*
33
* Tom St Denis, tstdenis82@gmail.com
44
*/
5-
#include "../tommath.h"
6-
#include "../tommath_private.h"
5+
#include "tommath_private.h"
76
#include <time.h>
87
#include <inttypes.h>
98
#include <errno.h>
109

10+
#define S_MP_RAND_JENKINS_C
11+
#include "../demo/s_mp_rand_jenkins.c"
12+
1113
/*
1214
Please take in mind that both multiplicands are of the same size. The balancing
1315
mechanism in mp_balance works well but has some overhead itself. You can test

helper.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ sub generate_def {
436436
;
437437
EXPORTS
438438
$files
439+
MP_MUL_KARATSUBA_CUTOFF
440+
MP_SQR_KARATSUBA_CUTOFF
441+
MP_MUL_TOOM_CUTOFF
442+
MP_SQR_TOOM_CUTOFF
439443
";
440444
return 0;
441445
}

libtommath_VS2008.vcproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@
648648
RelativePath="mp_rand.c"
649649
>
650650
</File>
651+
<File
652+
RelativePath="mp_rand_source.c"
653+
>
654+
</File>
651655
<File
652656
RelativePath="mp_read_radix.c"
653657
>
@@ -892,10 +896,6 @@
892896
RelativePath="s_mp_radix_size_overestimate.c"
893897
>
894898
</File>
895-
<File
896-
RelativePath="s_mp_rand_jenkins.c"
897-
>
898-
</File>
899899
<File
900900
RelativePath="s_mp_rand_platform.c"
901901
>

0 commit comments

Comments
 (0)