int main(int argc, char **argv) { int arg; char *argp; giantDigit *digit1; // mallocd arrays giantDigit *digit2; giantDigit *vect1; giantDigit *vect2; giantDigit *dig1p; // ptr into mallocd arrays giantDigit *dig2p; giantDigit *vect1p; giantDigit *vect2p; unsigned numDigits; unsigned i; PLAT_TIME startTime; PLAT_TIME endTime; unsigned elapsed; giantDigit scr1; // op result giantDigit scr2; // op result int loops = LOOPS_DEF; int seedSpec = 0; unsigned seed = 0; unsigned maxSize = MAX_SIZE_DEF; unsigned minSize = MIN_SIZE_DEF; initCryptKit(); #if macintosh argc = ccommand(&argv); #endif for(arg=1; arg<argc; arg++) { argp = argv[arg]; switch(argp[0]) { case 'x': maxSize = atoi(&argp[2]); break; case 'n': minSize = atoi(&argp[2]); break; case 'l': loops = atoi(&argp[2]); break; case 's': seed = atoi(&argp[2]); seedSpec = 1; break; case 'h': default: usage(argv); } } if(!seedSpec) { unsigned long tim; time(&tim); seed = (unsigned)tim; } SRAND(seed); /* * Scratch digits, big enough for anything. Malloc here, init with * random data before each test. */ digit1 = malloc(sizeof(giantDigit) * loops * 2); digit2 = malloc(sizeof(giantDigit) * loops * 2); /* vect1 and vect2 are arrays of giantDigit arrays */ vect1 = malloc(sizeof(giantDigit) * loops * maxSize); vect2 = malloc(sizeof(giantDigit) * loops * maxSize); if((digit1 == NULL) || (digit1 == NULL) || (vect1 == NULL) || (vect2 == NULL)) { printf("malloc error\n"); exit(1); } printf("Starting giantAsm test: seed %d\n", seed); /* giantAddDigits test */ randDigits(loops, digit1); randDigits(loops, digit2); dig1p = digit1; dig2p = digit2; PLAT_GET_TIME(startTime); for(i=0; i<loops; i++) { scr1 = giantAddDigits(*dig1p++, *dig2p++, &scr2); } PLAT_GET_TIME(endTime); elapsed = PLAT_GET_NS(startTime, endTime); printf("giantAddDigits: %f ns\n", (double)elapsed / (double)loops); /* giantAddDouble test */ randDigits(loops, digit1); randDigits(loops * 2, digit2); dig1p = digit1; dig2p = digit2; PLAT_GET_TIME(startTime); for(i=0; i<loops; i++) { giantAddDouble(dig2p, dig2p+1, *dig1p++); dig2p += 2; } PLAT_GET_TIME(endTime); elapsed = PLAT_GET_NS(startTime, endTime); printf("giantAddDouble: %f ns\n", (double)elapsed / (double)loops); /* giantSubDigits test */ randDigits(loops, digit1); randDigits(loops, digit2); dig1p = digit1; dig2p = digit2; PLAT_GET_TIME(startTime); for(i=0; i<loops; i++) { scr1 = giantSubDigits(*dig1p++, *dig2p++, &scr2); } PLAT_GET_TIME(endTime); elapsed = PLAT_GET_NS(startTime, endTime); printf("giantSubDigits: %f ns\n", (double)elapsed / (double)loops); /* giantMulDigits test */ randDigits(loops, digit1); randDigits(loops, digit2); dig1p = digit1; dig2p = digit2; PLAT_GET_TIME(startTime); for(i=0; i<loops; i++) { giantMulDigits(*dig1p++, *dig2p++, &scr1, &scr2); } PLAT_GET_TIME(endTime); elapsed = PLAT_GET_NS(startTime, endTime); printf("giantMulDigits: %f ns\n", (double)elapsed / (double)loops); printf("\nvectorMultiply:\n"); for(numDigits=minSize; numDigits<=maxSize; numDigits*=2) { randDigits(loops, digit1); // plierDigit randDigits(loops * numDigits, vect1); // candVector randDigits(loops * numDigits, vect2); // prodVector dig1p = digit1; vect1p = vect1; vect2p = vect2; PLAT_GET_TIME(startTime); for(i=0; i<loops; i++) { scr1 = VectorMultiply(*dig1p++, // plierDigit vect1p, // candVector numDigits, vect2p); // prodVector vect1p += numDigits; vect2p += numDigits; } PLAT_GET_TIME(endTime); elapsed = PLAT_GET_NS(startTime, endTime); printf(" bits = %4d : %f ns\n", numDigits * GIANT_BITS_PER_DIGIT, (double)elapsed / (double)loops); } /* for numDigits */ return 0; }
int main(int argc, char **argv) { int arg; char *argp; giant *g1; giant *g2; // ditto unsigned char *buf; // random data unsigned numDigits; unsigned i; unsigned numBytes; unsigned mulgElapsed; unsigned sqrElapsed; int loops = LOOPS_DEF; int seedSpec = 0; unsigned seed = 0; unsigned maxSize = MAX_SIZE_DEF; unsigned minSize = MIN_SIZE_DEF; int useOld = 0; initCryptKit(); #if macintosh argc = ccommand(&argv); #endif for(arg=1; arg<argc; arg++) { argp = argv[arg]; switch(argp[0]) { case 'x': maxSize = atoi(&argp[2]); break; case 'n': minSize = atoi(&argp[2]); break; case 'l': loops = atoi(&argp[2]); break; case 'o': useOld = 1; break; case 's': seed = atoi(&argp[2]); seedSpec = 1; break; case 'h': default: usage(argv); } } buf = malloc(maxSize); if(!seedSpec) { unsigned long tim; time(&tim); seed = (unsigned)tim; } SRAND(seed); /* * Scratch giants, big enough for anything. Malloc here, init with * random data before each test * note these mallocs will be too big in the useOld case... */ g1 = malloc(sizeof(giant) * loops); g2 = malloc(sizeof(giant) * loops); if((g1 == NULL) || (g2 == NULL)) { printf("malloc error\n"); exit(1); } if(useOld) { numDigits = ((2 * maxSize) + 1) / 2; } else { numDigits = BYTES_TO_GIANT_DIGITS(2 * maxSize); } for(i=0; i<loops; i++) { g1[i] = newGiant(numDigits); g2[i] = newGiant(numDigits); if((g1[i] == NULL) || (g2[i] == NULL)) { printf("malloc error\n"); exit(1); } } printf("Starting giants test: seed %d\n", seed); for(numBytes=minSize; numBytes<=maxSize; numBytes*=2) { initRandGiants(numBytes, buf, loops, g1, g2); mulgElapsed = mulgTest(loops, g1, g2); initRandGiants(numBytes, buf, loops, g1, g2); sqrElapsed = squareTest(loops, g1, g2); printf(" bits : %4d mulg : %3d ns gsquare : %3d ns\n", numBytes * 8, mulgElapsed / loops, sqrElapsed / loops); } /* for numBytes */ return 0; }