|
|
|
@ -749,6 +749,7 @@ namespace SixLabors.ImageSharp |
|
|
|
public static float Lerp(float value1, float value2, float amount) |
|
|
|
=> ((value2 - value1) * amount) + value1; |
|
|
|
|
|
|
|
#if SUPPORTS_RUNTIME_INTRINSICS
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static void Accumulate(ref Vector<uint> accumulator, Vector<byte> values) |
|
|
|
{ |
|
|
|
@ -762,5 +763,50 @@ namespace SixLabors.ImageSharp |
|
|
|
accumulator += intLow; |
|
|
|
accumulator += intHigh; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reduces elements of the vector into one sum.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="accumulator">The accumulator to reduce.</param>
|
|
|
|
/// <returns>The sum of all elements.</returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static int ReduceSum(Vector128<int> accumulator) |
|
|
|
{ |
|
|
|
if (Ssse3.IsSupported) |
|
|
|
{ |
|
|
|
Vector128<int> hadd = Ssse3.HorizontalAdd(accumulator, accumulator); |
|
|
|
Vector128<int> swapped = Sse2.Shuffle(hadd, 0x1); |
|
|
|
Vector128<int> tmp = Sse2.Add(hadd, swapped); |
|
|
|
|
|
|
|
// Vector128<int>.ToScalar() isn't optimized pre-net5.0 https://github.com/dotnet/runtime/pull/37882
|
|
|
|
return Sse2.ConvertToInt32(tmp); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
int sum = 0; |
|
|
|
for (int i = 0; i < Vector128<int>.Count; i++) |
|
|
|
{ |
|
|
|
sum += accumulator.GetElement(i); |
|
|
|
} |
|
|
|
|
|
|
|
return sum; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reduces even elements of the vector into one sum.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="accumulator">The accumulator to reduce.</param>
|
|
|
|
/// <returns>The sum of even elements.</returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static int EvenReduceSum(Vector256<int> accumulator) |
|
|
|
{ |
|
|
|
Vector128<int> vsum = Sse2.Add(accumulator.GetLower(), accumulator.GetUpper()); // add upper lane to lower lane
|
|
|
|
vsum = Sse2.Add(vsum, Sse2.Shuffle(vsum, 0b_11_10_11_10)); // add high to low
|
|
|
|
|
|
|
|
// Vector128<int>.ToScalar() isn't optimized pre-net5.0 https://github.com/dotnet/runtime/pull/37882
|
|
|
|
return Sse2.ConvertToInt32(vsum); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
} |
|
|
|
} |
|
|
|
|