Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::simd<T,Abi>::simd

      From cppreference.com
      <cpp‎ |experimental‎ |simd‎ |simd
       
       
       
       
       
       
      simd()noexcept=default;
      (1)(parallelism TS v2)
      template<class U>
      simd( U&& value)noexcept;
      (2)(parallelism TS v2)
      template<class U>
      simd(const simd<U, simd_abi::fixed_size<size()>>& other)noexcept;
      (3)(parallelism TS v2)
      template<class G>
      explicit simd( G&& generator)noexcept;
      (4)(parallelism TS v2)
      template<class U,class Flags>
      simd(const U* mem, Flags flags);
      (5)(parallelism TS v2)
      simd(const simd& other)noexcept=default;
      (6)(parallelism TS v2)
      (implicitly declared)
      simd( simd&& other)noexcept=default;
      (7)(parallelism TS v2)
      (implicitly declared)
      1) Constructs asimd usingdefault initialization (constructed without initializer) orvalue initialization (constructed with an empty initializer).
      2) The broadcast constructor constructs asimd with all values initialized tovalue. This overload participates in overload resolution only if the conversion fromU toT isvalue-preserving, orU is eitherint orunsignedint ifT is an unsigned integral type.
      3) Constructs asimd where the i-th element is initialized tostatic_cast<T>(other[i]) for alli in the range of[0size()). This overload participates in overload resolution only ifAbi issimd_abi::fixed_size<size()> and the conversion fromU toT isvalue-preserving, and, if bothU andT are integral, the integer conversion rank ofT is greater than the integer conversion rank ofU.
      4) The generator constructor constructs asimd where the i-th element is initialized togenerator(std::integral_constant<std::size_t, i>()). This overload participates in overload resolution only ifsimd(gen(std::integral_constant<std::size_t, i>())) is well-formed for alli in the range of[0size()). The calls togenerator are unsequenced with respect to each other.Vectorization-unsafe standard library functions may not be invoked bygenerator.
      5) The load constructor constructs asimd where the i-th element is initialized tostatic_cast<T>(mem[i]) for alli in the range of[0size()).
      6,7) Implicitly declared copy and move constructors. Constructs asimd where each element is initialized from the values of the elements inother.

      [edit]Parameters

      value - the value used for initialization of allsimd elements
      other - anothersimd to copy from
      generator - a function object used for initialization of eachsimd element
      mem - a pointer into an array where[memmem+ size()) is a valid range
      flags - if of typevector_aligned_tag, the load constructor may assumemem to point to storage aligned bymemory_alignment_v<simd, U>
      Type requirements
      -
      The conversion fromU toT must bevalue-preserving. The broadcast constructor (2) additionally allowsU to beint or to beunsignedint ifT is an unsigned integral type.
      -
      is_simd_flag_type_v<Flags> must betrue.

      [edit]Example

      Run this code
      #include <cstddef>#include <experimental/simd>#include <iostream>namespace stdx= std::experimental; int main(){    stdx::native_simd<int> a;// uninitialized    a=1;// all elements set to 1    stdx::native_simd<int> b([](int i){return i;});// {0, 1, 2, 3, ...}     alignas(stdx::memory_alignment_v<stdx::native_simd<int>>)std::array<int, stdx::native_simd<int>::size()*2> mem={};for(std::size_t i=0; i< mem.size();++i)        mem[i]= i&1;     stdx::native_simd<int> c(&mem[0], stdx::vector_aligned);// {0, 1, 0, 1, ...}    stdx::native_simd<int> d(&mem[1], stdx::element_aligned);// {1, 0, 1, 0, ...} auto sum= a+ b+ c+ d; for(std::size_t i=0; i< sum.size();++i)std::cout<< sum[i]<<' ';std::cout<<'\n';}

      Possible output:

      2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

      [edit]See also

      (parallelism TS v2)
      loadssimd elements from contiguous memory
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/simd/simd/simd&oldid=157774"

      [8]ページ先頭

      ©2009-2026 Movatter.jp