Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/experimental/simd/simd/operator mem arith2"

From cppreference.com
< cpp‎ | experimental‎ | simd‎ | simd
(Document simd unary operators)
 
Line 1: Line 1:
{{cpp/experimental/simd/title|operator!|operator~|operator+|operator-}}
+
{{cpp/experimental/simd/title|operator!,~,+,-}}
 
{{cpp/experimental/simd/simd/navbar}}
 
{{cpp/experimental/simd/simd/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
Line 16: Line 16:
 
{{dcl end}}
 
{{dcl end}}
  
Applies the given unary operator on each element of the {{tt|simd}}.
+
Applies the given unary operator on each element of the {{ltt|cpp/experimental/simd/simd}}.
 
@1@ Returns a {{ltt|cpp/experimental/simd/simd_mask|simd_mask<T, Abi>}} where the i-th element equals {{tt|!operator[](i)}} {{simd_for_all_i}}.
 
@1@ Returns a {{ltt|cpp/experimental/simd/simd_mask|simd_mask<T, Abi>}} where the i-th element equals {{tt|!operator[](i)}} {{simd_for_all_i}}.
 
@2@ Returns a {{tt|simd}} where each bit is the inverse of the corresponding bit in {{tt|*this}}. {{cpp/enable_if|{{tt|T}} is an integral type}}.
 
@2@ Returns a {{tt|simd}} where each bit is the inverse of the corresponding bit in {{tt|*this}}. {{cpp/enable_if|{{tt|T}} is an integral type}}.

Revision as of 12:36, 20 March 2023

 
 
Experimental
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
 
 
 
 
mask_type operator!() const noexcept;
(1) (parallelism TS v2)
simd operator~() const noexcept;
(2) (parallelism TS v2)
simd operator+() const noexcept;
(3) (parallelism TS v2)
simd operator-() const noexcept;
(4) (parallelism TS v2)

Applies the given unary operator on each element of the simd.

1) Returns a simd_mask<T, Abi> where the i-th element equals !operator[](i) for all i in the range of [0size()).
2) Returns a simd where each bit is the inverse of the corresponding bit in *this. This overload participates in overload resolution only if T is an integral type.
3) Returns a copy of itself.
4) Returns a simd where the i-th element is initialized to -operator[](i) for all i in the range of [0size()).

Example

#include <experimental/simd>
#include <iostream>
namespace stdx = std::experimental;
 
void print(const stdx::native_simd_mask<int> x) {
    for (std::size_t i = 0; i < x.size(); ++i) {
        std::cout << std::boolalpha << x[i] << ' ';
    }
    std::cout << std::endl;
}
 
void print(const stdx::native_simd<int> x) {
    for (std::size_t i = 0; i < x.size(); ++i) {
        std::cout << x[i] << ' ';
    }
    std::cout << std::endl;
}
 
int main()
{
    const stdx::native_simd<int> a([](int i) { return i; });
    print(!a);
    print(~a);
    print(+a);
    print(-a);
    return 0;
}

Possible output:

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