Merge pull request #2 from rasky/bugfix_sqr_destdigits

Bugfix sqr destdigits, c.f. 50f587c36f for further explanation
This commit is contained in:
Steffen Jaeckel 2011-09-21 03:31:20 -07:00
commit bfa4582842
19 changed files with 70 additions and 51 deletions

2
src/generators/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
comba_sqr_gen
comba_sqr_smallgen

View File

@ -16,10 +16,16 @@ int main(int argc, char **argv)
N = atoi(argv[1]);
printf(
"#define TFM_DEFINES\n"
"#include \"fp_sqr_comba.c\"\n"
"\n"
"#ifdef TFM_SQR%d\n"
"void fp_sqr_comba%d(fp_int *A, fp_int *B)\n"
"{\n"
" fp_digit *a, b[%d], c0, c1, c2, sc0, sc1, sc2;\n"
"#ifdef TFM_ISO\n"
" fp_word tt;\n"
"#endif\n"
"\n"
" a = A->dp;\n"
" COMBA_START; \n"
@ -90,8 +96,9 @@ printf(
" B->used = %d;\n"
" B->sign = FP_ZPOS;\n"
" memcpy(B->dp, b, %d * sizeof(fp_digit));\n"
" memset(B->dp + %d, 0, (FP_SIZE - %d) * sizeof(fp_digit));\n"
" fp_clamp(B);\n"
"}\n#endif\n\n\n", N+N, N+N);
"}\n#endif\n\n\n", N+N, N+N, N+N, N+N);
return 0;
}

View File

@ -16,9 +16,16 @@ int main(int argc, char **argv)
int x, y, z, N, f;
printf(
"#define TFM_DEFINES\n"
"#include \"fp_sqr_comba.c\"\n"
"\n"
"#if defined(TFM_SMALL_SET)\n"
"void fp_sqr_comba_small(fp_int *A, fp_int *B)\n"
"{\n"
" fp_digit *a, b[32], c0, c1, c2, sc0, sc1, sc2;\n"
"#ifdef TFM_ISO\n"
" fp_word tt;\n"
"#endif\n"
);
printf(" switch (A->used) { \n");
@ -95,11 +102,12 @@ printf(
" B->used = %d;\n"
" B->sign = FP_ZPOS;\n"
" memcpy(B->dp, b, %d * sizeof(fp_digit));\n"
" memset(B->dp + %d, 0, (FP_SIZE - %d) * sizeof(fp_digit));\n"
" fp_clamp(B);\n"
" break;\n\n", N+N, N+N);
" break;\n\n", N+N, N+N, N+N, N+N);
}
printf("}\n\n}\n");
printf("}\n}\n\n#endif /* TFM_SMALL_SET */\n");
return 0;
}

17
src/generators/makefile Normal file
View File

@ -0,0 +1,17 @@
all: comba_sqr_gen comba_sqr_smallgen
clean:
rm -f comba_sqr_gen
rm -f comba_sqr_smallgen
comba_sqr_gen: comba_sqr_gen.c
gcc -o comba_sqr_gen comba_sqr_gen.c
comba_sqr_smallgen: comba_sqr_smallgen.c
gcc -o comba_sqr_smallgen comba_sqr_smallgen.c
regen: comba_sqr_gen comba_sqr_smallgen
for i in 3 4 6 7 8 9 12 17 20 24 28 32 48 64; do \
./comba_sqr_gen $$i > ../sqr/fp_sqr_comba_$$i.c; \
done
./comba_sqr_smallgen > ../sqr/fp_sqr_comba_small_set.c

View File

@ -134,11 +134,9 @@ void fp_sqr_comba12(fp_int *A, fp_int *B)
B->used = 24;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 24 * sizeof(fp_digit));
memset(B->dp + 24, 0, (FP_SIZE - 24) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -184,11 +184,9 @@ void fp_sqr_comba17(fp_int *A, fp_int *B)
B->used = 34;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 34 * sizeof(fp_digit));
memset(B->dp + 34, 0, (FP_SIZE - 34) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -214,11 +214,9 @@ void fp_sqr_comba20(fp_int *A, fp_int *B)
B->used = 40;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 40 * sizeof(fp_digit));
memset(B->dp + 40, 0, (FP_SIZE - 40) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -254,11 +254,9 @@ void fp_sqr_comba24(fp_int *A, fp_int *B)
B->used = 48;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 48 * sizeof(fp_digit));
memset(B->dp + 48, 0, (FP_SIZE - 48) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -294,11 +294,9 @@ void fp_sqr_comba28(fp_int *A, fp_int *B)
B->used = 56;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 56 * sizeof(fp_digit));
memset(B->dp + 56, 0, (FP_SIZE - 56) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -44,11 +44,9 @@ void fp_sqr_comba3(fp_int *A, fp_int *B)
B->used = 6;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 6 * sizeof(fp_digit));
memset(B->dp + 6, 0, (FP_SIZE - 6) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -334,11 +334,9 @@ void fp_sqr_comba32(fp_int *A, fp_int *B)
B->used = 64;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 64 * sizeof(fp_digit));
memset(B->dp + 64, 0, (FP_SIZE - 64) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -54,11 +54,9 @@ void fp_sqr_comba4(fp_int *A, fp_int *B)
B->used = 8;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 8 * sizeof(fp_digit));
memset(B->dp + 8, 0, (FP_SIZE - 8) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -494,11 +494,9 @@ void fp_sqr_comba48(fp_int *A, fp_int *B)
B->used = 96;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 96 * sizeof(fp_digit));
memset(B->dp + 96, 0, (FP_SIZE - 96) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -74,11 +74,9 @@ void fp_sqr_comba6(fp_int *A, fp_int *B)
B->used = 12;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 12 * sizeof(fp_digit));
memset(B->dp + 12, 0, (FP_SIZE - 12) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -654,11 +654,9 @@ void fp_sqr_comba64(fp_int *A, fp_int *B)
B->used = 128;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 128 * sizeof(fp_digit));
memset(B->dp + 128, 0, (FP_SIZE - 128) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -84,11 +84,9 @@ void fp_sqr_comba7(fp_int *A, fp_int *B)
B->used = 14;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 14 * sizeof(fp_digit));
memset(B->dp + 14, 0, (FP_SIZE - 14) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -94,11 +94,9 @@ void fp_sqr_comba8(fp_int *A, fp_int *B)
B->used = 16;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 16 * sizeof(fp_digit));
memset(B->dp + 16, 0, (FP_SIZE - 16) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -104,11 +104,9 @@ void fp_sqr_comba9(fp_int *A, fp_int *B)
B->used = 18;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 18 * sizeof(fp_digit));
memset(B->dp + 18, 0, (FP_SIZE - 18) * sizeof(fp_digit));
fp_clamp(B);
}
#endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -25,6 +25,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 2;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 2 * sizeof(fp_digit));
memset(B->dp + 2, 0, (FP_SIZE - 2) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -54,6 +55,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 4;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 4 * sizeof(fp_digit));
memset(B->dp + 4, 0, (FP_SIZE - 4) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -93,6 +95,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 6;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 6 * sizeof(fp_digit));
memset(B->dp + 6, 0, (FP_SIZE - 6) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -142,6 +145,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 8;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 8 * sizeof(fp_digit));
memset(B->dp + 8, 0, (FP_SIZE - 8) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -201,6 +205,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 10;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 10 * sizeof(fp_digit));
memset(B->dp + 10, 0, (FP_SIZE - 10) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -270,6 +275,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 12;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 12 * sizeof(fp_digit));
memset(B->dp + 12, 0, (FP_SIZE - 12) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -349,6 +355,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 14;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 14 * sizeof(fp_digit));
memset(B->dp + 14, 0, (FP_SIZE - 14) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -438,6 +445,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 16;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 16 * sizeof(fp_digit));
memset(B->dp + 16, 0, (FP_SIZE - 16) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -537,6 +545,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 18;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 18 * sizeof(fp_digit));
memset(B->dp + 18, 0, (FP_SIZE - 18) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -646,6 +655,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 20;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 20 * sizeof(fp_digit));
memset(B->dp + 20, 0, (FP_SIZE - 20) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -765,6 +775,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 22;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 22 * sizeof(fp_digit));
memset(B->dp + 22, 0, (FP_SIZE - 22) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -894,6 +905,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 24;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 24 * sizeof(fp_digit));
memset(B->dp + 24, 0, (FP_SIZE - 24) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -1033,6 +1045,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 26;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 26 * sizeof(fp_digit));
memset(B->dp + 26, 0, (FP_SIZE - 26) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -1182,6 +1195,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 28;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 28 * sizeof(fp_digit));
memset(B->dp + 28, 0, (FP_SIZE - 28) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -1341,6 +1355,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 30;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 30 * sizeof(fp_digit));
memset(B->dp + 30, 0, (FP_SIZE - 30) * sizeof(fp_digit));
fp_clamp(B);
break;
@ -1510,13 +1525,11 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 32;
B->sign = FP_ZPOS;
memcpy(B->dp, b, 32 * sizeof(fp_digit));
memset(B->dp + 32, 0, (FP_SIZE - 32) * sizeof(fp_digit));
fp_clamp(B);
break;
}
}
#endif /* TFM_SMALL_SET */
/* $Source$ */
/* $Revision$ */
/* $Date$ */