File: operators5.ispc

package info (click to toggle)
ispc 1.28.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 97,620 kB
  • sloc: cpp: 77,067; python: 8,303; yacc: 3,337; lex: 1,126; ansic: 631; sh: 475; makefile: 17
file content (60 lines) | stat: -rw-r--r-- 1,161 bytes parent folder | download
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
#include "test_static.isph"

struct S {
    int a;
};

// Prefix increment (++x)
struct S& operator++(struct S &rs) {
    rs.a = rs.a + 2;
    return rs;
}

// Prefix decrement (--x)
struct S& operator--(struct S &rs) {
    rs.a = rs.a - 4;
    return rs;
}

// Postfix increment (x++)
struct S operator++(struct S &rs, int) {
    struct S temp;
    temp.a = rs.a;
    rs.a = rs.a + 1;
    return temp;
}

// Postfix decrement (x--)
struct S operator--(struct S &rs, int) {
    struct S temp;
    temp.a = rs.a;
    rs.a = rs.a - 1;
    return temp;
}

task void f_f(uniform float RET[], uniform float aFOO[]) {
    struct S a;
    struct S c;

    a.a = aFOO[programIndex];
    c.a = aFOO[programIndex];

    // Not using overloaded operator
    RET[programIndex] = ++a.a;

    // Test prefix increment
    RET[programIndex] += (++a).a;

    // Test prefix decrement
    RET[programIndex] += (--a).a;

    // Test postfix increment
    c = a++;
    RET[programIndex] += a.a - c.a; // 1

    // Test postfix decrement
    c = a--;
    RET[programIndex] += c.a - a.a; // 1
}

task void result(uniform float RET[16]) { RET[programIndex] = programIndex * 3 + 8; }