Narrow integer arithmetic instructions
Spec PR: https://github.com/FuelLabs/fuel-specs/pull/628
Adds NIOP r r r imm, an instruction to perform narrow integer (u8, u16, u32) operations with exact overflow checking. The instruction only supports operations for which the current u64 operations do not check overflow correctly.
Alternatives
We could instead add an operation that truncates the result of the previous u64 operation, asserting the flags-related conditions. Not sure if that would be any cleaner. The current approach is more compact, but further complicates the instruction set.
Checklist
- [x] Breaking changes are clearly marked as such in the PR description and changelog: none!
- [x] New behavior is reflected in tests
- [ ] If performance characteristic of an instruction change, update gas costs as well or make a follow-up PR for that
- [x] The specification matches the implemented behavior: https://github.com/FuelLabs/fuel-specs/pull/628
Before requesting review
- [ ] I have reviewed the code myself
- [ ] I have created follow-up issues caused by this PR and linked them here
What is the state of this PR? Also, do we have any benchmarks that shows how it improves the size of contracts? OR does it requires re-work of STD library to actually start using it?
What is the state of this PR? Also, do we have any benchmarks that shows how it improves the size of contracts? OR does it requires re-work of STD library to actually start using it?
This PR is waiting for #923. Requires some minor rework of sway std, which I haven't finished yet. But the purpose of this PR isn't really to reduce code size of contracts, but to get the edge cases right. The sway team has had trouble implementing all overflow checking and FLAGS-related complexities cleanly.