michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* This file contains routines that perform vector multiplication. */ michael@0: michael@0: #include "mpi-priv.h" michael@0: #include michael@0: michael@0: #include michael@0: /* #include */ michael@0: #include michael@0: michael@0: extern void multacc512( michael@0: int length, /* doublewords in multiplicand vector. */ michael@0: const mp_digit *scalaraddr, /* Address of scalar. */ michael@0: const mp_digit *multiplicand, /* The multiplicand vector. */ michael@0: mp_digit * result); /* Where to accumulate the result. */ michael@0: michael@0: extern void maxpy_little( michael@0: int length, /* doublewords in multiplicand vector. */ michael@0: const mp_digit *scalaraddr, /* Address of scalar. */ michael@0: const mp_digit *multiplicand, /* The multiplicand vector. */ michael@0: mp_digit * result); /* Where to accumulate the result. */ michael@0: michael@0: extern void add_diag_little( michael@0: int length, /* doublewords in input vector. */ michael@0: const mp_digit *root, /* The vector to square. */ michael@0: mp_digit * result); /* Where to accumulate the result. */ michael@0: michael@0: void michael@0: s_mpv_sqr_add_prop(const mp_digit *pa, mp_size a_len, mp_digit *ps) michael@0: { michael@0: add_diag_little(a_len, pa, ps); michael@0: } michael@0: michael@0: #define MAX_STACK_DIGITS 258 michael@0: #define MULTACC512_LEN (512 / MP_DIGIT_BIT) michael@0: #define HP_MPY_ADD_FN (a_len == MULTACC512_LEN ? multacc512 : maxpy_little) michael@0: michael@0: /* c = a * b */ michael@0: void michael@0: s_mpv_mul_d(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) michael@0: { michael@0: mp_digit x[MAX_STACK_DIGITS]; michael@0: mp_digit *px = x; michael@0: size_t xSize = 0; michael@0: michael@0: if (a == c) { michael@0: if (a_len > MAX_STACK_DIGITS) { michael@0: xSize = sizeof(mp_digit) * (a_len + 2); michael@0: px = malloc(xSize); michael@0: if (!px) michael@0: return; michael@0: } michael@0: memcpy(px, a, a_len * sizeof(*a)); michael@0: a = px; michael@0: } michael@0: s_mp_setz(c, a_len + 1); michael@0: HP_MPY_ADD_FN(a_len, &b, a, c); michael@0: if (px != x && px) { michael@0: memset(px, 0, xSize); michael@0: free(px); michael@0: } michael@0: } michael@0: michael@0: /* c += a * b, where a is a_len words long. */ michael@0: void michael@0: s_mpv_mul_d_add(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) michael@0: { michael@0: c[a_len] = 0; /* so carry propagation stops here. */ michael@0: HP_MPY_ADD_FN(a_len, &b, a, c); michael@0: } michael@0: michael@0: /* c += a * b, where a is y words long. */ michael@0: void michael@0: s_mpv_mul_d_add_prop(const mp_digit *a, mp_size a_len, mp_digit b, michael@0: mp_digit *c) michael@0: { michael@0: HP_MPY_ADD_FN(a_len, &b, a, c); michael@0: } michael@0: