From 4dd31ec1b6bc07543d9309e6a66f7ba940f4d0fa Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 29 Mar 2023 17:46:56 +0100 Subject: [PATCH] [ci skip] style: reformat & cleanup solution --- X10D.Tests/src/Core/SpanTest.cs | 34 +++++++++----------- X10D.Tests/src/Drawing/CuboidTests.cs | 2 +- X10D.Tests/src/Drawing/EllipseFTests.cs | 4 +-- X10D.Tests/src/Drawing/EllipseTests.cs | 2 +- X10D.Tests/src/Numerics/Vector2Tests.cs | 4 +-- X10D.Unity/src/Numerics/Vector4Extensions.cs | 1 - X10D/src/Collections/Int32Extensions.cs | 2 ++ X10D/src/Core/IntrinsicUtility.cs | 4 +-- X10D/src/Core/SpanExtensions.cs | 8 +++-- X10D/src/Text/RuneExtensions.cs | 3 +- 10 files changed, 33 insertions(+), 31 deletions(-) diff --git a/X10D.Tests/src/Core/SpanTest.cs b/X10D.Tests/src/Core/SpanTest.cs index 489ed18..a92befd 100644 --- a/X10D.Tests/src/Core/SpanTest.cs +++ b/X10D.Tests/src/Core/SpanTest.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using X10D.Collections; using X10D.Core; @@ -10,7 +10,7 @@ public class SpanTest [TestMethod] public void Pack8Bit_Should_Pack_Correctly() { - Span span = stackalloc bool[8] { true, true, false, false, true, true, false, false }; + Span span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; Assert.AreEqual(0b00110011, span.PackByte()); } @@ -29,9 +29,9 @@ public class SpanTest [TestMethod] public void Pack16Bit_Should_Pack_Correctly() { - ReadOnlySpan span = stackalloc bool[16] { - false, false, true, false, true, false, true, true, - true, false, true, true, false, true, false, false, + ReadOnlySpan span = stackalloc bool[16] + { + false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false, }; Assert.AreEqual(0b00101101_11010100, span.PackInt16()); } @@ -51,11 +51,10 @@ public class SpanTest [TestMethod] public void Pack32Bit_Should_Pack_Correctly() { - ReadOnlySpan span = stackalloc bool[] { - false, true, false, true, false, true, false, true, - true, false, true, false, true, false, true, false, - false, true, false, true, false, true, false, true, - true, false, true, false, true, false, true, false, + ReadOnlySpan span = stackalloc bool[] + { + false, true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, false, + true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, }; Assert.AreEqual(0b01010101_10101010_01010101_10101010, span.PackInt32()); } @@ -75,15 +74,12 @@ public class SpanTest [TestMethod] public void Pack64Bit_Should_Pack_Correctly() { - ReadOnlySpan span = stackalloc bool[] { - true, false, true, false, false, true, false, true, - false, false, true, true, false, true, false, false, - true, true, true, false, true, false, false, true, - false, true, false, false, true, false, false, false, - false, true, true, false, true, false, true, true, - true, false, false, true, false, true, true, false, - false, true, true, false, true, false, true, true, - true, false, true, false, true, false, true, false, + ReadOnlySpan span = stackalloc bool[] + { + true, false, true, false, false, true, false, true, false, false, true, true, false, true, false, false, true, + true, true, false, true, false, false, true, false, true, false, false, true, false, false, false, false, true, + true, false, true, false, true, true, true, false, false, true, false, true, true, false, false, true, true, + false, true, false, true, true, true, false, true, false, true, false, true, false, }; Assert.AreEqual(0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101, span.PackInt64()); } diff --git a/X10D.Tests/src/Drawing/CuboidTests.cs b/X10D.Tests/src/Drawing/CuboidTests.cs index d879a5b..3966af3 100644 --- a/X10D.Tests/src/Drawing/CuboidTests.cs +++ b/X10D.Tests/src/Drawing/CuboidTests.cs @@ -11,7 +11,7 @@ public class CuboidTests public void Corners_ShouldBeCorrect_GivenCubeOfSize1() { Cuboid cube = Cuboid.Cube; - + Assert.AreEqual(new Vector3(0.5f, 0.5f, -0.5f), cube.FrontTopRight); Assert.AreEqual(new Vector3(-0.5f, 0.5f, -0.5f), cube.FrontTopLeft); Assert.AreEqual(new Vector3(0.5f, -0.5f, -0.5f), cube.FrontBottomRight); diff --git a/X10D.Tests/src/Drawing/EllipseFTests.cs b/X10D.Tests/src/Drawing/EllipseFTests.cs index 750e900..43d24a4 100644 --- a/X10D.Tests/src/Drawing/EllipseFTests.cs +++ b/X10D.Tests/src/Drawing/EllipseFTests.cs @@ -32,11 +32,11 @@ public class EllipseFTests ellipse = new EllipseF(0, 0, 2, 1); Assert.AreEqual(new PointF(0, 0), ellipse.Center); Assert.AreEqual(new SizeF(2, 1), ellipse.Radius); - + ellipse = new EllipseF(PointF.Empty, new Vector2(2, 1)); Assert.AreEqual(new PointF(0, 0), ellipse.Center); Assert.AreEqual(new SizeF(2, 1), ellipse.Radius); - + ellipse = new EllipseF(Vector2.Zero, new Vector2(2, 1)); Assert.AreEqual(new PointF(0, 0), ellipse.Center); Assert.AreEqual(new SizeF(2, 1), ellipse.Radius); diff --git a/X10D.Tests/src/Drawing/EllipseTests.cs b/X10D.Tests/src/Drawing/EllipseTests.cs index 4ee2132..83f37a6 100644 --- a/X10D.Tests/src/Drawing/EllipseTests.cs +++ b/X10D.Tests/src/Drawing/EllipseTests.cs @@ -27,7 +27,7 @@ public class EllipseTests var ellipse = new Ellipse(Point.Empty, new Size(2, 1)); Assert.AreEqual(new Point(0, 0), ellipse.Center); Assert.AreEqual(new Size(2, 1), ellipse.Radius); - + ellipse = new Ellipse(0, 0, 2, 1); Assert.AreEqual(new Point(0, 0), ellipse.Center); Assert.AreEqual(new Size(2, 1), ellipse.Radius); diff --git a/X10D.Tests/src/Numerics/Vector2Tests.cs b/X10D.Tests/src/Numerics/Vector2Tests.cs index 941b13f..e2e5a7b 100644 --- a/X10D.Tests/src/Numerics/Vector2Tests.cs +++ b/X10D.Tests/src/Numerics/Vector2Tests.cs @@ -26,7 +26,7 @@ public class Vector2Tests Vector2 end = Vector2.UnitX; Vector2 point = new Vector2(0.5f, 0.0f); var line = new LineF(start, end); - + Assert.IsTrue(point.IsOnLine(line)); Assert.IsTrue(point.IsOnLine(line.Start, line.End)); Assert.IsTrue(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); @@ -39,7 +39,7 @@ public class Vector2Tests Vector2 end = Vector2.UnitX; Vector2 point = new Vector2(0.5f, 1.0f); var line = new LineF(start, end); - + Assert.IsFalse(point.IsOnLine(line)); Assert.IsFalse(point.IsOnLine(line.Start, line.End)); Assert.IsFalse(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); diff --git a/X10D.Unity/src/Numerics/Vector4Extensions.cs b/X10D.Unity/src/Numerics/Vector4Extensions.cs index 3b8cb95..e17ba25 100644 --- a/X10D.Unity/src/Numerics/Vector4Extensions.cs +++ b/X10D.Unity/src/Numerics/Vector4Extensions.cs @@ -66,7 +66,6 @@ public static class Vector4Extensions public static System.Numerics.Vector4 ToSystemVector(this Vector4 vector) { return UnsafeUtility.As(ref vector); - } /// diff --git a/X10D/src/Collections/Int32Extensions.cs b/X10D/src/Collections/Int32Extensions.cs index f6e8fd7..08cd006 100644 --- a/X10D/src/Collections/Int32Extensions.cs +++ b/X10D/src/Collections/Int32Extensions.cs @@ -49,6 +49,7 @@ public static class Int32Extensions Avx2Implementation(value, destination); return; } + if (Ssse3.IsSupported) { Ssse3Implementation(value, destination); @@ -85,6 +86,7 @@ public static class Int32Extensions Avx.Store((byte*)pDestination, correctness); } } + unsafe static void Ssse3Implementation(int value, Span destination) { fixed (bool* pDestination = destination) diff --git a/X10D/src/Core/IntrinsicUtility.cs b/X10D/src/Core/IntrinsicUtility.cs index b94edd1..94d5fd5 100644 --- a/X10D/src/Core/IntrinsicUtility.cs +++ b/X10D/src/Core/IntrinsicUtility.cs @@ -187,8 +187,8 @@ public static class IntrinsicUtility { if (Sse.IsSupported) { - var s1 = Sse.Shuffle(lhs, rhs, 0b10_00_10_00); // s1 = { lhs[0] ; lhs[2] ; rhs[0] ; rhs[2] } - var s2 = Sse.Shuffle(lhs, rhs, 0b11_01_11_01); // s2 = { lhs[1] ; lhs[3] ; rhs[1] ; rhs[3] } + var s1 = Sse.Shuffle(lhs, rhs, 0b10_00_10_00); // s1 = { lhs[0] ; lhs[2] ; rhs[0] ; rhs[2] } + var s2 = Sse.Shuffle(lhs, rhs, 0b11_01_11_01); // s2 = { lhs[1] ; lhs[3] ; rhs[1] ; rhs[3] } return Sse.Or(s1, s2); } diff --git a/X10D/src/Core/SpanExtensions.cs b/X10D/src/Core/SpanExtensions.cs index dedf5bb..2c7fcf1 100644 --- a/X10D/src/Core/SpanExtensions.cs +++ b/X10D/src/Core/SpanExtensions.cs @@ -22,6 +22,7 @@ public static class SpanExtensions { #if NETCOREAPP3_0_OR_GREATER private const ulong IntegerPackingMagic = 0x0102040810204080; + private static Vector64 IntegerPackingMagicV64 { get => Vector64.Create(IntegerPackingMagic); @@ -174,7 +175,8 @@ public static class SpanExtensions goto default; } - fixed (bool* pSource = source) { + fixed (bool* pSource = source) + { // TODO: .NET 8.0 Wasm support. if (Sse2.IsSupported) @@ -235,7 +237,7 @@ public static class SpanExtensions switch (source.Length) { case > 16: throw new ArgumentException("Source cannot contain more than than 16 elements.", nameof(source)); - case 8: return PackByte(source); // Potential optimization + case 8: return PackByte(source); // Potential optimization case 16: #if NETSTANDARD2_1 @@ -336,6 +338,7 @@ public static class SpanExtensions return (int)or2.GetElement(0); } + if (Sse2.IsSupported) { Vector128 load = Sse2.LoadVector128((byte*)pSource); @@ -357,6 +360,7 @@ public static class SpanExtensions return (int)or2.GetElement(0); } + if (AdvSimd.IsSupported) { // Hasn't been tested since March 6th 2023 (Reason: Unavailable hardware). diff --git a/X10D/src/Text/RuneExtensions.cs b/X10D/src/Text/RuneExtensions.cs index 2562fd8..8261096 100644 --- a/X10D/src/Text/RuneExtensions.cs +++ b/X10D/src/Text/RuneExtensions.cs @@ -84,7 +84,8 @@ public static class RuneExtensions { return string.Create(count * 2, value, (span, rune) => { - unsafe { + unsafe + { Span bytes = stackalloc byte[4]; value.EncodeToUtf8(bytes);