wabt icon indicating copy to clipboard operation
wabt copied to clipboard

wasm2c/spec/simd_address.txt fails on non-x86

Open rathann opened this issue 2 years ago • 7 comments

When running the test suite of wabt-1.0.33 on aarch64 on Fedora 38, I get this (new) test failure:

- test/wasm2c/spec/simd_address.txt
  expected error code 0, got 1.
  STDERR MISMATCH:
  --- expected
  +++ actual
  @@ -0,0 +1,11 @@
  +Traceback (most recent call last):
  +  File "/builddir/build/BUILD/wabt-1.0.33/test/run-spec-wasm2c.py", line 648, in <module>
  +    sys.exit(main(sys.argv[1:]))
  +             ^^^^^^^^^^^^^^^^^^
  +  File "/builddir/build/BUILD/wabt-1.0.33/test/run-spec-wasm2c.py", line 642, in main
  +    utils.Executable(main_exe, forward_stdout=True).RunWithArgs()
  +  File "/builddir/build/BUILD/wabt-1.0.33/test/utils.py", line 95, in RunWithArgs
  +    raise error
  +utils.Error: Error running "out/test/wasm2c/spec/simd_address/simd_address" (1):
  +None
  +out/test/wasm2c/spec/simd_address/simd_address-main.c:499: assertion failed: expected w2c_simd__address__1__wasm_v1280x2Eload_offset_65521(&simd__address__1__wasm_instance) to trap.
  STDOUT MISMATCH:
  --- expected
  +++ actual
  @@ -1 +1 @@
  -42/42 tests passed.
  +41/42 tests passed.

rathann avatar May 25 '23 19:05 rathann

Thanks as always for these reports! I think this particular one is expected and "disclosed" here: https://github.com/WebAssembly/wabt/blob/main/src/template/wasm2c_simd.declarations.c#L6

The root issue here is that:

  • out-of-bounds accesses on Wasm must trap deterministically, but
  • wasm2c tries to use the MMU to detect out-of-bounds accesses and raise a signal, but this kind of side-effect isn't something the compiler cares to preserve if the load can otherwise be optizmed out, so
  • wasm2c needs to force the C compiler not to optimize out a load, which is done with an empty inline asm statement that marks the result of the load as "read,"
  • but (unlike with a 32-bit or 64-bit register), there's no architecture-independent way to describe a 128-bit SIMD register, so at present we only have this for SIMD on x86.

Would happily take a contribution of the appropriate asm for aarch64 (possibly "w" per https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html) if somebody is able to test and say it works... I do wish we had CI tests on aarch64 given the interest in this architecture.

keithw avatar May 25 '23 20:05 keithw

Should we update the TODO such that it will #warning or #error when building on unsupported arch?

Also, I guess we should skip these tests on those platforms too..

sbc100 avatar May 25 '23 20:05 sbc100

@rathann do you actually care about using the SIMD support in wasm2c on arm64 or are you just interested in getting the tests to pass?

sbc100 avatar May 25 '23 20:05 sbc100

Personally, it's the latter. We do have a growing interest in WebAssembly in Fedora, so others might actually be interested. I'll ask the other SIG members.

rathann avatar May 26 '23 09:05 rathann

I see this on ppc64le and s390x, too.

rathann avatar May 26 '23 09:05 rathann