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
12 #include "fp_sqr_comba.c"
14 /* generic comba squarer */
15 void fp_sqr_comba(fp_int *A, fp_int *B)
24 /* get size of output and trim */
25 pa = A->used + A->used;
30 /* number of output digits to produce */
42 for (ix = 0; ix < pa; ix++) {
44 fp_digit *tmpy, *tmpx;
46 /* get offsets into the two bignums */
47 ty = MIN(A->used-1, ix);
50 /* setup temp aliases */
54 /* this is the number of times the loop will iterrate,
55 while (tx++ < a->used && ty-- >= 0) { ... }
57 iy = MIN(A->used-tx, ty+1);
59 /* now for squaring tx can never equal ty
60 * we halve the distance since they approach
61 * at a rate of 2x and we have to round because
62 * odd cases need to be executed
64 iy = MIN(iy, (ty-tx+1)>>1);
70 for (iz = 0; iz < iy; iz++) {
71 fp_digit _tmpx = *tmpx++;
72 fp_digit _tmpy = *tmpy--;
73 SQRADD2(_tmpx, _tmpy);
76 /* even columns have the square term in them */
78 fp_digit _a_dp = A->dp[ix>>1];
79 SQRADD(_a_dp, A->dp[ix>>1]);
83 COMBA_STORE(dst->dp[ix]);