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

b256 functions for stdlib. #256

Merged
merged 3 commits into from
Sep 22, 2021
Merged

b256 functions for stdlib. #256

merged 3 commits into from
Sep 22, 2021

Conversation

otrho
Copy link
Contributor

@otrho otrho commented Sep 21, 2021

This PR has a couple of changes. Addresses #218 but we will want to add more functionality in the future.

Firstly this fixes a bug in ASM gen which didn't account for the possibility of LWDataId using two VM ops when calculating offsets for labels.

Secondly it adds some initial support for b256 in the stdlib:

  • eq() but not lt() nor gt(). The latter will require some extra support either from the VM or from the Sway virtual ops (more likely).
  • hash_value() takes a single b256 value and hashes it to another b256 value using either SHA256 or Keccak256.
  • hash_pair() takes two b256 values and hashes them contiguously to a b256 value similarly.

Previously when replacing labels with offsets it assumed that all
virtual ops are 1 word in size after conversion to VM ops.

This isn't necessarily true for LWDataId which can be realised as an LW
followed by an ADD when loading a data section offset, for datatypes
larger than a single word.
- `eq()` for comparisons.
- `hash_value()` and `hash_pair()` for SHA256 or Keccak256 hashing.
@otrho otrho self-assigned this Sep 22, 2021
@otrho otrho marked this pull request as ready for review September 22, 2021 05:17
@otrho
Copy link
Contributor Author

otrho commented Sep 22, 2021

Hrmm, was just thinking maybe the hash functions should be split out into a std::hash module or something.

@sezna
Copy link
Contributor

sezna commented Sep 22, 2021

Hrmm, was just thinking maybe the hash functions should be split out into a std::hash module or something.

I have another PR where I do that for the chain module, I can split this one out there as well.

@sezna
Copy link
Contributor

sezna commented Sep 22, 2021

Going to pull this in now (sorry for stealing the "merge" button press from you) so I can organize the stdlib.

@sezna sezna merged commit fc7b4fc into master Sep 22, 2021
@sezna sezna deleted the otrho/218_b256_stdlib branch September 22, 2021 17:11
@adlerjohn adlerjohn added compiler General compiler. Should eventually become more specific as the issue is triaged lib: std Standard library labels Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged lib: std Standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants