-
Notifications
You must be signed in to change notification settings - Fork 699
Description
Summary
Add instructions to read multiple bytes at a time from (array i8).
Motivation
A number of languages currently use (array i8) as a backing store for custom data types and/or byte buffers style objects (e.g., custom structs, Dart typed arrays, JVM byte arrays). Reading and writing to these custom data types requires performing sequences of single-byte operations that are highly inefficient, and hindering performance.
More discussion on this issue in the GC repo.
Proposal
Add the following new array instructions. All of the instructions will be similar to the load/store memory instructions and take an immediate memarg {offset u32 , align u32 }. The load_X instructions will only be valid when expand($t) = array (mut i8) and the store_X instructions when expand($t) = array (var i8). All instructions will trap with out of bound offsets (including partially out of bounds).
array.load_i16_{u,s}
array.load_i32
array.load_i64
array.load_f32
array.load_f64
array.load_v128
array.store_i16
array.store_i32
array.store_i64
array.store_f32
array.store_f64
array.store_v128
Alternatives
In the original discussion a few alternatives were discussed. A summary of the different options:
- Use current load/store instructions, but use some of the memarg bits to signal load/stores from arrays.
- Reinterpret cast on array types.
- Pinning part of the array to a memory.
- Use the slice proposal.
The above options do have some advantages such as not introducing more instructions or reusing other proposals. However, they are all more complicated than adding relatively straightforward array instructions that would achieve the desired results.
Open Questions
- Do we need other simd load variants e.g. get_8x8_s, β¦?
- Would it be preferable to have get_X and set_X instructions that take indexes instead of memargs as an operand?