1 /* Tune the Karatsuba parameters
3 * Tom St Denis, tomstdenis@iahu.ca
8 /* how many times todo each size mult. Depends on your computer. For slow computers
9 * this can be low like 5 or 10. For fast [re: Athlon] should be 25 - 50 or so
11 #define TIMES (1UL<<14UL)
13 /* RDTSC from Scott Duplichan */
14 static ulong64 TIMFUNC (void)
17 #if defined(__i386__) || defined(__x86_64__)
19 __asm__ __volatile__ ("rdtsc\nmovl %%eax,%0\nmovl %%edx,4+%0\n"::"m"(a):"%eax","%edx");
21 #else /* gcc-IA64 version */
23 __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
24 while (__builtin_expect ((int) result == -1, 0))
25 __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
29 // Microsoft and Intel Windows compilers
32 #elif defined _M_AMD64
35 #if defined __INTEL_COMPILER
36 #include <ia64intrin.h>
38 return __getReg (3116);
40 #error need rdtsc function for this build
47 /* generic ISO C timer */
49 void t_start(void) { LBL_T = TIMFUNC(); }
50 ulong64 t_read(void) { return TIMFUNC() - LBL_T; }
53 extern void t_start(void);
54 extern ulong64 t_read(void);
57 ulong64 time_mult(int size, int s)
71 KARATSUBA_MUL_CUTOFF = size;
73 KARATSUBA_MUL_CUTOFF = 100000;
77 for (x = 0; x < TIMES; x++) {
87 ulong64 time_sqr(int size, int s)
99 KARATSUBA_SQR_CUTOFF = size;
101 KARATSUBA_SQR_CUTOFF = 100000;
105 for (x = 0; x < TIMES; x++) {
120 for (x = 8; ; x += 2) {
121 t1 = time_mult(x, 0);
122 t2 = time_mult(x, 1);
123 printf("%d: %9llu %9llu, %9llu\n", x, t1, t2, t2 - t1);
128 for (x = 8; ; x += 2) {
131 printf("%d: %9llu %9llu, %9llu\n", x, t1, t2, t2 - t1);
134 printf("KARATSUBA_MUL_CUTOFF = %d\n", y);
135 printf("KARATSUBA_SQR_CUTOFF = %d\n", x);