static uint32_t simpleMultiplyHighPrecision(uint64_t* arg1, int32_t length, uint64_t arg2) { /* assumes arg2 only holds 32 bits of information */ uint64_t product; int32_t index; index = 0; product = 0; do { product = HIGH_IN_U64 (product) + arg2 * LOW_U32_FROM_PTR (arg1 + index); LOW_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (product); product = HIGH_IN_U64 (product) + arg2 * HIGH_U32_FROM_PTR (arg1 + index); HIGH_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (product); } while (++index < length); return HIGH_U32_FROM_VAR (product); }
U_32 simpleMultiplyHighPrecision (U_64 * arg1, IDATA length, U_64 arg2) { /* assumes arg2 only holds 32 bits of information */ U_64 product; IDATA index; index = 0; product = 0; do { product = HIGH_IN_U64 (product) + arg2 * LOW_U32_FROM_PTR (arg1 + index); LOW_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (product); product = HIGH_IN_U64 (product) + arg2 * HIGH_U32_FROM_PTR (arg1 + index); HIGH_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (product); } while (++index < length); return HIGH_U32_FROM_VAR (product); }
U_32 simpleAppendDecimalDigitHighPrecision (U_64 * arg1, IDATA length, U_64 digit) { /* assumes digit is less than 32 bits */ U_64 arg; IDATA index = 0; digit <<= 32; do { arg = LOW_IN_U64 (arg1[index]); digit = HIGH_IN_U64 (digit) + TIMES_TEN (arg); LOW_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (digit); arg = HIGH_IN_U64 (arg1[index]); digit = HIGH_IN_U64 (digit) + TIMES_TEN (arg); HIGH_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (digit); } while (++index < length); return HIGH_U32_FROM_VAR (digit); }
uint32_t simpleAppendDecimalDigitHighPrecision (uint64_t * arg1, int32_t length, uint64_t digit) { /* assumes digit is less than 32 bits */ uint64_t arg; int32_t index = 0; digit <<= 32; do { arg = LOW_IN_U64 (arg1[index]); digit = HIGH_IN_U64 (digit) + TIMES_TEN (arg); LOW_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (digit); arg = HIGH_IN_U64 (arg1[index]); digit = HIGH_IN_U64 (digit) + TIMES_TEN (arg); HIGH_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (digit); } while (++index < length); return HIGH_U32_FROM_VAR (digit); }
void simpleMultiplyAddHighPrecisionBigEndianFix(uint64_t* arg1, int32_t length, uint64_t arg2, uint32_t* result) { /* Assumes result can hold the product and arg2 only holds 32 bits of information */ int32_t index = 0; int32_t resultIndex = 0; uint64_t product = 0; do { product = HIGH_IN_U64(product) + result[halfAt(resultIndex)] + arg2 * LOW_U32_FROM_PTR(arg1 + index); result[halfAt(resultIndex)] = LOW_U32_FROM_VAR(product); ++resultIndex; product = HIGH_IN_U64(product) + result[halfAt(resultIndex)] + arg2 * HIGH_U32_FROM_PTR(arg1 + index); result[halfAt(resultIndex)] = LOW_U32_FROM_VAR(product); ++resultIndex; } while (++index < length); result[halfAt(resultIndex)] += HIGH_U32_FROM_VAR(product); if (result[halfAt(resultIndex)] < HIGH_U32_FROM_VAR(product)) { /* must be careful with ++ operator and macro expansion */ ++resultIndex; while (++result[halfAt(resultIndex)] == 0) ++resultIndex; } }
void simpleMultiplyAddHighPrecision (U_64 * arg1, IDATA length, U_64 arg2, U_32 * result) { /* Assumes result can hold the product and arg2 only holds 32 bits of information */ U_64 product; IDATA index, resultIndex; index = resultIndex = 0; product = 0; do { product = HIGH_IN_U64 (product) + result[at (resultIndex)] + arg2 * LOW_U32_FROM_PTR (arg1 + index); result[at (resultIndex)] = LOW_U32_FROM_VAR (product); ++resultIndex; product = HIGH_IN_U64 (product) + result[at (resultIndex)] + arg2 * HIGH_U32_FROM_PTR (arg1 + index); result[at (resultIndex)] = LOW_U32_FROM_VAR (product); ++resultIndex; } while (++index < length); result[at (resultIndex)] += HIGH_U32_FROM_VAR (product); if (result[at (resultIndex)] < HIGH_U32_FROM_VAR (product)) { /* must be careful with ++ operator and macro expansion */ ++resultIndex; while (++result[at (resultIndex)] == 0) ++resultIndex; } }