pragma-loop.cpp
2.59 KB
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
// RUN: %clang_cc1 -emit-pch -o %t.a %s
// RUN: %clang_cc1 -include-pch %t.a %s -ast-print -o - | FileCheck %s
// CHECK: #pragma clang loop vectorize_width(4)
// CHECK: #pragma clang loop interleave_count(8)
// CHECK: #pragma clang loop unroll_count(16){{$}}
// CHECK: #pragma clang loop vectorize(enable)
// CHECK: #pragma clang loop interleave(disable)
// CHECK: #pragma clang loop unroll(disable)
// CHECK: #pragma clang loop distribute(enable)
// CHECK: #pragma clang loop vectorize(disable)
// CHECK: #pragma clang loop interleave(enable)
// CHECK: #pragma clang loop unroll(full)
// CHECK: #pragma clang loop distribute(disable)
// FIXME: "#pragma unroll (enable)" is invalid and is not the input source.
// CHECK: #pragma unroll (enable){{$}}
// CHECK: #pragma unroll (32){{$}}
// CHECK: #pragma nounroll{{$}}
// CHECK: #pragma clang loop vectorize_width(V)
// CHECK: #pragma clang loop interleave_count(I)
#ifndef HEADER
#define HEADER
class pragma_test {
public:
inline void run1(int *List, int Length) {
int i = 0;
#pragma clang loop vectorize_width(4)
#pragma clang loop interleave_count(8)
#pragma clang loop unroll_count(16)
while (i < Length) {
List[i] = i;
i++;
}
}
inline void run2(int *List, int Length) {
int i = 0;
#pragma clang loop vectorize(enable)
#pragma clang loop interleave(disable)
#pragma clang loop unroll(disable)
#pragma clang loop distribute(enable)
while (i - 1 < Length) {
List[i] = i;
i++;
}
}
inline void run3(int *List, int Length) {
int i = 0;
#pragma clang loop vectorize(disable)
#pragma clang loop interleave(enable)
#pragma clang loop unroll(full)
#pragma clang loop distribute(disable)
while (i - 3 < Length) {
List[i] = i;
i++;
}
}
inline void run4(int *List, int Length) {
int i = 0;
#pragma unroll
while (i - 3 < Length) {
List[i] = i;
i++;
}
}
inline void run5(int *List, int Length) {
int i = 0;
#pragma unroll 32
while (i - 3 < Length) {
List[i] = i;
i++;
}
}
inline void run6(int *List, int Length) {
int i = 0;
#pragma nounroll
while (i - 3 < Length) {
List[i] = i;
i++;
}
}
template <int V, int I>
inline void run7(int *List, int Length) {
#pragma clang loop vectorize_width(V)
#pragma clang loop interleave_count(I)
for (int i = 0; i < Length; i++) {
List[i] = i;
}
}
};
#else
void test() {
int List[100];
pragma_test pt;
pt.run1(List, 100);
pt.run2(List, 100);
pt.run3(List, 100);
pt.run4(List, 100);
pt.run5(List, 100);
pt.run6(List, 100);
pt.run7<2, 4>(List, 100);
}
#endif