using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; namespace Robust.Shared.Maths { /// /// Helper stuff for SIMD code. /// internal static class SimdHelpers { /// The min value is broadcast to the whole vector. public static Vector128 MinHorizontalSse(Vector128 v) { var b = Sse.Shuffle(v, v, 0b10_11_00_01); var m = Sse.Min(b, v); var c = Sse.Shuffle(m, m, 0b01_00_11_10); return Sse.Min(c, m); } /// The max value is broadcast to the whole vector. public static Vector128 MaxHorizontalSse(Vector128 v) { var b = Sse.Shuffle(v, v, 0b10_11_00_01); var m = Sse.Max(b, v); var c = Sse.Shuffle(m, m, 0b01_00_11_10); return Sse.Max(c, m); } } }