Skip to content

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

Merged
StanFromIreland merged 1 commit into
python:mainfrom
eendebakpt:longobject-vcomplement
Nov 2, 2026
Merged

StanFromIreland merged 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 <[email protected]>
@bedevere-app bedevere-app Bot added awaiting core review type-feature A feature request or enhancement labels Nov 1, 2026
@StanFromIreland
StanFromIreland self-requested a review November 1, 2026 20:13
@StanFromIreland
StanFromIreland merged commit e4dba41 into python:main Nov 2, 2026
59 of 63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants