Skip to content

[mypyc] Generate efficient code for (some) conversions i64(x) and i32(x) #13621

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 9, 2022

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Sep 7, 2022

These are now optimized for i32, i64 and int arguments.

i32(x) truncates from i64, but does a range check when converting from int. The rationale is that implicit conversions from int perform range checks to avoid silently corrupting data, and explicit coercions use the same semantics. However, conversions from i64 to i32 must be explicit and thus there is no implicit corruption possible. Truncation is also a very fast operation, which we generally prefer when working purely on native integers. A range check would introduce some overhead. I'm not sure if this is the best approach, however, and this feels a bit inconsistent.

I'll add optimized conversions from float in another PR once we support unboxed floats. Conversions from other types could also be improved in the future.

Work on mypyc/mypyc#837.

These are now optimized for i32, i64 and int arguments.

I'll add optimized conversions from float in another PR once we
support unboxed floats. Conversions from other types could also
be improved in the future.

Work on mypyc/mypyc#837.
@JukkaL JukkaL merged commit c8e5278 into master Sep 9, 2022
@JukkaL JukkaL deleted the native-int-conv-3 branch September 9, 2022 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants