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 module to the stdlib with wrapper functions for common (all?) opcodes #1074

Closed
1 task
nfurfaro opened this issue Feb 14, 2022 · 7 comments
Closed
1 task
Labels
big this task is hard and will take a while enhancement New feature or request good first issue Good for newcomers lib: std Standard library

Comments

@nfurfaro
Copy link
Contributor

nfurfaro commented Feb 14, 2022

Like FuelLabs/sway-lib-std#38 , the goal here would be to minimize the usage of assembly needed while building out the stdlib (and other libraries) by providing utilities for calling opcodes in a simpler way (in terms of writing , reviewing and reading/maintaining).
wrapper functions could be chained together to achieve whatever is needed for the current task at hand.
Idea by @otrho .

  • extract overflow FLAG wrapper functions enable_overfow() and disable_overflow() from U128 type module.
@nfurfaro nfurfaro added the enhancement New feature or request label Feb 14, 2022
@nfurfaro nfurfaro self-assigned this Feb 14, 2022
@otrho
Copy link
Contributor

otrho commented Feb 17, 2022

I'm not a huge fan of ASM blocks in general, but especially in the core & std libs. They definitely have their place, but they end up being black boxes as far as non-trivial optimisations go (i.e., in the IR stage). They can be quite buggy too, as they're not type checked and make assumptions about compiler codegen, which could change in the future (and probably should change as Sway matures) but we wouldn't necessarily notice them breaking if they did.

Introducing compiler 'intrinsics' -- typed functions which are axiomatically provided by the compiler -- which essentially wrap around useful special case opcodes, like those for hashing or copying memory, would prevent breaks based on assumptions and allow the IR to do its job.

Some GCC examples to illustrate what I mean: https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Other-Builtins.html#Other-Builtins
https://en.wikipedia.org/wiki/Intrinsic_function

@nfurfaro
Copy link
Contributor Author

@otrho Should we move this issue to the sway repo if the idea is to implement as part of the compile rather than as std-lib functions?
Also, I vote for assigning this fairly high priority so as not to not stall std-lib development.

@otrho
Copy link
Contributor

otrho commented Mar 1, 2022

We could have a twin in the Sway repo I think. It doesn't make as much sense to have these until we've switched to IR as the default, so yeah, high priority but pretty much blocked until then.

@otrho
Copy link
Contributor

otrho commented Mar 1, 2022

#855

@adlerjohn adlerjohn transferred this issue from FuelLabs/sway-lib-std Mar 29, 2022
@adlerjohn adlerjohn added lib: std Standard library good first issue Good for newcomers labels Mar 29, 2022
@nfurfaro nfurfaro removed their assignment Apr 13, 2022
@mohammadfawaz
Copy link
Contributor

I'm thinking we should start by transforming the implementation of all core ops into intrinsics (instead of asm blocks) that become IR instructions such as add, mul, etc. These would make writing optimization passes like "instruction combining" so much easier.

This was referenced May 25, 2022
@nfurfaro nfurfaro added the big this task is hard and will take a while label Jun 10, 2022
@vaivaswatha
Copy link
Contributor

I'm thinking we should start by transforming the implementation of all core ops into intrinsics (instead of asm blocks) that become IR instructions such as add, mul, etc. These would make writing optimization passes like "instruction combining" so much easier.

#1948 (comment)

@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Oct 30, 2022

I'm going to close this given that we have such wrappers in the form of intrinsics for most of the useful opcodes that need them. We are now adding new intrinsics as the need arises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big this task is hard and will take a while enhancement New feature or request good first issue Good for newcomers lib: std Standard library
Projects
Status: Done
Development

No branches or pull requests

5 participants