Skip to content

SIMD128 intrinsics support? #9255

@nsthorat

Description

@nsthorat

Feature request

What is the expected behavior?
When writing WASM (from Rust) that uses SIMD128 intrinsics, I get this error:

ERROR in ../pkg/test_wasm_bg.wasm
Module parse failed: Internal failure: parseVec could not cast the value
You may need an appropriate loader to handle this file type.
Error: Internal failure: parseVec could not cast the value
    at new CompileError (/Users/nsthorat/Code/rust/test-wasm/www/node_modules/@webassemblyjs/helper-api-error/lib/index.js:40:109)
    at parseVec (/Users/nsthorat/Code/rust/test-wasm/www/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:328:15)
    at parseTypeSection (/Users/nsthorat/Code/rust/test-wasm/www/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:352:29)
    at parseSection (/Users/nsthorat/Code/rust/test-wasm/www/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1347:24)
    at Object.decode (/Users/nsthorat/Code/rust/test-wasm/www/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1696:25)
    at decode (/Users/nsthorat/Code/rust/test-wasm/www/node_modules/@webassemblyjs/wasm-parser/lib/index.js:248:21)

I tracked it down to webassemblyjs (I don't totally understand the relationship between these projects, so maybe it needs to be filed there):
https://github.com/xtuc/webassemblyjs/blob/4ddbd20f23a320d134895829001374cfa1da84de/packages/wasm-parser/src/decoder.js#L354

What is motivation or use case for adding/changing the behavior?
I work on TensorFlow.js and we're trying to get SIMD128 support for vectorized machine learning primitives.

How should this be implemented in your opinion?
Webpack & webassemblyjs shouldn't fail.

Are you willing to work on this yourself?
yes

Coming from Rust, here is some code:

    let mut a: Vec<f32> = vec![0.0; 4];
    for i in 0..a.len() {
        a[i] = i as f32;
    }
    let raw = a.as_ptr() as *const core_arch::wasm32::v128;

    let lane1 = core_arch::wasm32::v128_load(raw);
    let out = core_arch::wasm32::f32x4_extract_lane(lane1, 0);

The generated WASM looks like this:

    call $core::slice::<impl__T_>::as_ptr::h561ee13c3c552cb4
    call $core_arch::core_arch::wasm32::simd128::v128_load::ha5b99643436b0934
    call $core_arch::core_arch::wasm32::simd128::f32x4_extract_lane::h2aaffb364379d64d

It's worth noting that some intrinsics work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions