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

Eliminate exponentiations in the IR #333

Closed
bobbinth opened this issue Jul 2, 2023 · 3 comments
Closed

Eliminate exponentiations in the IR #333

bobbinth opened this issue Jul 2, 2023 · 3 comments
Labels
enhancement New feature or request IR parser

Comments

@bobbinth
Copy link
Contributor

bobbinth commented Jul 2, 2023

Currently, one of possible Operation's in the IR is exponentiation (Exp(NodeIndex, usize)). I think this needlessly complicates the algebraic graph - especially, since it should be pretty simple to reduce all exponentiations to a sequence of multiplications.

We still should have the ability to do exponentiation in the language, but the parser should reduce exponentiation to an optimal expression using only multiplications.

@hackaugusto
Copy link
Contributor

hackaugusto commented Jul 3, 2023

We still should have the ability to do exponentiation in the language, but the parser should reduce exponentiation to an optimal expression using only multiplications.

Wouldn't it be best to leave that decision to each backend? For the Masm backend it does make sense to replace exponentiation with multiplication for quadratic elements (i mean, we have to do that because the VM doesn't support the operation).

But for the Winterfell backend that would make the generated code more complicated, since it can use a native exponentiation API, and the lowering would lose this information.

Edit: Well, from #130 it seems that is the plan? It seems I don't understand what are the benefits there.

@bobbinth
Copy link
Contributor Author

bobbinth commented Jul 3, 2023

The issue with using generic exponentiation is that we'd end up using a generic algorithm which includes while loops, if statements etc. In our case, exponents are pretty small (9 or smaller in Miden VM case) - so, unrolling should always produce better code, and it would make the overall structure simpler.

@bobbinth
Copy link
Contributor Author

bobbinth commented Aug 9, 2024

Closed by #352.

@bobbinth bobbinth closed this as completed Aug 9, 2024
@bobbinth bobbinth added this to the AirScript v0.4 milestone Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request IR parser
Projects
None yet
Development

No branches or pull requests

2 participants