1 /* TomsFastMath, a fast ISO C bignum library.
3 * This project is meant to fill in where LibTomMath
4 * falls short. That is speed ;-)
6 * This project is public domain and free for all purposes.
8 * Tom St Denis, tomstdenis@gmail.com
10 #include <tfm_private.h>
13 void fp_mul(fp_int *A, fp_int *B, fp_int *C)
22 /* call generic if we're out of range */
23 if (A->used + B->used > FP_SIZE) {
24 fp_mul_comba(A, B, C);
28 y = MAX(A->used, B->used);
30 yy = MIN(A->used, B->used);
32 /* pick a comba (unrolled 4/8/16/32 x or rolled) based on the size
33 of the largest input. We also want to avoid doing excess mults if the
34 inputs are not close to the next power of two. That is, for example,
35 if say y=17 then we would do (32-17)^2 = 225 unneeded multiplications
38 #if defined(TFM_MUL3) && FP_SIZE >= 6
44 #if defined(TFM_MUL4) && FP_SIZE >= 8
50 #if defined(TFM_MUL6) && FP_SIZE >= 12
56 #if defined(TFM_MUL7) && FP_SIZE >= 14
62 #if defined(TFM_MUL8) && FP_SIZE >= 16
68 #if defined(TFM_MUL9) && FP_SIZE >= 18
74 #if defined(TFM_MUL12) && FP_SIZE >= 24
76 fp_mul_comba12(A,B,C);
80 #if defined(TFM_MUL17) && FP_SIZE >= 34
82 fp_mul_comba17(A,B,C);
87 #if defined(TFM_SMALL_SET) && FP_SIZE >= 32
89 fp_mul_comba_small(A,B,C);
93 #if defined(TFM_MUL20) && FP_SIZE >= 40
95 fp_mul_comba20(A,B,C);
99 #if defined(TFM_MUL24) && FP_SIZE >= 48
100 if (yy >= 16 && y <= 24) {
101 fp_mul_comba24(A,B,C);
105 #if defined(TFM_MUL28) && FP_SIZE >= 56
106 if (yy >= 20 && y <= 28) {
107 fp_mul_comba28(A,B,C);
111 #if defined(TFM_MUL32) && FP_SIZE >= 64
112 if (yy >= 24 && y <= 32) {
113 fp_mul_comba32(A,B,C);
117 #if defined(TFM_MUL48) && FP_SIZE >= 96
118 if (yy >= 40 && y <= 48) {
119 fp_mul_comba48(A,B,C);
123 #if defined(TFM_MUL64) && FP_SIZE >= 128
124 if (yy >= 56 && y <= 64) {
125 fp_mul_comba64(A,B,C);
131 for (y = C->used; y < old_used; y++) {
137 /* $Source: /cvs/libtom/tomsfastmath/src/mul/fp_mul.c,v $ */
138 /* $Revision: 1.1 $ */
139 /* $Date: 2006/12/31 21:25:53 $ */