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 const String& error = String::Handle( | 16 const String& error = String::Handle( |
17 String::NewFormatted("mask (%" Pd64 ") must be in the range [0..256)", | 17 String::NewFormatted("mask (%" Pd64 ") must be in the range [0..256)", |
18 m)); | 18 m)); |
19 const Array& args = Array::Handle(Array::New(1)); | 19 const Array& args = Array::Handle(Array::New(1)); |
20 args.SetAt(0, error); | 20 args.SetAt(0, error); |
21 Exceptions::ThrowByType(Exceptions::kRange, args); | 21 Exceptions::ThrowByType(Exceptions::kRange, args); |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 | 25 |
26 DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 5) { | 26 DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 5) { |
27 ASSERT(AbstractTypeArguments::CheckedHandle( | 27 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
28 arguments->NativeArgAt(0)).IsNull()); | |
29 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); | 28 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); |
30 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2)); | 29 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2)); |
31 GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(3)); | 30 GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(3)); |
32 GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(4)); | 31 GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(4)); |
33 float _x = static_cast<float>(x.value()); | 32 float _x = static_cast<float>(x.value()); |
34 float _y = static_cast<float>(y.value()); | 33 float _y = static_cast<float>(y.value()); |
35 float _z = static_cast<float>(z.value()); | 34 float _z = static_cast<float>(z.value()); |
36 float _w = static_cast<float>(w.value()); | 35 float _w = static_cast<float>(w.value()); |
37 return Float32x4::New(_x, _y, _z, _w); | 36 return Float32x4::New(_x, _y, _z, _w); |
38 } | 37 } |
39 | 38 |
40 | 39 |
41 DEFINE_NATIVE_ENTRY(Float32x4_splat, 2) { | 40 DEFINE_NATIVE_ENTRY(Float32x4_splat, 2) { |
42 ASSERT(AbstractTypeArguments::CheckedHandle( | 41 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
43 arguments->NativeArgAt(0)).IsNull()); | |
44 GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(1)); | 42 GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(1)); |
45 float _v = v.value(); | 43 float _v = v.value(); |
46 return Float32x4::New(_v, _v, _v, _v); | 44 return Float32x4::New(_v, _v, _v, _v); |
47 } | 45 } |
48 | 46 |
49 | 47 |
50 DEFINE_NATIVE_ENTRY(Float32x4_zero, 1) { | 48 DEFINE_NATIVE_ENTRY(Float32x4_zero, 1) { |
51 ASSERT(AbstractTypeArguments::CheckedHandle( | 49 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
52 arguments->NativeArgAt(0)).IsNull()); | |
53 return Float32x4::New(0.0f, 0.0f, 0.0f, 0.0f); | 50 return Float32x4::New(0.0f, 0.0f, 0.0f, 0.0f); |
54 } | 51 } |
55 | 52 |
56 | 53 |
57 DEFINE_NATIVE_ENTRY(Float32x4_fromInt32x4Bits, 2) { | 54 DEFINE_NATIVE_ENTRY(Float32x4_fromInt32x4Bits, 2) { |
58 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, v, arguments->NativeArgAt(1)); | 55 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, v, arguments->NativeArgAt(1)); |
59 return Float32x4::New(v.value()); | 56 return Float32x4::New(v.value()); |
60 } | 57 } |
61 | 58 |
62 | 59 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); | 398 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0)); |
402 float _x = sqrtf(1.0f / self.x()); | 399 float _x = sqrtf(1.0f / self.x()); |
403 float _y = sqrtf(1.0f / self.y()); | 400 float _y = sqrtf(1.0f / self.y()); |
404 float _z = sqrtf(1.0f / self.z()); | 401 float _z = sqrtf(1.0f / self.z()); |
405 float _w = sqrtf(1.0f / self.w()); | 402 float _w = sqrtf(1.0f / self.w()); |
406 return Float32x4::New(_x, _y, _z, _w); | 403 return Float32x4::New(_x, _y, _z, _w); |
407 } | 404 } |
408 | 405 |
409 | 406 |
410 DEFINE_NATIVE_ENTRY(Int32x4_fromInts, 5) { | 407 DEFINE_NATIVE_ENTRY(Int32x4_fromInts, 5) { |
411 ASSERT(AbstractTypeArguments::CheckedHandle( | 408 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
412 arguments->NativeArgAt(0)).IsNull()); | |
413 GET_NON_NULL_NATIVE_ARGUMENT(Integer, x, arguments->NativeArgAt(1)); | 409 GET_NON_NULL_NATIVE_ARGUMENT(Integer, x, arguments->NativeArgAt(1)); |
414 GET_NON_NULL_NATIVE_ARGUMENT(Integer, y, arguments->NativeArgAt(2)); | 410 GET_NON_NULL_NATIVE_ARGUMENT(Integer, y, arguments->NativeArgAt(2)); |
415 GET_NON_NULL_NATIVE_ARGUMENT(Integer, z, arguments->NativeArgAt(3)); | 411 GET_NON_NULL_NATIVE_ARGUMENT(Integer, z, arguments->NativeArgAt(3)); |
416 GET_NON_NULL_NATIVE_ARGUMENT(Integer, w, arguments->NativeArgAt(4)); | 412 GET_NON_NULL_NATIVE_ARGUMENT(Integer, w, arguments->NativeArgAt(4)); |
417 int32_t _x = static_cast<int32_t>(x.AsTruncatedUint32Value()); | 413 int32_t _x = static_cast<int32_t>(x.AsTruncatedUint32Value()); |
418 int32_t _y = static_cast<int32_t>(y.AsTruncatedUint32Value()); | 414 int32_t _y = static_cast<int32_t>(y.AsTruncatedUint32Value()); |
419 int32_t _z = static_cast<int32_t>(z.AsTruncatedUint32Value()); | 415 int32_t _z = static_cast<int32_t>(z.AsTruncatedUint32Value()); |
420 int32_t _w = static_cast<int32_t>(w.AsTruncatedUint32Value()); | 416 int32_t _w = static_cast<int32_t>(w.AsTruncatedUint32Value()); |
421 return Int32x4::New(_x, _y, _z, _w); | 417 return Int32x4::New(_x, _y, _z, _w); |
422 } | 418 } |
423 | 419 |
424 | 420 |
425 DEFINE_NATIVE_ENTRY(Int32x4_fromBools, 5) { | 421 DEFINE_NATIVE_ENTRY(Int32x4_fromBools, 5) { |
426 ASSERT(AbstractTypeArguments::CheckedHandle( | 422 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
427 arguments->NativeArgAt(0)).IsNull()); | |
428 GET_NON_NULL_NATIVE_ARGUMENT(Bool, x, arguments->NativeArgAt(1)); | 423 GET_NON_NULL_NATIVE_ARGUMENT(Bool, x, arguments->NativeArgAt(1)); |
429 GET_NON_NULL_NATIVE_ARGUMENT(Bool, y, arguments->NativeArgAt(2)); | 424 GET_NON_NULL_NATIVE_ARGUMENT(Bool, y, arguments->NativeArgAt(2)); |
430 GET_NON_NULL_NATIVE_ARGUMENT(Bool, z, arguments->NativeArgAt(3)); | 425 GET_NON_NULL_NATIVE_ARGUMENT(Bool, z, arguments->NativeArgAt(3)); |
431 GET_NON_NULL_NATIVE_ARGUMENT(Bool, w, arguments->NativeArgAt(4)); | 426 GET_NON_NULL_NATIVE_ARGUMENT(Bool, w, arguments->NativeArgAt(4)); |
432 int32_t _x = x.value() ? 0xFFFFFFFF : 0x0; | 427 int32_t _x = x.value() ? 0xFFFFFFFF : 0x0; |
433 int32_t _y = y.value() ? 0xFFFFFFFF : 0x0; | 428 int32_t _y = y.value() ? 0xFFFFFFFF : 0x0; |
434 int32_t _z = z.value() ? 0xFFFFFFFF : 0x0; | 429 int32_t _z = z.value() ? 0xFFFFFFFF : 0x0; |
435 int32_t _w = w.value() ? 0xFFFFFFFF : 0x0; | 430 int32_t _w = w.value() ? 0xFFFFFFFF : 0x0; |
436 return Int32x4::New(_x, _y, _z, _w); | 431 return Int32x4::New(_x, _y, _z, _w); |
437 } | 432 } |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 // Perform select. | 705 // Perform select. |
711 float32_int32 tempX((_maskX & tvx.u) | (~_maskX & fvx.u)); | 706 float32_int32 tempX((_maskX & tvx.u) | (~_maskX & fvx.u)); |
712 float32_int32 tempY((_maskY & tvy.u) | (~_maskY & fvy.u)); | 707 float32_int32 tempY((_maskY & tvy.u) | (~_maskY & fvy.u)); |
713 float32_int32 tempZ((_maskZ & tvz.u) | (~_maskZ & fvz.u)); | 708 float32_int32 tempZ((_maskZ & tvz.u) | (~_maskZ & fvz.u)); |
714 float32_int32 tempW((_maskW & tvw.u) | (~_maskW & fvw.u)); | 709 float32_int32 tempW((_maskW & tvw.u) | (~_maskW & fvw.u)); |
715 return Float32x4::New(tempX.f, tempY.f, tempZ.f, tempW.f); | 710 return Float32x4::New(tempX.f, tempY.f, tempZ.f, tempW.f); |
716 } | 711 } |
717 | 712 |
718 | 713 |
719 DEFINE_NATIVE_ENTRY(Float64x2_fromDoubles, 3) { | 714 DEFINE_NATIVE_ENTRY(Float64x2_fromDoubles, 3) { |
720 ASSERT(AbstractTypeArguments::CheckedHandle( | 715 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
721 arguments->NativeArgAt(0)).IsNull()); | |
722 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); | 716 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1)); |
723 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2)); | 717 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2)); |
724 return Float64x2::New(x.value(), y.value()); | 718 return Float64x2::New(x.value(), y.value()); |
725 } | 719 } |
726 | 720 |
727 | 721 |
728 DEFINE_NATIVE_ENTRY(Float64x2_splat, 2) { | 722 DEFINE_NATIVE_ENTRY(Float64x2_splat, 2) { |
729 ASSERT(AbstractTypeArguments::CheckedHandle( | 723 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
730 arguments->NativeArgAt(0)).IsNull()); | |
731 GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(1)); | 724 GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(1)); |
732 return Float64x2::New(v.value(), v.value()); | 725 return Float64x2::New(v.value(), v.value()); |
733 } | 726 } |
734 | 727 |
735 | 728 |
736 DEFINE_NATIVE_ENTRY(Float64x2_zero, 1) { | 729 DEFINE_NATIVE_ENTRY(Float64x2_zero, 1) { |
737 ASSERT(AbstractTypeArguments::CheckedHandle( | 730 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
738 arguments->NativeArgAt(0)).IsNull()); | |
739 return Float64x2::New(0.0, 0.0); | 731 return Float64x2::New(0.0, 0.0); |
740 } | 732 } |
741 | 733 |
742 | 734 |
743 DEFINE_NATIVE_ENTRY(Float64x2_fromFloat32x4, 2) { | 735 DEFINE_NATIVE_ENTRY(Float64x2_fromFloat32x4, 2) { |
744 ASSERT(AbstractTypeArguments::CheckedHandle( | 736 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
745 arguments->NativeArgAt(0)).IsNull()); | |
746 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, v, arguments->NativeArgAt(1)); | 737 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, v, arguments->NativeArgAt(1)); |
747 double _x = v.x(); | 738 double _x = v.x(); |
748 double _y = v.y(); | 739 double _y = v.y(); |
749 return Float64x2::New(_x, _y); | 740 return Float64x2::New(_x, _y); |
750 } | 741 } |
751 | 742 |
752 | 743 |
753 DEFINE_NATIVE_ENTRY(Float64x2_add, 2) { | 744 DEFINE_NATIVE_ENTRY(Float64x2_add, 2) { |
754 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); | 745 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); |
755 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1)); | 746 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1)); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 | 877 |
887 | 878 |
888 DEFINE_NATIVE_ENTRY(Float64x2_sqrt, 1) { | 879 DEFINE_NATIVE_ENTRY(Float64x2_sqrt, 1) { |
889 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); | 880 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0)); |
890 double _x = sqrt(self.x()); | 881 double _x = sqrt(self.x()); |
891 double _y = sqrt(self.y()); | 882 double _y = sqrt(self.y()); |
892 return Float64x2::New(_x, _y); | 883 return Float64x2::New(_x, _y); |
893 } | 884 } |
894 | 885 |
895 } // namespace dart | 886 } // namespace dart |
OLD | NEW |