-
Notifications
You must be signed in to change notification settings - Fork 161
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
Prevent unnecessary bounds check in SCB::{get_priority, set_priority} #202
Prevent unnecessary bounds check in SCB::{get_priority, set_priority} #202
Conversation
r? @therealprof (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code change looks good to me, I'm not quite happy about the unsafety comments, though.
prevent unnecessary bounds check!
I don't think we need to provide a motivation here. The use of get_unchecked
makes it quite clear that the motivation here is to get rid of bound checks.
Index of shpr array is true by SystemHandler design.
I don't know what true
means in this context. Should rather say something along lines of "index
is bounded to [x,y] by SystemHandler design".
Alternatively we could also throw in an assert to ensure that this invariant is never violated and point to that instead. Not sure how that would fare with code generation though.
I tried adding assert!(index <16), but the compiler could not optimize it. Is there a reason why we cannot change SystemHandler definition to:
? |
This is an alternative proposal to #202 as suggested in #202 (comment) Signed-off-by: Daniel Egger <[email protected]>
Let's see how that goes. |
203: Use u8 repr for enum instead of custom method r=jonas-schievink a=therealprof This is an alternative proposal to #202 as suggested in #202 (comment) Signed-off-by: Daniel Egger <[email protected]> Co-authored-by: Daniel Egger <[email protected]>
@qwerty19106 Can you check whether #203 does the trick on its own or whether we still need to change use |
On #203 the code just got a little easier, but panic_bounds_check is still present. With temporary disabled #[inline] and armv7m target:
I updated unsafe comments. Now it produce this code:
I think one should to create issue in the Rust repository, since #203 should give enough information for compiler. I could do it if you don't mind. |
Agreed, this looks like a missed optimization. I'll file an issue. |
Looks like it's an old issue: rust-lang/rust#13926 |
@jonas-schievink Do you have a strong opinion on whether we should make this change in the interim? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
I don't have anything against merging this, but the comments should mention the upstream issue. |
Added TODO comment about rust-lang/rust#13926 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks you.
bors r+ |
Build succeeded |
202: Enable building semihosting for Armv8m r=korken89 a=aurabindo Semihosting protocol has not changed for Arvmv8m and hence it need not be disabled for this architecture. Co-authored-by: Aurabindo Jayamohanan <[email protected]>
SystemHandler.index() gives true index for SCB.shpr array.
But now it produce unnecessary bounds check. For example, SCB::set_priority:
This PR fix it.