1 /* $NetBSD: tune.c,v 1.1.1.2 2014/04/24 12:45:39 pettai Exp $ */
3 /* Tune the Karatsuba parameters
5 * Tom St Denis, tomstdenis@gmail.com
10 /* how many times todo each size mult. Depends on your computer. For slow computers
11 * this can be low like 5 or 10. For fast [re: Athlon] should be 25 - 50 or so
13 #define TIMES (1UL<<14UL)
15 /* RDTSC from Scott Duplichan */
16 static ulong64
TIMFUNC (void)
19 #if defined(__i386__) || defined(__x86_64__)
21 __asm__
__volatile__ ("rdtsc\nmovl %%eax,%0\nmovl %%edx,4+%0\n"::"m"(a
):"%eax","%edx");
23 #else /* gcc-IA64 version */
25 __asm__
__volatile__("mov %0=ar.itc" : "=r"(result
) :: "memory");
26 while (__builtin_expect ((int) result
== -1, 0))
27 __asm__
__volatile__("mov %0=ar.itc" : "=r"(result
) :: "memory");
31 // Microsoft and Intel Windows compilers
34 #elif defined _M_AMD64
37 #if defined __INTEL_COMPILER
38 #include <ia64intrin.h>
40 return __getReg (3116);
42 #error need rdtsc function for this build
49 /* generic ISO C timer */
51 void t_start(void) { LBL_T
= TIMFUNC(); }
52 ulong64
t_read(void) { return TIMFUNC() - LBL_T
; }
55 extern void t_start(void);
56 extern ulong64
t_read(void);
59 ulong64
time_mult(int size
, int s
)
73 KARATSUBA_MUL_CUTOFF
= size
;
75 KARATSUBA_MUL_CUTOFF
= 100000;
79 for (x
= 0; x
< TIMES
; x
++) {
89 ulong64
time_sqr(int size
, int s
)
101 KARATSUBA_SQR_CUTOFF
= size
;
103 KARATSUBA_SQR_CUTOFF
= 100000;
107 for (x
= 0; x
< TIMES
; x
++) {
122 for (x
= 8; ; x
+= 2) {
123 t1
= time_mult(x
, 0);
124 t2
= time_mult(x
, 1);
125 printf("%d: %9llu %9llu, %9llu\n", x
, t1
, t2
, t2
- t1
);
130 for (x
= 8; ; x
+= 2) {
133 printf("%d: %9llu %9llu, %9llu\n", x
, t1
, t2
, t2
- t1
);
136 printf("KARATSUBA_MUL_CUTOFF = %d\n", y
);
137 printf("KARATSUBA_SQR_CUTOFF = %d\n", x
);
142 /* Source: /cvs/libtom/libtommath/etc/tune.c,v */
144 /* Date: 2006/03/31 14:18:47 */