summaryrefslogtreecommitdiff
path: root/tests/java_api/RSTest_CompatLibLegacy/src/com/android/rs/test/fp_mad.rscript
blob: 3e8889ed72144f9ec542e26621e59af2c91fa1e9 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "shared.rsh"

const int TEST_COUNT = 1;

static float data_f1[1025];
static float4 data_f4[1025];

static void test_mad4(uint32_t index) {
    start();

    // Do ~1 billion ops
    for (int ct=0; ct < 1000 * (1000 / 80); ct++) {
        for (int i=0; i < (1000); i++) {
            data_f4[i] = (data_f4[i] * 0.02f +
                          data_f4[i+1] * 0.04f +
                          data_f4[i+2] * 0.05f +
                          data_f4[i+3] * 0.1f +
                          data_f4[i+4] * 0.2f +
                          data_f4[i+5] * 0.2f +
                          data_f4[i+6] * 0.1f +
                          data_f4[i+7] * 0.05f +
                          data_f4[i+8] * 0.04f +
                          data_f4[i+9] * 0.02f + 1.f);
        }
    }

    float time = end(index);
    rsDebug("fp_mad4 M ops", 1000.f / time);
}

static void test_mad(uint32_t index) {
    start();

    // Do ~1 billion ops
    for (int ct=0; ct < 1000 * (1000 / 20); ct++) {
        for (int i=0; i < (1000); i++) {
            data_f1[i] = (data_f1[i] * 0.02f +
                          data_f1[i+1] * 0.04f +
                          data_f1[i+2] * 0.05f +
                          data_f1[i+3] * 0.1f +
                          data_f1[i+4] * 0.2f +
                          data_f1[i+5] * 0.2f +
                          data_f1[i+6] * 0.1f +
                          data_f1[i+7] * 0.05f +
                          data_f1[i+8] * 0.04f +
                          data_f1[i+9] * 0.02f + 1.f);
        }
    }

    float time = end(index);
    rsDebug("fp_mad M ops", 1000.f / time);
}

static void test_norm(uint32_t index) {
    start();

    // Do ~10 M ops
    for (int ct=0; ct < 1000 * 10; ct++) {
        for (int i=0; i < (1000); i++) {
            data_f4[i] = normalize(data_f4[i]);
        }
    }

    float time = end(index);
    rsDebug("fp_norm M ops", 10.f / time);
}

static void test_sincos4(uint32_t index) {
    start();

    // Do ~10 M ops
    for (int ct=0; ct < 1000 * 10 / 4; ct++) {
        for (int i=0; i < (1000); i++) {
            data_f4[i] = sin(data_f4[i]) * cos(data_f4[i]);
        }
    }

    float time = end(index);
    rsDebug("fp_sincos4 M ops", 10.f / time);
}

static void test_sincos(uint32_t index) {
    start();

    // Do ~10 M ops
    for (int ct=0; ct < 1000 * 10; ct++) {
        for (int i=0; i < (1000); i++) {
            data_f1[i] = sin(data_f1[i]) * cos(data_f1[i]);
        }
    }

    float time = end(index);
    rsDebug("fp_sincos M ops", 10.f / time);
}

static void test_clamp(uint32_t index) {
    start();

    // Do ~100 M ops
    for (int ct=0; ct < 1000 * 100; ct++) {
        for (int i=0; i < (1000); i++) {
            data_f1[i] = clamp(data_f1[i], -1.f, 1.f);
        }
    }

    float time = end(index);
    rsDebug("fp_clamp M ops", 100.f / time);

    start();
    // Do ~100 M ops
    for (int ct=0; ct < 1000 * 100; ct++) {
        for (int i=0; i < (1000); i++) {
            if (data_f1[i] < -1.f) data_f1[i] = -1.f;
            if (data_f1[i] > -1.f) data_f1[i] = 1.f;
        }
    }

    time = end(index);
    rsDebug("fp_clamp ref M ops", 100.f / time);
}

static void test_clamp4(uint32_t index) {
    start();

    // Do ~100 M ops
    for (int ct=0; ct < 1000 * 100 /4; ct++) {
        for (int i=0; i < (1000); i++) {
            data_f4[i] = clamp(data_f4[i], -1.f, 1.f);
        }
    }

    float time = end(index);
    rsDebug("fp_clamp4 M ops", 100.f / time);
}

void fp_mad_test(uint32_t index, int test_num) {
    int x;
    for (x=0; x < 1025; x++) {
        data_f1[x] = (x & 0xf) * 0.1f;
        data_f4[x].x = (x & 0xf) * 0.1f;
        data_f4[x].y = (x & 0xf0) * 0.1f;
        data_f4[x].z = (x & 0x33) * 0.1f;
        data_f4[x].w = (x & 0x77) * 0.1f;
    }

    test_mad4(index);
    test_mad(index);

    for (x=0; x < 1025; x++) {
        data_f1[x] = (x & 0xf) * 0.1f + 1.f;
        data_f4[x].x = (x & 0xf) * 0.1f + 1.f;
        data_f4[x].y = (x & 0xf0) * 0.1f + 1.f;
        data_f4[x].z = (x & 0x33) * 0.1f + 1.f;
        data_f4[x].w = (x & 0x77) * 0.1f + 1.f;
    }

    test_norm(index);
    test_sincos4(index);
    test_sincos(index);
    test_clamp4(index);
    test_clamp(index);

    // TODO Actually verify test result accuracy
    rsDebug("fp_mad_test PASSED", 0);
    rsSendToClientBlocking(RS_MSG_TEST_PASSED);
}