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

Fix i686 host builds #34

Merged
merged 2 commits into from
Oct 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions generator/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
pub fn smallest_index(n: usize) -> usize {
for &x in [8, 16, 32].iter() {
if n < (1 << x) {
return x / 8;
/// Figure out whether we need `u8` (1 byte), `u16` (2 bytes) or `u32` (4 bytes) to store all
/// numbers. Returns the number of bytes
pub fn smallest_type<I: Iterator<Item = u32>>(x: I) -> usize {
let n = x.max().unwrap_or(0);
for (max, bytes) in [(u8::MAX as u32, 1), (u16::MAX as u32, 2)] {
if n <= max {
return bytes;
}
}
64
Copy link
Owner

@progval progval Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this line unreachable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it must have been, it's definitely incorrect in the old version, it should have been 8 and not 64. (I think this also explains why we saw a u512 in the broken build, we got u{64 * 8})

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized we can actually know that it is unreachable: The only caller was smallest_type, which takes a Iterator<Item = u32>, and all u32 are guaranteed to be smaller than (1 << 32).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
pub fn smallest_type<I: Iterator<Item = u32>>(x: I) -> usize {
smallest_index(x.max().unwrap_or(0) as usize)
4
}

pub fn smallest_u<I: Iterator<Item = u32>>(x: I) -> String {
format!("u{}", 8 * smallest_type(x))
}
Expand Down