Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int(simd.h): Make the simd types trivially_copyable #4173

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions src/include/OpenImageIO/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10360,6 +10360,24 @@ template<> struct formatter<OIIO::simd::matrix44>
: OIIO::pvt::array_formatter<OIIO::simd::matrix44, float, 16> {};
} // 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<OIIO::simd::vbool4> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vint4> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vfloat4> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vfloat3> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::matrix44> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vbool8> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vint8> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vfloat8> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vbool16> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vint16> : std::true_type {};
template<> struct is_trivially_copyable<OIIO::simd::vfloat16> : std::true_type {};
} // namespace std


#undef SIMD_DO
#undef SIMD_CONSTRUCT
#undef SIMD_CONSTRUCT_PAD
Expand Down
20 changes: 20 additions & 0 deletions src/libutil/simd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<vbool4>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vint4>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vfloat4>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vfloat3>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<matrix44>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vbool8>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vint8>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vfloat8>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vbool16>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vint16>::value);
OIIO_CHECK_ASSERT(std::is_trivially_copyable<vfloat16>::value);
}



int
main(int argc, char* argv[])
{
Expand Down Expand Up @@ -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";
Expand Down
Loading