Mercurial > dropbear
comparison tomsfastmath/src/generators/comba_sqr_gen.c @ 643:a362b62d38b2 dropbear-tfm
Add tomsfastmath from git rev bfa4582842bc3bab42e4be4aed5703437049502a
with Makefile.in renamed
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 23 Nov 2011 18:10:20 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
642:33fd2f3499d2 | 643:a362b62d38b2 |
---|---|
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, [email protected] | |
9 */ | |
10 | |
11 #include <stdio.h> | |
12 | |
13 int main(int argc, char **argv) | |
14 { | |
15 int x, y, z, N, f; | |
16 N = atoi(argv[1]); | |
17 | |
18 printf( | |
19 "#define TFM_DEFINES\n" | |
20 "#include \"fp_sqr_comba.c\"\n" | |
21 "\n" | |
22 "#ifdef TFM_SQR%d\n" | |
23 "void fp_sqr_comba%d(fp_int *A, fp_int *B)\n" | |
24 "{\n" | |
25 " fp_digit *a, b[%d], c0, c1, c2, sc0, sc1, sc2;\n" | |
26 "#ifdef TFM_ISO\n" | |
27 " fp_word tt;\n" | |
28 "#endif\n" | |
29 "\n" | |
30 " a = A->dp;\n" | |
31 " COMBA_START; \n" | |
32 "\n" | |
33 " /* clear carries */\n" | |
34 " CLEAR_CARRY;\n" | |
35 "\n" | |
36 " /* output 0 */\n" | |
37 " SQRADD(a[0],a[0]);\n" | |
38 " COMBA_STORE(b[0]);\n", N, N, N+N); | |
39 | |
40 for (x = 1; x < N+N-1; x++) { | |
41 printf( | |
42 "\n /* output %d */\n" | |
43 " CARRY_FORWARD;\n ", x); | |
44 | |
45 for (f = y = 0; y < N; y++) { | |
46 for (z = 0; z < N; z++) { | |
47 if (z != y && z + y == x && y <= z) { | |
48 ++f; | |
49 } | |
50 } | |
51 } | |
52 | |
53 if (f <= 2) { | |
54 for (y = 0; y < N; y++) { | |
55 for (z = 0; z < N; z++) { | |
56 if (y<=z && (y+z)==x) { | |
57 if (y == z) { | |
58 printf("SQRADD(a[%d], a[%d]); ", y, y); | |
59 } else { | |
60 printf("SQRADD2(a[%d], a[%d]); ", y, z); | |
61 } | |
62 } | |
63 } | |
64 } | |
65 } else { | |
66 // new method | |
67 /* do evens first */ | |
68 f = 0; | |
69 for (y = 0; y < N; y++) { | |
70 for (z = 0; z < N; z++) { | |
71 if (z != y && z + y == x && y <= z) { | |
72 if (f == 0) { | |
73 // first double | |
74 printf("SQRADDSC(a[%d], a[%d]); ", y, z); | |
75 f = 1; | |
76 } else { | |
77 printf("SQRADDAC(a[%d], a[%d]); ", y, z); | |
78 } | |
79 } | |
80 } | |
81 } | |
82 // forward the carry | |
83 printf("SQRADDDB; "); | |
84 if ((x&1) == 0) { | |
85 // add the square | |
86 printf("SQRADD(a[%d], a[%d]); ", x/2, x/2); | |
87 } | |
88 } | |
89 printf("\n COMBA_STORE(b[%d]);\n", x); | |
90 } | |
91 printf(" COMBA_STORE2(b[%d]);\n", N+N-1); | |
92 | |
93 printf( | |
94 " COMBA_FINI;\n" | |
95 "\n" | |
96 " B->used = %d;\n" | |
97 " B->sign = FP_ZPOS;\n" | |
98 " memcpy(B->dp, b, %d * sizeof(fp_digit));\n" | |
99 " memset(B->dp + %d, 0, (FP_SIZE - %d) * sizeof(fp_digit));\n" | |
100 " fp_clamp(B);\n" | |
101 "}\n#endif\n\n\n", N+N, N+N, N+N, N+N); | |
102 | |
103 return 0; | |
104 } | |
105 | |
106 /* $Source$ */ | |
107 /* $Revision$ */ | |
108 /* $Date$ */ |