scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
53 lines (52 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimdHelper = void 0;
/**
* Helper class for detecting WebAssembly SIMD support
*/
var SimdHelper = /** @class */ (function () {
function SimdHelper() {
}
/**
* Detects whether the current browser supports WebAssembly SIMD instructions.
* This code is run once and the result is cached. If your browser supports Wasm SIMD then all following calls will return true
*
* See also {@link SciChartDefaults.useWasmSimd} to globally enable or disable Wasm simd support in SciChart.js
*
* @returns true if WASM SIMD is supported, false otherwise
*/
SimdHelper.supportsWasmSIMD = function () {
// Return cached result if already detected
if (SimdHelper.supportsSimd !== undefined) {
return SimdHelper.supportsSimd;
}
try {
// Check if WebAssembly is available
if (typeof WebAssembly === "undefined" || typeof WebAssembly.validate !== "function") {
SimdHelper.supportsSimd = false;
return false;
}
// Create a minimal WASM module with SIMD instructions to test support
// This is a simple WASM module that uses v128 SIMD operations
// See https://www.jsdelivr.com/package/npm/wasm-feature-detect
var wasmBytes = new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 253, 15, 253,
98, 11
]);
// Try to compile the WASM module
SimdHelper.supportsSimd = WebAssembly.validate(wasmBytes);
return SimdHelper.supportsSimd;
}
catch (error) {
// If compilation fails, SIMD is not supported
SimdHelper.supportsSimd = false;
return false;
}
};
/**
* Cached result of SIMD detection to avoid repeated validation
*/
SimdHelper.supportsSimd = undefined;
return SimdHelper;
}());
exports.SimdHelper = SimdHelper;