Search in sources :

Example 1 with TypedArrayObject

use of com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject in project es6draft by anba.

the class SIMD method SIMDStoreInTypedArray.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDStoreInTypedArray( tarray, index, descriptor, n [, length] )
     * 
     * @param cx
     *            the execution context
     * @param tarray
     *            the typed array
     * @param index
     *            the write index
     * @param descriptor
     *            the SIMD type descriptor
     * @param n
     *            the SIMD value
     * @param length
     *            the write length
     * @return the input SIMD value
     */
public static SIMDValue SIMDStoreInTypedArray(ExecutionContext cx, Object tarray, Object index, SIMDType descriptor, SIMDValue n, int length) {
    // FIXME: spec bug - incorrect variable name in spec
    if (n.getType() != descriptor) {
        throw newTypeError(cx, Messages.Key.SIMDInvalidType);
    }
    // FIXME: spec bug - type check at wrong position
    if (!(tarray instanceof TypedArrayObject)) {
        throw newTypeError(cx, Messages.Key.IncompatibleObject);
    }
    TypedArrayObject typedArray = (TypedArrayObject) tarray;
    /* step 2 */
    assert 0 < length && length <= descriptor.getVectorLength();
    // FIXME: spec bug - missing ToNumber call
    // FIXME: ToNumber(index) comparing against ToLength(ToNumber(index)) does not match any ES2015 pattern.
    double numIndex = ToNumber(cx, index);
    /* step 3 */
    if (IsDetachedBuffer(typedArray.getBuffer())) {
        throw newTypeError(cx, Messages.Key.BufferDetached);
    }
    /* step 5 */
    // FIXME: spec issue - allow shared array buffers?
    ByteBuffer block = typedArray.getBuffer().getData();
    /* step 6 */
    if (numIndex != ToLength(numIndex)) {
        throw newTypeError(cx, Messages.Key.InvalidByteOffset);
    }
    /* step 7 */
    // FIXME: spec issue - should use typedArray.[[TypedArrayName]] and retrieve element size from table 49.
    // FIXME: spec issue - rename elementLength to elementSize to match ES2015.
    // long elementLength = typedArray.getByteLength() / typedArray.getArrayLength();
    long elementLength = typedArray.getElementType().size();
    /* step 8 */
    double byteIndex = numIndex * elementLength;
    /* step 9 */
    if (byteIndex < 0 || byteIndex + descriptor.getElementSize() * length > typedArray.getByteLength()) {
        throw newRangeError(cx, Messages.Key.InvalidByteOffset);
    }
    /* step 10 */
    // FIXME: spec bug - wrong variable name `simd` -> `n`
    SIMDStore(block, descriptor, (long) byteIndex, n, length);
    /* step 11 */
    return n;
}
Also used : TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) ByteBuffer(java.nio.ByteBuffer)

Example 2 with TypedArrayObject

use of com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject in project es6draft by anba.

the class AtomicsObject method ValidateSharedIntegerTypedArray.

/**
     * Runtime semantics: ValidateSharedIntegerTypedArray( typedArray [, onlyInt32] )
     * 
     * @param cx
     *            the execution context
     * @param typedArray
     *            the typed array object
     * @param onlyInt32
     *            if {@code true} only Int32 typed arrays are accepted
     * @return the typed array object
     */
public static TypedArrayObject ValidateSharedIntegerTypedArray(ExecutionContext cx, Object typedArray, boolean onlyInt32) {
    /* step 1, step 5 */
    if (!(typedArray instanceof TypedArrayObject)) {
        throw newTypeError(cx, Messages.Key.IncompatibleObject);
    }
    /* step 2 */
    TypedArrayObject array = (TypedArrayObject) typedArray;
    /* steps 3-4 */
    if (onlyInt32) {
        if (array.getElementType() != ElementType.Int32) {
            throw newTypeError(cx, Messages.Key.AtomicsInt32ArrayType);
        }
    } else {
        switch(array.getElementType()) {
            case Int8:
            case Uint8:
            case Int16:
            case Uint16:
            case Int32:
            case Uint32:
                break;
            default:
                throw newTypeError(cx, Messages.Key.AtomicsInvalidArrayType);
        }
    }
    /* step 6 */
    ArrayBuffer buffer = array.getBuffer();
    /* step 8 */
    if (!(buffer instanceof SharedArrayBufferObject)) {
        throw newTypeError(cx, Messages.Key.AtomicsNotSharedBuffer);
    }
    /* step 9 */
    return array;
}
Also used : TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) ArrayBuffer(com.github.anba.es6draft.runtime.objects.binary.ArrayBuffer)

Example 3 with TypedArrayObject

use of com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject in project es6draft by anba.

the class SIMD method SIMDLoadFromTypedArray.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDLoadFromTypedArray( tarray, index, descriptor [, length] )
     * 
     * @param cx
     *            the execution context
     * @param tarray
     *            the typed array
     * @param index
     *            the read index
     * @param descriptor
     *            the SIMD type descriptor
     * @param length
     *            the read length
     * @return the new SIMD value
     */
public static SIMDValue SIMDLoadFromTypedArray(ExecutionContext cx, Object tarray, Object index, SIMDType descriptor, int length) {
    // FIXME: spec bug - missing type check Type(tarray) = Object
    if (!(tarray instanceof TypedArrayObject)) {
        throw newTypeError(cx, Messages.Key.IncompatibleObject);
    }
    TypedArrayObject typedArray = (TypedArrayObject) tarray;
    /* step 2 */
    assert 0 < length && length <= descriptor.getVectorLength();
    // FIXME: spec bug - missing ToNumber call
    // FIXME: ToNumber(index) comparing against ToLength(ToNumber(index)) does not match any ES2015 pattern.
    // FIXME: spec issue - range checking does not match Mozilla SIMD.
    double numIndex = ToNumber(cx, index);
    /* step 3 */
    if (IsDetachedBuffer(typedArray.getBuffer())) {
        throw newTypeError(cx, Messages.Key.BufferDetached);
    }
    /* step 4 */
    // FIXME: spec issue - allow shared array buffers?
    ByteBuffer block = typedArray.getBuffer().getData();
    /* step 5 */
    if (numIndex != ToLength(numIndex)) {
        throw newTypeError(cx, Messages.Key.InvalidByteOffset);
    }
    /* step 6 */
    // FIXME: spec issue - should use typedArray.[[TypedArrayName]] and retrieve element size from table 49.
    // FIXME: spec issue - rename elementLength to elementSize to match ES2015.
    // long elementLength = typedArray.getByteLength() / typedArray.getArrayLength();
    long elementLength = typedArray.getElementType().size();
    /* step 7 */
    double byteIndex = numIndex * elementLength;
    /* step 8 */
    if (byteIndex < 0 || byteIndex + descriptor.getElementSize() * length > typedArray.getByteLength()) {
        throw newRangeError(cx, Messages.Key.InvalidByteOffset);
    }
    /* step 9 */
    return SIMDLoad(block, descriptor, (long) byteIndex, length);
}
Also used : TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayBuffer (com.github.anba.es6draft.runtime.objects.binary.ArrayBuffer)1