chsvlib
chsv helper source code

◆ memfmsub_BE()

void Chusov::Memory::memfmsub_BE ( void *restrict  pResult,
std::size_t  cbResult,
const void *restrict  pX,
std::size_t  cbX,
const void *restrict  pY,
std::size_t  cbY 
)
noexcept

Performs fused multiplication of two arbitrary-precision integers and a subtraction of the product from another arbitrary-precision integer in place. All integers are specified with vectors of bytes in the Big-Endian order.

Parameters
[in,out]pResultA pointer to a buffer which contains an integer whose value is decreased by the product of the values pointed to by pX and pY.
cbResultA byte size of the subtrahend and of the result. Fused multiplication and subtraction is performed by the function modulo bcbResult, where b = 2CHAR_BIT is a number of values that one byte can represent.
[in]pXA pointer to the first integral multiplicand.
cbXA byte size of the multiplicand pointed to by pX.
[in]pYA pointer to the second integer multiplicand.
cbYA byte size of the multiplicand pointed to by cbY.

The function considers the vectors pointed to by pResult, pX and pY to hold bytes of the integers in the Big-Endian byte order. That is, assuming that nx = cbX - 1, ny = cbY - 1 and nR = cbResult - 1, the respective vectors are \(V_R = \{r_0,\dots,r_{n_R}\}\), \(V_X = \{x_0,\dots, x_{n_x}\}\) and \(V_Y = \{y_0,\dots, y_{n_y}\}\), where the bytes \(r_0\), \(x_0\) and \(y_0\) are the first elements within the respective vectors, the function produces the result \(R \gets (R - X \cdot Y)\bmod b^{n_R + 1}\), where on input \(R = \sum_{i=0}^{n_R} r_{n_R-i}\cdot b^i\), \(X = \sum_{i=0}^{n_x} x_{n_x - i}\cdot b^i\), and \(Y = \sum_{i=0}^{n_y} y_{n_y - i}\cdot b^i\) with respect to the Big-Endian order. The result is then written to the buffer pointed to by pResult.

That is, the multiplicands pointed to by pX and pY are firstly zero-extended or contracted in order to produce the \(n_R\)-byte integers \(X' = \sum_{i=0}^{n_R}x'_i\cdot b^i\), where \(x'_i = x_{n_x-i}\), if \(0\le i \le n_x\), and \(x'_i = 0\) otherwise, and \(Y' = \sum_{i=0}^{n_R}y'_{n_y-i}\cdot b^i\), where \(y'_i = y_i\), if \(0\le i\le n_y\), and \(y'_i = 0\) otherwise. Secondly, the integers \(X'\) and \(Y'\) are multiplied modulo \(n_R\). Lastly, the product is subtracted from the integer pointed to by pResult in place of the latter, again modulo \(n_R\).

The buffers pointed to by pResult, pX and pY must not overlap.

The memfmsub_LE function performs the operation over Little-Endian integers.

See also
memfmsub_LE;
memfmadd_BE;
memsub_BE;
memmul_BE.