Samsung / walrus

WebAssembly Lightweight RUntime
Apache License 2.0
35 stars 10 forks source link

32 bit constant issues #163

Closed zherczeg closed 8 months ago

zherczeg commented 10 months ago

It seems sometimes 32 bit constant pairs are packed into 64 bit constants. This is a big problem for jit, since it cannot track constants properly. Is there a way to detect such const64 byte codes? I suspect that is not possible, that a constant is used as both 64 bit and a pair of 32 bit, so at parsing time we could replace them with two 32 bit constants in the latter case. A flag or a byte code type would be enough.

ksh8281 commented 10 months ago

Can you give a example code?

zherczeg commented 10 months ago

x86-32:

  (func (export "type-second-f32") (result f32)
    (call $f64-f32 (f64.const 64) (f32.const 32))
  )

Byte code dump:

     0 const64 dstOffset: 0 value: 4634204016564240384
    16 const32 dstOffset: 8 value: 1107296256
    28 call index: 0 paramOffsets: 0 4 8  resultOffsets: 12
    48 end resultOffsets: 12

It looks like I was wrong. The call has two arguments, but according to the byte code dump, the call has three. How the call should be handled on 32 bit?

ksh8281 commented 10 months ago

It is not bug. this is intended operation for copy arguments without reference function arguments type (f64.const 64) (f32.const 32) (copy4B, copy4B) (copy4B) each copy count of type is computed by function valueFunctionCopyCount but It could be confusing. may I add a function for original position?

zherczeg commented 10 months ago

I suspect this is something new. Are these true:

If this is true, I can create an algorithm to detect which "arguments" needs to be ignored by jit.

ksh8281 commented 10 months ago

Yes, three things are true.

zherczeg commented 10 months ago

It looks like End opcode is also affected.