]> pd.if.org Git - zpackage/blob - tomsfastmath/src/sqr/fp_sqr.c
commit files needed for zpm-fetchurl
[zpackage] / tomsfastmath / src / sqr / fp_sqr.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 #include <tfm_private.h>
11
12 /* b = a*a  */
13 void fp_sqr(fp_int *A, fp_int *B)
14 {
15     int     y, old_used;
16
17     old_used = B->used;
18
19     /* call generic if we're out of range */
20     if (A->used + A->used > FP_SIZE) {
21        fp_sqr_comba(A, B);
22        goto clean;
23     }
24
25     y = A->used;
26 #if defined(TFM_SQR3) && FP_SIZE >= 6
27         if (y <= 3) {
28            fp_sqr_comba3(A,B);
29            goto clean;
30         }
31 #endif
32 #if defined(TFM_SQR4) && FP_SIZE >= 8
33         if (y == 4) {
34            fp_sqr_comba4(A,B);
35            goto clean;
36         }
37 #endif
38 #if defined(TFM_SQR6) && FP_SIZE >= 12
39         if (y <= 6) {
40            fp_sqr_comba6(A,B);
41            goto clean;
42         }
43 #endif
44 #if defined(TFM_SQR7) && FP_SIZE >= 14
45         if (y == 7) {
46            fp_sqr_comba7(A,B);
47            goto clean;
48         }
49 #endif
50 #if defined(TFM_SQR8) && FP_SIZE >= 16
51         if (y == 8) {
52            fp_sqr_comba8(A,B);
53            goto clean;
54         }
55 #endif
56 #if defined(TFM_SQR9) && FP_SIZE >= 18
57         if (y == 9) {
58            fp_sqr_comba9(A,B);
59            goto clean;
60         }
61 #endif
62 #if defined(TFM_SQR12) && FP_SIZE >= 24
63         if (y <= 12) {
64            fp_sqr_comba12(A,B);
65            goto clean;
66         }
67 #endif
68 #if defined(TFM_SQR17) && FP_SIZE >= 34
69         if (y <= 17) {
70            fp_sqr_comba17(A,B);
71            goto clean;
72         }
73 #endif
74 #if defined(TFM_SMALL_SET)
75         if (y <= 16) {
76            fp_sqr_comba_small(A,B);
77            goto clean;
78         }
79 #endif
80 #if defined(TFM_SQR20) && FP_SIZE >= 40
81         if (y <= 20) {
82            fp_sqr_comba20(A,B);
83            goto clean;
84         }
85 #endif
86 #if defined(TFM_SQR24) && FP_SIZE >= 48
87         if (y <= 24) {
88            fp_sqr_comba24(A,B);
89            goto clean;
90         }
91 #endif
92 #if defined(TFM_SQR28) && FP_SIZE >= 56
93         if (y <= 28) {
94            fp_sqr_comba28(A,B);
95            goto clean;
96         }
97 #endif
98 #if defined(TFM_SQR32) && FP_SIZE >= 64
99         if (y <= 32) {
100            fp_sqr_comba32(A,B);
101            goto clean;
102         }
103 #endif
104 #if defined(TFM_SQR48) && FP_SIZE >= 96
105         if (y <= 48) {
106            fp_sqr_comba48(A,B);
107            goto clean;
108         }
109 #endif
110 #if defined(TFM_SQR64) && FP_SIZE >= 128
111         if (y <= 64) {
112            fp_sqr_comba64(A,B);
113            goto clean;
114         }
115 #endif
116        fp_sqr_comba(A, B);
117 clean:
118     for (y = B->used; y < old_used; y++) {
119        B->dp[y] = 0;
120     }
121 }
122
123
124 /* $Source: /cvs/libtom/tomsfastmath/src/sqr/fp_sqr.c,v $ */
125 /* $Revision: 1.1 $ */
126 /* $Date: 2006/12/31 21:25:53 $ */