Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sycl/include/CL/sycl/bit_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#pragma once

#include <CL/sycl/aliases.hpp>

#include <type_traits>

#if __cpp_lib_bit_cast
Expand All @@ -20,6 +22,10 @@ namespace sycl {
// forward decl
namespace detail {
inline void memcpy(void *Dst, const void *Src, std::size_t Size);

template <typename Type> struct type_helper { using T = Type; };

template <> struct type_helper<sycl::half> { using T = uint16_t; };
}

template <typename To, typename From>
Expand All @@ -41,7 +47,8 @@ constexpr
#if __has_builtin(__builtin_bit_cast)
return __builtin_bit_cast(To, from);
#else // __has_builtin(__builtin_bit_cast)
static_assert(std::is_trivially_default_constructible<To>::value,
static_assert(std::is_trivially_default_constructible<
typename detail::type_helper<To>::T>::value,
"To must be trivially default constructible");
To to;
sycl::detail::memcpy(&to, &from, sizeof(To));
Expand Down