31
31
32
32
#include < cstdint>
33
33
34
- template <int N> void dropFront (int64_t arr[N], int64_t *res) {
34
+ template <int N>
35
+ void dropFront (int64_t arr[N], int64_t *res) {
35
36
for (unsigned i = 1 ; i < N; ++i)
36
37
*(res + i - 1 ) = arr[i];
37
38
}
@@ -40,23 +41,13 @@ template <int N> void dropFront(int64_t arr[N], int64_t *res) {
40
41
// Codegen-compatible structures for Vector type.
41
42
// ===----------------------------------------------------------------------===//
42
43
namespace detail {
43
- template <unsigned N>
44
- constexpr bool isPowerOf2 () {
45
- return (!(N & (N - 1 )));
46
- }
47
-
48
- template <unsigned N>
49
- constexpr unsigned nextPowerOf2 ();
50
- template <>
51
- constexpr unsigned nextPowerOf2<0 >() {
52
- return 1 ;
53
- }
54
- template <>
55
- constexpr unsigned nextPowerOf2<1 >() {
56
- return 1 ;
57
- }
58
- template <unsigned N> constexpr unsigned nextPowerOf2 () {
59
- return isPowerOf2<N>() ? N : 2 * nextPowerOf2<(N + 1 ) / 2 >();
44
+
45
+ constexpr bool isPowerOf2 (int N) { return (!(N & (N - 1 ))); }
46
+
47
+ constexpr unsigned nextPowerOf2 (int N) {
48
+ if (N <= 1 )
49
+ return 1 ;
50
+ return isPowerOf2 (N) ? N : 2 * nextPowerOf2 ((N + 1 ) / 2 );
60
51
}
61
52
62
53
template <typename T, int Dim, bool IsPowerOf2>
@@ -65,7 +56,7 @@ struct Vector1D;
65
56
template <typename T, int Dim>
66
57
struct Vector1D <T, Dim, /* IsPowerOf2=*/ true > {
67
58
Vector1D () {
68
- static_assert (detail::nextPowerOf2< sizeof (T[Dim])>( ) == sizeof (T[Dim]),
59
+ static_assert (detail::nextPowerOf2 ( sizeof (T[Dim])) == sizeof (T[Dim]),
69
60
" size error" );
70
61
}
71
62
constexpr T &operator [](unsigned i) { return vector[i]; }
@@ -80,17 +71,17 @@ struct Vector1D<T, Dim, /*IsPowerOf2=*/true> {
80
71
template <typename T, int Dim>
81
72
struct Vector1D <T, Dim, /* IsPowerOf2=*/ false > {
82
73
Vector1D () {
83
- static_assert (detail::nextPowerOf2< sizeof (T[Dim])>( ) > sizeof (T[Dim]),
74
+ static_assert (detail::nextPowerOf2 ( sizeof (T[Dim])) > sizeof (T[Dim]),
84
75
" size error" );
85
- static_assert (detail::nextPowerOf2< sizeof (T[Dim])>( ) < 2 * sizeof (T[Dim]),
76
+ static_assert (detail::nextPowerOf2 ( sizeof (T[Dim])) < 2 * sizeof (T[Dim]),
86
77
" size error" );
87
78
}
88
79
constexpr T &operator [](unsigned i) { return vector[i]; }
89
80
constexpr const T &operator [](unsigned i) const { return vector[i]; }
90
81
91
82
private:
92
83
T vector[Dim];
93
- char padding[detail::nextPowerOf2< sizeof (T[Dim])>( ) - sizeof (T[Dim])];
84
+ char padding[detail::nextPowerOf2( sizeof (T[Dim])) - sizeof (T[Dim])];
94
85
};
95
86
} // end namespace detail
96
87
@@ -110,7 +101,7 @@ struct Vector {
110
101
// We insert explicit padding in to account for this.
111
102
template <typename T, int Dim>
112
103
struct Vector <T, Dim>
113
- : public detail::Vector1D<T, Dim, detail::isPowerOf2< sizeof (T[Dim])>( )> {};
104
+ : public detail::Vector1D<T, Dim, detail::isPowerOf2( sizeof (T[Dim]))> {};
114
105
115
106
template <int D1, typename T>
116
107
using Vector1D = Vector<T, D1>;
@@ -125,7 +116,8 @@ using Vector4D = Vector<T, D1, D2, D3, D4>;
125
116
// Codegen-compatible structures for StridedMemRef type.
126
117
// ===----------------------------------------------------------------------===//
127
118
// / StridedMemRef descriptor type with static rank.
128
- template <typename T, int N> struct StridedMemRefType {
119
+ template <typename T, int N>
120
+ struct StridedMemRefType {
129
121
T *basePtr;
130
122
T *data;
131
123
int64_t offset;
@@ -144,7 +136,8 @@ template <typename T, int N> struct StridedMemRefType {
144
136
};
145
137
146
138
// / StridedMemRef descriptor type specialized for rank 1.
147
- template <typename T> struct StridedMemRefType <T, 1 > {
139
+ template <typename T>
140
+ struct StridedMemRefType <T, 1 > {
148
141
T *basePtr;
149
142
T *data;
150
143
int64_t offset;
@@ -154,7 +147,8 @@ template <typename T> struct StridedMemRefType<T, 1> {
154
147
};
155
148
156
149
// / StridedMemRef descriptor type specialized for rank 0.
157
- template <typename T> struct StridedMemRefType <T, 0 > {
150
+ template <typename T>
151
+ struct StridedMemRefType <T, 0 > {
158
152
T *basePtr;
159
153
T *data;
160
154
int64_t offset;
@@ -164,7 +158,8 @@ template <typename T> struct StridedMemRefType<T, 0> {
164
158
// Codegen-compatible structure for UnrankedMemRef type.
165
159
// ===----------------------------------------------------------------------===//
166
160
// Unranked MemRef
167
- template <typename T> struct UnrankedMemRefType {
161
+ template <typename T>
162
+ struct UnrankedMemRefType {
168
163
int64_t rank;
169
164
void *descriptor;
170
165
};
0 commit comments