Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ErisianArchitect
Copy link
Contributor

Description

The is_alignment_ok function in builder.rs uses log2 to determine the number of bits that are number needs. It compares the result with 64. This is unnecessary as the align parameter is only 32-bits, so this comparison will always return true.

If align were 64-bit, the check would still be unnecessary because you can't have 2^64 as a 64-bit value. If align were 128-bit, then you could perform this check using align.trailing_zeros(), which is faster than converting to f64 and using log2, which would be inaccurate for an 128-bit integer anyway.

How This Has Been Tested

No tests needed. It's logically sound.

Checklist

@TheDan64 TheDan64 self-assigned this Aug 14, 2025
@TheDan64 TheDan64 self-requested a review August 14, 2025 03:04
Copy link
Owner

@TheDan64 TheDan64 left a comment

Choose a reason for hiding this comment

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

Good catch, thanks!

@TheDan64 TheDan64 merged commit 0b0a2c0 into TheDan64:master Aug 14, 2025
15 checks passed
@ErisianArchitect
Copy link
Contributor Author

I'm also working on some changes that will allow you to set the alignment during operations where the alignment could be specified. So for example, build_aligned_alloca where you can specify the alignment.
I also added an AlignmentError enum that can be used in place of the &'static str in BuilderError::AlignmentError.
I just didn't want to make these changes all at once.
If you're against any of these changes, let me know.

@TheDan64 TheDan64 added this to the 0.7.0 milestone Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants