5

Github Add NonZeroUn::is_power_of_two by scottmcm · Pull Request #81107 · rust-l...

 3 years ago
source link: https://github.com/rust-lang/rust/pull/81107
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Member

scottmcm commented 14 days ago

edited

This saves instructions on both new and old machines https://rust.godbolt.org/z/4fjTMz

  • On the default x64 target (with no fancy instructions available) it saves a few instructions by not needing to also check for zero.
  • On newer targets (with BMI1) it uses BLSR for super-short assembly.

This can be used for things like checks against alignments stored in NonZeroUsize.

EDIT: New demonstration now that this is available on nightly: https://rust.godbolt.org/z/7bPWxx


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK