WebAssembly / interface-types

Other
641 stars 57 forks source link

Perhaps lowering instructions should leave the i32 pointer on the stack #114

Closed lukewagner closed 4 years ago

lukewagner commented 4 years ago

A common pattern seems to be:

  1. call $malloc
  2. lower into the memory
  3. pass to core wasm

Lowering ops tend to take an i32 pointer (that they lower into) as the first operand, then pop it. This ensures that practically all cases of lowering will need to use let to pass the pointer to core wasm. It's a relatively minor detail, but I think it's worth considering having all lowering ops default to leaving the i32 pointer on the stack.

jgravelle-google commented 4 years ago

Indeed. Helper functions help with this: https://github.com/jgravelle-google/it-tools/blob/5ba7a5177f148400a7251fed442ae0dbf20bb012/examples/01%20-%20ITL/fizzbuzz.itl#L16, especially for C++ where we also need to null-terminate the strings. In general agree that this is worth having; I'm not sure where you'd prefer to drop the pointer, so it should add to savings and convenience overall.

fgmccabe commented 4 years ago

Overall, I am not sure this is worth it.

  1. It would not be consistent with other wasm instructions. (remember that stack ops are essentially 'free' in actual executing code)
  2. There are other occasions when dropping is the right thing to do (esp. all the numeric coercion instructions)

On Mon, May 11, 2020 at 1:36 PM Jacob Gravelle notifications@github.com wrote:

Indeed. Helper functions help with this: https://github.com/jgravelle-google/it-tools/blob/5ba7a5177f148400a7251fed442ae0dbf20bb012/examples/01%20-%20ITL/fizzbuzz.itl#L16, especially for C++ where we also need to null-terminate the strings. In general agree that this is worth having; I'm not sure where you'd prefer to drop the pointer, so it should add to savings and convenience overall.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/WebAssembly/interface-types/issues/114#issuecomment-626947544, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQAXUD6WCDOQXR3QNJX5UDRRBOU3ANCNFSM4M6GEKHQ .

-- Francis McCabe SWE

taralx commented 4 years ago

Also not sure if it's worth the asymmetry. For example, what about the string length? Sometimes you need it, and in those cases you end up using a let there too.

lukewagner commented 4 years ago

Yeah, on second thought, it would be a bit ad hoc; a few lets won't hurt anyone.