wasmerio / c-wasm-simd128-example

Example C++ repo emitting Wasm SIMD 128 instructions
31 stars 5 forks source link

Scattering factor #2

Open penzn opened 5 years ago

penzn commented 5 years ago

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.

nlewycky commented 5 years ago

Thanks! That is indeed a bug. I would have removed the squaring in update and added a sqrt to avg_motion.

I'm not sure I should change what the benchmark computes while it's the subject of performance analysis? Or we could mention in the README that it computes the motion of 4D mass-less particles in an inverse-quartic field.

penzn commented 5 years ago

That should not change timing numbers by much (on the other hand it would fix the output of avg_motion). You can add SIMD sqrt to distance if Wasmer supports f32x4.sqrt instruction (need to use -munimplemented-simd128 with Clang), otherwise it may result in scalar sqrt on each lanes. I am not 100% sure how this would work, as square root is a library function and so on.

I don't thing it is a big change from performance analysis point of view. And at any rate, it would be a good idea to put what is being simulated in the README.