Skip to content

Commit 6be8e10

Browse files
committed
Added printing benchmark lists and graphs
1 parent 5ece04f commit 6be8e10

File tree

5 files changed

+128
-11
lines changed

5 files changed

+128
-11
lines changed

etc/get_limbsize.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
#include "tommath.h"
5+
6+
int main(void)
7+
{
8+
printf("%d",MP_DIGIT_BIT);
9+
10+
exit(EXIT_SUCCESS);
11+
}

etc/makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LTM_TUNE_CFLAGS = $(CFLAGS) $(LTM_CFLAGS) -Wall -W -Wextra -Wshadow -O3 -I../
66
# libname when you can't install the lib with install
77
LIBNAME=../libtommath.a
88

9-
all: pprime tune test_standalone mersenne drprime 2kprime mont
9+
all: pprime tune test_standalone mersenne drprime 2kprime mont getlimbsize graph
1010

1111
#provable primes
1212
pprime: pprime.o
@@ -36,10 +36,17 @@ drprime: drprime.o
3636
mont: mont.o
3737
$(CC) $(LTM_TUNE_CFLAGS) mont.o $(LIBNAME) -o mont
3838

39+
getlimbsize: get_limbsize.o
40+
$(CC) $(LTM_TUNE_CFLAGS) get_limbsize.o $(LIBNAME) -o get_limbsize
41+
42+
# Make pretty pictures (500 is the maximum number of limbs)
43+
graphs: tune get_limbsize
44+
./tune -p -M 500
45+
gnuplot -c plot_graphs.gp `./get_limbsize`
3946

4047
clean:
4148
rm -f *.log *.o *.obj *.exe pprime tune mersenne drprime mont 2kprime pprime.dat \
42-
tuning_list multiplying squaring test *.da *.dyn *.dpi *~
49+
tuning_list multiplying squaring readradix writeradix test get_limbsize *png *.da *.dyn *.dpi *~
4350
rm -rf .libs
4451

4552
.PHONY: tune

etc/plot_graphs.gp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
set term pngcairo size 720,540
2+
# Good for most colorblinds
3+
set colorsequence podo
4+
5+
set key top left;
6+
7+
set ylabel "Time"
8+
set xlabel "Operand size (limbs)"
9+
10+
set output "multiplying.png";
11+
set title "Comparing fast and slow multiplying [".ARG1." bits limbsize]";
12+
plot "multiplying" using 1:2 w lines t "slow", "multiplying" using 1:3 w lines t "fast"
13+
14+
set output "squaring.png";
15+
set title "Comparing fast and slow squaring [".ARG1." bits limbsize]";
16+
plot "squaring" using 1:2 w lines t "slow", "squaring" using 1:3 w lines t "fast"
17+
18+
set xlabel "Operand size (bits)"
19+
set output "readradix.png";
20+
set title "Comparing fast and slow radix conversion (reading) [".ARG1." bits limbsize]";
21+
plot "readradix" using 1:2 w lines t "slow", "readradix" using 1:3 w lines t "fast"
22+
23+
set output "writeradix.png";
24+
set title "Comparing fast and slow radix conversion (writing) [".ARG1." bits limbsize]";
25+
plot "writeradix" using 1:2 w lines t "slow", "writeradix" using 1:3 w lines t "fast"
26+
27+
28+
29+

etc/tune.c

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ static void s_usage(char *s)
386386
fprintf(stderr," -T testmode, for use with testme.sh\n");
387387
fprintf(stderr," -v verbose, print all timings\n");
388388
fprintf(stderr," -c check results\n");
389-
fprintf(stderr," -p print benchmark of final cutoffs in files \"multiplying\"\n");
390-
fprintf(stderr," and \"squaring\"\n");
389+
fprintf(stderr," -p print benchmark of final cutoffs in files \"multiplying\",\n");
390+
fprintf(stderr," \"squaring\", \"readradix\", and \"writeradix\" \n");
391391
fprintf(stderr," -G [string] suffix for the filenames listed above\n");
392392
fprintf(stderr," Implies '-p'\n");
393393
fprintf(stderr," -b print benchmark of bncore.c\n");
@@ -457,9 +457,11 @@ int main(int argc, char **argv)
457457
int opt;
458458
struct cutoffs orig, updated;
459459

460-
FILE *squaring, *multiplying;
460+
FILE *squaring, *multiplying, *readradix, *writeradix;
461461
char mullog[256] = "multiplying";
462462
char sqrlog[256] = "squaring";
463+
char rcreadlog[256] = "readradix";
464+
char rcwritelog[256] = "writeradix";
463465
s_number_of_test_loops = 64;
464466
s_stabilization_extra = 3;
465467

@@ -525,6 +527,31 @@ int main(int argc, char **argv)
525527
break;
526528
}
527529
}
530+
531+
for (i = 0; i < 255; i++) {
532+
if (rcreadlog[i] == '\0') {
533+
break;
534+
}
535+
}
536+
for (j = 0; i < 255; j++, i++) {
537+
rcreadlog[i] = argv[opt][j];
538+
if (argv[opt][j] == '\0') {
539+
break;
540+
}
541+
}
542+
543+
for (i = 0; i < 255; i++) {
544+
if (rcwritelog[i] == '\0') {
545+
break;
546+
}
547+
}
548+
for (j = 0; i < 255; j++, i++) {
549+
rcwritelog[i] = argv[opt][j];
550+
if (argv[opt][j] == '\0') {
551+
break;
552+
}
553+
}
554+
528555
break;
529556
case 'b':
530557
args.bncore = 1;
@@ -693,7 +720,7 @@ int main(int argc, char **argv)
693720
}
694721
/* TODO: add graphs for radix conversion, too? */
695722
if (args.print == 1) {
696-
printf("Printing data for graphing to \"%s\" and \"%s\"\n",mullog, sqrlog);
723+
printf("Printing data for graphing to \"%s\", \"%s\", \"%s\", and \"%s\"\n",mullog, sqrlog, rcreadlog, rcwritelog);
697724

698725
multiplying = fopen(mullog, "w+");
699726
if (multiplying == NULL) {
@@ -707,6 +734,19 @@ int main(int argc, char **argv)
707734
exit(EXIT_FAILURE);
708735
}
709736

737+
readradix = fopen(rcreadlog, "w+");
738+
if (readradix == NULL) {
739+
fprintf(stderr, "Opening file \"%s\" failed\n",rcreadlog);
740+
exit(EXIT_FAILURE);
741+
}
742+
743+
writeradix = fopen(rcwritelog, "w+");
744+
if (readradix == NULL) {
745+
fprintf(stderr, "Opening file \"%s\" failed\n",rcwritelog);
746+
exit(EXIT_FAILURE);
747+
}
748+
749+
710750
for (x = 8; x < args.upper_limit_print; x += args.increment_print) {
711751
set_cutoffs(&max_cutoffs);
712752
t1 = s_time_mul(x);
@@ -728,23 +768,54 @@ int main(int argc, char **argv)
728768
printf("SQR %d: %9" PRIu64 " %9" PRIu64 ", %9" PRIi64 "\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
729769
fflush(stdout);
730770
}
771+
772+
773+
set_cutoffs(&max_cutoffs);
774+
t1 = s_time_radix_conversion_read(x);
775+
set_cutoffs(&orig);
776+
t2 = s_time_radix_conversion_read(x);
777+
fprintf(readradix,"%d: %9" PRIu64 " %9" PRIu64 ", %9" PRIi64 "\n", x * MP_DIGIT_BIT, t1, t2, (int64_t)t2 - (int64_t)t1);
778+
fflush(readradix);
779+
if (args.verbose == 1) {
780+
printf("RCR %d: %9" PRIu64 " %9" PRIu64 ", %9" PRIi64 "\n", x * MP_DIGIT_BIT, t1, t2, (int64_t)t2 - (int64_t)t1);
781+
fflush(stdout);
782+
}
783+
784+
set_cutoffs(&max_cutoffs);
785+
t1 = s_time_radix_conversion_write(x);
786+
set_cutoffs(&orig);
787+
t2 = s_time_radix_conversion_write(x);
788+
fprintf(writeradix,"%d: %9" PRIu64 " %9" PRIu64 ", %9" PRIi64 "\n", x * MP_DIGIT_BIT, t1, t2,
789+
(int64_t)t2 - (int64_t)t1);
790+
fflush(writeradix);
791+
if (args.verbose == 1) {
792+
printf("RCW %d: %9" PRIu64 " %9" PRIu64 ", %9" PRIi64 "\n", x * MP_DIGIT_BIT, t1, t2, (int64_t)t2 - (int64_t)t1);
793+
fflush(stdout);
794+
}
795+
731796
}
732-
printf("Finished. Data for graphing in \"%s\" and \"%s\"\n",mullog, sqrlog);
797+
printf("Finished. Data for graphing in \"%s\", \"%s\", \"%s\", and \"%s\"\n",mullog, sqrlog, rcreadlog, rcwritelog);
733798
if (args.verbose == 1) {
734799
set_cutoffs(&orig);
735800
if (args.terse == 1) {
736-
printf("%d %d %d %d\n",
801+
printf("%d %d %d %d %d %d\n",
737802
MP_MUL_KARATSUBA_CUTOFF,
738803
MP_SQR_KARATSUBA_CUTOFF,
739804
MP_MUL_TOOM_CUTOFF,
740-
MP_SQR_TOOM_CUTOFF);
805+
MP_SQR_TOOM_CUTOFF,
806+
MP_RADIX_READ_CUTOFF,
807+
MP_RADIX_WRITE_CUTOFF);
741808
} else {
742809
printf("MUL_KARATSUBA_CUTOFF = %d\n", MP_MUL_KARATSUBA_CUTOFF);
743810
printf("SQR_KARATSUBA_CUTOFF = %d\n", MP_SQR_KARATSUBA_CUTOFF);
744811
printf("MUL_TOOM_CUTOFF = %d\n", MP_MUL_TOOM_CUTOFF);
745812
printf("SQR_TOOM_CUTOFF = %d\n", MP_SQR_TOOM_CUTOFF);
813+
printf("MP_RADIX_READ_CUTOFF = %d\n", MP_RADIX_READ_CUTOFF);
814+
printf("MP_RADIX_WRITE_CUTOFF = %d\n", MP_RADIX_WRITE_CUTOFF);
746815
}
747816
}
817+
fclose(readradix);
818+
fclose(writeradix);
748819
}
749820
exit(EXIT_SUCCESS);
750821
}

mp_read_radix.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ mp_err mp_read_radix(mp_int *a, const char *str, int radix)
8686
slen_2 = slen * (size_t)(s_mp_log2_radix[radix] + 1);
8787

8888
mp_zero(a);
89-
9089
/* Try faster version first */
91-
if (MP_HAS(S_MP_FASTER_READ_RADIX) && (slen_2 < (size_t)MP_RADIX_READ_CUTOFF)) {
90+
if (MP_HAS(S_MP_FASTER_READ_RADIX) && (slen_2 > (size_t)MP_RADIX_READ_CUTOFF)) {
9291
if ((err = s_mp_faster_read_radix(a, str, 0, slen, radix)) != MP_OKAY) goto LTM_ERR;
9392
} else if (MP_HAS(S_MP_SLOWER_READ_RADIX)) {
9493
if ((err = s_mp_slower_read_radix(a, str, 0, slen, radix)) != MP_OKAY) goto LTM_ERR;

0 commit comments

Comments
 (0)