Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5552,14 +5552,20 @@ _PyLong_Lshift(PyObject *a, int64_t shiftby)
static void
v_complement(digit *z, digit *a, Py_ssize_t m)
{
Py_ssize_t i;
digit carry = 1;
for (i = 0; i < m; ++i) {
carry += a[i] ^ PyLong_MASK;
z[i] = carry & PyLong_MASK;
carry >>= PyLong_SHIFT;
Py_ssize_t i = 0;

/* -a is ~a + 1, and the +1 only carries through the trailing zero
digits: they stay zero, the first nonzero digit is negated, and the
digits above it are just inverted. No carry is passed between
iterations of the last loop, so it can be vectorized. */
while (i < m && a[i] == 0) {
z[i++] = 0;
}
assert(i < m);
z[i] = (0U - a[i]) & PyLong_MASK;
for (++i; i < m; ++i) {
z[i] = a[i] ^ PyLong_MASK;
}
assert(carry == 0);
}

/* Bitwise and/xor/or operations */
Expand Down
Loading