using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Unity.Burst.Intrinsics
{
public unsafe static partial class X86
{
///
/// FMA intrinsics
///
public static class Fma
{
///
/// Evaluates to true at compile time if FMA intrinsics are supported.
///
/// Burst ties FMA support to AVX2 support to simplify feature sets to support.
///
public static bool IsFmaSupported { get { return Avx2.IsAvx2Supported; } }
[DebuggerStepThrough]
private static float FmaHelper(float a, float b, float c)
{
return (float)((((double)a) * b) + c);
}
[StructLayout(LayoutKind.Explicit)]
private struct Union
{
[FieldOffset(0)]
public float f;
[FieldOffset(0)]
public uint u;
}
[DebuggerStepThrough]
private static float FnmaHelper(float a, float b, float c)
{
return FmaHelper(-a, b, c);
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, add the intermediate result to packed elements in c, and store the results in dst.
///
///
/// **** vfmadd213pd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector>
[DebuggerStepThrough]
public static v128 fmadd_pd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, add the intermediate result to packed elements in c, and store the results in dst.
///
///
/// **** vfmadd213pd ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fmadd_pd(v256 a, v256 b, v256 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, add the intermediate result to packed elements in c, and store the results in dst.
///
///
/// **** vfmadd213ps xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmadd_ps(v128 a, v128 b, v128 c)
{
return new v128(FmaHelper(a.Float0, b.Float0, c.Float0),
FmaHelper(a.Float1, b.Float1, c.Float1),
FmaHelper(a.Float2, b.Float2, c.Float2),
FmaHelper(a.Float3, b.Float3, c.Float3));
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, add the intermediate result to packed elements in c, and store the results in dst.
///
///
/// **** vfmadd213ps ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fmadd_ps(v256 a, v256 b, v256 c)
{
return new v256(FmaHelper(a.Float0, b.Float0, c.Float0),
FmaHelper(a.Float1, b.Float1, c.Float1),
FmaHelper(a.Float2, b.Float2, c.Float2),
FmaHelper(a.Float3, b.Float3, c.Float3),
FmaHelper(a.Float4, b.Float4, c.Float4),
FmaHelper(a.Float5, b.Float5, c.Float5),
FmaHelper(a.Float6, b.Float6, c.Float6),
FmaHelper(a.Float7, b.Float7, c.Float7));
}
///
/// Multiply the lower double-precision (64-bit) floating-point elements in a and b, and add the intermediate result to the lower element in c. Store the result in the lower element of dst, and copy the upper element from a to the upper element of dst.
///
///
/// **** vfmadd213sd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmadd_sd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply the lower single-precision (32-bit) floating-point elements in a and b, and add the intermediate result to the lower element in c. Store the result in the lower element of dst, and copy the upper 3 packed elements from a to the upper elements of dst.
///
///
/// **** vfmadd213ss xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmadd_ss(v128 a, v128 b, v128 c)
{
var result = a;
result.Float0 = FmaHelper(a.Float0, b.Float0, c.Float0);
return result;
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, alternatively add and subtract packed elements in c to/from the intermediate result, and store the results in dst.
///
///
/// **** vfmaddsub213pd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmaddsub_pd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, alternatively add and subtract packed elements in c to/from the intermediate result, and store the results in dst.
///
///
/// **** vfmaddsub213pd ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fmaddsub_pd(v256 a, v256 b, v256 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, alternatively add and subtract packed elements in c to/from the intermediate result, and store the results in dst.
///
///
/// **** vfmaddsub213ps xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmaddsub_ps(v128 a, v128 b, v128 c)
{
return new v128(FmaHelper(a.Float0, b.Float0, -c.Float0),
FmaHelper(a.Float1, b.Float1, c.Float1),
FmaHelper(a.Float2, b.Float2, -c.Float2),
FmaHelper(a.Float3, b.Float3, c.Float3));
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, alternatively add and subtract packed elements in c to/from the intermediate result, and store the results in dst.
///
///
/// **** vfmaddsub213ps ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fmaddsub_ps(v256 a, v256 b, v256 c)
{
return new v256(FmaHelper(a.Float0, b.Float0, -c.Float0),
FmaHelper(a.Float1, b.Float1, c.Float1),
FmaHelper(a.Float2, b.Float2, -c.Float2),
FmaHelper(a.Float3, b.Float3, c.Float3),
FmaHelper(a.Float4, b.Float4, -c.Float4),
FmaHelper(a.Float5, b.Float5, c.Float5),
FmaHelper(a.Float6, b.Float6, -c.Float6),
FmaHelper(a.Float7, b.Float7, c.Float7));
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, subtract packed elements in c from the intermediate result, and store the results in dst.
///
///
/// **** vfmsub213pd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmsub_pd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, subtract packed elements in c from the intermediate result, and store the results in dst.
///
///
/// **** vfmsub213pd ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fmsub_pd(v256 a, v256 b, v256 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, subtract packed elements in c from the intermediate result, and store the results in dst.
///
///
/// **** vfmsub213ps xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmsub_ps(v128 a, v128 b, v128 c)
{
return new v128(FmaHelper(a.Float0, b.Float0, -c.Float0),
FmaHelper(a.Float1, b.Float1, -c.Float1),
FmaHelper(a.Float2, b.Float2, -c.Float2),
FmaHelper(a.Float3, b.Float3, -c.Float3));
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, subtract packed elements in c from the intermediate result, and store the results in dst.
///
///
/// **** vfmsub213ps ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fmsub_ps(v256 a, v256 b, v256 c)
{
return new v256(FmaHelper(a.Float0, b.Float0, -c.Float0),
FmaHelper(a.Float1, b.Float1, -c.Float1),
FmaHelper(a.Float2, b.Float2, -c.Float2),
FmaHelper(a.Float3, b.Float3, -c.Float3),
FmaHelper(a.Float4, b.Float4, -c.Float4),
FmaHelper(a.Float5, b.Float5, -c.Float5),
FmaHelper(a.Float6, b.Float6, -c.Float6),
FmaHelper(a.Float7, b.Float7, -c.Float7));
}
///
/// Multiply the lower double-precision(64-bit) floating-point elements in a and b, and subtract the lower element in c from the intermediate result.Store the result in the lower element of dst, and copy the upper element from a to the upper element of dst.
///
///
/// **** vfmsub213sd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmsub_sd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply the lower single-precision (32-bit) floating-point elements in a and b, and subtract the lower element in c from the intermediate result. Store the result in the lower element of dst, and copy the upper 3 packed elements from a to the upper elements of dst.
///
///
/// **** vfmsub213ss xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmsub_ss(v128 a, v128 b, v128 c)
{
var result = a;
result.Float0 = FmaHelper(a.Float0, b.Float0, -c.Float0);
return result;
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, alternatively subtract and add packed elements in c to/from the intermediate result, and store the results in dst.
///
///
/// **** vfmsubadd213pd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmsubadd_pd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, alternatively subtract and add packed elements in c to/from the intermediate result, and store the results in dst.
///
///
/// **** vfmsubadd213pd ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fmsubadd_pd(v256 a, v256 b, v256 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, alternatively subtract and add packed elements in c to/from the intermediate result, and store the results in dst.
///
///
/// **** vfmsubadd213ps xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fmsubadd_ps(v128 a, v128 b, v128 c)
{
return new v128(FmaHelper(a.Float0, b.Float0, c.Float0),
FmaHelper(a.Float1, b.Float1, -c.Float1),
FmaHelper(a.Float2, b.Float2, c.Float2),
FmaHelper(a.Float3, b.Float3, -c.Float3));
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, alternatively subtract and add packed elements in c to/from the intermediate result, and store the results in dst.
///
///
/// **** vfmsubadd213ps ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fmsubadd_ps(v256 a, v256 b, v256 c)
{
return new v256(FmaHelper(a.Float0, b.Float0, c.Float0),
FmaHelper(a.Float1, b.Float1, -c.Float1),
FmaHelper(a.Float2, b.Float2, c.Float2),
FmaHelper(a.Float3, b.Float3, -c.Float3),
FmaHelper(a.Float4, b.Float4, c.Float4),
FmaHelper(a.Float5, b.Float5, -c.Float5),
FmaHelper(a.Float6, b.Float6, c.Float6),
FmaHelper(a.Float7, b.Float7, -c.Float7));
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, add the negated intermediate result to packed elements in c, and store the results in dst.
///
///
/// **** vfnmadd213pd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fnmadd_pd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, add the negated intermediate result to packed elements in c, and store the results in dst.
///
///
/// **** vfnmadd213pd ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fnmadd_pd(v256 a, v256 b, v256 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, add the negated intermediate result to packed elements in c, and store the results in dst.
///
///
/// **** vfnmadd213ps xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fnmadd_ps(v128 a, v128 b, v128 c)
{
return new v128(FnmaHelper(a.Float0, b.Float0, c.Float0),
FnmaHelper(a.Float1, b.Float1, c.Float1),
FnmaHelper(a.Float2, b.Float2, c.Float2),
FnmaHelper(a.Float3, b.Float3, c.Float3));
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, add the negated intermediate result to packed elements in c, and store the results in dst.
///
///
/// **** vfnmadd213ps ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fnmadd_ps(v256 a, v256 b, v256 c)
{
return new v256(FnmaHelper(a.Float0, b.Float0, c.Float0),
FnmaHelper(a.Float1, b.Float1, c.Float1),
FnmaHelper(a.Float2, b.Float2, c.Float2),
FnmaHelper(a.Float3, b.Float3, c.Float3),
FnmaHelper(a.Float4, b.Float4, c.Float4),
FnmaHelper(a.Float5, b.Float5, c.Float5),
FnmaHelper(a.Float6, b.Float6, c.Float6),
FnmaHelper(a.Float7, b.Float7, c.Float7));
}
///
/// Multiply the lower double-precision (64-bit) floating-point elements in a and b, and add the negated intermediate result to the lower element in c. Store the result in the lower element of dst, and copy the upper element from a to the upper element of dst.
///
///
/// **** vfnmadd213sd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fnmadd_sd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply the lower single-precision (32-bit) floating-point elements in a and b, and add the negated intermediate result to the lower element in c. Store the result in the lower element of dst, and copy the upper 3 packed elements from a to the upper elements of dst.
///
///
/// **** vfnmadd213ss xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fnmadd_ss(v128 a, v128 b, v128 c)
{
var result = a;
result.Float0 = FnmaHelper(a.Float0, b.Float0, c.Float0);
return result;
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, subtract packed elements in c from the negated intermediate result, and store the results in dst.
///
///
/// **** vfnmsub213pd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fnmsub_pd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed double-precision (64-bit) floating-point elements in a and b, subtract packed elements in c from the negated intermediate result, and store the results in dst.
///
///
/// **** vfnmsub213pd ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fnmsub_pd(v256 a, v256 b, v256 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, subtract packed elements in c from the negated intermediate result, and store the results in dst.
///
///
/// **** vfnmsub213ps xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fnmsub_ps(v128 a, v128 b, v128 c)
{
return new v128(FnmaHelper(a.Float0, b.Float0, -c.Float0),
FnmaHelper(a.Float1, b.Float1, -c.Float1),
FnmaHelper(a.Float2, b.Float2, -c.Float2),
FnmaHelper(a.Float3, b.Float3, -c.Float3));
}
///
/// Multiply packed single-precision (32-bit) floating-point elements in a and b, subtract packed elements in c from the negated intermediate result, and store the results in dst.
///
///
/// **** vfnmsub213ps ymm, ymm, ymm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v256 mm256_fnmsub_ps(v256 a, v256 b, v256 c)
{
return new v256(FnmaHelper(a.Float0, b.Float0, -c.Float0),
FnmaHelper(a.Float1, b.Float1, -c.Float1),
FnmaHelper(a.Float2, b.Float2, -c.Float2),
FnmaHelper(a.Float3, b.Float3, -c.Float3),
FnmaHelper(a.Float4, b.Float4, -c.Float4),
FnmaHelper(a.Float5, b.Float5, -c.Float5),
FnmaHelper(a.Float6, b.Float6, -c.Float6),
FnmaHelper(a.Float7, b.Float7, -c.Float7));
}
///
/// Multiply the lower double-precision(64-bit) floating-point elements in a and b, and subtract the lower element in c from the negated intermediate result.Store the result in the lower element of dst, and copy the upper element from a to the upper element of dst.
///
///
/// **** vfnmsub213sd xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fnmsub_sd(v128 a, v128 b, v128 c)
{
throw new Exception("Double-precision FMA not emulated in C#");
}
///
/// Multiply the lower single-precision (32-bit) floating-point elements in a and b, and subtract the lower element in c from the negated intermediate result. Store the result in the lower element of dst, and copy the upper 3 packed elements from a to the upper elements of dst.
///
///
/// **** vfnmsub213ss xmm, xmm, xmm
///
/// Vector a
/// Vector b
/// Vector c
/// Vector
[DebuggerStepThrough]
public static v128 fnmsub_ss(v128 a, v128 b, v128 c)
{
var result = a;
result.Float0 = FnmaHelper(a.Float0, b.Float0, -c.Float0);
return result;
}
}
}
}