clamav/libclamav/tomsfastmath/generators/comba_mult_smallgen.c
Micah Snyder 375ecf678c Update vendored TomsFastMath code to 0.13.1
Update the vendored TomsFastMath (TFM) library to v0.13.1.

Resolves: https://bugzilla.clamav.net/show_bug.cgi?id=11992

I removed compatibility macro's from when libTomMath was used.
This required removing a bunch of faux-error handling because
the fast-math equivalent functions return void, and cannot fail.

The previous version used had named the header "bignum_fast.h"
instead of "tfm.h" and had customizations in that header to enable
TFM_CHECK all the time, and also TFM_NO_ASM if __GNUC__ not defined
or if the system isn't 64bit architecture. This update uses tfm.h
as-is, and has CMake define TFM_CHECK and TFM_NO_ASM as needed.

I've kept bignum.h as an interface to including tfm.h so that in
the future we can more easily add support for system-installed
TomsFastMath instead of the vendored one, taking inspiration from
Debian's patch to support system-TomsFastMath.

See: https://salsa.debian.org/clamav-team/clamav/-/blob/unstable/debian/patches/add-support-for-system-tomsfastmath.patch
2022-02-10 12:54:23 -07:00

68 lines
1.3 KiB
C

/* program emits a NxN comba multiplier for 1x1 to 16x16 */
#include <stdio.h>
int main(int argc, char **argv)
{
int N, x, y, z;
/* print out preamble */
printf(
"#define TFM_DEFINES\n"
"#include \"fp_mul_comba.c\"\n"
"\n"
"#if defined(TFM_SMALL_SET)\n"
"void fp_mul_comba_small(fp_int *A, fp_int *B, fp_int *C)\n"
"{\n"
" fp_digit c0, c1, c2, at[32];\n"
" switch (MAX(A->used, B->used)) { \n"
);
for (N = 1; N <= 16; N++) {
printf(
"\n"
" case %d:\n"
" memcpy(at, A->dp, %d * sizeof(fp_digit));\n"
" memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\n"
" COMBA_START;\n"
"\n"
" COMBA_CLEAR;\n", N, N, N, N);
/* now do the rows */
for (x = 0; x < (N+N-1); x++) {
printf(
" /* %d */\n", x);
if (x > 0) {
printf(
" COMBA_FORWARD;\n");
}
for (y = 0; y < N; y++) {
for (z = 0; z < N; z++) {
if ((y+z)==x) {
printf(" MULADD(at[%d], at[%d]); ", y, z+N);
}
}
}
printf(
"\n"
" COMBA_STORE(C->dp[%d]);\n", x);
}
printf(
" COMBA_STORE2(C->dp[%d]);\n"
" C->used = %d;\n"
" C->sign = A->sign ^ B->sign;\n"
" fp_clamp(C);\n"
" COMBA_FINI;\n"
" break;\n", N+N-1, N+N);
}
printf(" }\n}\n\n#endif\n\n\n"
"/* $Source$ */\n"
"/* $Revision$ */\n"
"/* $Date$ */\n");
return 0;
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */