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

Add bitwise air constraints with currently supported syntax #58

Merged
merged 3 commits into from
Nov 25, 2022

Conversation

tohrnii
Copy link
Contributor

@tohrnii tohrnii commented Nov 3, 2022

This PR adds a modified version of existing bitwise air constraints to work with currently supported syntax and adds an integration test to check for expected code generation.

@tohrnii tohrnii changed the title test: add bitwise air constraints with currently supported syntax Add bitwise air constraints with currently supported syntax Nov 5, 2022
@tohrnii tohrnii marked this pull request as ready for review November 5, 2022 22:22
@tohrnii tohrnii requested review from grjte and bobbinth November 5, 2022 22:22
Copy link
Contributor

@grjte grjte left a comment

Choose a reason for hiding this comment

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

Thanks @tohrnii this is a good addition to the tests. I left a few comments inline. Also, I think maybe we should remove this from the examples now that we've created a new test for it. I'm not sure that it makes sense to have the duplication or to have unsupported syntax in our examples (although we can use a variation of that file for the next version)

air-script/tests/bitwise/bitwise.air Outdated Show resolved Hide resolved
air-script/tests/bitwise/bitwise.air Outdated Show resolved Hide resolved
air-script/tests/bitwise/bitwise.air Outdated Show resolved Hide resolved
air-script/tests/bitwise/bitwise.air Outdated Show resolved Hide resolved
air-script/tests/bitwise/bitwise.air Outdated Show resolved Hide resolved
@tohrnii tohrnii force-pushed the bitwise branch 2 times, most recently from 1217d1c to edf5d84 Compare November 11, 2022 08:41
@tohrnii
Copy link
Contributor Author

tohrnii commented Nov 11, 2022

Thank you @grjte for the review. Made suggested changes and fixes.

I'm not sure that it makes sense to have the duplication or to have unsupported syntax in our examples (although we can use a variation of that file for the next version)

I've removed the examples directory entirely as we have all those files in the integration tests now.

@tohrnii tohrnii requested a review from grjte November 11, 2022 08:47
@tohrnii tohrnii changed the base branch from main to next November 13, 2022 19:17
Copy link
Contributor

@grjte grjte left a comment

Choose a reason for hiding this comment

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

Thanks @tohrnii, all the bitwise work looks good now. I don't think we should delete all the examples though, since in the docs & CLI examples we mention that they can be used for testing transpilation with the CLI. Maybe it would be best to just restore them for this PR and then submit a separate PR that has just one example which could be the example from the docs that includes all the syntax. What do you think?

@tohrnii
Copy link
Contributor Author

tohrnii commented Nov 15, 2022

I don't think we should delete all the examples though, since in the docs & CLI examples we mention that they can be used for testing transpilation with the CLI. Maybe it would be best to just restore them for this PR and then submit a separate PR that has just one example which could be the example from the docs that includes all the syntax. What do you think?

Makes sense. I've opened #74 based on your suggestion.

let next = frame.next();
result[0] = (current[0]).exp(E::PositiveInteger::from(2_u64)) - (current[0]) - (E::from(0_u64));
result[1] = (periodic_values[1]) * (next[0] - (current[0])) - (E::from(0_u64));
result[2] = (current[3]).exp(E::PositiveInteger::from(2_u64)) - (current[3]) - (E::from(0_u64));
Copy link
Contributor

@bobbinth bobbinth Nov 15, 2022

Choose a reason for hiding this comment

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

Comment for the future: exponentiations could be really expensive, especially for constant-time implementations (like the one we are currently using). So, whenever possible, we should replace them with multiplications or more specialized operations.

For example, here, instead of doing (current[0]).exp(E::PositiveInteger::from(2_u64)) we should be doing (current[0] * current[0]) or current[0].square().

Also, if we know that a constant value is smaller than u32 we should try to use conversions from u32. For example: E::from(2_u32) instead of E::from(2_u64) as we may come up with a more efficient reduction for smaller values later on.

Copy link
Contributor

@grjte grjte left a comment

Choose a reason for hiding this comment

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

Thanks @tohrnii, this looks good!

@grjte grjte merged commit 0e1908d into 0xPolygonMiden:next Nov 25, 2022
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.

3 participants