chsvlib
chsv helper source code

◆ memor_BE()

void Chusov::Memory::memor_BE ( void *  pDest,
std::size_t  cbDest,
const void *  pSrc1,
std::size_t  cbSrc1,
const void *  pSrc2,
std::size_t  cbSrc2 
)
noexcept

The generic form of bitwise OR of two operands specified in Big-Endian byte order.

Parameters
[out]pDestA pointer to the output buffer receiving the result of bitwise OR.
cbDestThe capacity of the destination buffer pDest, in bytes.
[in]pSrc1A pointer to one of the operands.
cbSrc1A byte length of the operand pointed to by pSrc1.
[in]pSrc2A pointer to another of the operands.
cbSrc2A byte length of the operand pointed to by pSrc2.

The function computes bitwise OR of arbitrary-precision integers of possibly different byte sizes and stored in possibly overlapping buffers pSrc1 and pSrc2 and writes the result into the buffer pDest, of a custom size cbDest, that also can overlap with the buffers of the operands. That is, there are no restrictions on respective values of the sizes or respective positions of the buffers in memory.

Let \(n_1 = \textrm{cbSrc1}\), \(n_2 = \textrm{cbSrc2}\), \(m = \textrm{cbDest}\) and \(n = \min (n_1, n_2)\). Let also \(x\) be the value specified by the first buffer pSrc1, i.e. \(x=\sum_{i=0}^{n_1 - 1}x_i\cdot b^i\), and \(y\) be the value specified by the second buffer pSrc2, i.e. \(y=\sum_{i=0}^{n_2 - 1}y_i\cdot b^i\), where b = 2CHAR_BIT, that is a number of values that can be represented using one byte. Then the function produces the result \(R = \left(\sum_{i=0}^{n-1}(x_i⊞ y_i)\cdot b^i + \sum_{i=n}^{n_1 - 1}x_i\cdot b^i + \sum_{i=n}^{n_2 - 1}y_i\cdot b^i\right)\bmod b^m\), where \(⊞\) denotes bitwise OR of two bytes.

That is, if cbSrc1 is greater than cbSrc2, then the lowest cbSrc2 bytes of the result will actually be the result of bitwise OR of respective bytes in pSrc1 and pSrc2; the highest cbSrc1 - cbSrc2 bytes of the result will be copied from the respective bytes of pSrc1. Irrespective of that, if cbDest is less than the byte size of the result, i.e. max(cbSrc1, cbSrc2), the resulting value will be truncated so that only the lowest part of the result is written into the destination buffer pDest. If, on the other hand, cbDest is greater than the byte size of the result, the remaining high-order bytes of the destination buffer will be zeroed out.

The function considers the specified parameters be in the Big-Endian format. That is, using the notation above, the first byte of pSrc1 specifies \(x_{n_1 - 1}\), and the last one specifies \(x_{0}\). Likewise, the first byte of pSrc2 specifies the value of \(y_{n_2 - 1}\), and the last one specifies \(y_0\). The result is also written in the Big-Endian format, therefore the last byte of the destination buffer receives the value \(x_0⊞ y_0\), the penultimate byte receives \(x_1⊞ y_1\) and so on.

To perform a computation of values in the Little-Endian order, use the memor_LE function.

Compared to memor_copy and memor_inplace, the function also performs necessary calculations to match the process with the possibly overlapping buffers and differing sizes. If the operation of the function is known to be conducted with non-overlapping buffers of equal sizes, the preferable faster function for that is memor_copy. If the operation is done in place with otherwise non-overlapping buffers, the faster alternative is memor_inplace.

See also
memor_LE;
memor_copy;
memor_inplace;
memand_LE, memand_BE;
memxor_LE, memxor_BE;
memandnot_LE, memandnot_BE;
memornot_LE, memornot_BE;
memxornot_LE, memxornot_BE;
memnot_LE, memnot_BE.