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

Side by Side Diff: runtime/lib/typed_data.dart

Issue 51333005: Add Uint32x4List to typed_data (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « runtime/lib/typed_data.cc ('k') | runtime/vm/bootstrap_natives.h » ('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 (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 // patch classes for Int8List ..... Float64List and ByteData implementations. 5 // patch classes for Int8List ..... Float64List and ByteData implementations.
6 6
7 patch class Int8List { 7 patch class Int8List {
8 /* patch */ factory Int8List(int length) { 8 /* patch */ factory Int8List(int length) {
9 return new _Int8Array(length); 9 return new _Int8Array(length);
10 } 10 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 return result; 237 return result;
238 } 238 }
239 239
240 /* patch */ factory Float32x4List.view(ByteBuffer buffer, 240 /* patch */ factory Float32x4List.view(ByteBuffer buffer,
241 [int offsetInBytes = 0, int length]) { 241 [int offsetInBytes = 0, int length]) {
242 return new _Float32x4ArrayView(buffer, offsetInBytes, length); 242 return new _Float32x4ArrayView(buffer, offsetInBytes, length);
243 } 243 }
244 } 244 }
245 245
246 246
247 patch class Uint32x4List {
248 /* patch */ factory Uint32x4List(int length) {
249 return new _Uint32x4Array(length);
250 }
251
252 /* patch */ factory Uint32x4List.fromList(List<Uint32x4> elements) {
253 var result = new _Uint32x4Array(elements.length);
254 for (int i = 0; i < elements.length; i++) {
255 result[i] = elements[i];
256 }
257 return result;
258 }
259
260 /* patch */ factory Uint32x4List.view(ByteBuffer buffer,
261 [int offsetInBytes = 0, int length]) {
262 return new _Uint32x4ArrayView(buffer, offsetInBytes, length);
263 }
264 }
265
266
247 patch class Float32x4 { 267 patch class Float32x4 {
248 /* patch */ factory Float32x4(double x, double y, double z, double w) { 268 /* patch */ factory Float32x4(double x, double y, double z, double w) {
249 return new _Float32x4(x, y, z, w); 269 return new _Float32x4(x, y, z, w);
250 } 270 }
251 /* patch */ factory Float32x4.splat(double v) { 271 /* patch */ factory Float32x4.splat(double v) {
252 return new _Float32x4.splat(v); 272 return new _Float32x4.splat(v);
253 } 273 }
254 /* patch */ factory Float32x4.zero() { 274 /* patch */ factory Float32x4.zero() {
255 return new _Float32x4.zero(); 275 return new _Float32x4.zero();
256 } 276 }
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 void _setFloat32(int offsetInBytes, double value) 603 void _setFloat32(int offsetInBytes, double value)
584 native "TypedData_SetFloat32"; 604 native "TypedData_SetFloat32";
585 605
586 double _getFloat64(int offsetInBytes) native "TypedData_GetFloat64"; 606 double _getFloat64(int offsetInBytes) native "TypedData_GetFloat64";
587 void _setFloat64(int offsetInBytes, double value) 607 void _setFloat64(int offsetInBytes, double value)
588 native "TypedData_SetFloat64"; 608 native "TypedData_SetFloat64";
589 609
590 Float32x4 _getFloat32x4(int offsetInBytes) native "TypedData_GetFloat32x4"; 610 Float32x4 _getFloat32x4(int offsetInBytes) native "TypedData_GetFloat32x4";
591 void _setFloat32x4(int offsetInBytes, Float32x4 value) 611 void _setFloat32x4(int offsetInBytes, Float32x4 value)
592 native "TypedData_SetFloat32x4"; 612 native "TypedData_SetFloat32x4";
613
614 Uint32x4 _getUint32x4(int offsetInBytes) native "TypedData_GetUint32x4";
615 void _setUint32x4(int offsetInBytes, Uint32x4 value)
616 native "TypedData_SetUint32x4";
593 } 617 }
594 618
595 619
596 class _Int8Array extends _TypedList implements Int8List { 620 class _Int8Array extends _TypedList implements Int8List {
597 // Factory constructors. 621 // Factory constructors.
598 622
599 factory _Int8Array(int length) { 623 factory _Int8Array(int length) {
600 return _new(length); 624 return _new(length);
601 } 625 }
602 626
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 return _getFloat64(index * Float64List.BYTES_PER_ELEMENT); 1273 return _getFloat64(index * Float64List.BYTES_PER_ELEMENT);
1250 } 1274 }
1251 1275
1252 void _setIndexedFloat64(int index, double value) { 1276 void _setIndexedFloat64(int index, double value) {
1253 _setFloat64(index * Float64List.BYTES_PER_ELEMENT, value); 1277 _setFloat64(index * Float64List.BYTES_PER_ELEMENT, value);
1254 } 1278 }
1255 1279
1256 static _Float64Array _new(int length) native "TypedData_Float64Array_new"; 1280 static _Float64Array _new(int length) native "TypedData_Float64Array_new";
1257 } 1281 }
1258 1282
1283
1259 class _Float32x4Array extends _TypedList implements Float32x4List { 1284 class _Float32x4Array extends _TypedList implements Float32x4List {
1260 // Factory constructors. 1285 // Factory constructors.
1261 1286
1262 factory _Float32x4Array(int length) { 1287 factory _Float32x4Array(int length) {
1263 return _new(length); 1288 return _new(length);
1264 } 1289 }
1265 1290
1266 factory _Float32x4Array.view(ByteBuffer buffer, 1291 factory _Float32x4Array.view(ByteBuffer buffer,
1267 [int offsetInBytes = 0, int length]) { 1292 [int offsetInBytes = 0, int length]) {
1268 if (length == null) { 1293 if (length == null) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 } 1335 }
1311 1336
1312 void _setIndexedFloat32x4(int index, Float32x4 value) { 1337 void _setIndexedFloat32x4(int index, Float32x4 value) {
1313 _setFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT, value); 1338 _setFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT, value);
1314 } 1339 }
1315 1340
1316 static _Float32x4Array _new(int length) native "TypedData_Float32x4Array_new"; 1341 static _Float32x4Array _new(int length) native "TypedData_Float32x4Array_new";
1317 } 1342 }
1318 1343
1319 1344
1345 class _Uint32x4Array extends _TypedList implements Uint32x4List {
1346 // Factory constructors.
1347
1348 factory _Uint32x4Array(int length) {
1349 return _new(length);
1350 }
1351
1352 factory _Uint32x4Array.view(ByteBuffer buffer,
1353 [int offsetInBytes = 0, int length]) {
1354 if (length == null) {
1355 length = (buffer.lengthInBytes - offsetInBytes) ~/
1356 Uint32x4List.BYTES_PER_ELEMENT;
1357 }
1358 return new _Uint32x4ArrayView(buffer, offsetInBytes, length);
1359 }
1360
1361
1362 Uint32x4 operator[](int index) {
1363 if (index < 0 || index >= length) {
1364 _throwRangeError(index, length);
1365 }
1366 return _getIndexedUint32x4(index);
1367 }
1368
1369 void operator[]=(int index, Uint32x4 value) {
1370 if (index < 0 || index >= length) {
1371 _throwRangeError(index, length);
1372 }
1373 _setIndexedUint32x4(index, value);
1374 }
1375
1376 Iterator<Uint32x4> get iterator {
1377 return new _TypedListIterator<Uint32x4>(this);
1378 }
1379
1380
1381 // Method(s) implementing the TypedData interface.
1382
1383 int get elementSizeInBytes {
1384 return Uint32x4List.BYTES_PER_ELEMENT;
1385 }
1386
1387
1388 // Internal utility methods.
1389
1390 _Uint32x4Array _createList(int length) {
1391 return _new(length);
1392 }
1393
1394 Uint32x4 _getIndexedUint32x4(int index) {
1395 return _getUint32x4(index * Uint32x4List.BYTES_PER_ELEMENT);
1396 }
1397
1398 void _setIndexedUint32x4(int index, Uint32x4 value) {
1399 _setUint32x4(index * Uint32x4List.BYTES_PER_ELEMENT, value);
1400 }
1401
1402 static _Uint32x4Array _new(int length) native "TypedData_Uint32x4Array_new";
1403 }
1404
1405
1320 class _ExternalInt8Array extends _TypedList implements Int8List { 1406 class _ExternalInt8Array extends _TypedList implements Int8List {
1321 // Factory constructors. 1407 // Factory constructors.
1322 1408
1323 factory _ExternalInt8Array(int length) { 1409 factory _ExternalInt8Array(int length) {
1324 return _new(length); 1410 return _new(length);
1325 } 1411 }
1326 1412
1327 1413
1328 // Method(s) implementing the List interface. 1414 // Method(s) implementing the List interface.
1329 int operator[](int index) { 1415 int operator[](int index) {
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 2031
1946 void _setIndexedFloat32x4(int index, Float32x4 value) { 2032 void _setIndexedFloat32x4(int index, Float32x4 value) {
1947 _setFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT, value); 2033 _setFloat32x4(index * Float32x4List.BYTES_PER_ELEMENT, value);
1948 } 2034 }
1949 2035
1950 static _ExternalFloat32x4Array _new(int length) native 2036 static _ExternalFloat32x4Array _new(int length) native
1951 "ExternalTypedData_Float32x4Array_new"; 2037 "ExternalTypedData_Float32x4Array_new";
1952 } 2038 }
1953 2039
1954 2040
2041 class _ExternalUint32x4Array extends _TypedList implements Uint32x4List {
2042 // Factory constructors.
2043
2044 factory _ExternalUint32x4Array(int length) {
2045 return _new(length);
2046 }
2047
2048
2049 // Method(s) implementing the List interface.
2050
2051 Uint32x4 operator[](int index) {
2052 if (index < 0 || index >= length) {
2053 _throwRangeError(index, length);
2054 }
2055 return _getIndexedUint32x4(index);
2056 }
2057
2058 void operator[]=(int index, Uint32x4 value) {
2059 if (index < 0 || index >= length) {
2060 _throwRangeError(index, length);
2061 }
2062 _setIndexedUint32x4(index, value);
2063 }
2064
2065 Iterator<Uint32x4> get iterator {
2066 return new _TypedListIterator<Uint32x4>(this);
2067 }
2068
2069
2070 // Method(s) implementing the TypedData interface.
2071
2072 int get elementSizeInBytes {
2073 return Uint32x4List.BYTES_PER_ELEMENT;
2074 }
2075
2076
2077 // Internal utility methods.
2078
2079 Uint32x4List _createList(int length) {
2080 return new Uint32x4List(length);
2081 }
2082
2083 Uint32x4 _getIndexedUint32x4(int index) {
2084 return _getUint32x4(index * Uint32x4List.BYTES_PER_ELEMENT);
2085 }
2086
2087 void _setIndexedUint32x4(int index, Uint32x4 value) {
2088 _setUint32x4(index * Uint32x4List.BYTES_PER_ELEMENT, value);
2089 }
2090
2091 static _ExternalUint32x4Array _new(int length) native
2092 "ExternalTypedData_Uint32x4Array_new";
2093 }
2094
2095
1955 class _Float32x4 implements Float32x4 { 2096 class _Float32x4 implements Float32x4 {
1956 factory _Float32x4(double x, double y, double z, double w) 2097 factory _Float32x4(double x, double y, double z, double w)
1957 native "Float32x4_fromDoubles"; 2098 native "Float32x4_fromDoubles";
1958 factory _Float32x4.splat(double v) native "Float32x4_splat"; 2099 factory _Float32x4.splat(double v) native "Float32x4_splat";
1959 factory _Float32x4.zero() native "Float32x4_zero"; 2100 factory _Float32x4.zero() native "Float32x4_zero";
1960 factory _Float32x4.fromUint32x4Bits(Uint32x4 x) 2101 factory _Float32x4.fromUint32x4Bits(Uint32x4 x)
1961 native "Float32x4_fromUint32x4Bits"; 2102 native "Float32x4_fromUint32x4Bits";
1962 Float32x4 operator +(Float32x4 other) { 2103 Float32x4 operator +(Float32x4 other) {
1963 return _add(other); 2104 return _add(other);
1964 } 2105 }
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 2923
2783 2924
2784 // Internal utility methods. 2925 // Internal utility methods.
2785 2926
2786 Float32x4List _createList(int length) { 2927 Float32x4List _createList(int length) {
2787 return new Float32x4List(length); 2928 return new Float32x4List(length);
2788 } 2929 }
2789 } 2930 }
2790 2931
2791 2932
2933 class _Uint32x4ArrayView extends _TypedListView implements Uint32x4List {
2934 // Constructor.
2935 _Uint32x4ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
2936 : super(buffer, _offsetInBytes,
2937 _defaultIfNull(_length,
2938 ((buffer.lengthInBytes - _offsetInBytes) ~/
2939 Uint32x4List.BYTES_PER_ELEMENT))) {
2940 _rangeCheck(buffer.lengthInBytes,
2941 offsetInBytes,
2942 length * Uint32x4List.BYTES_PER_ELEMENT);
2943 _offsetAlignmentCheck(_offsetInBytes, Uint32x4List.BYTES_PER_ELEMENT);
2944 }
2945
2946
2947 // Method(s) implementing List interface.
2948
2949 Uint32x4 operator[](int index) {
2950 if (index < 0 || index >= length) {
2951 _throwRangeError(index, length);
2952 }
2953 return _typedData._getUint32x4(offsetInBytes +
2954 (index * Uint32x4List.BYTES_PER_ELEMENT));
2955 }
2956
2957 void operator[]=(int index, Uint32x4 value) {
2958 if (index < 0 || index >= length) {
2959 _throwRangeError(index, length);
2960 }
2961 _typedData._setUint32x4(offsetInBytes +
2962 (index * Uint32x4List.BYTES_PER_ELEMENT), value);
2963 }
2964
2965 Iterator<Uint32x4> get iterator {
2966 return new _TypedListIterator<Uint32x4>(this);
2967 }
2968
2969
2970 // Method(s) implementing TypedData interface.
2971
2972 int get elementSizeInBytes {
2973 return Uint32x4List.BYTES_PER_ELEMENT;
2974 }
2975
2976
2977 // Internal utility methods.
2978
2979 Uint32x4List _createList(int length) {
2980 return new Uint32x4List(length);
2981 }
2982 }
2983
2984
2792 class _ByteDataView implements ByteData { 2985 class _ByteDataView implements ByteData {
2793 _ByteDataView(ByteBuffer _buffer, int _offsetInBytes, int _lengthInBytes) 2986 _ByteDataView(ByteBuffer _buffer, int _offsetInBytes, int _lengthInBytes)
2794 : _typedData = _buffer, // _buffer is guaranteed to be a TypedData here. 2987 : _typedData = _buffer, // _buffer is guaranteed to be a TypedData here.
2795 _offset = _offsetInBytes, 2988 _offset = _offsetInBytes,
2796 length = _lengthInBytes { 2989 length = _lengthInBytes {
2797 _rangeCheck(_buffer.lengthInBytes, _offset, length); 2990 _rangeCheck(_buffer.lengthInBytes, _offset, length);
2798 } 2991 }
2799 2992
2800 2993
2801 // Method(s) implementing TypedData interface. 2994 // Method(s) implementing TypedData interface.
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 return value; 3346 return value;
3154 } 3347 }
3155 return object; 3348 return object;
3156 } 3349 }
3157 3350
3158 3351
3159 void _throwRangeError(int index, int length) { 3352 void _throwRangeError(int index, int length) {
3160 String message = "$index must be in the range [0..$length)"; 3353 String message = "$index must be in the range [0..$length)";
3161 throw new RangeError(message); 3354 throw new RangeError(message);
3162 } 3355 }
OLDNEW
« no previous file with comments | « runtime/lib/typed_data.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698