std::experimental::simd<T,Abi>::operator+=,-=,*=,/=,%=,&=,|=,^=,<<=,>>=

来自cppreference.com
< cpp‎ | experimental‎ | simd‎ | simd
 
 
实验性
技术规范
文件系统库 (文件系统 TS)
库基础 (库基础 TS)
库基础 2 (库基础 TS v2)
库基础 3 (库基础 TS v3)
并行扩展 (并行 TS)
并行扩展 2 (并行 TS v2)
并发扩展 (并发 TS)
并发扩展 2 (并发 TS v2)
概念 (概念 TS)
范围 (范围 TS)
反射 (反射 TS)
数学特殊函数 (特殊函数 TR)
实验性非 TS 功能特性
模式匹配
线性代数
std::execution
契约
2D 图形
 
 
 
 
friend simd& operator+=( simd& lhs, const simd& rhs ) noexcept;
(1) (并行 TS v2)
friend simd& operator-=( simd& lhs, const simd& rhs ) noexcept;
(2) (并行 TS v2)
friend simd& operator*=( simd& lhs, const simd& rhs ) noexcept;
(3) (并行 TS v2)
friend simd& operator/=( simd& lhs, const simd& rhs ) noexcept;
(4) (并行 TS v2)
friend simd& operator%=( simd& lhs, const simd& rhs ) noexcept;
(5) (并行 TS v2)
friend simd& operator&=( simd& lhs, const simd& rhs ) noexcept;
(6) (并行 TS v2)
friend simd& operator|=( simd& lhs, const simd& rhs ) noexcept;
(7) (并行 TS v2)
friend simd& operator^=( simd& lhs, const simd& rhs ) noexcept;
(8) (并行 TS v2)
friend simd& operator<<=( simd& lhs, const simd& rhs ) noexcept;
(9) (并行 TS v2)
friend simd& operator<<=( simd& lhs, int n ) noexcept;
(10) (并行 TS v2)
friend simd& operator>>=( simd& lhs, const simd& rhs ) noexcept;
(11) (并行 TS v2)
friend simd& operator>>=( simd& lhs, int n ) noexcept;
(12) (并行 TS v2)

逐元素对操作数的每个对应元素运用给定的复合赋值运算符,使得对于范围 [0size()) 中的所有 i,其结果等价于:

1) lhs[i] += rhs[i]
2) lhs[i] -= rhs[i]
3) lhs[i] *= rhs[i]
4) lhs[i] /= rhs[i]
5) lhs[i] %= rhs[i]
6) lhs[i] &= rhs[i]
7) lhs[i] |= rhs[i]
8) lhs[i] ^= rhs[i]
9) lhs[i] <<= rhs[i]
10) lhs[i] <<= n
11) lhs[i] >>= rhs[i]
12) lhs[i] >>= n

Parameters

lhs - 左操作数
rhs - 右操作数
n - lhs 中各元素位移的位数。

Return value

lhs

示例

在 SIMD 数据上,对某个任意角度 β 计算 cosh(β)² - sinh(β)² (== 1)。

#include <cstddef>
#include <experimental/simd>
#include <iomanip>
#include <iostream>
#include <string_view>
namespace stq = std::experimental;
 
void print(const std::string_view rem, const auto x)
{
    std::cout << rem << '\n' << std::fixed;
    for (std::size_t t{}; t != x.size(); ++t)
        std::cout << std::setw(10) << x[t] << ((t + 1) % 8 ? ',' : '\n');
    std::cout << '\n';
}
 
int main()
{
    constexpr auto N = 32UZ;
    using elem_t = long double;
 
    stq::fixed_size_simd<elem_t, N> x{[](elem_t i) { return i / N; }};
    stq::fixed_size_simd<elem_t, N> y{x};
    x = stq::cosh(x);
    y = stq::sinh(y);
    x *= x;
    y *= y;
    print("cosh(x)²:", x);
    print("sinh(x)²:", y);
    auto z = x - y;
    print("cosh(x)² - sinh(x)²:", z);
    std::cout << "reduce(z) = " << stq::reduce(z) << '\n';
}

输出:

cosh(x)²:
  1.000000,  1.000977,  1.003911,  1.008815,  1.015707,  1.024613,  1.035570,  1.048620
  1.063813,  1.081209,  1.100877,  1.122892,  1.147342,  1.174321,  1.203934,  1.236299
  1.271540,  1.309797,  1.351217,  1.395964,  1.444212,  1.496149,  1.551979,  1.611920
  1.676205,  1.745086,  1.818833,  1.897733,  1.982094,  2.072247,  2.168544,  2.271360
 
sinh(x)²:
  0.000000,  0.000977,  0.003911,  0.008815,  0.015707,  0.024613,  0.035570,  0.048620
  0.063813,  0.081209,  0.100877,  0.122892,  0.147342,  0.174321,  0.203934,  0.236299
  0.271540,  0.309797,  0.351217,  0.395964,  0.444212,  0.496149,  0.551979,  0.611920
  0.676205,  0.745086,  0.818833,  0.897733,  0.982094,  1.072247,  1.168544,  1.271360
 
cosh(x)² - sinh(x)²:
  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000
  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000
  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000
  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000,  1.000000
 
reduce(z) = 32.000000

参阅

逐元素二元运算符
(函数)