File: func_template_7.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 (26 lines) | stat: -rw-r--r-- 927 bytes parent folder | download | duplicates (2)
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
// Check that operator overloading kicks-in for template parameter arguments.
// If it doesn't, the test will crash, because type check will alarm binary operation on non-atomic types.

// RUN: %{ispc} %s --nostdlib --target=host -o %t.o

struct S {
    float<4> V;
};

inline uniform S operator+(const uniform S &A, const uniform S &B) {
    varying float S0, S1, Result;
    *((uniform S * uniform) & S0) = *((uniform S * uniform) & A);
    *((uniform S * uniform) & S1) = *((uniform S * uniform) & B);

    Result = S0 + S1;

    return *((uniform S * uniform) & Result);
}

template <typename T> inline T VectorAdd(const T &A, const T &B) { return A + B; }

export void Add(uniform float A[], uniform float B[], uniform float C[], uniform int i) {
    const uniform S Vb = *((uniform S * uniform) & B[i]);
    const uniform S Vc = *((uniform S * uniform) & C[i]);
    *((uniform S * uniform) & A[i]) = VectorAdd(Vb, Vc);
}