namespace std::simd {
template<math-floating-point V>
constexpr deduced-vec-t<V> fma(const V& x, const V& y, const V& z); // (1) C++26
template<math-floating-point V>
constexpr deduced-vec-t<V>
fma(const deduced-vec-t<V>& x, const V& y, const V& z); // (2) C++26
template<math-floating-point V>
constexpr deduced-vec-t<V>
fma(const V& x, const deduced-vec-t<V>& y, const V& z); // (3) C++26
template<math-floating-point V>
constexpr deduced-vec-t<V>
fma(const V& x, const V& y, const deduced-vec-t<V>& z); // (4) C++26
template<math-floating-point V>
constexpr deduced-vec-t<V>
fma(const deduced-vec-t<V>& x, const deduced-vec-t<V>& y, const V& z); // (5) C++26
template<math-floating-point V>
constexpr deduced-vec-t<V>
fma(const deduced-vec-t<V>& x, const V& y, const deduced-vec-t<V>& z); // (6) C++26
template<math-floating-point V>
constexpr deduced-vec-t<V>
fma(const V& x, const deduced-vec-t<V>& y, const deduced-vec-t<V>& z); // (7) C++26
}
概要
basic_vecの各要素について、積和演算x * y + zを、途中結果を丸めずに1回の丸めで計算する(fused multiply-add)。
制約math-floating-pointは、Vが浮動小数点要素のbasic_vec、またはそこからbasic_vecを導出可能なスカラー浮動小数点型であることを表す説明専用のコンセプトである。deduced-vec-t<V>は、Vに対応するbasic_vec型(Vがスカラー型のときはそれを要素型とするbasic_vec)を表す。
- (1) : 3引数が同じ型
Vの場合。 - (2)-(7) : 一部の引数を
basic_vec、残りをスカラー値として、スカラー側を全要素に対して適用する場合。
戻り値
各要素iについて、x・y・zの対応する要素に<cmath>のfmaを適用した結果で初期化されたdeduced-vec-t<V>型のオブジェクトを返す。
ある要素iについて定義域エラー・極エラー・値域エラーが発生する場合、その要素の値は未規定である。
備考
例
#include <simd>
#include <print>
namespace simd = std::simd;
int main()
{
simd::vec<float, 4> x{[](int i) { return i + 1.0f; }}; // {1, 2, 3, 4}
simd::vec<float, 4> y = 2.0f; // {2, 2, 2, 2}
simd::vec<float, 4> z = 1.0f; // {1, 1, 1, 1}
// 各要素について x * y + z を計算する
simd::vec<float, 4> r = simd::fma(x, y, z);
for (int i = 0; i < r.size(); ++i)
std::print("{} ", r[i]);
std::println("");
}
出力
3 5 7 9
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌