Refactor and enhance math utilities and code generation
Refactored `StbImage` classes to be publicly accessible. Updated namespaces and introduced `NumericTypeAttribute` for metadata. Enhanced `VectorGenerator` with new utility methods (`any`, `all`, `length`, etc.) and improved code generation. Consolidated vector operations in `math` utilities. Refactored `Plane` and `svd` classes for better encapsulation and readability. Improved `DynamicArray` with `uint` indexer support and cleaner loops. Added SIMD-based benchmarking placeholders in `MathematicsBenchmark`. Removed redundant code and unused files, including `IUnsafeSet.cs`. Updated project file to include `CodeGen` as an analyzer. Introduced `SupportedVectorMath` and `SupportedMatrixMath` enums for better operation definitions. Improved code style, fixed minor bugs, and cleaned up unused code in `Program.cs`. Enhanced maintainability and readability across the codebase.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Misaki.HighPerformance.Mathematics;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
|
||||
namespace Misaki.HighPerformance.Test.Benchmark;
|
||||
|
||||
@@ -9,13 +12,18 @@ public class MathematicsBenchmark
|
||||
[Params(10)]
|
||||
public int count = 10;
|
||||
|
||||
private unsafe static Vector128<float> CreateVector128(float2 value)
|
||||
{
|
||||
return Vector128.AsSingle(Sse2.LoadScalarVector128((double*)&value));
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void Vector2Add()
|
||||
{
|
||||
var a = new Vector2(1, 2);
|
||||
var b = new Vector2(5, 6);
|
||||
var result = new Vector2();
|
||||
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
result += a + b;
|
||||
@@ -28,14 +36,18 @@ public class MathematicsBenchmark
|
||||
var a = new float2(1, 2);
|
||||
var b = new float2(5, 6);
|
||||
var result = new float2();
|
||||
//var vr = CreateVector128(result);
|
||||
//var va = CreateVector128(a);
|
||||
//var vb = CreateVector128(b);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
result += a + b;
|
||||
//vr = Sse.Add(va, vb);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
//[Benchmark]
|
||||
public void Vector4Add()
|
||||
{
|
||||
var a = new Vector4(1, 2, 3, 4);
|
||||
@@ -48,7 +60,7 @@ public class MathematicsBenchmark
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
//[Benchmark]
|
||||
public void Float4Add()
|
||||
{
|
||||
var a = new float4(1, 2, 3, 4);
|
||||
|
||||
@@ -18,23 +18,24 @@
|
||||
|
||||
//Console.WriteLine($"Count should be {threadCount * 990}, actual: {map.Count}");
|
||||
|
||||
//using Misaki.HighPerformance.Test.Benchmark;
|
||||
using Misaki.HighPerformance.Test.Benchmark;
|
||||
|
||||
//BenchmarkDotNet.Running.BenchmarkRunner.Run<MathematicsBenchmark>();
|
||||
BenchmarkDotNet.Running.BenchmarkRunner.Run<MathematicsBenchmark>();
|
||||
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
//using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
//using Misaki.HighPerformance.LowLevel.Collections;
|
||||
//using Misaki.HighPerformance.LowLevel.Utilities;
|
||||
|
||||
var scope = AllocationManager.CreateStackScope();
|
||||
var array = new UnsafeArray<int>(10, Allocator.Stack);
|
||||
for (var i = 0; i < array.Count; i++)
|
||||
{
|
||||
array[i] = i;
|
||||
}
|
||||
//using (AllocationManager.CreateStackScope())
|
||||
//{
|
||||
// var array = new UnsafeArray<int>(10, Allocator.Stack);
|
||||
// for (var i = 0; i < array.Count; i++)
|
||||
// {
|
||||
// array[i] = i;
|
||||
// }
|
||||
|
||||
foreach (var item in array)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
|
||||
scope.Dispose();
|
||||
// foreach (var item in array.AsSpan())
|
||||
// {
|
||||
// Console.WriteLine(item);
|
||||
// }
|
||||
//}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Misaki.HighPerformance.Mathematics;
|
||||
|
||||
namespace Misaki.HighPerformance.Test.UnitTest.Mathematics;
|
||||
|
||||
Reference in New Issue
Block a user