Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-100239: specialize left and right shift ops on ints#129431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
eendebakpt wants to merge13 commits intopython:main
base:main
Choose a base branch
Loading
fromeendebakpt:binaryops_shift

Conversation

@eendebakpt
Copy link
Contributor

@eendebakpteendebakpt commentedJan 29, 2025
edited
Loading

We add a specialization for>> and>> on compact integers.

  • For both lshift and rshift we have to avoid undefined behavior for shifts larger than the number of bits in a C long.
  • The lshift operator<< can overflow, so we restrict shifts to values smaller than 17. Under this assumption the value ofa << b withb <= 16) fit into a 32-bit or 64-bit integer depending on the platform.

Benchmark:

bench_lshift_compactint: Mean +- std dev: [mainx2] 381 us +- 33 us -> [prx2] 334 us +- 46 us: 1.14x fasterbench_rshift_compactint: Mean +- std dev: [mainx2] 398 us +- 34 us -> [prx2] 281 us +- 46 us: 1.41x fasterBenchmark hidden because not significant (1): bench_rshift_largeintGeometric mean: 1.17x **faster**

(non-PGO, Windows)

There is a gain with the specialization, but on the other hand: how many shift operations on compact ints are there? For example the shifts are used in theuuid module, but always on large ints.

@eendebakpteendebakpt added this to the hhhhhhhhhhhhhhhhhhhhhhhhhbbbbbbbb milestoneJan 29, 2025
@bswck
Copy link
Contributor

bswck commentedJan 29, 2025
edited
Loading

@eendebakpt, something happened with the milestone.
image

eendebakpt reacted with confused emoji

@skirpichevskirpichev removed this from the hhhhhhhhhhhhhhhhhhhhhhhhhbbbbbbbb milestoneJan 29, 2025
@eendebakpteendebakpt marked this pull request as draftJanuary 29, 2025 19:51
@eendebakpteendebakpt changed the titlegh-100239: specialize right shift ops on intsgh-100239: specialize left and right shift ops on intsJan 29, 2025
@eendebakpteendebakpt marked this pull request as ready for reviewJanuary 30, 2025 20:16
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@eendebakpt@bswck@skirpichev

[8]ページ先頭

©2009-2025 Movatter.jp