Simd: Names of load instructions

Created on 11 Aug 2020  路  6Comments  路  Source: WebAssembly/simd

I would like to discuss the names of load instructions (this came up in #237 and #271).

Currently, we have:

  • v128.load
  • load splats, v8x16.load_splat, v16x8.load_splat, v32x4.load_splat, v64x2.load_splat
  • load extends, i16x8.load8x8_s ,i16x8.load8x8_u ,i32x4.load16x4_s ,i32x4.load16x4_u ,i64x2.load32x2_s ,i64x2.load32x2_u
  • (proposed addition), v128.load32_zero, v128.load64_zero

Some issues:

  1. There is some inconsistency in the prefix, v128 v.s. v8x16 v.s. i8x16.
  2. The suffix (ignoring the sign extension) is also adhoc: in some cases, it has a shape (load8x8_s), in some cases it has the number of bytes loaded (in load32_zero), and sometimes it's just a word (splat).
  3. This also makes writing the formal text a bit more involved since these are all separate syntax, even though they are all loads.

A more consistent naming convention will be:

  • all instructions use v128.load prefix, this is the return type, it makes it clear that all the loads return a v128
  • followed by number of bits to load, similar to MVP (i32.load8_s)
  • followed by the "kind" of load, splat, extend, zero

With this convention, all the loads now look like:

  • v128.load
  • load splats, v128.load8_splat, v128.load16_splat, v128.load32_splat, v128.load64_splat
  • load extends, v128.load64_extend8x8_s, v128.load64_extend8x8_u, v128.load64_extend16x4_s, v128.load64_extend16x4_u, v128.load64_extend32x2_s, v128.load64_extend32x2_s
  • load extends, v128.load8x8_s, v128.load8x8_u, v128.load16x4_s, v128.load16x4_u, v128.load32x2_s, v128.load32x2_s
  • (proposed addition), v128.load32_zero, v128.load64_zero

(The load extends are a bit wordy, maybe we can come up with a better name.)

cc @tlively @Maratyszcza

Most helpful comment

In the basic numeric load instructions we don't spell out "extend", so wouldn't the most symmetric names simply be v128.load<shape>_{s,u}?

All 6 comments

I like that this is more explicit about the load size. It seems like it's a win for the splat/zero cases, but the extend case is less clear, IMO. Not sure quite how to improve, though.

Could we balance spec simplicity with readability by having the load-extends be v128.load<shape>_extend_{s,u}? Maybe we could say that 32, 64 and 8x8 are all members of some shape abstraction the syntax can use here?

Edit: In more detail, perhaps 32 and 64 could be aliases for the shapes 32x1 and 64x1?

In the basic numeric load instructions we don't spell out "extend", so wouldn't the most symmetric names simply be v128.load<shape>_{s,u}?

Good point, so the names will be:

  • v128.load
  • load splats, v128.load8_splat, v128.load16_splat, v128.load32_splat, v128.load64_splat
  • load extends, v128.load8x8_s, v128.load8x8_u, v128.load16x4_s, v128.load16x4_u, v128.load32x2_s, v128.load32x2_s
  • (proposed addition), v128.load32_zero, v128.load64_zero

Those look great to me!

Yes, these look pretty good to me too. I still think the extend instructions are not super clear, but that's OK. (still not as bad as i64.extend_i32_s vs. i64.extend32_s)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sirinath picture sirinath  路  9Comments

penzn picture penzn  路  7Comments

tlively picture tlively  路  10Comments

tlively picture tlively  路  6Comments

unicomp21 picture unicomp21  路  4Comments