Giter Site home page Giter Site logo

c-wasm-simd128-example's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c-wasm-simd128-example's Issues

Analysis of benchmark

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.

Scattering factor

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.