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 /** | 5 /** |
6 * Specialized integers and floating point numbers, | 6 * Specialized integers and floating point numbers, |
7 * with SIMD support and efficient lists. | 7 * with SIMD support and efficient lists. |
8 */ | 8 */ |
9 library dart.typed_data; | 9 library dart.typed_data; |
10 | 10 |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 _storage[(index*4)+3] = value._storage[3]; | 788 _storage[(index*4)+3] = value._storage[3]; |
789 } | 789 } |
790 | 790 |
791 List<Float32x4> sublist(int start, [int end]) { | 791 List<Float32x4> sublist(int start, [int end]) { |
792 end = _checkSublistArguments(start, end, length); | 792 end = _checkSublistArguments(start, end, length); |
793 return new Float32x4List._externalStorage(_storage.sublist(start*4, end*4)); | 793 return new Float32x4List._externalStorage(_storage.sublist(start*4, end*4)); |
794 } | 794 } |
795 } | 795 } |
796 | 796 |
797 | 797 |
798 class Uint32x4List | 798 class Int32x4List |
799 extends Object with ListMixin<Uint32x4>, FixedLengthListMixin<Uint32x4> | 799 extends Object with ListMixin<Int32x4>, FixedLengthListMixin<Int32x4> |
800 implements List<Uint32x4>, TypedData { | 800 implements List<Int32x4>, TypedData { |
801 | 801 |
802 final Uint32List _storage; | 802 final Uint32List _storage; |
803 | 803 |
804 ByteBuffer get buffer => _storage.buffer; | 804 ByteBuffer get buffer => _storage.buffer; |
805 | 805 |
806 int get lengthInBytes => _storage.lengthInBytes; | 806 int get lengthInBytes => _storage.lengthInBytes; |
807 | 807 |
808 int get offsetInBytes => _storage.offsetInBytes; | 808 int get offsetInBytes => _storage.offsetInBytes; |
809 | 809 |
810 final int elementSizeInBytes = 16; | 810 final int elementSizeInBytes = 16; |
(...skipping 17 matching lines...) Expand all Loading... |
828 // [length]. However, [_checkIndex] only allows indices in the range | 828 // [length]. However, [_checkIndex] only allows indices in the range |
829 // 0 .. length - 1. We therefore increment the [length] argument by one | 829 // 0 .. length - 1. We therefore increment the [length] argument by one |
830 // for the [_checkIndex] checks. | 830 // for the [_checkIndex] checks. |
831 _checkIndex(start, length + 1); | 831 _checkIndex(start, length + 1); |
832 if (end == null) return length; | 832 if (end == null) return length; |
833 _checkIndex(end, length + 1); | 833 _checkIndex(end, length + 1); |
834 if (start > end) throw new RangeError.range(start, 0, end); | 834 if (start > end) throw new RangeError.range(start, 0, end); |
835 return end; | 835 return end; |
836 } | 836 } |
837 | 837 |
838 Uint32x4List(int length) : _storage = new Uint32List(length*4); | 838 Int32x4List(int length) : _storage = new Uint32List(length*4); |
839 | 839 |
840 Uint32x4List._externalStorage(Uint32List storage) : _storage = storage; | 840 Int32x4List._externalStorage(Uint32List storage) : _storage = storage; |
841 | 841 |
842 Uint32x4List._slowFromList(List<Uint32x4> list) | 842 Int32x4List._slowFromList(List<Int32x4> list) |
843 : _storage = new Uint32List(list.length * 4) { | 843 : _storage = new Uint32List(list.length * 4) { |
844 for (int i = 0; i < list.length; i++) { | 844 for (int i = 0; i < list.length; i++) { |
845 var e = list[i]; | 845 var e = list[i]; |
846 _storage[(i*4)+0] = e.x; | 846 _storage[(i*4)+0] = e.x; |
847 _storage[(i*4)+1] = e.y; | 847 _storage[(i*4)+1] = e.y; |
848 _storage[(i*4)+2] = e.z; | 848 _storage[(i*4)+2] = e.z; |
849 _storage[(i*4)+3] = e.w; | 849 _storage[(i*4)+3] = e.w; |
850 } | 850 } |
851 } | 851 } |
852 | 852 |
853 factory Uint32x4List.fromList(List<Uint32x4> list) { | 853 factory Int32x4List.fromList(List<Int32x4> list) { |
854 if (list is Uint32x4List) { | 854 if (list is Int32x4List) { |
855 Uint32x4List nativeList = list as Uint32x4List; | 855 Int32x4List nativeList = list as Int32x4List; |
856 return new Uint32x4List._externalStorage( | 856 return new Int32x4List._externalStorage( |
857 new Uint32List.fromList(nativeList._storage)); | 857 new Uint32List.fromList(nativeList._storage)); |
858 } else { | 858 } else { |
859 return new Uint32x4List._slowFromList(list); | 859 return new Int32x4List._slowFromList(list); |
860 } | 860 } |
861 } | 861 } |
862 | 862 |
863 Uint32x4List.view(ByteBuffer buffer, | 863 Int32x4List.view(ByteBuffer buffer, |
864 [int byteOffset = 0, int length]) | 864 [int byteOffset = 0, int length]) |
865 : _storage = new Uint32List.view(buffer, byteOffset, length); | 865 : _storage = new Uint32List.view(buffer, byteOffset, length); |
866 | 866 |
867 static const int BYTES_PER_ELEMENT = 16; | 867 static const int BYTES_PER_ELEMENT = 16; |
868 | 868 |
869 int get length => _storage.length ~/ 4; | 869 int get length => _storage.length ~/ 4; |
870 | 870 |
871 Uint32x4 operator[](int index) { | 871 Int32x4 operator[](int index) { |
872 _checkIndex(index, length); | 872 _checkIndex(index, length); |
873 int _x = _storage[(index*4)+0]; | 873 int _x = _storage[(index*4)+0]; |
874 int _y = _storage[(index*4)+1]; | 874 int _y = _storage[(index*4)+1]; |
875 int _z = _storage[(index*4)+2]; | 875 int _z = _storage[(index*4)+2]; |
876 int _w = _storage[(index*4)+3]; | 876 int _w = _storage[(index*4)+3]; |
877 return new Uint32x4(_x, _y, _z, _w); | 877 return new Int32x4(_x, _y, _z, _w); |
878 } | 878 } |
879 | 879 |
880 void operator[]=(int index, Uint32x4 value) { | 880 void operator[]=(int index, Int32x4 value) { |
881 _checkIndex(index, length); | 881 _checkIndex(index, length); |
882 _storage[(index*4)+0] = value._storage[0]; | 882 _storage[(index*4)+0] = value._storage[0]; |
883 _storage[(index*4)+1] = value._storage[1]; | 883 _storage[(index*4)+1] = value._storage[1]; |
884 _storage[(index*4)+2] = value._storage[2]; | 884 _storage[(index*4)+2] = value._storage[2]; |
885 _storage[(index*4)+3] = value._storage[3]; | 885 _storage[(index*4)+3] = value._storage[3]; |
886 } | 886 } |
887 | 887 |
888 List<Uint32x4> sublist(int start, [int end]) { | 888 List<Int32x4> sublist(int start, [int end]) { |
889 end = _checkSublistArguments(start, end, length); | 889 end = _checkSublistArguments(start, end, length); |
890 return new Uint32x4List._externalStorage(_storage.sublist(start*4, end*4)); | 890 return new Int32x4List._externalStorage(_storage.sublist(start*4, end*4)); |
891 } | 891 } |
892 } | 892 } |
893 | 893 |
894 | 894 |
895 class Float32x4 { | 895 class Float32x4 { |
896 final _storage = new Float32List(4); | 896 final _storage = new Float32List(4); |
897 | 897 |
898 Float32x4(double x, double y, double z, double w) { | 898 Float32x4(double x, double y, double z, double w) { |
899 _storage[0] = x; | 899 _storage[0] = x; |
900 _storage[1] = y; | 900 _storage[1] = y; |
901 _storage[2] = z; | 901 _storage[2] = z; |
902 _storage[3] = w; | 902 _storage[3] = w; |
903 } | 903 } |
904 Float32x4.splat(double v) { | 904 Float32x4.splat(double v) { |
905 _storage[0] = v; | 905 _storage[0] = v; |
906 _storage[1] = v; | 906 _storage[1] = v; |
907 _storage[2] = v; | 907 _storage[2] = v; |
908 _storage[3] = v; | 908 _storage[3] = v; |
909 } | 909 } |
910 Float32x4.zero(); | 910 Float32x4.zero(); |
911 /// Returns a bit-wise copy of [x] as a Float32x4. | 911 /// Returns a bit-wise copy of [x] as a Float32x4. |
912 Float32x4.fromUint32x4Bits(Uint32x4 x) { | 912 Float32x4.fromInt32x4Bits(Int32x4 x) { |
913 var view = new Float32List.view(x._storage.buffer); | 913 var view = new Float32List.view(x._storage.buffer); |
914 _storage[0] = view[0]; | 914 _storage[0] = view[0]; |
915 _storage[1] = view[1]; | 915 _storage[1] = view[1]; |
916 _storage[2] = view[2]; | 916 _storage[2] = view[2]; |
917 _storage[3] = view[3]; | 917 _storage[3] = view[3]; |
918 } | 918 } |
919 | 919 |
920 /// Addition operator. | 920 /// Addition operator. |
921 Float32x4 operator+(Float32x4 other) { | 921 Float32x4 operator+(Float32x4 other) { |
922 double _x = _storage[0] + other._storage[0]; | 922 double _x = _storage[0] + other._storage[0]; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 /// Division operator. | 956 /// Division operator. |
957 Float32x4 operator/(Float32x4 other) { | 957 Float32x4 operator/(Float32x4 other) { |
958 double _x = _storage[0] / other._storage[0]; | 958 double _x = _storage[0] / other._storage[0]; |
959 double _y = _storage[1] / other._storage[1]; | 959 double _y = _storage[1] / other._storage[1]; |
960 double _z = _storage[2] / other._storage[2]; | 960 double _z = _storage[2] / other._storage[2]; |
961 double _w = _storage[3] / other._storage[3]; | 961 double _w = _storage[3] / other._storage[3]; |
962 return new Float32x4(_x, _y, _z, _w); | 962 return new Float32x4(_x, _y, _z, _w); |
963 } | 963 } |
964 | 964 |
965 /// Relational less than. | 965 /// Relational less than. |
966 Uint32x4 lessThan(Float32x4 other) { | 966 Int32x4 lessThan(Float32x4 other) { |
967 bool _cx = _storage[0] < other._storage[0]; | 967 bool _cx = _storage[0] < other._storage[0]; |
968 bool _cy = _storage[1] < other._storage[1]; | 968 bool _cy = _storage[1] < other._storage[1]; |
969 bool _cz = _storage[2] < other._storage[2]; | 969 bool _cz = _storage[2] < other._storage[2]; |
970 bool _cw = _storage[3] < other._storage[3]; | 970 bool _cw = _storage[3] < other._storage[3]; |
971 return new Uint32x4(_cx == true ? 0xFFFFFFFF : 0x0, | 971 return new Int32x4(_cx == true ? 0xFFFFFFFF : 0x0, |
972 _cy == true ? 0xFFFFFFFF : 0x0, | 972 _cy == true ? 0xFFFFFFFF : 0x0, |
973 _cz == true ? 0xFFFFFFFF : 0x0, | 973 _cz == true ? 0xFFFFFFFF : 0x0, |
974 _cw == true ? 0xFFFFFFFF : 0x0); | 974 _cw == true ? 0xFFFFFFFF : 0x0); |
975 } | 975 } |
976 | 976 |
977 /// Relational less than or equal. | 977 /// Relational less than or equal. |
978 Uint32x4 lessThanOrEqual(Float32x4 other) { | 978 Int32x4 lessThanOrEqual(Float32x4 other) { |
979 bool _cx = _storage[0] <= other._storage[0]; | 979 bool _cx = _storage[0] <= other._storage[0]; |
980 bool _cy = _storage[1] <= other._storage[1]; | 980 bool _cy = _storage[1] <= other._storage[1]; |
981 bool _cz = _storage[2] <= other._storage[2]; | 981 bool _cz = _storage[2] <= other._storage[2]; |
982 bool _cw = _storage[3] <= other._storage[3]; | 982 bool _cw = _storage[3] <= other._storage[3]; |
983 return new Uint32x4(_cx == true ? 0xFFFFFFFF : 0x0, | 983 return new Int32x4(_cx == true ? 0xFFFFFFFF : 0x0, |
984 _cy == true ? 0xFFFFFFFF : 0x0, | 984 _cy == true ? 0xFFFFFFFF : 0x0, |
985 _cz == true ? 0xFFFFFFFF : 0x0, | 985 _cz == true ? 0xFFFFFFFF : 0x0, |
986 _cw == true ? 0xFFFFFFFF : 0x0); | 986 _cw == true ? 0xFFFFFFFF : 0x0); |
987 } | 987 } |
988 | 988 |
989 /// Relational greater than. | 989 /// Relational greater than. |
990 Uint32x4 greaterThan(Float32x4 other) { | 990 Int32x4 greaterThan(Float32x4 other) { |
991 bool _cx = _storage[0] > other._storage[0]; | 991 bool _cx = _storage[0] > other._storage[0]; |
992 bool _cy = _storage[1] > other._storage[1]; | 992 bool _cy = _storage[1] > other._storage[1]; |
993 bool _cz = _storage[2] > other._storage[2]; | 993 bool _cz = _storage[2] > other._storage[2]; |
994 bool _cw = _storage[3] > other._storage[3]; | 994 bool _cw = _storage[3] > other._storage[3]; |
995 return new Uint32x4(_cx == true ? 0xFFFFFFFF : 0x0, | 995 return new Int32x4(_cx == true ? 0xFFFFFFFF : 0x0, |
996 _cy == true ? 0xFFFFFFFF : 0x0, | 996 _cy == true ? 0xFFFFFFFF : 0x0, |
997 _cz == true ? 0xFFFFFFFF : 0x0, | 997 _cz == true ? 0xFFFFFFFF : 0x0, |
998 _cw == true ? 0xFFFFFFFF : 0x0); | 998 _cw == true ? 0xFFFFFFFF : 0x0); |
999 } | 999 } |
1000 | 1000 |
1001 /// Relational greater than or equal. | 1001 /// Relational greater than or equal. |
1002 Uint32x4 greaterThanOrEqual(Float32x4 other) { | 1002 Int32x4 greaterThanOrEqual(Float32x4 other) { |
1003 bool _cx = _storage[0] >= other._storage[0]; | 1003 bool _cx = _storage[0] >= other._storage[0]; |
1004 bool _cy = _storage[1] >= other._storage[1]; | 1004 bool _cy = _storage[1] >= other._storage[1]; |
1005 bool _cz = _storage[2] >= other._storage[2]; | 1005 bool _cz = _storage[2] >= other._storage[2]; |
1006 bool _cw = _storage[3] >= other._storage[3]; | 1006 bool _cw = _storage[3] >= other._storage[3]; |
1007 return new Uint32x4(_cx == true ? 0xFFFFFFFF : 0x0, | 1007 return new Int32x4(_cx == true ? 0xFFFFFFFF : 0x0, |
1008 _cy == true ? 0xFFFFFFFF : 0x0, | 1008 _cy == true ? 0xFFFFFFFF : 0x0, |
1009 _cz == true ? 0xFFFFFFFF : 0x0, | 1009 _cz == true ? 0xFFFFFFFF : 0x0, |
1010 _cw == true ? 0xFFFFFFFF : 0x0); | 1010 _cw == true ? 0xFFFFFFFF : 0x0); |
1011 } | 1011 } |
1012 | 1012 |
1013 /// Relational equal. | 1013 /// Relational equal. |
1014 Uint32x4 equal(Float32x4 other) { | 1014 Int32x4 equal(Float32x4 other) { |
1015 bool _cx = _storage[0] == other._storage[0]; | 1015 bool _cx = _storage[0] == other._storage[0]; |
1016 bool _cy = _storage[1] == other._storage[1]; | 1016 bool _cy = _storage[1] == other._storage[1]; |
1017 bool _cz = _storage[2] == other._storage[2]; | 1017 bool _cz = _storage[2] == other._storage[2]; |
1018 bool _cw = _storage[3] == other._storage[3]; | 1018 bool _cw = _storage[3] == other._storage[3]; |
1019 return new Uint32x4(_cx == true ? 0xFFFFFFFF : 0x0, | 1019 return new Int32x4(_cx == true ? 0xFFFFFFFF : 0x0, |
1020 _cy == true ? 0xFFFFFFFF : 0x0, | 1020 _cy == true ? 0xFFFFFFFF : 0x0, |
1021 _cz == true ? 0xFFFFFFFF : 0x0, | 1021 _cz == true ? 0xFFFFFFFF : 0x0, |
1022 _cw == true ? 0xFFFFFFFF : 0x0); | 1022 _cw == true ? 0xFFFFFFFF : 0x0); |
1023 } | 1023 } |
1024 | 1024 |
1025 /// Relational not-equal. | 1025 /// Relational not-equal. |
1026 Uint32x4 notEqual(Float32x4 other) { | 1026 Int32x4 notEqual(Float32x4 other) { |
1027 bool _cx = _storage[0] != other._storage[0]; | 1027 bool _cx = _storage[0] != other._storage[0]; |
1028 bool _cy = _storage[1] != other._storage[1]; | 1028 bool _cy = _storage[1] != other._storage[1]; |
1029 bool _cz = _storage[2] != other._storage[2]; | 1029 bool _cz = _storage[2] != other._storage[2]; |
1030 bool _cw = _storage[3] != other._storage[3]; | 1030 bool _cw = _storage[3] != other._storage[3]; |
1031 return new Uint32x4(_cx == true ? 0xFFFFFFFF : 0x0, | 1031 return new Int32x4(_cx == true ? 0xFFFFFFFF : 0x0, |
1032 _cy == true ? 0xFFFFFFFF : 0x0, | 1032 _cy == true ? 0xFFFFFFFF : 0x0, |
1033 _cz == true ? 0xFFFFFFFF : 0x0, | 1033 _cz == true ? 0xFFFFFFFF : 0x0, |
1034 _cw == true ? 0xFFFFFFFF : 0x0); | 1034 _cw == true ? 0xFFFFFFFF : 0x0); |
1035 } | 1035 } |
1036 | 1036 |
1037 /// Returns a copy of [this] each lane being scaled by [s]. | 1037 /// Returns a copy of [this] each lane being scaled by [s]. |
1038 Float32x4 scale(double s) { | 1038 Float32x4 scale(double s) { |
1039 double _x = s * _storage[0]; | 1039 double _x = s * _storage[0]; |
1040 double _y = s * _storage[1]; | 1040 double _y = s * _storage[1]; |
1041 double _z = s * _storage[2]; | 1041 double _z = s * _storage[2]; |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 Float32x4 reciprocalSqrt() { | 1465 Float32x4 reciprocalSqrt() { |
1466 double _x = Math.sqrt(1.0 / _storage[0]); | 1466 double _x = Math.sqrt(1.0 / _storage[0]); |
1467 double _y = Math.sqrt(1.0 / _storage[1]); | 1467 double _y = Math.sqrt(1.0 / _storage[1]); |
1468 double _z = Math.sqrt(1.0 / _storage[2]); | 1468 double _z = Math.sqrt(1.0 / _storage[2]); |
1469 double _w = Math.sqrt(1.0 / _storage[3]); | 1469 double _w = Math.sqrt(1.0 / _storage[3]); |
1470 return new Float32x4(_x, _y, _z, _w); | 1470 return new Float32x4(_x, _y, _z, _w); |
1471 } | 1471 } |
1472 } | 1472 } |
1473 | 1473 |
1474 | 1474 |
1475 class Uint32x4 { | 1475 class Int32x4 { |
1476 final _storage = new Uint32List(4); | 1476 final _storage = new Int32List(4); |
1477 | 1477 |
1478 Uint32x4(int x, int y, int z, int w) { | 1478 Int32x4(int x, int y, int z, int w) { |
1479 _storage[0] = x; | 1479 _storage[0] = x; |
1480 _storage[1] = y; | 1480 _storage[1] = y; |
1481 _storage[2] = z; | 1481 _storage[2] = z; |
1482 _storage[3] = w; | 1482 _storage[3] = w; |
1483 } | 1483 } |
1484 | 1484 |
1485 Uint32x4.bool(bool x, bool y, bool z, bool w) { | 1485 Int32x4.bool(bool x, bool y, bool z, bool w) { |
1486 _storage[0] = x == true ? 0xFFFFFFFF : 0x0; | 1486 _storage[0] = x == true ? 0xFFFFFFFF : 0x0; |
1487 _storage[1] = y == true ? 0xFFFFFFFF : 0x0; | 1487 _storage[1] = y == true ? 0xFFFFFFFF : 0x0; |
1488 _storage[2] = z == true ? 0xFFFFFFFF : 0x0; | 1488 _storage[2] = z == true ? 0xFFFFFFFF : 0x0; |
1489 _storage[3] = w == true ? 0xFFFFFFFF : 0x0; | 1489 _storage[3] = w == true ? 0xFFFFFFFF : 0x0; |
1490 } | 1490 } |
1491 | 1491 |
1492 /// Returns a bit-wise copy of [x] as a Uint32x4. | 1492 /// Returns a bit-wise copy of [x] as a Int32x4. |
1493 Uint32x4.fromFloat32x4Bits(Float32x4 x) { | 1493 Int32x4.fromFloat32x4Bits(Float32x4 x) { |
1494 var view = new Uint32List.view(x._storage.buffer); | 1494 var view = new Uint32List.view(x._storage.buffer); |
1495 _storage[0] = view[0]; | 1495 _storage[0] = view[0]; |
1496 _storage[1] = view[1]; | 1496 _storage[1] = view[1]; |
1497 _storage[2] = view[2]; | 1497 _storage[2] = view[2]; |
1498 _storage[3] = view[3]; | 1498 _storage[3] = view[3]; |
1499 } | 1499 } |
1500 | 1500 |
1501 /// The bit-wise or operator. | 1501 /// The bit-wise or operator. |
1502 Uint32x4 operator|(Uint32x4 other) { | 1502 Int32x4 operator|(Int32x4 other) { |
1503 int _x = _storage[0] | other._storage[0]; | 1503 int _x = _storage[0] | other._storage[0]; |
1504 int _y = _storage[1] | other._storage[1]; | 1504 int _y = _storage[1] | other._storage[1]; |
1505 int _z = _storage[2] | other._storage[2]; | 1505 int _z = _storage[2] | other._storage[2]; |
1506 int _w = _storage[3] | other._storage[3]; | 1506 int _w = _storage[3] | other._storage[3]; |
1507 return new Uint32x4(_x, _y, _z, _w); | 1507 return new Int32x4(_x, _y, _z, _w); |
1508 } | 1508 } |
1509 | 1509 |
1510 /// The bit-wise and operator. | 1510 /// The bit-wise and operator. |
1511 Uint32x4 operator&(Uint32x4 other) { | 1511 Int32x4 operator&(Int32x4 other) { |
1512 int _x = _storage[0] & other._storage[0]; | 1512 int _x = _storage[0] & other._storage[0]; |
1513 int _y = _storage[1] & other._storage[1]; | 1513 int _y = _storage[1] & other._storage[1]; |
1514 int _z = _storage[2] & other._storage[2]; | 1514 int _z = _storage[2] & other._storage[2]; |
1515 int _w = _storage[3] & other._storage[3]; | 1515 int _w = _storage[3] & other._storage[3]; |
1516 return new Uint32x4(_x, _y, _z, _w); | 1516 return new Int32x4(_x, _y, _z, _w); |
1517 } | 1517 } |
1518 | 1518 |
1519 /// The bit-wise xor operator. | 1519 /// The bit-wise xor operator. |
1520 Uint32x4 operator^(Uint32x4 other) { | 1520 Int32x4 operator^(Int32x4 other) { |
1521 int _x = _storage[0] ^ other._storage[0]; | 1521 int _x = _storage[0] ^ other._storage[0]; |
1522 int _y = _storage[1] ^ other._storage[1]; | 1522 int _y = _storage[1] ^ other._storage[1]; |
1523 int _z = _storage[2] ^ other._storage[2]; | 1523 int _z = _storage[2] ^ other._storage[2]; |
1524 int _w = _storage[3] ^ other._storage[3]; | 1524 int _w = _storage[3] ^ other._storage[3]; |
1525 return new Uint32x4(_x, _y, _z, _w); | 1525 return new Int32x4(_x, _y, _z, _w); |
1526 } | 1526 } |
1527 | 1527 |
1528 Uint32x4 operator+(Uint32x4 other) { | 1528 Int32x4 operator+(Int32x4 other) { |
1529 var r = new Uint32x4(0, 0, 0, 0); | 1529 var r = new Int32x4(0, 0, 0, 0); |
1530 r._storage[0] = (_storage[0] + other._storage[0]); | 1530 r._storage[0] = (_storage[0] + other._storage[0]); |
1531 r._storage[1] = (_storage[1] + other._storage[1]); | 1531 r._storage[1] = (_storage[1] + other._storage[1]); |
1532 r._storage[2] = (_storage[2] + other._storage[2]); | 1532 r._storage[2] = (_storage[2] + other._storage[2]); |
1533 r._storage[3] = (_storage[3] + other._storage[3]); | 1533 r._storage[3] = (_storage[3] + other._storage[3]); |
1534 return r; | 1534 return r; |
1535 } | 1535 } |
1536 | 1536 |
1537 Uint32x4 operator-(Uint32x4 other) { | 1537 Int32x4 operator-(Int32x4 other) { |
1538 var r = new Uint32x4(0, 0, 0, 0); | 1538 var r = new Int32x4(0, 0, 0, 0); |
1539 r._storage[0] = (_storage[0] - other._storage[0]); | 1539 r._storage[0] = (_storage[0] - other._storage[0]); |
1540 r._storage[1] = (_storage[1] - other._storage[1]); | 1540 r._storage[1] = (_storage[1] - other._storage[1]); |
1541 r._storage[2] = (_storage[2] - other._storage[2]); | 1541 r._storage[2] = (_storage[2] - other._storage[2]); |
1542 r._storage[3] = (_storage[3] - other._storage[3]); | 1542 r._storage[3] = (_storage[3] - other._storage[3]); |
1543 return r; | 1543 return r; |
1544 } | 1544 } |
1545 | 1545 |
1546 /// Extract 32-bit mask from x lane. | 1546 /// Extract 32-bit mask from x lane. |
1547 int get x => _storage[0]; | 1547 int get x => _storage[0]; |
1548 /// Extract 32-bit mask from y lane. | 1548 /// Extract 32-bit mask from y lane. |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 static const int WWZX = 0x2F; | 1813 static const int WWZX = 0x2F; |
1814 static const int WWZY = 0x6F; | 1814 static const int WWZY = 0x6F; |
1815 static const int WWZZ = 0xAF; | 1815 static const int WWZZ = 0xAF; |
1816 static const int WWZW = 0xEF; | 1816 static const int WWZW = 0xEF; |
1817 static const int WWWX = 0x3F; | 1817 static const int WWWX = 0x3F; |
1818 static const int WWWY = 0x7F; | 1818 static const int WWWY = 0x7F; |
1819 static const int WWWZ = 0xBF; | 1819 static const int WWWZ = 0xBF; |
1820 static const int WWWW = 0xFF; | 1820 static const int WWWW = 0xFF; |
1821 | 1821 |
1822 /// Shuffle the lane values. [mask] must be one of the 256 shuffle constants. | 1822 /// Shuffle the lane values. [mask] must be one of the 256 shuffle constants. |
1823 Uint32x4 shuffle(int mask) { | 1823 Int32x4 shuffle(int mask) { |
1824 if ((mask < 0) || (mask > 255)) { | 1824 if ((mask < 0) || (mask > 255)) { |
1825 throw new RangeError('mask $mask must be in the range [0..256)'); | 1825 throw new RangeError('mask $mask must be in the range [0..256)'); |
1826 } | 1826 } |
1827 int _x = _storage[mask & 0x3]; | 1827 int _x = _storage[mask & 0x3]; |
1828 int _y = _storage[(mask >> 2) & 0x3]; | 1828 int _y = _storage[(mask >> 2) & 0x3]; |
1829 int _z = _storage[(mask >> 4) & 0x3]; | 1829 int _z = _storage[(mask >> 4) & 0x3]; |
1830 int _w = _storage[(mask >> 6) & 0x3]; | 1830 int _w = _storage[(mask >> 6) & 0x3]; |
1831 return new Uint32x4(_x, _y, _z, _w); | 1831 return new Int32x4(_x, _y, _z, _w); |
1832 } | 1832 } |
1833 | 1833 |
1834 /// Shuffle the lane values in [this] and [other]. The returned | 1834 /// Shuffle the lane values in [this] and [other]. The returned |
1835 /// Uint32x4 will have XY lanes from [this] and ZW lanes from [other]. | 1835 /// Int32x4 will have XY lanes from [this] and ZW lanes from [other]. |
1836 /// Uses the same [mask] as [shuffle]. | 1836 /// Uses the same [mask] as [shuffle]. |
1837 Uint32x4 shuffleMix(Uint32x4 other, int mask) { | 1837 Int32x4 shuffleMix(Int32x4 other, int mask) { |
1838 if ((mask < 0) || (mask > 255)) { | 1838 if ((mask < 0) || (mask > 255)) { |
1839 throw new RangeError('mask $mask must be in the range [0..256)'); | 1839 throw new RangeError('mask $mask must be in the range [0..256)'); |
1840 } | 1840 } |
1841 int _x = _storage[mask & 0x3]; | 1841 int _x = _storage[mask & 0x3]; |
1842 int _y = _storage[(mask >> 2) & 0x3]; | 1842 int _y = _storage[(mask >> 2) & 0x3]; |
1843 int _z = other._storage[(mask >> 4) & 0x3]; | 1843 int _z = other._storage[(mask >> 4) & 0x3]; |
1844 int _w = other._storage[(mask >> 6) & 0x3]; | 1844 int _w = other._storage[(mask >> 6) & 0x3]; |
1845 return new Uint32x4(_x, _y, _z, _w); | 1845 return new Int32x4(_x, _y, _z, _w); |
1846 } | 1846 } |
1847 | 1847 |
1848 /// Returns a new [Uint32x4] copied from [this] with a new x value. | 1848 /// Returns a new [Int32x4] copied from [this] with a new x value. |
1849 Uint32x4 withX(int x) { | 1849 Int32x4 withX(int x) { |
1850 int _x = x; | 1850 int _x = x; |
1851 int _y = _storage[1]; | 1851 int _y = _storage[1]; |
1852 int _z = _storage[2]; | 1852 int _z = _storage[2]; |
1853 int _w = _storage[3]; | 1853 int _w = _storage[3]; |
1854 return new Uint32x4(_x, _y, _z, _w); | 1854 return new Int32x4(_x, _y, _z, _w); |
1855 } | 1855 } |
1856 | 1856 |
1857 /// Returns a new [Uint32x4] copied from [this] with a new y value. | 1857 /// Returns a new [Int32x4] copied from [this] with a new y value. |
1858 Uint32x4 withY(int y) { | 1858 Int32x4 withY(int y) { |
1859 int _x = _storage[0]; | 1859 int _x = _storage[0]; |
1860 int _y = y; | 1860 int _y = y; |
1861 int _z = _storage[2]; | 1861 int _z = _storage[2]; |
1862 int _w = _storage[3]; | 1862 int _w = _storage[3]; |
1863 return new Uint32x4(_x, _y, _z, _w); | 1863 return new Int32x4(_x, _y, _z, _w); |
1864 } | 1864 } |
1865 | 1865 |
1866 /// Returns a new [Uint32x4] copied from [this] with a new z value. | 1866 /// Returns a new [Int32x4] copied from [this] with a new z value. |
1867 Uint32x4 withZ(int z) { | 1867 Int32x4 withZ(int z) { |
1868 int _x = _storage[0]; | 1868 int _x = _storage[0]; |
1869 int _y = _storage[1]; | 1869 int _y = _storage[1]; |
1870 int _z = z; | 1870 int _z = z; |
1871 int _w = _storage[3]; | 1871 int _w = _storage[3]; |
1872 return new Uint32x4(_x, _y, _z, _w); | 1872 return new Int32x4(_x, _y, _z, _w); |
1873 } | 1873 } |
1874 | 1874 |
1875 /// Returns a new [Uint32x4] copied from [this] with a new w value. | 1875 /// Returns a new [Int32x4] copied from [this] with a new w value. |
1876 Uint32x4 withW(int w) { | 1876 Int32x4 withW(int w) { |
1877 int _x = _storage[0]; | 1877 int _x = _storage[0]; |
1878 int _y = _storage[1]; | 1878 int _y = _storage[1]; |
1879 int _z = _storage[2]; | 1879 int _z = _storage[2]; |
1880 int _w = w; | 1880 int _w = w; |
1881 return new Uint32x4(_x, _y, _z, _w); | 1881 return new Int32x4(_x, _y, _z, _w); |
1882 } | 1882 } |
1883 | 1883 |
1884 /// Extracted x value. Returns false for 0, true for any other value. | 1884 /// Extracted x value. Returns false for 0, true for any other value. |
1885 bool get flagX => _storage[0] != 0x0; | 1885 bool get flagX => _storage[0] != 0x0; |
1886 /// Extracted y value. Returns false for 0, true for any other value. | 1886 /// Extracted y value. Returns false for 0, true for any other value. |
1887 bool get flagY => _storage[1] != 0x0; | 1887 bool get flagY => _storage[1] != 0x0; |
1888 /// Extracted z value. Returns false for 0, true for any other value. | 1888 /// Extracted z value. Returns false for 0, true for any other value. |
1889 bool get flagZ => _storage[2] != 0x0; | 1889 bool get flagZ => _storage[2] != 0x0; |
1890 /// Extracted w value. Returns false for 0, true for any other value. | 1890 /// Extracted w value. Returns false for 0, true for any other value. |
1891 bool get flagW => _storage[3] != 0x0; | 1891 bool get flagW => _storage[3] != 0x0; |
1892 | 1892 |
1893 /// Returns a new [Uint32x4] copied from [this] with a new x value. | 1893 /// Returns a new [Int32x4] copied from [this] with a new x value. |
1894 Uint32x4 withFlagX(bool x) { | 1894 Int32x4 withFlagX(bool x) { |
1895 int _x = x == true ? 0xFFFFFFFF : 0x0; | 1895 int _x = x == true ? 0xFFFFFFFF : 0x0; |
1896 int _y = _storage[1]; | 1896 int _y = _storage[1]; |
1897 int _z = _storage[2]; | 1897 int _z = _storage[2]; |
1898 int _w = _storage[3]; | 1898 int _w = _storage[3]; |
1899 return new Uint32x4(_x, _y, _z, _w); | 1899 return new Int32x4(_x, _y, _z, _w); |
1900 } | 1900 } |
1901 | 1901 |
1902 /// Returns a new [Uint32x4] copied from [this] with a new y value. | 1902 /// Returns a new [Int32x4] copied from [this] with a new y value. |
1903 Uint32x4 withFlagY(bool y) { | 1903 Int32x4 withFlagY(bool y) { |
1904 int _x = _storage[0]; | 1904 int _x = _storage[0]; |
1905 int _y = y == true ? 0xFFFFFFFF : 0x0; | 1905 int _y = y == true ? 0xFFFFFFFF : 0x0; |
1906 int _z = _storage[2]; | 1906 int _z = _storage[2]; |
1907 int _w = _storage[3]; | 1907 int _w = _storage[3]; |
1908 return new Uint32x4(_x, _y, _z, _w); | 1908 return new Int32x4(_x, _y, _z, _w); |
1909 } | 1909 } |
1910 | 1910 |
1911 /// Returns a new [Uint32x4] copied from [this] with a new z value. | 1911 /// Returns a new [Int32x4] copied from [this] with a new z value. |
1912 Uint32x4 withFlagZ(bool z) { | 1912 Int32x4 withFlagZ(bool z) { |
1913 int _x = _storage[0]; | 1913 int _x = _storage[0]; |
1914 int _y = _storage[1]; | 1914 int _y = _storage[1]; |
1915 int _z = z == true ? 0xFFFFFFFF : 0x0; | 1915 int _z = z == true ? 0xFFFFFFFF : 0x0; |
1916 int _w = _storage[3]; | 1916 int _w = _storage[3]; |
1917 return new Uint32x4(_x, _y, _z, _w); | 1917 return new Int32x4(_x, _y, _z, _w); |
1918 } | 1918 } |
1919 | 1919 |
1920 /// Returns a new [Uint32x4] copied from [this] with a new w value. | 1920 /// Returns a new [Int32x4] copied from [this] with a new w value. |
1921 Uint32x4 withFlagW(bool w) { | 1921 Int32x4 withFlagW(bool w) { |
1922 int _x = _storage[0]; | 1922 int _x = _storage[0]; |
1923 int _y = _storage[1]; | 1923 int _y = _storage[1]; |
1924 int _z = _storage[2]; | 1924 int _z = _storage[2]; |
1925 int _w = w == true ? 0xFFFFFFFF : 0x0; | 1925 int _w = w == true ? 0xFFFFFFFF : 0x0; |
1926 return new Uint32x4(_x, _y, _z, _w); | 1926 return new Int32x4(_x, _y, _z, _w); |
1927 } | 1927 } |
1928 | 1928 |
1929 /// Merge [trueValue] and [falseValue] based on [this]' bit mask: | 1929 /// Merge [trueValue] and [falseValue] based on [this]' bit mask: |
1930 /// Select bit from [trueValue] when bit in [this] is on. | 1930 /// Select bit from [trueValue] when bit in [this] is on. |
1931 /// Select bit from [falseValue] when bit in [this] is off. | 1931 /// Select bit from [falseValue] when bit in [this] is off. |
1932 Float32x4 select(Float32x4 trueValue, Float32x4 falseValue) { | 1932 Float32x4 select(Float32x4 trueValue, Float32x4 falseValue) { |
1933 var trueView = new Uint32List.view(trueValue._storage.buffer); | 1933 var trueView = new Int32List.view(trueValue._storage.buffer); |
1934 var falseView = new Uint32List.view(falseValue._storage.buffer); | 1934 var falseView = new Int32List.view(falseValue._storage.buffer); |
1935 int cmx = _storage[0]; | 1935 int cmx = _storage[0]; |
1936 int cmy = _storage[1]; | 1936 int cmy = _storage[1]; |
1937 int cmz = _storage[2]; | 1937 int cmz = _storage[2]; |
1938 int cmw = _storage[3]; | 1938 int cmw = _storage[3]; |
1939 int stx = trueView[0]; | 1939 int stx = trueView[0]; |
1940 int sty = trueView[1]; | 1940 int sty = trueView[1]; |
1941 int stz = trueView[2]; | 1941 int stz = trueView[2]; |
1942 int stw = trueView[3]; | 1942 int stw = trueView[3]; |
1943 int sfx = falseView[0]; | 1943 int sfx = falseView[0]; |
1944 int sfy = falseView[1]; | 1944 int sfy = falseView[1]; |
1945 int sfz = falseView[2]; | 1945 int sfz = falseView[2]; |
1946 int sfw = falseView[3]; | 1946 int sfw = falseView[3]; |
1947 int _x = (cmx & stx) | (~cmx & sfx); | 1947 int _x = (cmx & stx) | (~cmx & sfx); |
1948 int _y = (cmy & sty) | (~cmy & sfy); | 1948 int _y = (cmy & sty) | (~cmy & sfy); |
1949 int _z = (cmz & stz) | (~cmz & sfz); | 1949 int _z = (cmz & stz) | (~cmz & sfz); |
1950 int _w = (cmw & stw) | (~cmw & sfw); | 1950 int _w = (cmw & stw) | (~cmw & sfw); |
1951 var r = new Float32x4(0.0, 0.0, 0.0, 0.0); | 1951 var r = new Float32x4(0.0, 0.0, 0.0, 0.0); |
1952 var rView = new Uint32List.view(r._storage.buffer); | 1952 var rView = new Int32List.view(r._storage.buffer); |
1953 rView[0] = _x; | 1953 rView[0] = _x; |
1954 rView[1] = _y; | 1954 rView[1] = _y; |
1955 rView[2] = _z; | 1955 rView[2] = _z; |
1956 rView[3] = _w; | 1956 rView[3] = _w; |
1957 return r; | 1957 return r; |
1958 } | 1958 } |
1959 } | 1959 } |
OLD | NEW |