Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- using System.Runtime.Intrinsics;
- using System.Runtime.Intrinsics.X86;
- namespace System.Numerics.System.Numerics
- {
- internal static class VectorMath
- {
- public static Vector128<float> Lerp(Vector128<float> a, Vector128<float> b, Vector128<float> t)
- {
- if (Fma.IsSupported)
- {
- return Fma.MultiplyAdd(Sse.Subtract(b, a), t, a);
- }
- else if (Sse.IsSupported)
- {
- return Sse.Add(a, Sse.Multiply(Sse.Subtract(b, a), t));
- }
- else
- {
- throw new NotSupportedException();
- }
- }
- public static bool Equal(Vector128<float> vector1, Vector128<float> vector2)
- {
- if (Sse.IsSupported)
- {
- return Sse.MoveMask(Sse.CompareNotEqual(vector1, vector2)) == 0;
- }
- else
- {
- throw new NotSupportedException();
- }
- }
- public static unsafe float HorizontalSum(Vector128<float> vector)
- {
- if (Sse3.IsSupported)
- {
- var ha = Sse3.HorizontalAdd(vector, vector);
- ha = Sse3.HorizontalAdd(ha, ha);
- return Sse.ConvertToSingle(ha);
- }
- else if (Sse.IsSupported)
- {
- float* values = stackalloc float[4];
- Sse.Store(values, vector);
- return values[0] + values[1] + values[2] + values[4];
- }
- else
- {
- throw new NotSupportedException();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment