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

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

Issue 148043003: Add Float64x2, Float64x2List, etc... with runtime and dart2js implementations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months 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
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 import "dart:_internal"; 7 import "dart:_internal";
8 import 'dart:math' show Random; 8 import 'dart:math' show Random;
9 9
10 patch class Int8List { 10 patch class Int8List {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 ..setRange(0, elements.length, elements); 223 ..setRange(0, elements.length, elements);
224 } 224 }
225 225
226 /* patch */ factory Int32x4List.view(ByteBuffer buffer, 226 /* patch */ factory Int32x4List.view(ByteBuffer buffer,
227 [int offsetInBytes = 0, int length]) { 227 [int offsetInBytes = 0, int length]) {
228 return new _Int32x4ArrayView(buffer, offsetInBytes, length); 228 return new _Int32x4ArrayView(buffer, offsetInBytes, length);
229 } 229 }
230 } 230 }
231 231
232 232
233 patch class Float64x2List {
234 /* patch */ factory Float64x2List(int length) {
235 return new _Float64x2Array(length);
236 }
237
238 /* patch */ factory Float64x2List.fromList(List<Float64x2> elements) {
239 return new _Float64x2Array(elements.length)
240 ..setRange(0, elements.length, elements);
241 }
242
243 /* patch */ factory Float64x2List.view(ByteBuffer buffer,
244 [int offsetInBytes = 0, int length]) {
245 return new _Float64x2ArrayView(buffer, offsetInBytes, length);
246 }
247 }
248
249
233 patch class Float32x4 { 250 patch class Float32x4 {
234 /* patch */ factory Float32x4(double x, double y, double z, double w) { 251 /* patch */ factory Float32x4(double x, double y, double z, double w) {
235 return new _Float32x4(x, y, z, w); 252 return new _Float32x4(x, y, z, w);
236 } 253 }
237 /* patch */ factory Float32x4.splat(double v) { 254 /* patch */ factory Float32x4.splat(double v) {
238 return new _Float32x4.splat(v); 255 return new _Float32x4.splat(v);
239 } 256 }
240 /* patch */ factory Float32x4.zero() { 257 /* patch */ factory Float32x4.zero() {
241 return new _Float32x4.zero(); 258 return new _Float32x4.zero();
242 } 259 }
243 /* patch */ factory Float32x4.fromInt32x4Bits(Int32x4 x) { 260 /* patch */ factory Float32x4.fromInt32x4Bits(Int32x4 x) {
244 return new _Float32x4.fromInt32x4Bits(x); 261 return new _Float32x4.fromInt32x4Bits(x);
245 } 262 }
263 /* patch */ factory Float32x4.fromFloat64x2(Float64x2 v) {
264 return new _Float32x4.fromFloat64x2(v);
265 }
246 } 266 }
247 267
248 268
249 patch class Int32x4 { 269 patch class Int32x4 {
250 /* patch */ factory Int32x4(int x, int y, int z, int w) { 270 /* patch */ factory Int32x4(int x, int y, int z, int w) {
251 return new _Int32x4(x, y, z, w); 271 return new _Int32x4(x, y, z, w);
252 } 272 }
253 /* patch */ factory Int32x4.bool(bool x, bool y, bool z, bool w) { 273 /* patch */ factory Int32x4.bool(bool x, bool y, bool z, bool w) {
254 return new _Int32x4.bool(x, y, z, w); 274 return new _Int32x4.bool(x, y, z, w);
255 } 275 }
256 /* patch */ factory Int32x4.fromFloat32x4Bits(Float32x4 x) { 276 /* patch */ factory Int32x4.fromFloat32x4Bits(Float32x4 x) {
257 return new _Int32x4.fromFloat32x4Bits(x); 277 return new _Int32x4.fromFloat32x4Bits(x);
258 } 278 }
259 } 279 }
260 280
261 281
282 patch class Float64x2 {
283 /* patch */ factory Float64x2(double x, double y) {
284 return new _Float64x2(x, y);
285 }
286
287 /* patch */ factory Float64x2.splat(double v) {
288 return new _Float64x2.splat(v);
289 }
290
291 /* patch */ factory Float64x2.zero() {
292 return new _Float64x2.zero();
293 }
294
295 /* patch */ factory Float64x2.fromFloat32x4(Float32x4 v) {
296 return new _Float64x2.fromFloat32x4(v);
297 }
298 }
299
300
262 patch class ByteData { 301 patch class ByteData {
263 /* patch */ factory ByteData(int length) { 302 /* patch */ factory ByteData(int length) {
264 var list = new _Uint8Array(length); 303 var list = new _Uint8Array(length);
265 return new _ByteDataView(list.buffer, 0, length); 304 return new _ByteDataView(list.buffer, 0, length);
266 } 305 }
267 306
268 /* patch */ factory ByteData.view(ByteBuffer buffer, 307 /* patch */ factory ByteData.view(ByteBuffer buffer,
269 [int offsetInBytes = 0, int length]) { 308 [int offsetInBytes = 0, int length]) {
270 if (length == null) { 309 if (length == null) {
271 length = buffer.lengthInBytes - offsetInBytes; 310 length = buffer.lengthInBytes - offsetInBytes;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 void _setFloat64(int offsetInBytes, double value) 662 void _setFloat64(int offsetInBytes, double value)
624 native "TypedData_SetFloat64"; 663 native "TypedData_SetFloat64";
625 664
626 Float32x4 _getFloat32x4(int offsetInBytes) native "TypedData_GetFloat32x4"; 665 Float32x4 _getFloat32x4(int offsetInBytes) native "TypedData_GetFloat32x4";
627 void _setFloat32x4(int offsetInBytes, Float32x4 value) 666 void _setFloat32x4(int offsetInBytes, Float32x4 value)
628 native "TypedData_SetFloat32x4"; 667 native "TypedData_SetFloat32x4";
629 668
630 Int32x4 _getInt32x4(int offsetInBytes) native "TypedData_GetInt32x4"; 669 Int32x4 _getInt32x4(int offsetInBytes) native "TypedData_GetInt32x4";
631 void _setInt32x4(int offsetInBytes, Int32x4 value) 670 void _setInt32x4(int offsetInBytes, Int32x4 value)
632 native "TypedData_SetInt32x4"; 671 native "TypedData_SetInt32x4";
672
673 Float64x2 _getFloat64x2(int offsetInBytes) native "TypedData_GetFloat64x2";
674 void _setFloat64x2(int offsetInBytes, Float64x2 value)
675 native "TypedData_SetFloat64x2";
633 } 676 }
634 677
635 678
636 class _Int8Array extends _TypedList implements Int8List { 679 class _Int8Array extends _TypedList implements Int8List {
637 // Factory constructors. 680 // Factory constructors.
638 681
639 factory _Int8Array(int length) { 682 factory _Int8Array(int length) {
640 return _new(length); 683 return _new(length);
641 } 684 }
642 685
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 } 1456 }
1414 1457
1415 void _setIndexedInt32x4(int index, Int32x4 value) { 1458 void _setIndexedInt32x4(int index, Int32x4 value) {
1416 _setInt32x4(index * Int32x4List.BYTES_PER_ELEMENT, value); 1459 _setInt32x4(index * Int32x4List.BYTES_PER_ELEMENT, value);
1417 } 1460 }
1418 1461
1419 static _Int32x4Array _new(int length) native "TypedData_Int32x4Array_new"; 1462 static _Int32x4Array _new(int length) native "TypedData_Int32x4Array_new";
1420 } 1463 }
1421 1464
1422 1465
1466 class _Float64x2Array extends _TypedList implements Float64x2List {
1467 // Factory constructors.
1468
1469 factory _Float64x2Array(int length) {
1470 return _new(length);
1471 }
1472
1473 factory _Float64x2Array.view(ByteBuffer buffer,
1474 [int offsetInBytes = 0, int length]) {
1475 if (length == null) {
1476 length = (buffer.lengthInBytes - offsetInBytes) ~/
1477 Float64x2List.BYTES_PER_ELEMENT;
1478 }
1479 return new _Float64x2ArrayView(buffer, offsetInBytes, length);
1480 }
1481
1482
1483 Float64x2 operator[](int index) {
1484 if (index < 0 || index >= length) {
1485 _throwRangeError(index, length);
1486 }
1487 return _getIndexedFloat64x2(index);
1488 }
1489
1490 void operator[]=(int index, Float64x2 value) {
1491 if (index < 0 || index >= length) {
1492 _throwRangeError(index, length);
1493 }
1494 _setIndexedFloat64x2(index, value);
1495 }
1496
1497 Iterator<Float64x2> get iterator {
1498 return new _TypedListIterator<Float64x2>(this);
1499 }
1500
1501
1502 // Method(s) implementing the TypedData interface.
1503
1504 int get elementSizeInBytes {
1505 return Float64x2List.BYTES_PER_ELEMENT;
1506 }
1507
1508
1509 // Internal utility methods.
1510
1511 _Float64x2Array _createList(int length) {
1512 return _new(length);
1513 }
1514
1515 Float64x2 _getIndexedFloat64x2(int index) {
1516 return _getFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT);
1517 }
1518
1519 void _setIndexedFloat64x2(int index, Float64x2 value) {
1520 _setFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT, value);
1521 }
1522
1523 static _Float64x2Array _new(int length) native "TypedData_Float64x2Array_new";
1524 }
1525
1526
1423 class _ExternalInt8Array extends _TypedList implements Int8List { 1527 class _ExternalInt8Array extends _TypedList implements Int8List {
1424 // Factory constructors. 1528 // Factory constructors.
1425 1529
1426 factory _ExternalInt8Array(int length) { 1530 factory _ExternalInt8Array(int length) {
1427 return _new(length); 1531 return _new(length);
1428 } 1532 }
1429 1533
1430 1534
1431 // Method(s) implementing the List interface. 1535 // Method(s) implementing the List interface.
1432 int operator[](int index) { 1536 int operator[](int index) {
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 2208
2105 void _setIndexedInt32x4(int index, Int32x4 value) { 2209 void _setIndexedInt32x4(int index, Int32x4 value) {
2106 _setInt32x4(index * Int32x4List.BYTES_PER_ELEMENT, value); 2210 _setInt32x4(index * Int32x4List.BYTES_PER_ELEMENT, value);
2107 } 2211 }
2108 2212
2109 static _ExternalInt32x4Array _new(int length) native 2213 static _ExternalInt32x4Array _new(int length) native
2110 "ExternalTypedData_Int32x4Array_new"; 2214 "ExternalTypedData_Int32x4Array_new";
2111 } 2215 }
2112 2216
2113 2217
2218 class _ExternalFloat64x2Array extends _TypedList implements Float64x2List {
2219 // Factory constructors.
2220
2221 factory _ExternalFloat64x2Array(int length) {
2222 return _new(length);
2223 }
2224
2225
2226 // Method(s) implementing the List interface.
2227
2228 Float64x2 operator[](int index) {
2229 if (index < 0 || index >= length) {
2230 _throwRangeError(index, length);
2231 }
2232 return _getIndexedFloat64x2(index);
2233 }
2234
2235 void operator[]=(int index, Float64x2 value) {
2236 if (index < 0 || index >= length) {
2237 _throwRangeError(index, length);
2238 }
2239 _setIndexedFloat64x2(index, value);
2240 }
2241
2242 Iterator<Float64x2> get iterator {
2243 return new _TypedListIterator<Float64x2>(this);
2244 }
2245
2246
2247 // Method(s) implementing the TypedData interface.
2248
2249 int get elementSizeInBytes {
2250 return Float64x2List.BYTES_PER_ELEMENT;
2251 }
2252
2253
2254 // Internal utility methods.
2255
2256 Float64x2List _createList(int length) {
2257 return new Float64x2List(length);
2258 }
2259
2260 Float64x2 _getIndexedFloat64x2(int index) {
2261 return _getFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT);
2262 }
2263
2264 void _setIndexedFloat64x2(int index, Float64x2 value) {
2265 _setFloat64x2(index * Float64x2List.BYTES_PER_ELEMENT, value);
2266 }
2267
2268 static _ExternalFloat64x2Array _new(int length) native
2269 "ExternalTypedData_Float64x2Array_new";
2270 }
2271
2272
2114 class _Float32x4 implements Float32x4 { 2273 class _Float32x4 implements Float32x4 {
2115 factory _Float32x4(double x, double y, double z, double w) 2274 factory _Float32x4(double x, double y, double z, double w)
2116 native "Float32x4_fromDoubles"; 2275 native "Float32x4_fromDoubles";
2117 factory _Float32x4.splat(double v) native "Float32x4_splat"; 2276 factory _Float32x4.splat(double v) native "Float32x4_splat";
2118 factory _Float32x4.zero() native "Float32x4_zero"; 2277 factory _Float32x4.zero() native "Float32x4_zero";
2119 factory _Float32x4.fromInt32x4Bits(Int32x4 x) 2278 factory _Float32x4.fromInt32x4Bits(Int32x4 x)
2120 native "Float32x4_fromInt32x4Bits"; 2279 native "Float32x4_fromInt32x4Bits";
2280 factory _Float32x4.fromFloat64x2(Float64x2 v)
2281 native "Float32x4_fromFloat64x2";
2121 Float32x4 operator +(Float32x4 other) { 2282 Float32x4 operator +(Float32x4 other) {
2122 return _add(other); 2283 return _add(other);
2123 } 2284 }
2124 Float32x4 _add(Float32x4 other) native "Float32x4_add"; 2285 Float32x4 _add(Float32x4 other) native "Float32x4_add";
2125 Float32x4 operator -() { 2286 Float32x4 operator -() {
2126 return _negate(); 2287 return _negate();
2127 } 2288 }
2128 Float32x4 _negate() native "Float32x4_negate"; 2289 Float32x4 _negate() native "Float32x4_negate";
2129 Float32x4 operator -(Float32x4 other) { 2290 Float32x4 operator -(Float32x4 other) {
2130 return _sub(other); 2291 return _sub(other);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 Int32x4 withFlagW(bool w) native "Int32x4_setFlagW"; 2424 Int32x4 withFlagW(bool w) native "Int32x4_setFlagW";
2264 Float32x4 select(Float32x4 trueValue, 2425 Float32x4 select(Float32x4 trueValue,
2265 Float32x4 falseValue) { 2426 Float32x4 falseValue) {
2266 return _select(trueValue, falseValue); 2427 return _select(trueValue, falseValue);
2267 } 2428 }
2268 Float32x4 _select(Float32x4 trueValue, 2429 Float32x4 _select(Float32x4 trueValue,
2269 Float32x4 falseValue) 2430 Float32x4 falseValue)
2270 native "Int32x4_select"; 2431 native "Int32x4_select";
2271 } 2432 }
2272 2433
2434
2435 class _Float64x2 implements Float64x2 {
2436 factory _Float64x2(double x, double y) native "Float64x2_fromDoubles";
2437 factory _Float64x2.splat(double v) native "Float64x2_splat";
2438 factory _Float64x2.zero() native "Float64x2_zero";
2439 factory _Float64x2.fromFloat32x4(Float32x4 v) native "Float64x2_fromFloat32x4" ;
2440
2441 Float64x2 operator +(Float64x2 other) {
2442 return _add(other);
2443 }
2444 Float64x2 _add(Float64x2 other) native "Float64x2_add";
2445 Float64x2 operator -() {
2446 return _negate();
2447 }
2448 Float64x2 _negate() native "Float64x2_negate";
2449 Float64x2 operator -(Float64x2 other) {
2450 return _sub(other);
2451 }
2452 Float64x2 _sub(Float64x2 other) native "Float64x2_sub";
2453 Float64x2 operator *(Float64x2 other) {
2454 return _mul(other);
2455 }
2456 Float64x2 _mul(Float64x2 other) native "Float64x2_mul";
2457 Float64x2 operator /(Float64x2 other) {
2458 return _div(other);
2459 }
2460 Float64x2 _div(Float64x2 other) native "Float64x2_div";
2461
2462
2463 /// Returns a copy of [this] each lane being scaled by [s].
2464 Float64x2 scale(double s) native "Float64x2_scale";
2465 /// Returns the absolute value of this [Float64x2].
2466 Float64x2 abs() native "Float64x2_abs";
2467
2468 /// Clamps [this] to be in the range [lowerLimit]-[upperLimit].
2469 Float64x2 clamp(Float64x2 lowerLimit,
2470 Float64x2 upperLimit) native "Float64x2_clamp";
2471
2472 /// Extracted x value.
2473 double get x native "Float64x2_getX";
2474 /// Extracted y value.
2475 double get y native "Float64x2_getY";
2476
2477 /// Extract the sign bits from each lane return them in the first 2 bits.
2478 int get signMask native "Float64x2_getSignMask";
2479
2480 /// Returns a new [Float64x2] copied from [this] with a new x value.
2481 Float64x2 withX(double x) native "Float64x2_setX";
2482 /// Returns a new [Float64x2] copied from [this] with a new y value.
2483 Float64x2 withY(double y) native "Float64x2_setY";
2484
2485 /// Returns the lane-wise minimum value in [this] or [other].
2486 Float64x2 min(Float64x2 other) native "Float64x2_min";
2487
2488 /// Returns the lane-wise maximum value in [this] or [other].
2489 Float64x2 max(Float64x2 other) native "Float64x2_max";
2490
2491 /// Returns the lane-wise square root of [this].
2492 Float64x2 sqrt() native "Float64x2_sqrt";
2493 }
2494
2495
2496
2273 class _TypedListIterator<E> implements Iterator<E> { 2497 class _TypedListIterator<E> implements Iterator<E> {
2274 final List<E> _array; 2498 final List<E> _array;
2275 final int _length; 2499 final int _length;
2276 int _position; 2500 int _position;
2277 E _current; 2501 E _current;
2278 2502
2279 _TypedListIterator(List array) 2503 _TypedListIterator(List array)
2280 : _array = array, _length = array.length, _position = -1 { 2504 : _array = array, _length = array.length, _position = -1 {
2281 assert(array is _TypedList || array is _TypedListView); 2505 assert(array is _TypedList || array is _TypedListView);
2282 } 2506 }
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
2989 3213
2990 3214
2991 // Internal utility methods. 3215 // Internal utility methods.
2992 3216
2993 Int32x4List _createList(int length) { 3217 Int32x4List _createList(int length) {
2994 return new Int32x4List(length); 3218 return new Int32x4List(length);
2995 } 3219 }
2996 } 3220 }
2997 3221
2998 3222
3223 class _Float64x2ArrayView extends _TypedListView implements Float64x2List {
3224 // Constructor.
3225 _Float64x2ArrayView(ByteBuffer buffer, [int _offsetInBytes = 0, int _length])
3226 : super(buffer, _offsetInBytes,
3227 _defaultIfNull(_length,
3228 ((buffer.lengthInBytes - _offsetInBytes) ~/
3229 Float64x2List.BYTES_PER_ELEMENT))) {
3230 _rangeCheck(buffer.lengthInBytes,
3231 offsetInBytes,
3232 length * Float64x2List.BYTES_PER_ELEMENT);
3233 _offsetAlignmentCheck(_offsetInBytes, Float64x2List.BYTES_PER_ELEMENT);
3234 }
3235
3236
3237 // Method(s) implementing List interface.
3238
3239 Float64x2 operator[](int index) {
3240 if (index < 0 || index >= length) {
3241 _throwRangeError(index, length);
3242 }
3243 return _typedData._getFloat64x2(offsetInBytes +
3244 (index * Float64x2List.BYTES_PER_ELEMENT));
3245 }
3246
3247 void operator[]=(int index, Float64x2 value) {
3248 if (index < 0 || index >= length) {
3249 _throwRangeError(index, length);
3250 }
3251 _typedData._setFloat64x2(offsetInBytes +
3252 (index * Float64x2List.BYTES_PER_ELEMENT), value);
3253 }
3254
3255 Iterator<Float64x2> get iterator {
3256 return new _TypedListIterator<Float64x2>(this);
3257 }
3258
3259
3260 // Method(s) implementing TypedData interface.
3261
3262 int get elementSizeInBytes {
3263 return Float64x2List.BYTES_PER_ELEMENT;
3264 }
3265
3266
3267 // Internal utility methods.
3268
3269 Float64x2List _createList(int length) {
3270 return new Float64x2List(length);
3271 }
3272 }
3273
3274
2999 class _ByteDataView implements ByteData { 3275 class _ByteDataView implements ByteData {
3000 _ByteDataView(ByteBuffer _buffer, int _offsetInBytes, int _lengthInBytes) 3276 _ByteDataView(ByteBuffer _buffer, int _offsetInBytes, int _lengthInBytes)
3001 : _typedData = _buffer, // _buffer is guaranteed to be a TypedData here. 3277 : _typedData = _buffer, // _buffer is guaranteed to be a TypedData here.
3002 _offset = _offsetInBytes, 3278 _offset = _offsetInBytes,
3003 length = _lengthInBytes { 3279 length = _lengthInBytes {
3004 _rangeCheck(_buffer.lengthInBytes, _offset, length); 3280 _rangeCheck(_buffer.lengthInBytes, _offset, length);
3005 } 3281 }
3006 3282
3007 3283
3008 // Method(s) implementing TypedData interface. 3284 // Method(s) implementing TypedData interface.
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
3364 return value; 3640 return value;
3365 } 3641 }
3366 return object; 3642 return object;
3367 } 3643 }
3368 3644
3369 3645
3370 void _throwRangeError(int index, int length) { 3646 void _throwRangeError(int index, int length) {
3371 String message = "$index must be in the range [0..$length)"; 3647 String message = "$index must be in the range [0..$length)";
3372 throw new RangeError(message); 3648 throw new RangeError(message);
3373 } 3649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698