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

Suboptimal codegen for quadratic extension #925

Open
shamatar opened this issue Jan 30, 2025 · 1 comment
Open

Suboptimal codegen for quadratic extension #925

shamatar opened this issue Jan 30, 2025 · 1 comment

Comments

@shamatar
Copy link
Contributor

shamatar commented Jan 30, 2025

I was profiling pairing code on different architectures and noticed that this comparison

if P::NONRESIDUE == -P::BaseField::ONE {

is not optimized to nop after monomorphization, most likely because negation is not constant trait. Even though branch predictor should be ok on this place, it's still suboptimal. Most likely the easiest solution until const traits are available is to make additional boolean constant on QuadExtConfig trait that covers such case, or try to provide minus one constant the same way as ONE is provided (and MINUS_ONE is well-defined as there is ONE and Neg + AdditiveGroup) and expect that compiler would optimize-out an equality check (that also is questionable because types are "large")

@shamatar
Copy link
Contributor Author

I tried a quick local patch to add MINUS_ONE and it eliminates the comparison in the codegen and from profiling. Let me know if you want it to be upstreamed (and it is backward compatible if someone defined e.g. custom MontBackend)

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

No branches or pull requests

1 participant