File: func_template_array_3.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 (35 lines) | stat: -rw-r--r-- 1,054 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
// The test checks that enum type can be used for array indexing
// RUN: %{ispc} %s --ast-dump --target=host --nostdlib | FileCheck %s
// RUN: %{ispc} %s --target=host --nostdlib -o %t.o

// CHECK: FunctionTemplate {{.*}} [ /*unbound*/ T(varying int32 * uniform a)] "func"
// CHECK Variable arr (/*unbound*/ T[C])
// CHECK: (instantiation <varying int32, 64, 0, 3>) {{.*}}  [ varying int32(varying int32 * uniform a)] "func"
// CHECK: ReturnStmt
// CHECK: IndexExpr
// CHECK: SymbolExpr {{.*}} [varying int32[64]] symbol name: arr
// CHECK: ConstExpr {{.*}} [const uniform unsigned int64] (0)
// CHECK: IndexExpr
// CHECK: SymbolExpr {{.*}} [varying int32[64]] symbol name: arr
// CHECK: ConstExpr {{.*}} [const uniform unsigned int64] (3)

enum Foo {
    ZERO,
    ONE,
    TWO,
    THREE
};

template<typename T, uint C, Foo N1, Foo N2>
noinline T func(int a[]) {
    T arr[C];
    for (uniform uint i = 0; i < C; i++) {
        arr[i] = a[i] + i;
    }
    return arr[N1] + arr[N2];
}

int test(int a[]) {
    return func<int, 64, ZERO, THREE>(a);
}