std::experi...::copy_from(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌈 std::experimental::simd::copy_from 🌈

okay bestie, this is the C++ Standard Libary manual page for std::experimental::simd::copy_from β€” and it's lowkey giving "load stuff into a simd and make it make sense" energy. πŸ’…βœ¨


πŸ’– NAME πŸ’–

std::experimental::simd::copy_from β€” std::experimental::simd::copy_from

🌸 Synopsis 🌸

template< class U, class Flags >              (parallelism TS v2)
void copy_from( const U* mem, Flags flags );

The load function replaces all elements of a simd such that the i^th element is assigned with static_cast<T>(mem[i]) for all i in the range of [0, size()).

πŸŽ€ Parameters πŸŽ€

  • mem β€” a pointer into an array where [mem, mem + size()) is a valid range.
  • flags β€” if it's of type vector_aligned_tag, the load constructor may assume mem points to storage aligned by memory_alignment_v<simd, U>.

✨ Type requirements ✨

  • U must be a vectorizable type.
  • is_simd_flag_type_v<Flags> must be true.

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <cstddef>
#include <experimental/simd>
#include <iostream>
#include <numeric>
namespace stdx = std::experimental;

void print(auto const& a)
{
    for (std::size_t i{}; i != std::size(a); ++i)
        std::cout << a[i] << ' ';
    std::cout << '\n';
}

int main()
{
    alignas(stdx::memory_alignment_v<stdx::native_simd<int>>)
        std::array<int, stdx::native_simd<int>::size() * 2> mem = {};
    std::iota(mem.begin(), mem.end(), 0);
    print(mem);

    stdx::native_simd<int> a; // uninitialized

    a.copy_from(&mem[0], stdx::vector_aligned);
    print(a);

    a.copy_from(&mem[1], stdx::element_aligned); // vector_aligned
       would likely crash
    print(a);
}

πŸ’« Possible output πŸ’«

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 1 2 3 4 5 6 7
1 2 3 4 5 6 7 8

πŸ‘‘ See also πŸ‘‘

  • memory_alignment β€” obtains an appropriate alignment for vector_aligned (parallelism TS v2) (class template)
  • copy_to β€” stores simd elements to contiguous memory (parallelism TS v2) (public member function)
  • constructor β€” constructs a simd object (parallelism TS v2) (public member function)

and that's the whole vibe, bestie 🫢 β€” source/version: http://cppreference.com, date: 2024.06.10, page tag: std::experi...::copy_from(3). periodt. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from