Chromium Code Reviews| Index: sdk/lib/scalarlist/simd128.dart |
| diff --git a/sdk/lib/scalarlist/simd128.dart b/sdk/lib/scalarlist/simd128.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4beda24d22ab33e85377fa4d4473d4d755a9bda9 |
| --- /dev/null |
| +++ b/sdk/lib/scalarlist/simd128.dart |
| @@ -0,0 +1,188 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of dart.scalarlist; |
| + |
| +/** |
| + * Interface of Dart Simd128Float32 and operations. |
| + * Simd128Float32 stores 4 32-bit floating point values in "lanes". |
|
sra1
2013/02/19 01:13:45
Why not call it Float32x4 ?
|
| + * The lanes are "x", "y", "z", and "w" respectively. |
| + */ |
| +abstract class Simd128Float32 { |
| + external factory Simd128Float32(double x, double y, double z, double w); |
| + external factory Simd128Float32.zero(); |
| + |
| + /// Addition operator. |
| + Simd128Float32 operator+(Simd128Float32 other); |
| + /// Negate operator. |
| + Simd128Float32 operator-(); |
| + /// Subtraction operator. |
| + Simd128Float32 operator-(Simd128Float32 other); |
| + /// Multiplication operator. |
| + Simd128Float32 operator*(Simd128Float32 other); |
| + /// Division operator. |
| + Simd128Float32 operator/(Simd128Float32 other); |
| + |
| + /// Relational less than operator. |
| + Simd128Mask operator<(Simd128Float32 other); |
| + /// Relational less than or equal operator. |
| + Simd128Mask operator<=(Simd128Float32 other); |
| + /// Relational greater than operator. |
| + Simd128Mask operator>(Simd128Float32 other); |
| + /// Relational greater than or equal operator. |
| + Simd128Mask operator>=(Simd128Float32 other); |
| + /// Relational equal operator. |
| + Simd128Mask operator==(Simd128Float32 other); |
| + |
| + /// Returns a copy of [this] each lane being scaled by [s]. |
| + Simd128Float32 scale(double s); |
| + /// Returns the absolute value of this [Simd128Float32]. |
| + Simd128Float32 abs(); |
| + /// Clamps [this] to be in the range [lowerLimit]-[upperLimit]. |
| + Simd128Float32 clamp(Simd128Float32 lowerLimit, Simd128Float32 upperLimit); |
| + |
| + /// Extracted x value. |
| + double get x; |
| + /// Extracted y value. |
| + double get y; |
| + /// Extracted z value. |
| + double get z; |
| + /// Extracted w value. |
| + double get w; |
| + |
| + /// Returns a new [Simd128Float32] with [this]' x value in all four lanes. |
| + Simd128Float32 get xxxx; |
| + /// Returns a new [Simd128Float32] with [this]' y value in all four lanes. |
| + Simd128Float32 get yyyy; |
| + /// Returns a new [Simd128Float32] with [this]' z value in all four lanes. |
| + Simd128Float32 get zzzz; |
| + /// Returns a new [Simd128Float32] with [this]' w value in all four lanes. |
| + Simd128Float32 get wwww; |
| + // TODO(johnmccutchan): Add all 256 possible combinations. |
| + |
| + /// Returns a new [Simd128Float32] copied from [this] with a new x value. |
| + Simd128Float32 setX(double x); |
| + /// Returns a new [Simd128Float32] copied from [this] with a new y value. |
| + Simd128Float32 setY(double y); |
| + /// Returns a new [Simd128Float32] copied from [this] with a new z value. |
| + Simd128Float32 setZ(double z); |
| + /// Returns a new [Simd128Float32] copied from [this] with a new w value. |
| + Simd128Float32 setW(double w); |
| + |
| + /// Returns the lane-wise minimum value in [this] or [other]. |
| + Simd128Float32 min(Simd128 other); |
| + |
| + /// Returns the lane-wise maximum value in [this] or [other]. |
| + Simd128Float32 max(Simd128 other); |
| + |
| + /// Returns the square root of [this]. |
| + Simd128Float32 sqrt(); |
| + |
| + /// Returns the reciprocal of [this]. |
| + Simd128Float32 reciprocal(); |
| + |
| + /// Returns the square root of the reciprocal of [this]. |
| + Simd128Float32 reciprocalSqrt(); |
| + |
| + /// Returns a copy of [this] as a [Simd128Mask]. |
| + Simd128Mask toSimd128Mask(); |
| +} |
| + |
| +/** |
| + * Interface of Dart Simd128Mask and operations. |
| + * Simd128Mask stores 4 32-bit bit-masks in "lanes". |
| + * The lanes are "x", "y", "z", and "w" respectively. |
| + */ |
| +abstract class Simd128Mask { |
| + external factory Simd128Mask(int x, int y, int z, int w); |
| + external factory Simd128Mask.bool(bool x, bool y, bool z, bool w); |
| + |
| + /// The bit-wise or operator. |
| + Simd128Mask operator|(Simd128Mask other); |
| + /// The bit-wise and operator. |
| + Simd128Mask operator&(Simd128Mask other); |
| + /// The bit-wise xor operator. |
| + Simd128Mask operator^(Simd128Mask other); |
| + |
| + /// Extract 32-bit mask from x lane. |
| + int get x; |
| + /// Extract 32-bit mask from y lane. |
| + int get y; |
| + /// Extract 32-bit mask from z lane. |
| + int get z; |
| + /// Extract 32-bit mask from w lane. |
| + int get w; |
| + |
| + /// Returns a new [Simd128Mask] copied from [this] with a new x value. |
| + Simd128Mask setX(int x); |
| + /// Returns a new [Simd128Mask] copied from [this] with a new y value. |
| + Simd128Mask setY(int y); |
| + /// Returns a new [Simd128Mask] copied from [this] with a new z value. |
| + Simd128Mask setZ(int z); |
| + /// Returns a new [Simd128Mask] copied from [this] with a new w value. |
| + Simd128Mask setW(int w); |
| + |
| + /// Extracted x value. Returns false for 0, true for any other value. |
| + bool get flagX; |
| + /// Extracted y value. Returns false for 0, true for any other value. |
| + bool get flagY; |
| + /// Extracted z value. Returns false for 0, true for any other value. |
| + bool get flagZ; |
| + /// Extracted w value. Returns false for 0, true for any other value. |
| + bool get flagW; |
| + |
| + /// Returns a new [Simd128Mask] copied from [this] with a new x value. |
| + Simd128Mask setFlagX(bool x); |
|
sra1
2013/02/19 01:13:45
Nothing is modified, so perhaps withFlagX would be
|
| + /// Returns a new [Simd128Mask] copied from [this] with a new y value. |
| + Simd128Mask setFlagY(bool y); |
| + /// Returns a new [Simd128Mask] copied from [this] with a new z value. |
| + Simd128Mask setFlagZ(bool z); |
| + /// Returns a new [Simd128Mask] copied from [this] with a new w value. |
| + Simd128Mask setFlagW(bool w); |
| + |
| + /// Merge [trueValue] and [falseValue] based on [this]' bit mask: |
| + /// Select bit from [trueValue] when bit in [this] is on. |
| + /// Select bit from [falseValue] when bit in [this] is off. |
| + Simd128Float32 select(Simd128Float32 trueValue, Simd128Float32 falseValue); |
| + |
| + /// Returns a copy of [this] as a [Simd128Float32]. |
|
sra1
2013/02/19 01:13:45
Converting from int to float32 or bitwise copy?
|
| + Simd128Float32 toSimd128Float32(); |
| +} |
| + |
| +/** |
| + * A fixed-length list of Simd128Float32 numbers that is viewable as a |
| + * [ByteArray]. For long lists, this |
| + * implementation will be considerably more space- and time-efficient than |
| + * the default [List] implementation. |
| + */ |
| +abstract class Simd128Float32List implements List<Simd128Float32>, |
| + ByteArrayViewable { |
| + /** |
| + * Creates a [Simd128Float32List] of the specified length (in elements), |
| + * all of whose elements are initially zero. |
| + */ |
| + external factory Simd128Float32List(int length); |
| + |
| + /** |
| + * Creates a [Simd128Float32List] _view_ of the specified region in the |
| + * specified byte [array]. Changes in the [Simd128Float32List] will be visible |
| + * in the byte array and vice versa. If the [start] index of the region is |
| + * not specified, |
| + * it defaults to zero (the first byte in the byte array). If the length is |
| + * not specified, it defaults to null, which indicates that the view extends |
| + * to the end of the byte array. |
| + * |
| + * Throws [ArgumentError] if the length of the specified region |
| + * is not divisible by 16 (the size of a "Simd128Float32" in bytes), or if the |
| + * [start] of the region is not divisible by 16. If, however, [array] |
| + * is a view of another byte array, this constructor will throw |
| + * [ArgumentError] if the implicit starting position in the |
| + * "ultimately backing" byte array is not divisible by 16. In plain terms, |
| + * this constructor throws [ArgumentError] if the specified |
| + * region does not contain an integral number of "Simd128Float32s," or if it |
| + * is not "Simd128Float32-aligned." |
| + */ |
| + external factory Simd128Float32List.view(ByteArray array, |
| + [int start = 0, int length]); |
| +} |