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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var $float32x4ToString;
6
7 (function(global, utils) { 5 (function(global, utils) {
8 6
9 "use strict"; 7 "use strict";
10 8
11 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
12 10
13 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
14 // Imports 12 // Imports
15 13
16 var GlobalSIMD = global.SIMD; 14 var GlobalSIMD = global.SIMD;
17 var GlobalFloat32x4 = GlobalSIMD.Float32x4; 15
16 macro SIMD_TYPES(FUNCTION)
17 FUNCTION(Float32x4, float32x4, 4)
18 FUNCTION(Int32x4, int32x4, 4)
19 FUNCTION(Bool32x4, bool32x4, 4)
20 FUNCTION(Int16x8, int16x8, 8)
21 FUNCTION(Bool16x8, bool16x8, 8)
22 FUNCTION(Int8x16, int8x16, 16)
23 FUNCTION(Bool8x16, bool8x16, 16)
24 endmacro
25
26 macro DECLARE_GLOBALS(NAME, TYPE, LANES)
27 var GlobalNAME = GlobalSIMD.NAME;
28 endmacro
29
30 SIMD_TYPES(DECLARE_GLOBALS)
31
32 macro DECLARE_COMMON_FUNCTIONS(NAME, TYPE, LANES)
33 function NAMECheckJS(a) {
34 return %NAMECheck(a);
35 }
36
37 function NAMEToString() {
38 if (typeof(this) !== 'TYPE' && %_ClassOf(this) !== 'NAME') {
39 throw MakeTypeError(kIncompatibleMethodReceiver,
40 "NAME.prototype.toString", this);
41 }
42 var value = %_ValueOf(this);
43 var str = "SIMD.NAME(";
44 str += %NAMEExtractLane(value, 0);
45 for (var i = 1; i < LANES; i++) {
46 str += ", " + %NAMEExtractLane(value, i);
47 }
48 return str + ")";
49 }
50
51 function NAMEToLocaleString() {
52 if (typeof(this) !== 'TYPE' && %_ClassOf(this) !== 'NAME') {
53 throw MakeTypeError(kIncompatibleMethodReceiver,
54 "NAME.prototype.toLocaleString", this);
55 }
56 var value = %_ValueOf(this);
57 var str = "SIMD.NAME(";
58 str += %NAMEExtractLane(value, 0).toLocaleString();
59 for (var i = 1; i < LANES; i++) {
60 str += ", " + %NAMEExtractLane(value, i).toLocaleString();
61 }
62 return str + ")";
63 }
64
65 function NAMEValueOf() {
66 if (typeof(this) !== 'TYPE' && %_ClassOf(this) !== 'NAME') {
67 throw MakeTypeError(kIncompatibleMethodReceiver,
68 "NAME.prototype.valueOf", this);
69 }
70 return %_ValueOf(this);
71 }
72
73 function NAMEExtractLaneJS(instance, lane) {
74 return %NAMEExtractLane(instance, lane);
75 }
76 endmacro
77
78 SIMD_TYPES(DECLARE_COMMON_FUNCTIONS)
79
80 macro SIMD_NUMERIC_TYPES(FUNCTION)
81 FUNCTION(Float32x4)
82 FUNCTION(Int32x4)
83 FUNCTION(Int16x8)
84 FUNCTION(Int8x16)
85 endmacro
86
87 macro DECLARE_NUMERIC_FUNCTIONS(NAME)
88 function NAMEReplaceLaneJS(instance, lane, value) {
89 return %NAMEReplaceLane(instance, lane, TO_NUMBER_INLINE(value));
90 }
91 endmacro
92
93 SIMD_NUMERIC_TYPES(DECLARE_NUMERIC_FUNCTIONS)
94
95 macro SIMD_BOOL_TYPES(FUNCTION)
96 FUNCTION(Bool32x4)
97 FUNCTION(Bool16x8)
98 FUNCTION(Bool8x16)
99 endmacro
100
101 macro DECLARE_BOOL_FUNCTIONS(NAME)
102 function NAMEReplaceLaneJS(instance, lane, value) {
103 return %NAMEReplaceLane(instance, lane, value);
104 }
105 endmacro
106
107 SIMD_BOOL_TYPES(DECLARE_BOOL_FUNCTIONS)
108
109 macro SIMD_UNSIGNED_INT_TYPES(FUNCTION)
110 FUNCTION(Int16x8)
111 FUNCTION(Int8x16)
112 endmacro
113
114 macro DECLARE_UNSIGNED_INT_FUNCTIONS(NAME)
115 function NAMEUnsignedExtractLaneJS(instance, lane) {
116 return %NAMEUnsignedExtractLane(instance, lane);
117 }
118 endmacro
119
120 SIMD_UNSIGNED_INT_TYPES(DECLARE_UNSIGNED_INT_FUNCTIONS)
18 121
19 //------------------------------------------------------------------- 122 //-------------------------------------------------------------------
20 123
21 function Float32x4Constructor(x, y, z, w) { 124 function Float32x4Constructor(c0, c1, c2, c3) {
22 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Float32x4"); 125 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Float32x4");
23 if (!IS_NUMBER(x) || !IS_NUMBER(y) || !IS_NUMBER(z) || !IS_NUMBER(w)) { 126 return %CreateFloat32x4(TO_NUMBER_INLINE(c0), TO_NUMBER_INLINE(c1),
24 throw MakeTypeError(kInvalidArgument); 127 TO_NUMBER_INLINE(c2), TO_NUMBER_INLINE(c3));
25 } 128 }
26 return %CreateFloat32x4(x, y, z, w); 129
27 }
28 130
29 function Float32x4Splat(s) { 131 function Float32x4Splat(s) {
30 return %CreateFloat32x4(s, s, s, s); 132 return %CreateFloat32x4(s, s, s, s);
31 } 133 }
32 134
33 function Float32x4CheckJS(a) { 135
34 return %Float32x4Check(a); 136 function Int32x4Constructor(c0, c1, c2, c3) {
35 } 137 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int32x4");
36 138 return %CreateInt32x4(TO_NUMBER_INLINE(c0), TO_NUMBER_INLINE(c1),
37 function Float32x4ToString() { 139 TO_NUMBER_INLINE(c2), TO_NUMBER_INLINE(c3));
38 if (!(IS_FLOAT32X4(this) || IS_FLOAT32X4_WRAPPER(this))) { 140 }
39 throw MakeTypeError(kIncompatibleMethodReceiver, 141
40 "Float32x4.prototype.toString", this); 142
41 } 143 function Int32x4Splat(s) {
42 var value = %_ValueOf(this); 144 return %CreateInt32x4(s, s, s, s);
43 var w = GlobalFloat32x4.extractLane(value, 0), 145 }
44 x = GlobalFloat32x4.extractLane(value, 1), 146
45 y = GlobalFloat32x4.extractLane(value, 2), 147
46 z = GlobalFloat32x4.extractLane(value, 3); 148 function Bool32x4Constructor(c0, c1, c2, c3) {
47 return "SIMD.Float32x4(" + w + ", " + x + ", " + y + ", " + z + ")"; 149 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool32x4");
48 } 150 return %CreateBool32x4(c0, c1, c2, c3);
49 151 }
50 function Float32x4ToLocaleString() { 152
51 if (!(IS_FLOAT32X4(this) || IS_FLOAT32X4_WRAPPER(this))) { 153
52 throw MakeTypeError(kIncompatibleMethodReceiver, 154 function Bool32x4Splat(s) {
53 "Float32x4.prototype.toLocaleString", this); 155 return %CreateBool32x4(s, s, s, s);
54 } 156 }
55 var value = %_ValueOf(this); 157
56 var w = GlobalFloat32x4.extractLane(value, 0).toLocaleString(), 158
57 x = GlobalFloat32x4.extractLane(value, 1).toLocaleString(), 159 function Int16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
58 y = GlobalFloat32x4.extractLane(value, 2).toLocaleString(), 160 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int16x8");
59 z = GlobalFloat32x4.extractLane(value, 3).toLocaleString(); 161 return %CreateInt16x8(TO_NUMBER_INLINE(c0), TO_NUMBER_INLINE(c1),
60 return "SIMD.Float32x4(" + w + ", " + x + ", " + y + ", " + z + ")"; 162 TO_NUMBER_INLINE(c2), TO_NUMBER_INLINE(c3),
61 } 163 TO_NUMBER_INLINE(c4), TO_NUMBER_INLINE(c5),
62 164 TO_NUMBER_INLINE(c6), TO_NUMBER_INLINE(c7));
63 function Float32x4ValueOf() { 165 }
64 if (!(IS_FLOAT32X4(this) || IS_FLOAT32X4_WRAPPER(this))) { 166
65 throw MakeTypeError(kIncompatibleMethodReceiver, 167
66 "Float32x4.prototype.valueOf", this); 168 function Int16x8Splat(s) {
67 } 169 return %CreateInt16x8(s, s, s, s, s, s, s, s);
68 return %_ValueOf(this); 170 }
69 } 171
172
173 function Bool16x8Constructor(c0, c1, c2, c3, c4, c5, c6, c7) {
174 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool16x8");
175 return %CreateBool16x8(c0, c1, c2, c3, c4, c5, c6, c7);
176 }
177
178
179 function Bool16x8Splat(s) {
180 return %CreateBool16x8(s, s, s, s, s, s, s, s);
181 }
182
183
184 function Int8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
185 c12, c13, c14, c15) {
186 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Int8x16");
187 return %CreateInt8x16(TO_NUMBER_INLINE(c0), TO_NUMBER_INLINE(c1),
188 TO_NUMBER_INLINE(c2), TO_NUMBER_INLINE(c3),
189 TO_NUMBER_INLINE(c4), TO_NUMBER_INLINE(c5),
190 TO_NUMBER_INLINE(c6), TO_NUMBER_INLINE(c7),
191 TO_NUMBER_INLINE(c8), TO_NUMBER_INLINE(c9),
192 TO_NUMBER_INLINE(c10), TO_NUMBER_INLINE(c11),
193 TO_NUMBER_INLINE(c12), TO_NUMBER_INLINE(c13),
194 TO_NUMBER_INLINE(c14), TO_NUMBER_INLINE(c15));
195 }
196
197
198 function Int8x16Splat(s) {
199 return %CreateInt8x16(s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s);
200 }
201
202
203 function Bool8x16Constructor(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11,
204 c12, c13, c14, c15) {
205 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Bool8x16");
206 return %CreateBool8x16(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,
207 c13, c14, c15);
208 }
209
210
211 function Bool8x16Splat(s) {
212 return %CreateBool8x16(s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s);
213 }
214
215
216 %AddNamedProperty(GlobalSIMD, symbolToStringTag, 'SIMD', READ_ONLY | DONT_ENUM);
217
218 macro SETUP_SIMD_TYPE(NAME, TYPE, LANES)
219 %SetCode(GlobalNAME, NAMEConstructor);
220 %FunctionSetPrototype(GlobalNAME, {});
221 %AddNamedProperty(GlobalNAME.prototype, 'constructor', GlobalNAME,
222 DONT_ENUM);
223 %AddNamedProperty(GlobalNAME.prototype, symbolToStringTag, 'NAME',
224 DONT_ENUM | READ_ONLY);
225 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [
226 'toLocaleString', NAMEToLocaleString,
227 'toString', NAMEToString,
228 'valueOf', NAMEValueOf,
229 ]);
230 endmacro
231
232 SIMD_TYPES(SETUP_SIMD_TYPE)
70 233
71 //------------------------------------------------------------------- 234 //-------------------------------------------------------------------
72 235
73 function Float32x4ExtractLaneJS(value, lane) {
74 return %Float32x4ExtractLane(value, lane);
75 }
76
77 // -------------------------------------------------------------------
78
79 %AddNamedProperty(GlobalSIMD, symbolToStringTag, 'SIMD', READ_ONLY | DONT_ENUM);
80
81 %SetCode(GlobalFloat32x4, Float32x4Constructor);
82 %FunctionSetPrototype(GlobalFloat32x4, {});
83 %AddNamedProperty(
84 GlobalFloat32x4.prototype, 'constructor', GlobalFloat32x4, DONT_ENUM);
85 %AddNamedProperty(
86 GlobalFloat32x4.prototype, symbolToStringTag, 'Float32x4',
87 DONT_ENUM | READ_ONLY);
88
89 utils.InstallFunctions(GlobalFloat32x4.prototype, DONT_ENUM, [
90 'toLocaleString', Float32x4ToLocaleString,
91 'toString', Float32x4ToString,
92 'valueOf', Float32x4ValueOf,
93 ]);
94
95 utils.InstallFunctions(GlobalFloat32x4, DONT_ENUM, [ 236 utils.InstallFunctions(GlobalFloat32x4, DONT_ENUM, [
96 'splat', Float32x4Splat, 237 'splat', Float32x4Splat,
97 'check', Float32x4CheckJS, 238 'check', Float32x4CheckJS,
98 'extractLane', Float32x4ExtractLaneJS, 239 'extractLane', Float32x4ExtractLaneJS,
99 ]); 240 'replaceLane', Float32x4ReplaceLaneJS,
100 241 ]);
101 $float32x4ToString = Float32x4ToString; 242
243 utils.InstallFunctions(GlobalInt32x4, DONT_ENUM, [
244 'splat', Int32x4Splat,
245 'check', Int32x4CheckJS,
246 'extractLane', Int32x4ExtractLaneJS,
247 'replaceLane', Int32x4ReplaceLaneJS,
248 ]);
249
250 utils.InstallFunctions(GlobalBool32x4, DONT_ENUM, [
251 'splat', Bool32x4Splat,
252 'check', Bool32x4CheckJS,
253 'extractLane', Bool32x4ExtractLaneJS,
254 'replaceLane', Bool32x4ReplaceLaneJS,
255 ]);
256
257 utils.InstallFunctions(GlobalInt16x8, DONT_ENUM, [
258 'splat', Int16x8Splat,
259 'check', Int16x8CheckJS,
260 'extractLane', Int16x8ExtractLaneJS,
261 'unsignedExtractLane', Int16x8UnsignedExtractLaneJS,
262 'replaceLane', Int16x8ReplaceLaneJS,
263 ]);
264
265 utils.InstallFunctions(GlobalBool16x8, DONT_ENUM, [
266 'splat', Bool16x8Splat,
267 'check', Bool16x8CheckJS,
268 'extractLane', Bool16x8ExtractLaneJS,
269 'replaceLane', Bool16x8ReplaceLaneJS,
270 ]);
271
272 utils.InstallFunctions(GlobalInt8x16, DONT_ENUM, [
273 'splat', Int8x16Splat,
274 'check', Int8x16CheckJS,
275 'extractLane', Int8x16ExtractLaneJS,
276 'unsignedExtractLane', Int8x16UnsignedExtractLaneJS,
277 'replaceLane', Int8x16ReplaceLaneJS,
278 ]);
279
280 utils.InstallFunctions(GlobalBool8x16, DONT_ENUM, [
281 'splat', Bool8x16Splat,
282 'check', Bool8x16CheckJS,
283 'extractLane', Bool8x16ExtractLaneJS,
284 'replaceLane', Bool8x16ReplaceLaneJS,
285 ]);
102 286
103 }) 287 })
OLDNEW
« 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