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

Support for large unsigned integer constants up to 256 bits #35

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

jeanmon
Copy link
Collaborator

@jeanmon jeanmon commented Dec 20, 2023

Currently a literal unsigned integer larger than 32 bits is not supported.

We suffix unsigned integer literals below 64 bits with the "UL" suffix.

Integers with more than 64 bits and less than 256 is supported through a uint256_t constructor call.

Copy link
Member

@Maddiaa0 Maddiaa0 left a comment

Choose a reason for hiding this comment

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

Nice

@@ -328,7 +329,27 @@ fn craft_expression<T: FieldElement>(
collected_public_identities: &mut HashSet<String>,
) -> BBIdentity {
match expr {
Expression::Number(n) => (1, format!("FF({})", n.to_arbitrary_integer())),
Expression::Number(n) => {
Copy link
Member

Choose a reason for hiding this comment

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

Could all of these be covered by the FF("hex string") constructor ?

Copy link
Collaborator Author

@jeanmon jeanmon Dec 20, 2023

Choose a reason for hiding this comment

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

Good idea. According to the current cpp source code, this constructor takes only zero-padded/fixed size hex representation. This means that the cpp generated code would have very long string even for small constants which is not so nice I would say.

See relevant cpp source code:
https://github.com/AztecProtocol/aztec-packages/blob/f1eb6d5b6e3221e5a5b8f55632dba066d4cfbc24/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.hpp#L61

}
if number.bits() < 256 {
let mut chunks: Vec<u64> = number.iter_u64_digits().collect::<Vec<u64>>();
chunks.resize(4, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Is the endianness of this concrete ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You meant "correct"? Yes I checked this.

@jeanmon jeanmon merged commit a1733e2 into avm Dec 20, 2023
1 of 2 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