Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Unified Diff: src/harmony-simd.js

Issue 1250733005: SIMD.js Add the other SIMD Phase 1 types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Don't run downloaded SIMD value type tests. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/full-codegen/x87/full-codegen-x87.cc ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-simd.js
diff --git a/src/harmony-simd.js b/src/harmony-simd.js
index a4378167dacdbb5e3729ad7ad53d6bfad8a19a9d..5119adc9296fc51f452d168f5d79133f4cd6ab74 100644
--- a/src/harmony-simd.js
+++ b/src/harmony-simd.js
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-var $float32x4ToString;
-
(function(global, utils) {
"use strict";
@@ -14,90 +12,276 @@ var $float32x4ToString;
// Imports
var GlobalSIMD = global.SIMD;
-var GlobalFloat32x4 = GlobalSIMD.Float32x4;
-//-------------------------------------------------------------------
+macro SIMD_TYPES(FUNCTION)
+FUNCTION(Float32x4, float32x4, 4)
+FUNCTION(Int32x4, int32x4, 4)
+FUNCTION(Bool32x4, bool32x4, 4)
+FUNCTION(Int16x8, int16x8, 8)
+FUNCTION(Bool16x8, bool16x8, 8)
+FUNCTION(Int8x16, int8x16, 16)
+FUNCTION(Bool8x16, bool8x16, 16)
+endmacro
-function Float32x4Constructor(x, y, z, w) {
- if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Float32x4");
- if (!IS_NUMBER(x) || !IS_NUMBER(y) || !IS_NUMBER(z) || !IS_NUMBER(w)) {
- throw MakeTypeError(kInvalidArgument);
- }
- return %CreateFloat32x4(x, y, z, w);
-}
+macro DECLARE_GLOBALS(NAME, TYPE, LANES)
+var GlobalNAME = GlobalSIMD.NAME;
+endmacro
-function Float32x4Splat(s) {
- return %CreateFloat32x4(s, s, s, s);
-}
+SIMD_TYPES(DECLARE_GLOBALS)
-function Float32x4CheckJS(a) {
- return %Float32x4Check(a);
+macro DECLARE_COMMON_FUNCTIONS(NAME, TYPE, LANES)
+function NAMECheckJS(a) {
+ return %NAMECheck(a);
}
-function Float32x4ToString() {
- if (!(IS_FLOAT32X4(this) || IS_FLOAT32X4_WRAPPER(this))) {
+function NAMEToString() {
+ if (typeof(this) !== 'TYPE' && %_ClassOf(this) !== 'NAME') {
throw MakeTypeError(kIncompatibleMethodReceiver,
- "Float32x4.prototype.toString", this);
+ "NAME.prototype.toString", this);
}
var value = %_ValueOf(this);
- var w = GlobalFloat32x4.extractLane(value, 0),
- x = GlobalFloat32x4.extractLane(value, 1),
- y = GlobalFloat32x4.extractLane(value, 2),
- z = GlobalFloat32x4.extractLane(value, 3);
- return "SIMD.Float32x4(" + w + ", " + x + ", " + y + ", " + z + ")";
+ var str = "SIMD.NAME(";
+ str += %NAMEExtractLane(value, 0);
+ for (var i = 1; i < LANES; i++) {
+ str += ", " + %NAMEExtractLane(value, i);
+ }
+ return str + ")";
}
-function Float32x4ToLocaleString() {
- if (!(IS_FLOAT32X4(this) || IS_FLOAT32X4_WRAPPER(this))) {
+function NAMEToLocaleString() {
+ if (typeof(this) !== 'TYPE' && %_ClassOf(this) !== 'NAME') {
throw MakeTypeError(kIncompatibleMethodReceiver,
- "Float32x4.prototype.toLocaleString", this);
+ "NAME.prototype.toLocaleString", this);
}
var value = %_ValueOf(this);
- var w = GlobalFloat32x4.extractLane(value, 0).toLocaleString(),
- x = GlobalFloat32x4.extractLane(value, 1).toLocaleString(),
- y = GlobalFloat32x4.extractLane(value, 2).toLocaleString(),
- z = GlobalFloat32x4.extractLane(value, 3).toLocaleString();
- return "SIMD.Float32x4(" + w + ", " + x + ", " + y + ", " + z + ")";
+ var str = "SIMD.NAME(";
+ str += %NAMEExtractLane(value, 0).toLocaleString();
+ for (var i = 1; i < LANES; i++) {
+ str += ", " + %NAMEExtractLane(value, i).toLocaleString();
+ }
+ return str + ")";
}
-function Float32x4ValueOf() {
- if (!(IS_FLOAT32X4(this) || IS_FLOAT32X4_WRAPPER(this))) {
+function NAMEValueOf() {
+ if (typeof(this) !== 'TYPE' && %_ClassOf(this) !== 'NAME') {
throw MakeTypeError(kIncompatibleMethodReceiver,
- "Float32x4.prototype.valueOf", this);
+ "NAME.prototype.valueOf", this);
}
return %_ValueOf(this);
}
+function NAMEExtractLaneJS(instance, lane) {
+ return %NAMEExtractLane(instance, lane);
+}
+endmacro
+
+SIMD_TYPES(DECLARE_COMMON_FUNCTIONS)
+
+macro SIMD_NUMERIC_TYPES(FUNCTION)
+FUNCTION(Float32x4)
+FUNCTION(Int32x4)
+FUNCTION(Int16x8)
+FUNCTION(Int8x16)
+endmacro
+
+macro DECLARE_NUMERIC_FUNCTIONS(NAME)
+function NAMEReplaceLaneJS(instance, lane, value) {
+ return %NAMEReplaceLane(instance, lane, TO_NUMBER_INLINE(value));
+}
+endmacro
+
+SIMD_NUMERIC_TYPES(DECLARE_NUMERIC_FUNCTIONS)
+
+macro SIMD_BOOL_TYPES(FUNCTION)
+FUNCTION(Bool32x4)
+FUNCTION(Bool16x8)
+FUNCTION(Bool8x16)
+endmacro
+
+macro DECLARE_BOOL_FUNCTIONS(NAME)
+function NAMEReplaceLaneJS(instance, lane, value) {
+ return %NAMEReplaceLane(instance, lane, value);
+}
+endmacro
+
+SIMD_BOOL_TYPES(DECLARE_BOOL_FUNCTIONS)
+
+macro SIMD_UNSIGNED_INT_TYPES(FUNCTION)
+FUNCTION(Int16x8)
+FUNCTION(Int8x16)
+endmacro
+
+macro DECLARE_UNSIGNED_INT_FUNCTIONS(NAME)
+function NAMEUnsignedExtractLaneJS(instance, lane) {
+ return %NAMEUnsignedExtractLane(instance, lane);
+}
+endmacro
+
+SIMD_UNSIGNED_INT_TYPES(DECLARE_UNSIGNED_INT_FUNCTIONS)
+
//-------------------------------------------------------------------
-function Float32x4ExtractLaneJS(value, lane) {
- return %Float32x4ExtractLane(value, lane);
+function Float32x4Constructor(c0, c1, c2, c3) {
+ if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Float32x4");
+ return %CreateFloat32x4(TO_NUMBER_INLINE(c0), TO_NUMBER_INLINE(c1),
+ TO_NUMBER_INLINE(c2), TO_NUMBER_INLINE(c3));
+}
+
+
+function Float32x4Splat(s) {
+ return %CreateFloat32x4(s, s, s, s);
+}
+
+
+function Int32x4Constructor(c0, c1, c2, c3) {
+ if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int32x4");
+ return %CreateInt32x4(TO_NUMBER_INLINE(c0), TO_NUMBER_INLINE(c1),
+ TO_NUMBER_INLINE(c2), TO_NUMBER_INLINE(c3));
+}
+
+
+function Int32x4Splat(s) {
+ return %CreateInt32x4(s, s, s, s);
+}
+
+
+function Bool32x4Constructor(c0, c1, c2, c3) {
+ if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool32x4");
+ return %CreateBool32x4(c0, c1, c2, c3);
+}
+
+
+function Bool32x4Splat(s) {
+ return %CreateBool32x4(s, s, s, s);
+}
+
+
+function Int16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
+ if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int16x8");
+ return %CreateInt16x8(TO_NUMBER_INLINE(c0), TO_NUMBER_INLINE(c1),
+ TO_NUMBER_INLINE(c2), TO_NUMBER_INLINE(c3),
+ TO_NUMBER_INLINE(c4), TO_NUMBER_INLINE(c5),
+ TO_NUMBER_INLINE(c6), TO_NUMBER_INLINE(c7));
+}
+
+
+function Int16x8Splat(s) {
+ return %CreateInt16x8(s, s, s, s, s, s, s, s);
+}
+
+
+function Bool16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
+ if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool16x8");
+ return %CreateBool16x8(c0, c1, c2, c3, c4, c5, c6, c7);
+}
+
+
+function Bool16x8Splat(s) {
+ return %CreateBool16x8(s, s, s, s, s, s, s, s);
+}
+
+
+function Int8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
+ c12, c13, c14, c15) {
+ if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int8x16");
+ return %CreateInt8x16(TO_NUMBER_INLINE(c0), TO_NUMBER_INLINE(c1),
+ TO_NUMBER_INLINE(c2), TO_NUMBER_INLINE(c3),
+ TO_NUMBER_INLINE(c4), TO_NUMBER_INLINE(c5),
+ TO_NUMBER_INLINE(c6), TO_NUMBER_INLINE(c7),
+ TO_NUMBER_INLINE(c8), TO_NUMBER_INLINE(c9),
+ TO_NUMBER_INLINE(c10), TO_NUMBER_INLINE(c11),
+ TO_NUMBER_INLINE(c12), TO_NUMBER_INLINE(c13),
+ TO_NUMBER_INLINE(c14), TO_NUMBER_INLINE(c15));
+}
+
+
+function Int8x16Splat(s) {
+ return %CreateInt8x16(s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s);
+}
+
+
+function Bool8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
+ c12, c13, c14, c15) {
+ if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool8x16");
+ return %CreateBool8x16(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,
+ c13, c14, c15);
+}
+
+
+function Bool8x16Splat(s) {
+ return %CreateBool8x16(s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s);
}
-// -------------------------------------------------------------------
%AddNamedProperty(GlobalSIMD, symbolToStringTag, 'SIMD', READ_ONLY | DONT_ENUM);
-%SetCode(GlobalFloat32x4, Float32x4Constructor);
-%FunctionSetPrototype(GlobalFloat32x4, {});
-%AddNamedProperty(
- GlobalFloat32x4.prototype, 'constructor', GlobalFloat32x4, DONT_ENUM);
-%AddNamedProperty(
- GlobalFloat32x4.prototype, symbolToStringTag, 'Float32x4',
+macro SETUP_SIMD_TYPE(NAME, TYPE, LANES)
+%SetCode(GlobalNAME, NAMEConstructor);
+%FunctionSetPrototype(GlobalNAME, {});
+%AddNamedProperty(GlobalNAME.prototype, 'constructor', GlobalNAME,
+ DONT_ENUM);
+%AddNamedProperty(GlobalNAME.prototype, symbolToStringTag, 'NAME',
DONT_ENUM | READ_ONLY);
-
-utils.InstallFunctions(GlobalFloat32x4.prototype, DONT_ENUM, [
- 'toLocaleString', Float32x4ToLocaleString,
- 'toString', Float32x4ToString,
- 'valueOf', Float32x4ValueOf,
+utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [
+ 'toLocaleString', NAMEToLocaleString,
+ 'toString', NAMEToString,
+ 'valueOf', NAMEValueOf,
]);
+endmacro
+
+SIMD_TYPES(SETUP_SIMD_TYPE)
+
+//-------------------------------------------------------------------
utils.InstallFunctions(GlobalFloat32x4, DONT_ENUM, [
'splat', Float32x4Splat,
'check', Float32x4CheckJS,
'extractLane', Float32x4ExtractLaneJS,
+ 'replaceLane', Float32x4ReplaceLaneJS,
+]);
+
+utils.InstallFunctions(GlobalInt32x4, DONT_ENUM, [
+ 'splat', Int32x4Splat,
+ 'check', Int32x4CheckJS,
+ 'extractLane', Int32x4ExtractLaneJS,
+ 'replaceLane', Int32x4ReplaceLaneJS,
+]);
+
+utils.InstallFunctions(GlobalBool32x4, DONT_ENUM, [
+ 'splat', Bool32x4Splat,
+ 'check', Bool32x4CheckJS,
+ 'extractLane', Bool32x4ExtractLaneJS,
+ 'replaceLane', Bool32x4ReplaceLaneJS,
+]);
+
+utils.InstallFunctions(GlobalInt16x8, DONT_ENUM, [
+ 'splat', Int16x8Splat,
+ 'check', Int16x8CheckJS,
+ 'extractLane', Int16x8ExtractLaneJS,
+ 'unsignedExtractLane', Int16x8UnsignedExtractLaneJS,
+ 'replaceLane', Int16x8ReplaceLaneJS,
]);
-$float32x4ToString = Float32x4ToString;
+utils.InstallFunctions(GlobalBool16x8, DONT_ENUM, [
+ 'splat', Bool16x8Splat,
+ 'check', Bool16x8CheckJS,
+ 'extractLane', Bool16x8ExtractLaneJS,
+ 'replaceLane', Bool16x8ReplaceLaneJS,
+]);
+
+utils.InstallFunctions(GlobalInt8x16, DONT_ENUM, [
+ 'splat', Int8x16Splat,
+ 'check', Int8x16CheckJS,
+ 'extractLane', Int8x16ExtractLaneJS,
+ 'unsignedExtractLane', Int8x16UnsignedExtractLaneJS,
+ 'replaceLane', Int8x16ReplaceLaneJS,
+]);
+
+utils.InstallFunctions(GlobalBool8x16, DONT_ENUM, [
+ 'splat', Bool8x16Splat,
+ 'check', Bool8x16CheckJS,
+ 'extractLane', Bool8x16ExtractLaneJS,
+ 'replaceLane', Bool8x16ReplaceLaneJS,
+]);
})
« no previous file with comments | « src/full-codegen/x87/full-codegen-x87.cc ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698