-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Pack u128 in the compiler to mitigate new alignment #120080
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::stable_hasher::{HashStable, StableHasher}; | ||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; | ||
use std::cmp::Ordering; | ||
use std::fmt; | ||
|
||
#[repr(packed(8))] | ||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct Pu128(pub u128); | ||
|
||
impl Pu128 { | ||
#[inline] | ||
pub fn get(self) -> u128 { | ||
self.0 | ||
} | ||
} | ||
|
||
impl From<u128> for Pu128 { | ||
#[inline] | ||
fn from(value: u128) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl PartialEq<u128> for Pu128 { | ||
#[inline] | ||
fn eq(&self, other: &u128) -> bool { | ||
({ self.0 }) == *other | ||
} | ||
} | ||
|
||
impl PartialOrd<u128> for Pu128 { | ||
#[inline] | ||
fn partial_cmp(&self, other: &u128) -> Option<Ordering> { | ||
{ self.0 }.partial_cmp(other) | ||
} | ||
} | ||
|
||
impl fmt::Display for Pu128 { | ||
#[inline] | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
{ self.0 }.fmt(f) | ||
} | ||
} | ||
|
||
impl fmt::UpperHex for Pu128 { | ||
#[inline] | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
{ self.0 }.fmt(f) | ||
} | ||
} | ||
|
||
impl<CTX> HashStable<CTX> for Pu128 { | ||
#[inline] | ||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { | ||
{ self.0 }.hash_stable(ctx, hasher) | ||
} | ||
} | ||
|
||
impl<S: Encoder> Encodable<S> for Pu128 { | ||
#[inline] | ||
fn encode(&self, s: &mut S) { | ||
{ self.0 }.encode(s); | ||
} | ||
} | ||
|
||
impl<D: Decoder> Decodable<D> for Pu128 { | ||
#[inline] | ||
fn decode(d: &mut D) -> Self { | ||
Self(u128::decode(d)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there any reason this needs to be 8-aligned? Is there anything to be gained from reducing alignment further?
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.
I just chose that to match its former alignment, which should still be a nice "native" alignment (on 64-bit hosts). We could try smaller, but in a quick local check, even a full
#[repr(packed)]
didn't change thesestatic_assert_size
s any further. Generally, I suspect there's almost always going to be ausize
or pointer nearby keeping overall struct alignment up.Maybe we should make it match
target_pointer_width
? But we don't test performance on other targets...