summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/SIMD/select.js
blob: 3f0d783dac0dd14df7f6dbae5721bb96368b284f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
load(libdir + 'simd.js');

setJitCompilerOption("ion.warmup.trigger", 50);

function select(type, mask, ifTrue, ifFalse) {
    var arr = [];
    for (var i = 0; i < 4; i++) {
        var selector = SIMD.Bool32x4.extractLane(mask, i);
        arr.push(type.extractLane(selector ? ifTrue : ifFalse, i));
    }
    return arr;
}

function f() {
    var f1 = SIMD.Float32x4(1, 2, 3, 4);
    var f2 = SIMD.Float32x4(NaN, Infinity, 3.14, -0);

    var i1 = SIMD.Int32x4(2, 3, 5, 8);
    var i2 = SIMD.Int32x4(13, 37, 24, 42);

    var TTFT = SIMD.Bool32x4(true, true, false, true);
    var TFTF = SIMD.Bool32x4(true, false, true, false);

    var mask = SIMD.Int32x4(0xdeadbeef, 0xbaadf00d, 0x00ff1ce, 0xdeadc0de);

    for (var i = 0; i < 150; i++) {
        assertEqX4(SIMD.Float32x4.select(TTFT, f1, f2), select(SIMD.Float32x4, TTFT, f1, f2));
        assertEqX4(SIMD.Float32x4.select(TFTF, f1, f2), select(SIMD.Float32x4, TFTF, f1, f2));

        assertEqX4(SIMD.Int32x4.select(TFTF, i1, i2), select(SIMD.Int32x4, TFTF, i1, i2));
        assertEqX4(SIMD.Int32x4.select(TTFT, i1, i2), select(SIMD.Int32x4, TTFT, i1, i2));
    }
}

f();