]> pd.if.org Git - zpackage/blob - tomsfastmath/src/generators/comba_mult_gen.c
commit files needed for zpm-fetchurl
[zpackage] / tomsfastmath / src / generators / comba_mult_gen.c
1 /* TomsFastMath, a fast ISO C bignum library.
2  *
3  * This project is meant to fill in where LibTomMath
4  * falls short.  That is speed ;-)
5  *
6  * This project is public domain and free for all purposes.
7  *
8  * Tom St Denis, tomstdenis@gmail.com
9  */
10
11 /* program emits a NxN comba multiplier */
12 #include <stdio.h>
13
14 int main(int argc, char **argv)
15 {
16    int N, x, y, z;
17    N = atoi(argv[1]);
18
19    /* print out preamble */
20 printf(
21 "#define TFM_DEFINES\n"
22 "#include \"fp_mul_comba.c\"\n"
23 "\n"
24 "#if defined(TFM_MUL%d) && FP_SIZE >= %d\n"
25 "void fp_mul_comba%d(fp_int *A, fp_int *B, fp_int *C)\n"
26 "{\n"
27 "   fp_digit c0, c1, c2, at[%d];\n"
28 "\n"
29 "   memcpy(at, A->dp, %d * sizeof(fp_digit));\n"
30 "   memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\n"
31 "   COMBA_START;\n"
32 "\n"
33 "   COMBA_CLEAR;\n", N, N+N, N, N+N, N, N, N);
34
35    /* now do the rows */
36    for (x = 0; x < (N+N-1); x++) {
37 printf(
38 "   /* %d */\n", x);
39 if (x > 0) {
40 printf(
41 "   COMBA_FORWARD;\n");
42 }
43       for (y = 0; y < N; y++) {
44       for (z = 0; z < N; z++) {
45           if ((y+z)==x) {
46              printf("   MULADD(at[%d], at[%d]); ", y, z+N);
47           }
48       }
49       }
50 printf(
51 "\n"
52 "   COMBA_STORE(C->dp[%d]);\n", x);
53    }
54 printf(
55 "   COMBA_STORE2(C->dp[%d]);\n"
56 "   C->used = %d;\n"
57 "   C->sign = A->sign ^ B->sign;\n"
58 "   fp_clamp(C);\n"
59 "   COMBA_FINI;\n"
60 "}\n#endif\n\n\n"
61 "/* $Source$ */\n"
62 "/* $Revision$ */\n"
63 "/* $Date$ */\n"
64 , N+N-1, N+N);
65
66   return 0;
67 }
68
69 /* $Source$ */
70 /* $Revision$ */
71 /* $Date$ */