Narrow integer instructions #628
Merged
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.
Closes #626. VM PRs: FuelLabs/fuel-vm#922 and FuelLabs/fuel-vm#923.
Implementing correct overflow handling for narrow integer types (
u8,u16,u32) is tedious, error prone, and needs lots of instructions. Likewise, memory load/store operations with these involve lots of expensive bitmasking. This change provides the functionality on the vm level.Only operations for which the overflow handling is different with narrow integers are implemented. For instance, multiplication is definitely different as
256 * 2overflowsu8but doesn't overflowu64. In comparison, division is not, it never creates results larger than the original value.The operations silently truncate the input operands to the correct bit width, meaning that
niop $ra $rb $rc NIOP_U8 | NIOP_ADDwith$rb = 0xff01,$rc = 0x02sets$ra = 3without panicking. Same goes for store operations, and that was already the case withSB. It's up to the compiler or user to take this into account.As always I'm trying to sneak in cool new features. Here it's the
XNORoperating mode, which is extremely useful for generating bitmasks. For instanceniop $ra $zero $zero NIOP_U32 | NIOP_XNORsets$rato0xffffffff.Before requesting review
After merging, notify other teams