| ... | @@ -1410,12 +1410,19 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) { | ... | @@ -1410,12 +1410,19 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) { |
| 1410 | } | 1410 | } |
| 1411 | | 1411 | |
| 1412 | dest->digit_count = op1->digit_count - digit_shift_count; | 1412 | dest->digit_count = op1->digit_count - digit_shift_count; |
| 1413 | dest->data.digits = allocate<uint64_t>(dest->digit_count); | 1413 | uint64_t *digits; |
| | 1414 | if (dest->digit_count == 1) { |
| | 1415 | digits = &dest->data.digit; |
| | 1416 | } else { |
| | 1417 | digits = allocate<uint64_t>(dest->digit_count); |
| | 1418 | dest->data.digits = digits; |
| | 1419 | } |
| | 1420 | |
| 1414 | uint64_t carry = 0; | 1421 | uint64_t carry = 0; |
| 1415 | for (size_t op_digit_index = op1->digit_count - 1;;) { | 1422 | for (size_t op_digit_index = op1->digit_count - 1;;) { |
| 1416 | uint64_t digit = op1_digits[op_digit_index]; | 1423 | uint64_t digit = op1_digits[op_digit_index]; |
| 1417 | size_t dest_digit_index = op_digit_index - digit_shift_count; | 1424 | size_t dest_digit_index = op_digit_index - digit_shift_count; |
| 1418 | dest->data.digits[dest_digit_index] = carry | (digit >> leftover_shift_count); | 1425 | digits[dest_digit_index] = carry | (digit >> leftover_shift_count); |
| 1419 | carry = digit << (64 - leftover_shift_count); | 1426 | carry = digit << (64 - leftover_shift_count); |
| 1420 | | 1427 | |
| 1421 | if (dest_digit_index == 0) { break; } | 1428 | if (dest_digit_index == 0) { break; } |