mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 16:15:41 +00:00
[ci skip] style: reformat & cleanup solution
This commit is contained in:
parent
436f56d912
commit
4dd31ec1b6
@ -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<bool> span = stackalloc bool[8] { true, true, false, false, true, true, false, false };
|
||||
Span<bool> 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<bool> span = stackalloc bool[16] {
|
||||
false, false, true, false, true, false, true, true,
|
||||
true, false, true, true, false, true, false, false,
|
||||
ReadOnlySpan<bool> 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<bool> 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<bool> 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<bool> 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<bool> 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());
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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()));
|
||||
|
@ -66,7 +66,6 @@ public static class Vector4Extensions
|
||||
public static System.Numerics.Vector4 ToSystemVector(this Vector4 vector)
|
||||
{
|
||||
return UnsafeUtility.As<Vector4, System.Numerics.Vector4>(ref vector);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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<bool> destination)
|
||||
{
|
||||
fixed (bool* pDestination = destination)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ public static class SpanExtensions
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
private const ulong IntegerPackingMagic = 0x0102040810204080;
|
||||
|
||||
private static Vector64<ulong> 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<byte> 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).
|
||||
|
@ -84,7 +84,8 @@ public static class RuneExtensions
|
||||
{
|
||||
return string.Create(count * 2, value, (span, rune) =>
|
||||
{
|
||||
unsafe {
|
||||
unsafe
|
||||
{
|
||||
Span<byte> bytes = stackalloc byte[4];
|
||||
value.EncodeToUtf8(bytes);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user