-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
u256 implementation #4794
Closed
Closed
u256 implementation #4794
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xunilrj
force-pushed
the
xunilrj/u256
branch
2 times, most recently
from
July 21, 2023 10:49
cf7dcb8
to
bf3db1f
Compare
7 tasks
xunilrj
force-pushed
the
xunilrj/u256
branch
3 times, most recently
from
July 24, 2023 14:13
74338ee
to
dee029c
Compare
xunilrj
added a commit
that referenced
this pull request
Jul 31, 2023
## Description This PR is part of #4794. It implements the bare minimum to support `u256` constants across the stack. They are represented in sway in hex literals with `u256` suffixes. Hex without suffix will still be `b256`, for backward compatibility until we implement `u256` completely. Then we can decide what to do. There are multiple places in the code that will fail if the literal does not fit in u64. This will be fixed later in a specific PR for big u256. Some places have temporary `unwrap()`, that will be removed later. I can try to remove them now, if necessary. I am leaving all documentation updates for when everything is implemented. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Anton Trunov <[email protected]>
xunilrj
added a commit
that referenced
this pull request
Aug 2, 2023
## Description This PR is part of #4794. It implements support for u256 add operators. The IR generated is a vanilla `add` operator as any other integer. ```rust script { entry fn main() -> u256, !1 { entry(): v0 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001, !2 v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002, !3 v2 = call add_0(v0, v1), !4 ret u256 v2 } } ``` This will then be transformed by `miscdemotion` pass to something like: ```rust script { entry fn main() -> u256 { local u256 __wide_lhs local mut u256 __wide_result local u256 __wide_rhs entry(): v0 = get_local ptr u256, __wide_lhs, !0 v1 = const u256 0x0000000000000000000000000000000000000000000000000000000000000001, !0 store v1 to v0, !0 v2 = get_local ptr u256, __wide_rhs, !0 v3 = const u256 0x0000000000000000000000000000000000000000000000000000000000000002, !0 store v3 to v2, !0 v4 = get_local ptr u256, __wide_result, !0 wide add v0, v2 to v4, !0 v5 = load v4, !0 ret u256 v5 } } ``` Mind the `wide add` here. It is a Fuel specific operation, giving space to other targets to implement this differently. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
xunilrj
added a commit
that referenced
this pull request
Aug 7, 2023
## Description This PR is part of #4794 and implements more operators for u256: - [x] sub - [x] mul - [x] div - [x] comparisions - [x] mod ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Vaivaswatha N <[email protected]>
Unless I'm missing something, the Todo needs to include const expressions evaluation. We want that for |
xunilrj
added a commit
that referenced
this pull request
Aug 8, 2023
## Description This PR is part of #4794. It implements the `not` operator for u256 and allows values bigger than `u64`. To support that it implements `U256` inside `sway-types`. For now, it is a bare minimum wrapper around `BigUint`. We may use fuel macro in the future, which implements all necessary functions. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Anton Trunov <[email protected]>
xunilrj
added a commit
that referenced
this pull request
Aug 14, 2023
## Description This PR is part of #4794. It implements left and right shifts. These have a little difference because the `rhs` is always `u64`, which means that the WQOP used the `rhs` is not indirect. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
This was referenced Aug 14, 2023
xunilrj
added a commit
that referenced
this pull request
Aug 23, 2023
## Description This PR is part of #4794. It implements const eval and optimizations for `u256`. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Joshua Batty <[email protected]> Co-authored-by: IGI-111 <[email protected]>
xunilrj
added a commit
that referenced
this pull request
Aug 30, 2023
## Description This PR is part of #4794. It implements the missing operators: bitwise and comparison. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Anton Trunov <[email protected]>
7 tasks
anton-trunov
pushed a commit
that referenced
this pull request
Sep 21, 2023
## Description This PR is part of #4794 and updates documentation for `u256` and improves test for edge cases. Code also prints more info when tests run in `verbose` mode. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: IGI-111 <[email protected]>
IGI-111
pushed a commit
that referenced
this pull request
Sep 26, 2023
## Description This PR is part of #4794. `u256` was not being considered a reference type which was creating some issues when using it in `storage`. This PR fixes this problem. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
xunilrj
added a commit
that referenced
this pull request
Oct 3, 2023
## Description This PR is part of #4794. It is the minimum implementation for deprecation. Pretty much only what was needed for deprecating `U256`. It also minimally implements `#[allow(deprecated)]`. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
This was referenced Oct 13, 2023
Merged
xunilrj
added a commit
that referenced
this pull request
Oct 16, 2023
## Description This PR is part of #4794. It fix an issue necessary to use `u256` on configurables. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
IGI-111
pushed a commit
that referenced
this pull request
Oct 24, 2023
## Description This PR is part of #4794 and it implements `pow` for u256. It is using the same algorithm as Rust stdlib https://github.com/rust-lang/rust/blob/193e8a196b7700542473a477effd8c6c5786f8de/library/core/src/num/uint_macros.rs#L1976. #4900 implements `pow` for `U256` (upper case `U`) which is being deprecated. Closes #4449 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Andrew O'Brien <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR implements complete support for u256 through the stack:
u256
.U256
(capital U) obsolete, but it does not remove it yet.u256 works as any other copy-able value. So passing by value is memcpy-ing all 32 bytes.
A particular complication is that all wide operations (WQOP, WQML, WQDIV etc...) have their write register as indirect. Which means that I have to allocate stack space for their result.
Single-Step Debugging
This PR also implements an option to run e2e tests using single-step debugging. It is a handy tool to understand what is happening. It prints the current instruction, the before and after of which affect register, and on an ad-hoc manner also the affected memory.
The worst part is that there is no way to set single-stepping. I had to use a transmute. This part is totally optional and I can remove this.
Given that this is completely apart. My suggestion is actually to detach this to a different PR.
Todo
Checklist
Breaking*
orNew Feature
labels where relevant.