@@ -137,19 +137,11 @@ inline constexpr bool is_fundamental_or_half_or_bfloat16 =
137137 std::is_fundamental_v<T> || std::is_same_v<std::remove_const_t <T>, half> ||
138138 std::is_same_v<std::remove_const_t <T>, ext::oneapi::bfloat16>;
139139
140- // Proposed SYCL specification changes have sycl::vec having different ctors
141- // available based on the number of elements. Without C++20's concepts we'll
142- // have to use partial specialization to represent that. This is a helper to do
143- // that. An alternative could be to have different specializations of the
144- // `sycl::vec` itself but then we'd need to outline all the common interfaces to
145- // re-use them.
146- //
147- // Note: the functional changes haven't been implemented yet, we've split
148- // vec_base in advance as a way to make changes easier to review/verify.
149- //
150- // Another note: `vector_t` is going to be removed, so corresponding ctor was
151- // kept inside `sycl::vec` to have all `vector_t` functionality in a single
152- // place.
140+ // Per SYCL specification sycl::vec has different ctors available based on the
141+ // number of elements. Without C++20's concepts we'd have to use partial
142+ // specialization to represent that. This is a helper to do that. An alternative
143+ // could be to have different specializations of the `sycl::vec` itself but then
144+ // we'd need to outline all the common interfaces to re-use them.
153145template <typename DataT, int NumElements> class vec_base {
154146 // https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#memory-layout-and-alignment
155147 // It is required by the SPEC to align vec<DataT, 3> with vec<DataT, 4>.
@@ -271,6 +263,43 @@ template <typename DataT, int NumElements> class vec_base {
271263 : vec_base{VecArgArrayCreator<DataT, argTN...>::Create (args...),
272264 std::make_index_sequence<NumElements>()} {}
273265};
266+
267+ #if __SYCL_USE_PREVIEW_VEC_IMPL
268+ template <typename DataT> class vec_base <DataT, 1 > {
269+ using DataType = std::conditional_t <
270+ #if __SYCL_USE_PLAIN_ARRAY_AS_VEC_STORAGE
271+ true ,
272+ #else
273+ sizeof (std::array<DataT, 1 >) == sizeof (DataT[1 ]) &&
274+ alignof (std::array<DataT, 1 >) == alignof(DataT[1 ]),
275+ #endif
276+ DataT[1 ], std::array<DataT, 1 >>;
277+
278+ protected:
279+ static constexpr int alignment = (std::min)((size_t )64 , sizeof (DataType));
280+ alignas (alignment) DataType m_Data{};
281+
282+ public:
283+ constexpr vec_base () = default;
284+ constexpr vec_base (const vec_base &) = default;
285+ constexpr vec_base (vec_base &&) = default;
286+ constexpr vec_base &operator =(const vec_base &) = default ;
287+ constexpr vec_base &operator =(vec_base &&) = default ;
288+
289+ // Not `explicit` on purpose, differs from NumElements > 1.
290+ constexpr vec_base (const DataT &arg) : m_Data{{arg}} {}
291+
292+ // FIXME: Temporary workaround because swizzle's `operator DataT` is a
293+ // template.
294+ template <typename Swizzle,
295+ typename = std::enable_if_t <is_swizzle_v<Swizzle>>,
296+ typename = std::enable_if_t <Swizzle::size() == 1 >,
297+ typename = std::enable_if<
298+ std::is_convertible_v<typename Swizzle::element_type, DataT>>>
299+ constexpr vec_base (const Swizzle &other)
300+ : vec_base(static_cast <DataT>(other)) {}
301+ };
302+ #endif
274303} // namespace detail
275304
276305// /////////////////////// class sycl::vec /////////////////////////
0 commit comments