Skip to content

Commit

Permalink
[SYCL] Implement "swizzle" member function on swizzles (#16353)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aelovikov-intel authored Dec 13, 2024
1 parent 4e8b647 commit 3524739
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 10 additions & 0 deletions sycl/include/sycl/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,16 @@ class SwizzleOp {
};

public:
template <int... swizzleIndexes>
ConstSwizzle<Indexer<swizzleIndexes>::value...> swizzle() const {
return m_Vector;
}

template <int... swizzleIndexes>
Swizzle<Indexer<swizzleIndexes>::value...> swizzle() {
return m_Vector;
}

#ifdef __SYCL_ACCESS_RETURN
#error "Undefine __SYCL_ACCESS_RETURN macro"
#endif
Expand Down
16 changes: 4 additions & 12 deletions sycl/test/basic_tests/vectors/swizzle.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// RUN: %clangxx -fsycl %s -o %t_default.out
// RUN: %t_default.out

// FIXME: Everything should compile cleanly.
// RUN: %clangxx -fsycl -fsycl-device-only -DCHECK_ERRORS -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,error %s

#include <sycl/vector.hpp>

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

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

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

{
// expected-error-re@+1 {{no template named 'swizzle' in {{.*}}}}
auto tmp = (sw + sw).swizzle<1, 0>();
assert(tmp[0] == 6);
assert(tmp[1] == 4);

// FIXME: Should be "6" and "4", respectively.
assert(tmp[0] == 3);
assert(tmp[1] == 2);
}
#endif

return 0;
}

0 comments on commit 3524739

Please sign in to comment.