Skip to content

Commit 3524739

Browse files
[SYCL] Implement "swizzle" member function on swizzles (#16353)
It brings it closer to SYCL spec and makes more consistent by having "named" swizzle member functions (like `.hi()`/`.lo()`) and `.swizzle<...>()` behave in a similar way, i.e. we still have a bug when doing a swizzle on an expression tree. Note that the whole "expression tree" machinery is not standard-conformant and will be completely removed separately (under `-fpreview-breaking-changes` flag). I still want to implement this partial bugfix so that I could switch to a unified mixin-based implementation for swizzles on `vec`/`swizzle` classes, instead of doing preprocessor tricks with `swizzles.def` file.
1 parent 4e8b647 commit 3524739

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

sycl/include/sycl/vector.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,16 @@ class SwizzleOp {
12071207
};
12081208

12091209
public:
1210+
template <int... swizzleIndexes>
1211+
ConstSwizzle<Indexer<swizzleIndexes>::value...> swizzle() const {
1212+
return m_Vector;
1213+
}
1214+
1215+
template <int... swizzleIndexes>
1216+
Swizzle<Indexer<swizzleIndexes>::value...> swizzle() {
1217+
return m_Vector;
1218+
}
1219+
12101220
#ifdef __SYCL_ACCESS_RETURN
12111221
#error "Undefine __SYCL_ACCESS_RETURN macro"
12121222
#endif
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// RUN: %clangxx -fsycl %s -o %t_default.out
22
// RUN: %t_default.out
33

4-
// FIXME: Everything should compile cleanly.
5-
// RUN: %clangxx -fsycl -fsycl-device-only -DCHECK_ERRORS -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,error %s
6-
74
#include <sycl/vector.hpp>
85

96
int main() {
@@ -15,27 +12,22 @@ int main() {
1512
// FIXME: Should be "4":
1613
assert((sw + sw).lo()[0] == 2);
1714

18-
// FIXME: The below should compile.
19-
#if CHECK_ERRORS
20-
// expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}}
2115
assert(sw.swizzle<0>()[0] == 2);
22-
// expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}}
2316
assert(sw.swizzle<1>()[0] == 3);
2417

2518
{
26-
// expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}}
2719
auto tmp = sw.swizzle<1, 0>();
2820
assert(tmp[0] == 3);
2921
assert(tmp[1] == 2);
3022
}
3123

3224
{
33-
// expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}}
3425
auto tmp = (sw + sw).swizzle<1, 0>();
35-
assert(tmp[0] == 6);
36-
assert(tmp[1] == 4);
26+
27+
// FIXME: Should be "6" and "4", respectively.
28+
assert(tmp[0] == 3);
29+
assert(tmp[1] == 2);
3730
}
38-
#endif
3931

4032
return 0;
4133
}

0 commit comments

Comments
 (0)