JavaScript参考手册
SIMD
SIMD.load
SIMD.js已经从TC39中取消了积极的开发,并从第三阶段中删除了。它不再被网页浏览器所追求。暴露在 web 上的SIMD 操作在 WebAssembly 中正处于积极的发展之中, 其操作基于 SIMD. js 操作。
静态SIMD.%type%.load()
方法创建一个新的SIMD数据类型,其中从一个类型数组中加载通道值。
语法
SIMD.Float64x2.load(tarray, index)
SIMD.Float64x2.load1(tarray, index)
SIMD.Float32x4.load(tarray, index)
SIMD.Float32x4.load1(tarray, index)
SIMD.Float32x4.load2(tarray, index)
SIMD.Float32x4.load3(tarray, index)
SIMD.Int32x4.load(tarray, index)
SIMD.Int32x4.load1(tarray, index)
SIMD.Int32x4.load2(tarray, index)
SIMD.Int32x4.load3(tarray, index)
SIMD.Uint32x4.load(tarray, index)
SIMD.Uint32x4.load1(tarray, index)
SIMD.Uint32x4.load2(tarray, index)
SIMD.Uint32x4.load3(tarray, index)
SIMD.Int8x16.load(tarray, index)
SIMD.Int16x8.load(tarray, index)
SIMD.Uint8x16.load(tarray, index)
SIMD.Uint16x8.load(tarray, index)
参数
tarray
类型数组的一个实例。这可以是以下之一:
-
Int8Array
,Uint8Array
,Uint8ClampedArray
,Int16Array
,Uint16Array
,Int32Array
,Uint32Array
,Float32Array
,或Float64Array
。index
一个索引号从哪里开始在类型化数组中加载。返回值是一个新的SIMD数据类型。
- 如果
index
超出范围,例如SIMD.Int32x4.load(tarray, -1)
或大于tarray
a 的大小,RangeError
则抛出a。
- 如果
tarray
不是其中一种类型的数组类型,SIMD.Int32x4.load(tarray.buffer, 0)
(数组缓冲区无效),TypeError
则抛出a。
描述
SIMD load
和store
方法与类型数组混合。使用load
,您可以将类型化数组传递到SIMD类型,并且store,
可以将SIMD数据存储到类型化数组中。
您可以使用加载所有通道值load()
,或仅与方法加载一个,两个或三个通道值load1()
,load2()
或load3()
。
例子
以下示例使用Int32Array
加载到SIMD.Int32x4
数据类型。
加载所有值
var a = new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
SIMD.Int32x4.load(a, 0);
// Int32x4[1,2,3,4]
var b = new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
SIMD.Int32x4.load(a, 2);
// Int32x4[3,4,5,6]
加载一个值
var a = new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
SIMD.Int32x4.load1(a, 0);
// Int32x4[1,0,0,0]
var b = new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
SIMD.Int32x4.load1(a, 2);
// Int32x4[3,0,0,0]
加载两个值
var a = new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
SIMD.Int32x4.load2(a, 0);
// Int32x4[1,2,0,0]
var b = new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
SIMD.Int32x4.load2(a, 2);
// Int32x4[3,4,0,0]
加载三个值
var a = new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
SIMD.Int32x4.load3(a, 0);
// Int32x4[1,2,3,0]
var b = new Int32Array([1, 2, 3, 4, 5, 6, 7, 8]);
SIMD.Int32x4.load3(a, 2);
// Int32x4[3,4,5,0]
规范
Specification |
Status |
Comment |
---|---|---|
SIMDThe definition of 'SIMDConstructor.load' in that specification. |
Draft |
Initial definition. |
浏览器兼容性
Feature |
Chrome |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari |
---|---|---|---|---|---|
Basic support |
No support |
Nightly build |
No support |
No support |
No support |
Feature |
Android |
Chrome for Android |
Firefox Mobile (Gecko) |
IE Mobile |
Opera Mobile |
Safari Mobile |
---|---|---|---|---|---|---|
Basic support |
No support |
No support |
Nightly build |
No support |
No support |
No support |
SIMD相关

JavaScript 是一种高级编程语言,通过解释执行,是一门动态类型,面向对象(基于原型)的解释型语言。它已经由ECMA(欧洲电脑制造商协会)通过 ECMAScript 实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器( Chrome、IE、FireFox、Safari、Opera )支持。JavaScript 是一门基于原型、函数先行的语言,是一门多范式的语言,它支持面向对象编程,命令式编程,以及函数式编程。它提供语法来操控文本、数组、日期以及正则表达式等,不支持 I/O,比如网络