| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Parallel exceptions | ||||
| Additional execution policies | ||||
| Algorithms | ||||
| Task blocks | ||||
| Data-parallel vectors | ||||
| Member functions | ||||
| Non-member functions | ||||
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) |
simd usingdefault initialization (constructed without initializer) orvalue initialization (constructed with an empty initializer).simd 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.simd where the i-th element is initialized tostatic_cast<T>(other[i]) for alli in the range of[0, size()). 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.simd 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[0, size()). The calls togenerator are unsequenced with respect to each other.Vectorization-unsafe standard library functions may not be invoked bygenerator.simd where the i-th element is initialized tostatic_cast<T>(mem[i]) for alli in the range of[0, size()).simd where each element is initialized from the values of the elements inother.| 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[mem, mem+ 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. | ||
#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
(parallelism TS v2) | loadssimd elements from contiguous memory (public member function)[edit] |