Search in sources :

Example 11 with SIMDType

use of com.github.anba.es6draft.runtime.objects.simd.SIMDType in project es6draft by anba.

the class SIMD method SIMDBinaryOpFloat.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDBinaryOp( a, b, op, outputDescriptor )
     * 
     * @param a
     *            the first operand
     * @param b
     *            the second operand
     * @param op
     *            the binary operator
     * @return the new SIMD value
     */
public static SIMDValue SIMDBinaryOpFloat(SIMDValue a, SIMDValue b, DoubleBinaryOperator op) {
    /* step 1 */
    assert a.getType() == b.getType();
    assert a.getType() == SIMDType.Float32x4;
    /* step 2 */
    SIMDType descriptor = a.getType();
    /* step 3 */
    SIMDType outputDescriptor = a.getType();
    /* step 4 */
    double[] list = new double[descriptor.getVectorLength()];
    /* step 5 */
    for (int i = 0, len = descriptor.getVectorLength(); i < len; ++i) {
        /* step 5.a */
        double ax = MaybeFlushDenormalFloat(SIMDExtractLaneFloat(a, i));
        /* step 5.b */
        double bx = MaybeFlushDenormalFloat(SIMDExtractLaneFloat(b, i));
        /* steps 5.c-d */
        double res = op.applyAsDouble(ax, bx);
        /* step 5.e */
        res = MaybeFlushDenormalFloat(res);
        /* step 5.f */
        list[i] = res;
    }
    /* step 6 */
    return SIMDCreate(outputDescriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Example 12 with SIMDType

use of com.github.anba.es6draft.runtime.objects.simd.SIMDType in project es6draft by anba.

the class SIMD method SIMDUnaryOpDouble.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDUnaryOp( a, op [ , flushDenormal ] )
     * 
     * @param a
     *            the operand value
     * @param op
     *            the unary operator
     * @param flushDenormal
     *            if {@code true} denormals are flushed to zero
     * @return the new SIMD value
     */
public static SIMDValue SIMDUnaryOpDouble(SIMDValue a, DoubleUnaryOperator op, boolean flushDenormal) {
    /* step 1 */
    SIMDType descriptor = a.getType();
    assert descriptor == SIMDType.Float64x2;
    /* step 2 (not applicable) */
    /* step 3 */
    double[] list = new double[descriptor.getVectorLength()];
    /* step 5 */
    for (int i = 0, len = descriptor.getVectorLength(); i < len; ++i) {
        /* step 5.a */
        double ax = SIMDExtractLaneFloat(a, i);
        /* step 5.b */
        if (flushDenormal) {
            ax = MaybeFlushDenormalDouble(ax);
        }
        /* steps 5.c-d */
        double res = op.applyAsDouble(ax);
        /* step 5.e */
        if (flushDenormal) {
            res = MaybeFlushDenormalDouble(res);
        }
        /* step 5.f */
        list[i] = res;
    }
    /* step 6 */
    return SIMDCreate(descriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Example 13 with SIMDType

use of com.github.anba.es6draft.runtime.objects.simd.SIMDType in project es6draft by anba.

the class SIMD method SIMDBinaryOpBool.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDBinaryOp( a, b, op, outputDescriptor )
     * 
     * @param a
     *            the first operand
     * @param b
     *            the second operand
     * @param op
     *            the binary operator
     * @return the new SIMD value
     */
public static SIMDValue SIMDBinaryOpBool(SIMDValue a, SIMDValue b, BooleanBinaryOperator op) {
    /* step 1 */
    assert a.getType() == b.getType();
    assert a.getType().isBoolean();
    /* step 2 */
    SIMDType descriptor = a.getType();
    /* step 3 */
    SIMDType outputDescriptor = a.getType();
    /* step 4 */
    boolean[] list = new boolean[descriptor.getVectorLength()];
    /* step 5 */
    for (int i = 0, len = descriptor.getVectorLength(); i < len; ++i) {
        /* step 5.a */
        boolean ax = SIMDExtractLaneBool(a, i);
        /* step 5.b */
        boolean bx = SIMDExtractLaneBool(b, i);
        /* steps 5.c-d */
        boolean res = op.applyAsBoolean(ax, bx);
        /* step 5.e (not applicable) */
        /* step 5.f */
        list[i] = res;
    }
    /* step 6 */
    return SIMDCreate(outputDescriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Example 14 with SIMDType

use of com.github.anba.es6draft.runtime.objects.simd.SIMDType in project es6draft by anba.

the class SIMD method SIMDBinaryOpInt.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDBinaryOp( a, b, op, outputDescriptor )
     * 
     * @param a
     *            the first operand
     * @param b
     *            the second operand
     * @param op
     *            the binary operator
     * @return the new SIMD value
     */
public static SIMDValue SIMDBinaryOpInt(SIMDValue a, SIMDValue b, IntBinaryOperator op) {
    /* step 1 */
    assert a.getType() == b.getType();
    assert a.getType().isInteger();
    /* step 2 */
    SIMDType descriptor = a.getType();
    /* step 3 */
    SIMDType outputDescriptor = a.getType();
    /* step 4 */
    int[] list = new int[descriptor.getVectorLength()];
    /* step 5 */
    for (int i = 0, len = descriptor.getVectorLength(); i < len; ++i) {
        /* step 5.a */
        int ax = SIMDExtractLaneInt(a, i);
        /* step 5.b */
        int bx = SIMDExtractLaneInt(b, i);
        /* steps 5.c-d */
        int res = op.applyAsInt(ax, bx);
        /* step 5.e (not applicable) */
        /* step 5.f */
        list[i] = res;
    }
    /* step 6 */
    return SIMDCreate(outputDescriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Example 15 with SIMDType

use of com.github.anba.es6draft.runtime.objects.simd.SIMDType in project es6draft by anba.

the class SIMD method SIMDUnaryOpFloat.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDUnaryOp( a, op [ , flushDenormal ] )
     * 
     * @param a
     *            the operand value
     * @param op
     *            the unary operator
     * @param flushDenormal
     *            if {@code true} denormals are flushed to zero
     * @return the new SIMD value
     */
public static SIMDValue SIMDUnaryOpFloat(SIMDValue a, DoubleUnaryOperator op, boolean flushDenormal) {
    /* step 1 */
    SIMDType descriptor = a.getType();
    assert descriptor == SIMDType.Float32x4;
    /* step 2 (not applicable) */
    /* step 3 */
    double[] list = new double[descriptor.getVectorLength()];
    /* step 5 */
    for (int i = 0, len = descriptor.getVectorLength(); i < len; ++i) {
        /* step 5.a */
        double ax = SIMDExtractLaneFloat(a, i);
        /* step 5.b */
        if (flushDenormal) {
            ax = MaybeFlushDenormalFloat(ax);
        }
        /* steps 5.c-d */
        double res = op.applyAsDouble(ax);
        /* step 5.e */
        if (flushDenormal) {
            res = MaybeFlushDenormalFloat(res);
        }
        /* step 5.f */
        list[i] = res;
    }
    /* step 6 */
    return SIMDCreate(descriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Aggregations

SIMDType (com.github.anba.es6draft.runtime.objects.simd.SIMDType)15