-
Notifications
You must be signed in to change notification settings - Fork 132
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
Improve PageTableIndex and PageOffset. #122
Conversation
m-ou-se
commented
Jan 25, 2020
- There are now const functions to make them: new_truncate.
- The new truncating are used in VirtAddr to avoid needless checks.
- The guarantee that they are in 0..512 and 0..4096 is documented.
- This guarantee is used in Index for PageTable to avoid needless checks.
- They are now both Into, to make it easier to use them as index.
- There are now const functions to make them: new_truncate. - The new truncating are used in VirtAddr to avoid needless checks. - The guarantee that they are in 0..512 and 0..4096 is documented. - This guarantee is used in Index for PageTable to avoid needless checks. - They are now both Into<usize>, to make it easier to use them as index.
Thanks a lot for the pull request! Most of the changes look good to me, I'm just not sure about the new uses of unsafe. While I agree that the two I would prefer if we could run some benchmarks before adding any I think it's best to merge this pull request without the unsafe changes first and then discuss these changes in a followup PR. |
@m-ou-se Friendly ping :). |
The compiler probably optimizes the checks away anyway.
Pong! |
As the documentation now makes the guarantee that a PageTableIndex is always <512, users of this crate might also start to use unsafe indexing using it. So I don't think there would be much space for changing PageTableIndex anyway. But I definitely agree that less unsafe code is better. In this case, I'd guess that in pretty much all cases where PageTableIndex is used, the compiler can track the index back to where it is created, and should know it is <512, thus dropping any redundant asserts. I added |
Thanks a lot for the update!
Sounds reasonable. I think with link time optimization, the compiler does cross-crate inlining also without the attribute, but not everyone is using lto. |
Released as version 0.9.1 |