Skip to content
New issue

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

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Missing fast path in PyLong_From*() functions for compact integers #129149

Open
chris-eibl opened this issue Jan 21, 2025 · 1 comment
Open

Missing fast path in PyLong_From*() functions for compact integers #129149

chris-eibl opened this issue Jan 21, 2025 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage type-feature A feature request or enhancement

Comments

@chris-eibl
Copy link
Contributor

chris-eibl commented Jan 21, 2025

Feature or enhancement

Proposal:

See e.g. the fast path using_PyLong_FromMedium() in PyLong_FromLong(). PyLong_FromLongLong() is almost identical.

Maybe then implement PyLong_FromSsize_t(), PyLong_FromLong() and PyLong_FromLongLong()) using a macro similar to PYLONG_FROM_UINT to get rid of the repetitive code?

PYLONG_FROM_UINT is missing the fast path for medium values, too.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

Per encouragement from @iritkatriel in #128927 (comment)

Linked PRs

@chris-eibl chris-eibl added the type-feature A feature request or enhancement label Jan 21, 2025
@picnixz picnixz added performance Performance or resource usage interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jan 21, 2025
@picnixz picnixz changed the title PyLong_FromSsize_t(), PyLong_FromUnsignedLong(), PyLong_FromUnsignedLong() and PyLong_FromSize_t() miss the fast path for compact integers Missing fast path in PyLong_From*() functions for compact integers Jan 21, 2025
@chris-eibl
Copy link
Contributor Author

PyLong_FromInt32(), PyLong_FromUInt32() and PyLong_FromUInt64() could maybe use these macros, too.
They do "the same thing" in a totally different way ...

vstinner added a commit that referenced this issue Jan 23, 2025
…rs (#129168)

Add fast path in PyLong_From*() functions for compact integers.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
chris-eibl added a commit to chris-eibl/cpython that referenced this issue Jan 25, 2025
Use it in PyLong_FromLong() and PyLong_FromLongLong().
This is just a refactoring and will create the same binary code.
skirpichev added a commit to chris-eibl/cpython that referenced this issue Jan 26, 2025
chris-eibl added a commit to chris-eibl/cpython that referenced this issue Jan 29, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants