diff --git a/src/include/OpenImageIO/simd.h b/src/include/OpenImageIO/simd.h index 46c8b392b8..2cbeb343fe 100644 --- a/src/include/OpenImageIO/simd.h +++ b/src/include/OpenImageIO/simd.h @@ -10360,6 +10360,24 @@ template<> struct formatter : OIIO::pvt::array_formatter {}; } // namespace fmt + +// Allow C++ metaprogramming to understand that the simd types are trivially +// copyable (i.e. memcpy to copy simd types is fine). +namespace std { // not necessary in C++17, just say std::is_trivially_copyable +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +template<> struct is_trivially_copyable : std::true_type {}; +} // namespace std + + #undef SIMD_DO #undef SIMD_CONSTRUCT #undef SIMD_CONSTRUCT_PAD diff --git a/src/libutil/simd_test.cpp b/src/libutil/simd_test.cpp index 4ecee7054e..4d0276f042 100644 --- a/src/libutil/simd_test.cpp +++ b/src/libutil/simd_test.cpp @@ -1939,6 +1939,25 @@ test_matrix() +static void +test_trivially_copyable() +{ + print("\nTesting trivially_copyable on all SIMD classes\n"); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); + OIIO_CHECK_ASSERT(std::is_trivially_copyable::value); +} + + + int main(int argc, char* argv[]) { @@ -2094,6 +2113,7 @@ main(int argc, char* argv[]) test_special(); test_metaprogramming(); test_matrix(); + test_trivially_copyable(); std::cout << "\nTotal time: " << Strutil::timeintervalformat(timer()) << "\n";