wasmerio / c-wasm-simd128-example Goto Github PK
View Code? Open in Web Editor NEWExample C++ repo emitting Wasm SIMD 128 instructions
Example C++ repo emitting Wasm SIMD 128 instructions
Nice work!
I looked into this benchmark with @tlively now. It's interesting, but we're not sure what's going on here. The main issue is that the SIMD code emitted by the LLVM wasm backend is quite poor, e.g., here is horizontal_add
:
(func $horizontal_add\28float\20vector\5b4\5d\29 (; 28 ;) (type $7) (param $0 v128) (result f32)
(f32.add
(f32x4.extract_lane 0
(local.tee $0
(f32x4.add
(local.get $0)
(v8x16.shuffle 8 9 10 11 12 13 14 15 0 0 0 0 0 0 0 0
(local.get $0)
(local.get $0)
)
)
)
)
(f32x4.extract_lane 1
(local.get $0)
)
)
)
That looks quite painful as really just 3 scalar adds are needed here :( But this seems like a limitation of the current wasm SIMD spec. Indeed, testing on V8, the SIMD version is significantly slower (80%) than the scalar version.
So it is puzzling that you see such a big speedup in the wasmer LLVM backend when running on the SIMD wasm. We would guess that LLVM gets this unoptimal SIMD wasm code and autovectorizes it into something fast. That is slightly puzzling though as in simple code like this LLVM might also be able to do the same for the non-SIMD wasm as well. In other words, it seems like the speedup you see is due to the SIMD wasm having slightly better "hinting" that the wasmer LLVM backend takes advantage of?
cc @sunfishcode who may have ideas on what's going on, and may be interested in this example of a wasm VM doing very powerful backend optimizations, that at least some other VMs do not expect.
Just curious, noticed that scatter velocity component between two particles is inverse proportional to distance to the power or 4, since distance
function seems to return a square of the distance (as it lacks a square root) and update
squares its output. Wondering if that is intentional, I know that not every Wasm runtime implements SIMD square root.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.