Skip to content

Commit

Permalink
Add implementation of bit_cast in <Kokkos_BitManipulation.hpp>
Browse files Browse the repository at this point in the history
  • Loading branch information
dalg24 committed May 4, 2023
1 parent 4b6d971 commit ab41ef8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/src/Kokkos_BitManipulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <Kokkos_Macros.hpp>
#include <Kokkos_NumericTraits.hpp>
#include <climits> // CHAR_BIT
#include <cstring> //memcpy
#include <type_traits>

namespace Kokkos::Impl {
Expand Down Expand Up @@ -98,6 +99,19 @@ inline constexpr bool is_standard_unsigned_integer_type_v =

namespace Kokkos {

//<editor-fold desc="[bit.cast], bit_cast">
template <class To, class From>
KOKKOS_FUNCTION std::enable_if_t<sizeof(To) == sizeof(From) &&
std::is_trivially_copyable_v<To> &&
std::is_trivially_copyable_v<From>,
To>
bit_cast(From const& from) noexcept {
To to;
memcpy(&to, &from, sizeof(To));
return to;
}
//</editor-fold>

//<editor-fold desc="[bit.byteswap], byteswap">
template <class T>
KOKKOS_FUNCTION constexpr std::enable_if_t<std::is_integral_v<T>, T> byteswap(
Expand Down

0 comments on commit ab41ef8

Please sign in to comment.