| ... | @@ -1271,6 +1271,12 @@ void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2) { | ... | @@ -1271,6 +1271,12 @@ void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2) { |
| 1271 | } | 1271 | } |
| 1272 | | 1272 | |
| 1273 | void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) { | 1273 | void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) { |
| | 1274 | if (op1->digit_count == 0) { |
| | 1275 | return bigint_init_bigint(dest, op2); |
| | 1276 | } |
| | 1277 | if (op2->digit_count == 0) { |
| | 1278 | return bigint_init_bigint(dest, op1); |
| | 1279 | } |
| 1274 | if (op1->is_negative || op2->is_negative) { | 1280 | if (op1->is_negative || op2->is_negative) { |
| 1275 | // TODO this code path is untested | 1281 | // TODO this code path is untested |
| 1276 | size_t big_bit_count = max(bigint_bits_needed(op1), bigint_bits_needed(op2)); | 1282 | size_t big_bit_count = max(bigint_bits_needed(op1), bigint_bits_needed(op2)); |
| ... | @@ -1289,14 +1295,16 @@ void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) { | ... | @@ -1289,14 +1295,16 @@ void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) { |
| 1289 | dest->is_negative = false; | 1295 | dest->is_negative = false; |
| 1290 | const uint64_t *op1_digits = bigint_ptr(op1); | 1296 | const uint64_t *op1_digits = bigint_ptr(op1); |
| 1291 | const uint64_t *op2_digits = bigint_ptr(op2); | 1297 | const uint64_t *op2_digits = bigint_ptr(op2); |
| | 1298 | |
| | 1299 | assert(op1->digit_count > 0 && op2->digit_count > 0); |
| | 1300 | uint64_t first_digit = op1_digits[0] ^ op2_digits[0]; |
| 1292 | if (op1->digit_count == 1 && op2->digit_count == 1) { | 1301 | if (op1->digit_count == 1 && op2->digit_count == 1) { |
| 1293 | dest->digit_count = 1; | 1302 | dest->digit_count = 1; |
| 1294 | dest->data.digit = op1_digits[0] ^ op2_digits[0]; | 1303 | dest->data.digit = first_digit; |
| 1295 | bigint_normalize(dest); | 1304 | bigint_normalize(dest); |
| 1296 | return; | 1305 | return; |
| 1297 | } | 1306 | } |
| 1298 | // TODO this code path is untested | 1307 | // TODO this code path is untested |
| 1299 | uint64_t first_digit = dest->data.digit; | | |
| 1300 | dest->digit_count = max(op1->digit_count, op2->digit_count); | 1308 | dest->digit_count = max(op1->digit_count, op2->digit_count); |
| 1301 | dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count); | 1309 | dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count); |
| 1302 | dest->data.digits[0] = first_digit; | 1310 | dest->data.digits[0] = first_digit; |