Guest User

Untitled

a guest
Aug 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4.  
  5. using System.Runtime.Intrinsics;
  6. using System.Runtime.Intrinsics.X86;
  7.  
  8. namespace System.Numerics.System.Numerics
  9. {
  10. internal static class VectorMath
  11. {
  12. public static Vector128<float> Lerp(Vector128<float> a, Vector128<float> b, Vector128<float> t)
  13. {
  14. if (Fma.IsSupported)
  15. {
  16. return Fma.MultiplyAdd(Sse.Subtract(b, a), t, a);
  17. }
  18. else if (Sse.IsSupported)
  19. {
  20. return Sse.Add(a, Sse.Multiply(Sse.Subtract(b, a), t));
  21. }
  22. else
  23. {
  24. throw new NotSupportedException();
  25. }
  26. }
  27.  
  28. public static bool Equal(Vector128<float> vector1, Vector128<float> vector2)
  29. {
  30. if (Sse.IsSupported)
  31. {
  32. return Sse.MoveMask(Sse.CompareNotEqual(vector1, vector2)) == 0;
  33. }
  34. else
  35. {
  36. throw new NotSupportedException();
  37. }
  38. }
  39.  
  40. public static unsafe float HorizontalSum(Vector128<float> vector)
  41. {
  42. if (Sse3.IsSupported)
  43. {
  44. var ha = Sse3.HorizontalAdd(vector, vector);
  45. ha = Sse3.HorizontalAdd(ha, ha);
  46. return Sse.ConvertToSingle(ha);
  47. }
  48. else if (Sse.IsSupported)
  49. {
  50. float* values = stackalloc float[4];
  51. Sse.Store(values, vector);
  52. return values[0] + values[1] + values[2] + values[4];
  53. }
  54. else
  55. {
  56. throw new NotSupportedException();
  57. }
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment