8000 perf: improve, specialize leading_zeros by DaniPopes · Pull Request #485 · recmo/uint · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

perf: improve, specialize leading_zeros #485

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

Merged
merged 1 commit into from
Jun 27, 2025
Merged

Conversation

DaniPopes
Copy link
Contributor
@DaniPopes DaniPopes commented Jun 12, 2025

specialize for <= u256

I couldn't figure out a way to have a branchless clz directly, so I opted to specialize for small bit widths instead by using u64/u128 primitives

@DaniPopes DaniPopes changed the title perf: specialize leading_zeros perf: improve, specialize leading_zeros Jun 12, 2025
Copy link
codspeed-hq bot commented Jun 12, 2025

CodSpeed Performance Report

Merging #485 will not alter performance

Comparing DaniPopes:spec-clz (22ca580) with main (9426574)

Summary

✅ 253 untouched benchmarks

@@ -155,13 +155,24 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
#[inline]
#[must_use]
pub const fn leading_zeros(&self) -> usize {
let fixed = Self::MASK.leading_zeros() as usize;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be a computed const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't matter, it's always optimized

Copy link
Collaborator

Choose a reason for hiding this comment

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

it doesn't matter for perf in this context, it does matter for potential reuse by other fns or downstream users. the question is whether it's more intuitive and legible to access this as Self::MASK.leading_zeros() or as Self::MASK_LEADING_ZEROS. I'm not convinced it's better either way (especailly as MASK is not exactly a clear constant name on its own)

@prestwich prestwich merged commit 78cc7fa into recmo:main Jun 27, 2025
19 checks passed
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
0