WebAssembly / binaryen

Optimizer and compiler/toolchain library for WebAssembly
Apache License 2.0
7.51k stars 746 forks source link

asm2wasm fails to convert SIMD instructions #855

Open CryZe opened 7 years ago

CryZe commented 7 years ago

When it encounters a SIMD instruction it fails to compile the asm.js code to wasm:

/home/Chris/Projekte/wasm/emsdk_portable/clang/fastcomp/build_incoming_64/bin/llvm-nm: /home/Chris/.multirust/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcompiler_builtins-e428224f6caf212a.rlib(rust.metadata.bin) The end of the file was unexpectedly encountered

HEAPU8
asm2wasm: /home/Chris/.emscripten_ports/binaryen/binaryen-version_19/src/asm2wasm.h:1335: auto wasm::Asm2WasmBuilder::processFunction(cashew::Ref)::(anonymous class)::operator()(cashew::Ref) const: Assertion `mappedGlobals.find(name) != mappedGlobals.end() ? true : (std::cerr << name.str << '\n', false)' failed.
Traceback (most recent call last):
  File "/home/Chris/Projekte/wasm/emsdk_portable/emscripten/incoming/emcc", line 13, in <module>
    emcc.run()
  File "/home/Chris/Projekte/wasm/emsdk_portable/emscripten/incoming/emcc.py", line 2030, in run
    subprocess.check_call(cmd, stdout=open(wasm_text_target, 'w'))
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '[u'/home/Chris/.emscripten_ports/binaryen/binaryen-version_19/bin/asm2wasm', '/mnt/d/Projekte/wasm/advent-of-code-2016/day-05/target/wasm32-unknown-emscripten/release/aoc.asm.js', '--total-memory=16777216', '-O3', '--mem-init=/mnt/d/Projekte/wasm/advent-of-code-2016/day-05/target/wasm32-unknown-emscripten/release/aoc.js.mem', '--mem-base=1024', '--wasm-only']' returned non-zero exit status -6

The asm.js line looks like this:

 temp_Int32x4_ptr = $context$i;SIMD_Int32x4_store(HEAPU8, temp_Int32x4_ptr, SIMD_Int32x4(0,0,1732584193,-271733879));

If this is not intended to work yet, what can I do to prevent emscripten from generating vector instructions then? -fno-vectorize -s SIMD=0 and the following llvm-args -disable-loop-vectorization -disable-slp-vectorization -vectorize-loops=false -vectorize-slp=false -vectorize-slp-aggressive=false didn't do anything.

kripken commented 7 years ago

Yes, wasm doesn't have simd yet, so that isn't expected to work.

How are you generating that code? I'm not sure which clang/opt flags you need, but if you use emcc, it should pass those to those tools for you. You can run it with EMCC_DEBUG=1 in the env to see what flags it passes.

brson commented 7 years ago

Is the error here on rustc's side, where we are emitting simd IR to a platform that doesn't support it?

CryZe commented 7 years ago

That seems likely, but I didn't dig too deep into this back when I was getting these errors a lot.