OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 | 6 |
7 #include "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
8 #include "vm/native_entry.h" | 8 #include "vm/native_entry.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
| 14 static void ThrowMaskRangeException(int64_t m) { |
| 15 if ((m < 0) || (m > 255)) { |
| 16 const String& error = String::Handle( |
| 17 String::NewFormatted("mask (%" Pd64 ") must be in the range [0..256)", |
| 18 m)); |
| 19 const Array& args = Array::Handle(Array::New(1)); |
| 20 args.SetAt(0, error); |
| 21 Exceptions::ThrowByType(Exceptions::kRange, args); |
| 22 } |
| 23 } |
| 24 |
| 25 |
14 DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 5) { | 26 DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 5) { |
15 ASSERT(AbstractTypeArguments::CheckedHandle( | 27 ASSERT(AbstractTypeArguments::CheckedHandle( |
16 arguments->NativeArgAt(0)).IsNull()); | 28 arguments->NativeArgAt(0)).IsNull()); |
17 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); | 29 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); |
18 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2)); | 30 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2)); |
19 GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(3)); | 31 GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(3)); |
20 GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(4)); | 32 GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(4)); |
21 float _x = x.value(); | 33 float _x = x.value(); |
22 float _y = y.value(); | 34 float _y = y.value(); |
23 float _z = z.value(); | 35 float _z = z.value(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 uint32_t mw = (self.w() & 0x80000000) >> 31; | 268 uint32_t mw = (self.w() & 0x80000000) >> 31; |
257 uint32_t value = mx | (my << 1) | (mz << 2) | (mw << 3); | 269 uint32_t value = mx | (my << 1) | (mz << 2) | (mw << 3); |
258 return Integer::New(value); | 270 return Integer::New(value); |
259 } | 271 } |
260 | 272 |
261 | 273 |
262 DEFINE_NATIVE_ENTRY(Float32x4_shuffle, 2) { | 274 DEFINE_NATIVE_ENTRY(Float32x4_shuffle, 2) { |
263 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 275 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
264 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1)); | 276 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1)); |
265 int64_t m = mask.AsInt64Value(); | 277 int64_t m = mask.AsInt64Value(); |
266 if (m < 0 || m > 255) { | 278 ThrowMaskRangeException(m); |
267 const String& error = String::Handle( | |
268 String::NewFormatted("mask (%" Pd64 ") must be in the range [0..256)", | |
269 m)); | |
270 const Array& args = Array::Handle(Array::New(1)); | |
271 args.SetAt(0, error); | |
272 Exceptions::ThrowByType(Exceptions::kRange, args); | |
273 } | |
274 float data[4] = { self.x(), self.y(), self.z(), self.w() }; | 279 float data[4] = { self.x(), self.y(), self.z(), self.w() }; |
275 float _x = data[m & 0x3]; | 280 float _x = data[m & 0x3]; |
276 float _y = data[(m >> 2) & 0x3]; | 281 float _y = data[(m >> 2) & 0x3]; |
277 float _z = data[(m >> 4) & 0x3]; | 282 float _z = data[(m >> 4) & 0x3]; |
278 float _w = data[(m >> 6) & 0x3]; | 283 float _w = data[(m >> 6) & 0x3]; |
279 return Float32x4::New(_x, _y, _z, _w); | 284 return Float32x4::New(_x, _y, _z, _w); |
280 } | 285 } |
281 | 286 |
282 | 287 |
283 DEFINE_NATIVE_ENTRY(Float32x4_withZWInXY, 2) { | 288 DEFINE_NATIVE_ENTRY(Float32x4_shuffleMix, 3) { |
284 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 289 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
285 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); | 290 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); |
286 float _x = other.z(); | 291 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2)); |
287 float _y = other.w(); | 292 int64_t m = mask.AsInt64Value(); |
288 float _z = self.z(); | 293 ThrowMaskRangeException(m); |
289 float _w = self.w(); | 294 float data[4] = { self.x(), self.y(), self.z(), self.w() }; |
| 295 float other_data[4] = { other.x(), other.y(), other.z(), other.w() }; |
| 296 float _x = data[m & 0x3]; |
| 297 float _y = data[(m >> 2) & 0x3]; |
| 298 float _z = other_data[(m >> 4) & 0x3]; |
| 299 float _w = other_data[(m >> 6) & 0x3]; |
290 return Float32x4::New(_x, _y, _z, _w); | 300 return Float32x4::New(_x, _y, _z, _w); |
291 } | 301 } |
292 | 302 |
293 | |
294 DEFINE_NATIVE_ENTRY(Float32x4_interleaveXY, 2) { | |
295 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | |
296 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); | |
297 float _x = self.x(); | |
298 float _y = other.x(); | |
299 float _z = self.y(); | |
300 float _w = other.y(); | |
301 return Float32x4::New(_x, _y, _z, _w); | |
302 } | |
303 | |
304 | |
305 DEFINE_NATIVE_ENTRY(Float32x4_interleaveZW, 2) { | |
306 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | |
307 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); | |
308 float _x = self.z(); | |
309 float _y = other.z(); | |
310 float _z = self.w(); | |
311 float _w = other.w(); | |
312 return Float32x4::New(_x, _y, _z, _w); | |
313 } | |
314 | |
315 | |
316 DEFINE_NATIVE_ENTRY(Float32x4_interleaveXYPairs, 2) { | |
317 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | |
318 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); | |
319 float _x = self.x(); | |
320 float _y = self.y(); | |
321 float _z = other.x(); | |
322 float _w = other.y(); | |
323 return Float32x4::New(_x, _y, _z, _w); | |
324 } | |
325 | |
326 | |
327 DEFINE_NATIVE_ENTRY(Float32x4_interleaveZWPairs, 2) { | |
328 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | |
329 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); | |
330 float _x = self.z(); | |
331 float _y = self.w(); | |
332 float _z = other.z(); | |
333 float _w = other.w(); | |
334 return Float32x4::New(_x, _y, _z, _w); | |
335 } | |
336 | |
337 | 303 |
338 DEFINE_NATIVE_ENTRY(Float32x4_setX, 2) { | 304 DEFINE_NATIVE_ENTRY(Float32x4_setX, 2) { |
339 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 305 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
340 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); | 306 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); |
341 float _x = static_cast<float>(x.value()); | 307 float _x = static_cast<float>(x.value()); |
342 float _y = self.y(); | 308 float _y = self.y(); |
343 float _z = self.z(); | 309 float _z = self.z(); |
344 float _w = self.w(); | 310 float _w = self.w(); |
345 return Float32x4::New(_x, _y, _z, _w); | 311 return Float32x4::New(_x, _y, _z, _w); |
346 } | 312 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 511 } |
546 | 512 |
547 | 513 |
548 DEFINE_NATIVE_ENTRY(Uint32x4_getW, 1) { | 514 DEFINE_NATIVE_ENTRY(Uint32x4_getW, 1) { |
549 GET_NON_NULL_NATIVE_ARGUMENT(Uint32x4, self, arguments->NativeArgAt(0)); | 515 GET_NON_NULL_NATIVE_ARGUMENT(Uint32x4, self, arguments->NativeArgAt(0)); |
550 uint32_t value = self.w(); | 516 uint32_t value = self.w(); |
551 return Integer::New(value); | 517 return Integer::New(value); |
552 } | 518 } |
553 | 519 |
554 | 520 |
| 521 DEFINE_NATIVE_ENTRY(Uint32x4_shuffle, 2) { |
| 522 GET_NON_NULL_NATIVE_ARGUMENT(Uint32x4, self, arguments->NativeArgAt(0)); |
| 523 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1)); |
| 524 int64_t m = mask.AsInt64Value(); |
| 525 ThrowMaskRangeException(m); |
| 526 uint32_t data[4] = { self.x(), self.y(), self.z(), self.w() }; |
| 527 uint32_t _x = data[m & 0x3]; |
| 528 uint32_t _y = data[(m >> 2) & 0x3]; |
| 529 uint32_t _z = data[(m >> 4) & 0x3]; |
| 530 uint32_t _w = data[(m >> 6) & 0x3]; |
| 531 return Uint32x4::New(_x, _y, _z, _w); |
| 532 } |
| 533 |
| 534 |
| 535 DEFINE_NATIVE_ENTRY(Uint32x4_shuffleMix, 3) { |
| 536 GET_NON_NULL_NATIVE_ARGUMENT(Uint32x4, self, arguments->NativeArgAt(0)); |
| 537 GET_NON_NULL_NATIVE_ARGUMENT(Uint32x4, zw, arguments->NativeArgAt(1)); |
| 538 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2)); |
| 539 int64_t m = mask.AsInt64Value(); |
| 540 ThrowMaskRangeException(m); |
| 541 uint32_t data[4] = { self.x(), self.y(), self.z(), self.w() }; |
| 542 uint32_t zw_data[4] = { zw.x(), zw.y(), zw.z(), zw.w() }; |
| 543 uint32_t _x = data[m & 0x3]; |
| 544 uint32_t _y = data[(m >> 2) & 0x3]; |
| 545 uint32_t _z = zw_data[(m >> 4) & 0x3]; |
| 546 uint32_t _w = zw_data[(m >> 6) & 0x3]; |
| 547 return Uint32x4::New(_x, _y, _z, _w); |
| 548 } |
| 549 |
| 550 |
555 DEFINE_NATIVE_ENTRY(Uint32x4_setX, 2) { | 551 DEFINE_NATIVE_ENTRY(Uint32x4_setX, 2) { |
556 GET_NON_NULL_NATIVE_ARGUMENT(Uint32x4, self, arguments->NativeArgAt(0)); | 552 GET_NON_NULL_NATIVE_ARGUMENT(Uint32x4, self, arguments->NativeArgAt(0)); |
557 GET_NON_NULL_NATIVE_ARGUMENT(Integer, x, arguments->NativeArgAt(1)); | 553 GET_NON_NULL_NATIVE_ARGUMENT(Integer, x, arguments->NativeArgAt(1)); |
558 uint32_t _x = static_cast<uint32_t>(x.AsInt64Value() & 0xFFFFFFFF); | 554 uint32_t _x = static_cast<uint32_t>(x.AsInt64Value() & 0xFFFFFFFF); |
559 uint32_t _y = self.y(); | 555 uint32_t _y = self.y(); |
560 uint32_t _z = self.z(); | 556 uint32_t _z = self.z(); |
561 uint32_t _w = self.w(); | 557 uint32_t _w = self.w(); |
562 return Uint32x4::New(_x, _y, _z, _w); | 558 return Uint32x4::New(_x, _y, _z, _w); |
563 } | 559 } |
564 | 560 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 // Perform select. | 702 // Perform select. |
707 float32_uint32 tempX((_maskX & tvx.u) | (~_maskX & fvx.u)); | 703 float32_uint32 tempX((_maskX & tvx.u) | (~_maskX & fvx.u)); |
708 float32_uint32 tempY((_maskY & tvy.u) | (~_maskY & fvy.u)); | 704 float32_uint32 tempY((_maskY & tvy.u) | (~_maskY & fvy.u)); |
709 float32_uint32 tempZ((_maskZ & tvz.u) | (~_maskZ & fvz.u)); | 705 float32_uint32 tempZ((_maskZ & tvz.u) | (~_maskZ & fvz.u)); |
710 float32_uint32 tempW((_maskW & tvw.u) | (~_maskW & fvw.u)); | 706 float32_uint32 tempW((_maskW & tvw.u) | (~_maskW & fvw.u)); |
711 return Float32x4::New(tempX.f, tempY.f, tempZ.f, tempW.f); | 707 return Float32x4::New(tempX.f, tempY.f, tempZ.f, tempW.f); |
712 } | 708 } |
713 | 709 |
714 | 710 |
715 } // namespace dart | 711 } // namespace dart |
OLD | NEW |