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) { | 14 static void ThrowMaskRangeException(int64_t m) { |
15 if ((m < 0) || (m > 255)) { | 15 if ((m < 0) || (m > 255)) { |
16 Exceptions::ThrowRangeError( | 16 Exceptions::ThrowRangeError("mask", Integer::Handle(Integer::New(m)), 0, |
17 "mask", Integer::Handle(Integer::New(m)), 0, 255); | 17 255); |
18 } | 18 } |
19 } | 19 } |
20 | 20 |
21 | 21 |
22 DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 5) { | 22 DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 5) { |
23 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); | 23 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
24 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); | 24 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); |
25 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2)); | 25 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2)); |
26 GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(3)); | 26 GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(3)); |
27 GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(4)); | 27 GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(4)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 float _x = self.x() - other.x(); | 88 float _x = self.x() - other.x(); |
89 float _y = self.y() - other.y(); | 89 float _y = self.y() - other.y(); |
90 float _z = self.z() - other.z(); | 90 float _z = self.z() - other.z(); |
91 float _w = self.w() - other.w(); | 91 float _w = self.w() - other.w(); |
92 return Float32x4::New(_x, _y, _z, _w); | 92 return Float32x4::New(_x, _y, _z, _w); |
93 } | 93 } |
94 | 94 |
95 | 95 |
96 DEFINE_NATIVE_ENTRY(Float32x4_mul, 2) { | 96 DEFINE_NATIVE_ENTRY(Float32x4_mul, 2) { |
97 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 97 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
98 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, | 98 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); |
99 arguments->NativeArgAt(1)); | |
100 float _x = self.x() * other.x(); | 99 float _x = self.x() * other.x(); |
101 float _y = self.y() * other.y(); | 100 float _y = self.y() * other.y(); |
102 float _z = self.z() * other.z(); | 101 float _z = self.z() * other.z(); |
103 float _w = self.w() * other.w(); | 102 float _w = self.w() * other.w(); |
104 return Float32x4::New(_x, _y, _z, _w); | 103 return Float32x4::New(_x, _y, _z, _w); |
105 } | 104 } |
106 | 105 |
107 | 106 |
108 DEFINE_NATIVE_ENTRY(Float32x4_div, 2) { | 107 DEFINE_NATIVE_ENTRY(Float32x4_div, 2) { |
109 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 108 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 uint32_t value = mx | (my << 1) | (mz << 2) | (mw << 3); | 269 uint32_t value = mx | (my << 1) | (mz << 2) | (mw << 3); |
271 return Integer::New(value); | 270 return Integer::New(value); |
272 } | 271 } |
273 | 272 |
274 | 273 |
275 DEFINE_NATIVE_ENTRY(Float32x4_shuffle, 2) { | 274 DEFINE_NATIVE_ENTRY(Float32x4_shuffle, 2) { |
276 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 275 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
277 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1)); | 276 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1)); |
278 int64_t m = mask.AsInt64Value(); | 277 int64_t m = mask.AsInt64Value(); |
279 ThrowMaskRangeException(m); | 278 ThrowMaskRangeException(m); |
280 float data[4] = { self.x(), self.y(), self.z(), self.w() }; | 279 float data[4] = {self.x(), self.y(), self.z(), self.w()}; |
281 float _x = data[m & 0x3]; | 280 float _x = data[m & 0x3]; |
282 float _y = data[(m >> 2) & 0x3]; | 281 float _y = data[(m >> 2) & 0x3]; |
283 float _z = data[(m >> 4) & 0x3]; | 282 float _z = data[(m >> 4) & 0x3]; |
284 float _w = data[(m >> 6) & 0x3]; | 283 float _w = data[(m >> 6) & 0x3]; |
285 return Float32x4::New(_x, _y, _z, _w); | 284 return Float32x4::New(_x, _y, _z, _w); |
286 } | 285 } |
287 | 286 |
288 | 287 |
289 DEFINE_NATIVE_ENTRY(Float32x4_shuffleMix, 3) { | 288 DEFINE_NATIVE_ENTRY(Float32x4_shuffleMix, 3) { |
290 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 289 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
291 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); | 290 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); |
292 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2)); | 291 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2)); |
293 int64_t m = mask.AsInt64Value(); | 292 int64_t m = mask.AsInt64Value(); |
294 ThrowMaskRangeException(m); | 293 ThrowMaskRangeException(m); |
295 float data[4] = { self.x(), self.y(), self.z(), self.w() }; | 294 float data[4] = {self.x(), self.y(), self.z(), self.w()}; |
296 float other_data[4] = { other.x(), other.y(), other.z(), other.w() }; | 295 float other_data[4] = {other.x(), other.y(), other.z(), other.w()}; |
297 float _x = data[m & 0x3]; | 296 float _x = data[m & 0x3]; |
298 float _y = data[(m >> 2) & 0x3]; | 297 float _y = data[(m >> 2) & 0x3]; |
299 float _z = other_data[(m >> 4) & 0x3]; | 298 float _z = other_data[(m >> 4) & 0x3]; |
300 float _w = other_data[(m >> 6) & 0x3]; | 299 float _w = other_data[(m >> 6) & 0x3]; |
301 return Float32x4::New(_x, _y, _z, _w); | 300 return Float32x4::New(_x, _y, _z, _w); |
302 } | 301 } |
303 | 302 |
304 | 303 |
305 DEFINE_NATIVE_ENTRY(Float32x4_setX, 2) { | 304 DEFINE_NATIVE_ENTRY(Float32x4_setX, 2) { |
306 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 305 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 float _x = self.x(); | 340 float _x = self.x(); |
342 float _y = self.y(); | 341 float _y = self.y(); |
343 float _z = self.z(); | 342 float _z = self.z(); |
344 float _w = static_cast<float>(w.value()); | 343 float _w = static_cast<float>(w.value()); |
345 return Float32x4::New(_x, _y, _z, _w); | 344 return Float32x4::New(_x, _y, _z, _w); |
346 } | 345 } |
347 | 346 |
348 | 347 |
349 DEFINE_NATIVE_ENTRY(Float32x4_min, 2) { | 348 DEFINE_NATIVE_ENTRY(Float32x4_min, 2) { |
350 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 349 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
351 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, | 350 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); |
352 arguments->NativeArgAt(1)); | |
353 float _x = self.x() < other.x() ? self.x() : other.x(); | 351 float _x = self.x() < other.x() ? self.x() : other.x(); |
354 float _y = self.y() < other.y() ? self.y() : other.y(); | 352 float _y = self.y() < other.y() ? self.y() : other.y(); |
355 float _z = self.z() < other.z() ? self.z() : other.z(); | 353 float _z = self.z() < other.z() ? self.z() : other.z(); |
356 float _w = self.w() < other.w() ? self.w() : other.w(); | 354 float _w = self.w() < other.w() ? self.w() : other.w(); |
357 return Float32x4::New(_x, _y, _z, _w); | 355 return Float32x4::New(_x, _y, _z, _w); |
358 } | 356 } |
359 | 357 |
360 | 358 |
361 DEFINE_NATIVE_ENTRY(Float32x4_max, 2) { | 359 DEFINE_NATIVE_ENTRY(Float32x4_max, 2) { |
362 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 360 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
363 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, | 361 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1)); |
364 arguments->NativeArgAt(1)); | |
365 float _x = self.x() > other.x() ? self.x() : other.x(); | 362 float _x = self.x() > other.x() ? self.x() : other.x(); |
366 float _y = self.y() > other.y() ? self.y() : other.y(); | 363 float _y = self.y() > other.y() ? self.y() : other.y(); |
367 float _z = self.z() > other.z() ? self.z() : other.z(); | 364 float _z = self.z() > other.z() ? self.z() : other.z(); |
368 float _w = self.w() > other.w() ? self.w() : other.w(); | 365 float _w = self.w() > other.w() ? self.w() : other.w(); |
369 return Float32x4::New(_x, _y, _z, _w); | 366 return Float32x4::New(_x, _y, _z, _w); |
370 } | 367 } |
371 | 368 |
372 | 369 |
373 DEFINE_NATIVE_ENTRY(Float32x4_sqrt, 1) { | 370 DEFINE_NATIVE_ENTRY(Float32x4_sqrt, 1) { |
374 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 371 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 int32_t value = self.w(); | 512 int32_t value = self.w(); |
516 return Integer::New(value); | 513 return Integer::New(value); |
517 } | 514 } |
518 | 515 |
519 | 516 |
520 DEFINE_NATIVE_ENTRY(Int32x4_shuffle, 2) { | 517 DEFINE_NATIVE_ENTRY(Int32x4_shuffle, 2) { |
521 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0)); | 518 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0)); |
522 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1)); | 519 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1)); |
523 int64_t m = mask.AsInt64Value(); | 520 int64_t m = mask.AsInt64Value(); |
524 ThrowMaskRangeException(m); | 521 ThrowMaskRangeException(m); |
525 int32_t data[4] = { self.x(), self.y(), self.z(), self.w() }; | 522 int32_t data[4] = {self.x(), self.y(), self.z(), self.w()}; |
526 int32_t _x = data[m & 0x3]; | 523 int32_t _x = data[m & 0x3]; |
527 int32_t _y = data[(m >> 2) & 0x3]; | 524 int32_t _y = data[(m >> 2) & 0x3]; |
528 int32_t _z = data[(m >> 4) & 0x3]; | 525 int32_t _z = data[(m >> 4) & 0x3]; |
529 int32_t _w = data[(m >> 6) & 0x3]; | 526 int32_t _w = data[(m >> 6) & 0x3]; |
530 return Int32x4::New(_x, _y, _z, _w); | 527 return Int32x4::New(_x, _y, _z, _w); |
531 } | 528 } |
532 | 529 |
533 | 530 |
534 DEFINE_NATIVE_ENTRY(Int32x4_shuffleMix, 3) { | 531 DEFINE_NATIVE_ENTRY(Int32x4_shuffleMix, 3) { |
535 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0)); | 532 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0)); |
536 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, zw, arguments->NativeArgAt(1)); | 533 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, zw, arguments->NativeArgAt(1)); |
537 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2)); | 534 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2)); |
538 int64_t m = mask.AsInt64Value(); | 535 int64_t m = mask.AsInt64Value(); |
539 ThrowMaskRangeException(m); | 536 ThrowMaskRangeException(m); |
540 int32_t data[4] = { self.x(), self.y(), self.z(), self.w() }; | 537 int32_t data[4] = {self.x(), self.y(), self.z(), self.w()}; |
541 int32_t zw_data[4] = { zw.x(), zw.y(), zw.z(), zw.w() }; | 538 int32_t zw_data[4] = {zw.x(), zw.y(), zw.z(), zw.w()}; |
542 int32_t _x = data[m & 0x3]; | 539 int32_t _x = data[m & 0x3]; |
543 int32_t _y = data[(m >> 2) & 0x3]; | 540 int32_t _y = data[(m >> 2) & 0x3]; |
544 int32_t _z = zw_data[(m >> 4) & 0x3]; | 541 int32_t _z = zw_data[(m >> 4) & 0x3]; |
545 int32_t _w = zw_data[(m >> 6) & 0x3]; | 542 int32_t _w = zw_data[(m >> 6) & 0x3]; |
546 return Int32x4::New(_x, _y, _z, _w); | 543 return Int32x4::New(_x, _y, _z, _w); |
547 } | 544 } |
548 | 545 |
549 | 546 |
550 DEFINE_NATIVE_ENTRY(Int32x4_setX, 2) { | 547 DEFINE_NATIVE_ENTRY(Int32x4_setX, 2) { |
551 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0)); | 548 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0)); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 _w = flagW.raw() == Bool::True().raw() ? 0xFFFFFFFF : 0x0; | 662 _w = flagW.raw() == Bool::True().raw() ? 0xFFFFFFFF : 0x0; |
666 return Int32x4::New(_x, _y, _z, _w); | 663 return Int32x4::New(_x, _y, _z, _w); |
667 } | 664 } |
668 | 665 |
669 | 666 |
670 // Used to convert between int32_t and float32 without breaking strict | 667 // Used to convert between int32_t and float32 without breaking strict |
671 // aliasing rules. | 668 // aliasing rules. |
672 union float32_int32 { | 669 union float32_int32 { |
673 float f; | 670 float f; |
674 int32_t u; | 671 int32_t u; |
675 float32_int32(float v) { | 672 float32_int32(float v) { f = v; } |
676 f = v; | 673 float32_int32(int32_t v) { u = v; } |
677 } | |
678 float32_int32(int32_t v) { | |
679 u = v; | |
680 } | |
681 }; | 674 }; |
682 | 675 |
683 | 676 |
684 DEFINE_NATIVE_ENTRY(Int32x4_select, 3) { | 677 DEFINE_NATIVE_ENTRY(Int32x4_select, 3) { |
685 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0)); | 678 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0)); |
686 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, tv, arguments->NativeArgAt(1)); | 679 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, tv, arguments->NativeArgAt(1)); |
687 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, fv, arguments->NativeArgAt(2)); | 680 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, fv, arguments->NativeArgAt(2)); |
688 int32_t _maskX = self.x(); | 681 int32_t _maskX = self.x(); |
689 int32_t _maskY = self.y(); | 682 int32_t _maskY = self.y(); |
690 int32_t _maskZ = self.z(); | 683 int32_t _maskZ = self.z(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); | 840 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); |
848 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(1)); | 841 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(1)); |
849 double _x = self.x(); | 842 double _x = self.x(); |
850 double _y = y.value(); | 843 double _y = y.value(); |
851 return Float64x2::New(_x, _y); | 844 return Float64x2::New(_x, _y); |
852 } | 845 } |
853 | 846 |
854 | 847 |
855 DEFINE_NATIVE_ENTRY(Float64x2_min, 2) { | 848 DEFINE_NATIVE_ENTRY(Float64x2_min, 2) { |
856 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); | 849 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); |
857 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, | 850 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1)); |
858 arguments->NativeArgAt(1)); | |
859 double _x = self.x() < other.x() ? self.x() : other.x(); | 851 double _x = self.x() < other.x() ? self.x() : other.x(); |
860 double _y = self.y() < other.y() ? self.y() : other.y(); | 852 double _y = self.y() < other.y() ? self.y() : other.y(); |
861 return Float64x2::New(_x, _y); | 853 return Float64x2::New(_x, _y); |
862 } | 854 } |
863 | 855 |
864 | 856 |
865 DEFINE_NATIVE_ENTRY(Float64x2_max, 2) { | 857 DEFINE_NATIVE_ENTRY(Float64x2_max, 2) { |
866 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); | 858 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); |
867 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, | 859 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1)); |
868 arguments->NativeArgAt(1)); | |
869 double _x = self.x() > other.x() ? self.x() : other.x(); | 860 double _x = self.x() > other.x() ? self.x() : other.x(); |
870 double _y = self.y() > other.y() ? self.y() : other.y(); | 861 double _y = self.y() > other.y() ? self.y() : other.y(); |
871 return Float64x2::New(_x, _y); | 862 return Float64x2::New(_x, _y); |
872 } | 863 } |
873 | 864 |
874 | 865 |
875 DEFINE_NATIVE_ENTRY(Float64x2_sqrt, 1) { | 866 DEFINE_NATIVE_ENTRY(Float64x2_sqrt, 1) { |
876 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); | 867 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); |
877 double _x = sqrt(self.x()); | 868 double _x = sqrt(self.x()); |
878 double _y = sqrt(self.y()); | 869 double _y = sqrt(self.y()); |
879 return Float64x2::New(_x, _y); | 870 return Float64x2::New(_x, _y); |
880 } | 871 } |
881 | 872 |
882 } // namespace dart | 873 } // namespace dart |
OLD | NEW |