Skip to content
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

Make wrapping_neg and overflowing_neg functions into const #57536

Closed
Lokathor opened this issue Jan 12, 2019 · 3 comments
Closed

Make wrapping_neg and overflowing_neg functions into const #57536

Lokathor opened this issue Jan 12, 2019 · 3 comments
Labels
A-const-eval Area: constant evaluation (mir interpretation) T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Lokathor
Copy link
Contributor

With the merge of #57234, we can now make wrapping_neg and overflowing_neg into const as well. They are currently branching, but with a small amount of bit math you can make it branchless instead.

Basic formulas given here, along with some tests: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6a800d9c97885c1aba464ea3103c86e6

(Issue filed per the general request of @Centril to seek and const all possible const targets)

@Centril Centril added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 12, 2019
@Centril
Copy link
Contributor

Centril commented Jan 12, 2019

cc @SimonSapin

(I have no opinions on whether this is feasible to do branchless and w/o control flow, seems like something that needs to be perf tested to not regress non-CTFE...)

@Centril Centril added the A-const-eval Area: constant evaluation (mir interpretation) label Jan 12, 2019
@Lokathor
Copy link
Contributor Author

There appears to be the same performance once you go through optimization (with 1.31, and on x86_64, I didn't check every single target). The overflowing versions are slightly different, but the wrapping versions are the exact same.

https://godbolt.org/z/IWJ2ev

example::CORE_wrapping_neg_u8:
        neg     dil
        mov     eax, edi
        ret

example::NEW_wrapping_neg_u8:
        neg     dil
        mov     eax, edi
        ret

example::CORE_wrapping_neg_i8:
        neg     dil
        mov     eax, edi
        ret

example::NEW_wrapping_neg_i8:
        neg     dil
        mov     eax, edi
        ret

@Centril
Copy link
Contributor

Centril commented Mar 28, 2019

This was done in #58044.

@Centril Centril closed this as completed Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants