Skip to content

Commit 13794c6

Browse files
1 parent 0eeae2a commit 13794c6

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

sycl/include/sycl/vector_preview.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,15 +1031,15 @@ class SwizzleOp {
10311031
SwizzleOp &operator=(const vec<DataT, IdxNum> &Rhs) {
10321032
std::array<int, IdxNum> Idxs{Indexes...};
10331033
for (size_t I = 0; I < Idxs.size(); ++I) {
1034-
m_Vector[Idxs[I]] = Rhs.getValue(I);
1034+
(*m_Vector)[Idxs[I]] = Rhs.getValue(I);
10351035
}
10361036
return *this;
10371037
}
10381038

10391039
template <int IdxNum = getNumElements(), typename = EnableIfOneIndex<IdxNum>>
10401040
SwizzleOp &operator=(const DataT &Rhs) {
10411041
std::array<int, IdxNum> Idxs{Indexes...};
1042-
m_Vector[Idxs[0]] = Rhs;
1042+
(*m_Vector)[Idxs[0]] = Rhs;
10431043
return *this;
10441044
}
10451045

@@ -1048,15 +1048,15 @@ class SwizzleOp {
10481048
SwizzleOp &operator=(const DataT &Rhs) {
10491049
std::array<int, IdxNum> Idxs{Indexes...};
10501050
for (auto Idx : Idxs) {
1051-
m_Vector[Idx] = Rhs;
1051+
(*m_Vector)[Idx] = Rhs;
10521052
}
10531053
return *this;
10541054
}
10551055

10561056
template <int IdxNum = getNumElements(), typename = EnableIfOneIndex<IdxNum>>
10571057
SwizzleOp &operator=(DataT &&Rhs) {
10581058
std::array<int, IdxNum> Idxs{Indexes...};
1059-
m_Vector[Idxs[0]] = Rhs;
1059+
(*m_Vector)[Idxs[0]] = Rhs;
10601060
return *this;
10611061
}
10621062

@@ -1209,7 +1209,7 @@ class SwizzleOp {
12091209
SwizzleOp &operator=(const SwizzleOp<T1, T2, T3, T4, T5...> &Rhs) {
12101210
std::array<int, getNumElements()> Idxs{Indexes...};
12111211
for (size_t I = 0; I < Idxs.size(); ++I) {
1212-
m_Vector[Idxs[I]] = Rhs.getValue(I);
1212+
(*m_Vector)[Idxs[I]] = Rhs.getValue(I);
12131213
}
12141214
return *this;
12151215
}
@@ -1221,7 +1221,7 @@ class SwizzleOp {
12211221
SwizzleOp &operator=(SwizzleOp<T1, T2, T3, T4, T5...> &&Rhs) {
12221222
std::array<int, getNumElements()> Idxs{Indexes...};
12231223
for (size_t I = 0; I < Idxs.size(); ++I) {
1224-
m_Vector[Idxs[I]] = Rhs.getValue(I);
1224+
(*m_Vector)[Idxs[I]] = Rhs.getValue(I);
12251225
}
12261226
return *this;
12271227
}
@@ -1436,7 +1436,7 @@ class SwizzleOp {
14361436
std::array<int, getNumElements()> Idxs{Indexes...};
14371437
for (size_t I = 0; I < Idxs.size(); ++I) {
14381438
DataT Res = Op(m_Vector->getValue(Idxs[I]), Rhs.getValue(I));
1439-
m_Vector[Idxs[I]] = Res;
1439+
(*m_Vector)[Idxs[I]] = Res;
14401440
}
14411441
}
14421442

sycl/test/basic_tests/vectors/vectors.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,26 @@ int main() {
168168
assert((!inputVec4.lo().as<sycl::vec<bool, 2>>()[0]));
169169
assert((inputVec4.lo().as<sycl::vec<bool, 2>>()[1]));
170170

171+
// Check assignment operator for swizzles.
172+
{
173+
sycl::vec<int8_t, 2> inputVec1 = sycl::vec<int8_t, 2>(0, 1);
174+
sycl::vec<int8_t, 2> inputVec2 = sycl::vec<int8_t, 2>(2, 3);
175+
auto swiz1 = inputVec1.template swizzle<sycl::elem::s1, sycl::elem::s0>();
176+
auto swiz2 = inputVec2.template swizzle<sycl::elem::s0, sycl::elem::s1>();
177+
178+
// Assign swizzle to swizzle.
179+
swiz1 = swiz2;
180+
assert(inputVec1[0] == 3 && inputVec1[1] == 2);
181+
182+
// Assign vec to swizzle.
183+
swiz1 = sycl::vec<int8_t, 2>(0, 1);
184+
assert(inputVec1[0] == 1 && inputVec1[1] == 0);
185+
186+
// Assign single element to swizzle.
187+
swiz1 = (int8_t)5;
188+
assert(inputVec1[0] == 5 && inputVec1[1] == 5);
189+
}
190+
171191
// Check that [u]long[n] type aliases match vec<[u]int64_t, n> types.
172192
assert((std::is_same<sycl::vec<std::int64_t, 2>, sycl::long2>::value));
173193
assert((std::is_same<sycl::vec<std::int64_t, 3>, sycl::long3>::value));

0 commit comments

Comments
 (0)