Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect whether a browser supports SIMD by JS code?

I found a way to detect but it's not work on my computer with the latest chrome enabling simd flag:

var simd =  async () => WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 9, 1, 7, 0, 65, 0, 253, 4, 26, 11]));
await simd();

Is there another way to detect?

like image 752
Amanda Zhao Avatar asked Aug 31 '25 22:08

Amanda Zhao


1 Answers

There is an opensource library for wasm feature detection here:

https://github.com/GoogleChromeLabs/wasm-feature-detect

The way it works is that it attempts to instantiate a wasm module with the given features, catching an error should it arise (which indicates that the feature is not supported).

Here's the SIMD module it attempts to create:

https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/master/src/detectors/simd/module.wat

like image 121
ColinE Avatar answered Sep 03 '25 10:09

ColinE