Search in sources :

Example 6 with SIMDType

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

the class SIMD method SIMDReplaceLaneBool.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDReplaceLane( value, lane, replacement )
     * 
     * @param cx
     *            the execution context
     * @param value
     *            the SIMD value
     * @param lane
     *            the lane index
     * @param replacement
     *            the replacement value
     * @param cast
     *            the cast function
     * @return the new SIMD value
     */
public static SIMDValue SIMDReplaceLaneBool(ExecutionContext cx, SIMDValue value, Object lane, Object replacement, ToBooleanFunction<Object> cast) {
    /* step 1 (not applicable) */
    /* step 2 */
    SIMDType descriptor = value.getType();
    /* steps 3-4 */
    int index = SIMDToLane(cx, descriptor.getVectorLength(), lane);
    /* step 5 */
    boolean[] list = value.asBoolean().clone();
    /* step 6 (inlined SIMDCreate - [[Cast]]) */
    list[index] = cast.applyAsBoolean(replacement);
    /* step 7 */
    return SIMDCreate(descriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Example 7 with SIMDType

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

the class SIMD method SIMDReplaceLaneInt.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDReplaceLane( value, lane, replacement )
     * 
     * @param cx
     *            the execution context
     * @param value
     *            the SIMD value
     * @param lane
     *            the lane index
     * @param replacement
     *            the replacement value
     * @param cast
     *            the cast function
     * @return the new SIMD value
     */
public static SIMDValue SIMDReplaceLaneInt(ExecutionContext cx, SIMDValue value, Object lane, Object replacement, ToIntBiFunction<ExecutionContext, Object> cast) {
    /* step 1 (not applicable) */
    /* step 2 */
    SIMDType descriptor = value.getType();
    /* steps 3-4 */
    int index = SIMDToLane(cx, descriptor.getVectorLength(), lane);
    /* step 5 */
    int[] list = value.asInt().clone();
    /* step 6 (inlined SIMDCreate - [[Cast]]) */
    list[index] = cast.applyAsInt(cx, replacement);
    /* step 7 */
    return SIMDCreate(descriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Example 8 with SIMDType

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

the class SIMD method SIMDReplaceLaneFloat.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDReplaceLane( value, lane, replacement )
     * 
     * @param cx
     *            the execution context
     * @param value
     *            the SIMD value
     * @param lane
     *            the lane index
     * @param replacement
     *            the replacement value
     * @param cast
     *            the cast function
     * @return the new SIMD value
     */
public static SIMDValue SIMDReplaceLaneFloat(ExecutionContext cx, SIMDValue value, Object lane, Object replacement, ToDoubleBiFunction<ExecutionContext, Object> cast) {
    /* step 1 (not applicable) */
    /* step 2 */
    SIMDType descriptor = value.getType();
    /* steps 3-4 */
    int index = SIMDToLane(cx, descriptor.getVectorLength(), lane);
    /* step 5 */
    double[] list = value.asDouble().clone();
    /* step 6 (inlined SIMDCreate - [[Cast]]) */
    list[index] = cast.applyAsDouble(cx, replacement);
    /* step 7 */
    return SIMDCreate(descriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Example 9 with SIMDType

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

the class SIMD method SIMDUnaryOpBool.

/**
     * Internal algorithms on SIMD types
     * <p>
     * SIMDUnaryOp( a, op [ , flushDenormal ] )
     * 
     * @param a
     *            the operand value
     * @param op
     *            the unary operator
     * @return the new SIMD value
     */
public static SIMDValue SIMDUnaryOpBool(SIMDValue a, BooleanUnaryOperator op) {
    /* step 1 */
    SIMDType descriptor = a.getType();
    assert descriptor.isBoolean();
    /* step 2 (not applicable) */
    /* step 3 */
    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 (not applicable) */
        /* steps 5.c-d */
        boolean res = op.applyAsBoolean(ax);
        /* step 5.e (not applicable) */
        /* step 5.f */
        list[i] = res;
    }
    /* step 6 */
    return SIMDCreate(descriptor, list);
}
Also used : SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType)

Example 10 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
     * @param outputDescriptor
     *            the output type descriptor, always boolean SIMD type
     * @return the new SIMD value
     */
public static SIMDValue SIMDBinaryOpInt(SIMDValue a, SIMDValue b, IntBiPredicate op, SIMDType outputDescriptor) {
    /* step 1 */
    assert a.getType() == b.getType();
    assert a.getType().getVectorLength() == outputDescriptor.getVectorLength();
    assert a.getType().isInteger() && outputDescriptor.isBoolean();
    /* step 2 */
    SIMDType descriptor = a.getType();
    /* step 3 (not applicable) */
    /* step 4 */
    boolean[] list = new boolean[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 */
        boolean res = op.test(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)

Aggregations

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