Skip to content

gh-161127: Let compilers vectorize v_complement() - #161128

Open
eendebakpt wants to merge 1 commit into
python:mainfrom
eendebakpt:longobject-vcomplement
Open

eendebakpt wants to merge 1 commit into
python:mainfrom
eendebakpt:longobject-vcomplement

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

The two's complement of a digit vector 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. See corresponding issue for benchmarks.

The two's complement of a digit vector 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.  Written that way
no carry is passed between loop iterations, so the loop can be vectorized.

v_complement() runs for every bitwise operation with a negative multi-digit
operand, up to three times per operation.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant