Some checks failed
Publish NuGet Packages / publish (push) Failing after 3m12s
Refactored `sincos` usage across `quaternion` and `random` to use `out` parameters for improved performance. Enhanced `random` struct with updated random direction generation methods. Added new benchmarks in `MathematicsBenchmark` for vector operations, including SIMD-based `f4` struct. Downgraded target framework to `net9.0` for compatibility. Introduced `ReadOnlyUnsafeCollection` for low-level memory management. Added utility methods in `CollectionUtility` for span creation and optimized list operations. Renamed `MemoryUtilities` to `MemoryUtility` and updated all references. Enhanced `ObjectPool` with `Rent` and `TryRent` methods. Enabled `AllowUnsafeBlocks` and AOT compatibility in project configuration. Performed general code cleanup, including removal of unused methods, improved formatting, and alignment with modern coding practices.
93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
using Microsoft.CodeAnalysis;
|
|
using Misaki.HighPerformance.Mathematics.CodeGen.Models;
|
|
using System.Text;
|
|
|
|
namespace Misaki.HighPerformance.Mathematics.CodeGen.Generators
|
|
{
|
|
internal abstract class GeneratorBase
|
|
{
|
|
protected const string INLINE_METHOD_ATTRIBUTE = "[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining | global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveOptimization)]";
|
|
|
|
protected static readonly string[] s_matrixComponents = new[] { "c0", "c1", "c2", "c3" };
|
|
protected static readonly string[] s_vectorComponents = new[] { "x", "y", "z", "w" };
|
|
|
|
protected readonly StringBuilder sourceBuilder = new();
|
|
protected NumericTypeInfo typeInfo = null!;
|
|
|
|
public string Generate(NumericTypeInfo typeInfo)
|
|
{
|
|
this.typeInfo = typeInfo;
|
|
sourceBuilder.Clear();
|
|
|
|
Initialize();
|
|
|
|
GenerateHeader();
|
|
GenerateNamespaceStart();
|
|
GenerateTypeStart();
|
|
|
|
GenerateBody();
|
|
|
|
GenerateTypeEnd();
|
|
GenerateNamespaceEnd();
|
|
|
|
return sourceBuilder.ToString();
|
|
}
|
|
|
|
protected void StartRegion(string name)
|
|
{
|
|
sourceBuilder.AppendLine($@"
|
|
#region {name}");
|
|
}
|
|
|
|
protected void EndRegion()
|
|
{
|
|
sourceBuilder.AppendLine($@"
|
|
#endregion");
|
|
}
|
|
|
|
protected virtual void Initialize()
|
|
{
|
|
}
|
|
|
|
protected virtual void GenerateHeader()
|
|
{
|
|
sourceBuilder.AppendLine(@"// <auto-generated>
|
|
// This code is generated by tool. Do not edit manually.
|
|
// Update this file may introduce incorrect behavior and will be lost if the code is regenerated.
|
|
// To update this file, edit the generator in the Misaki.HighPerformance.Mathematics.CodeGen and recompile it.
|
|
// </auto-generated>
|
|
");
|
|
sourceBuilder.AppendLine("#nullable enable");
|
|
}
|
|
|
|
protected virtual void GenerateNamespaceStart()
|
|
{
|
|
sourceBuilder.Append($@"
|
|
namespace {typeInfo.TypeSymbol.ContainingNamespace.ToDisplayString()}
|
|
{{");
|
|
}
|
|
|
|
protected virtual void GenerateTypeStart()
|
|
{
|
|
sourceBuilder.Append($@"
|
|
//[global::System.Runtime.CompilerServices.SkipLocalsInit]
|
|
public partial struct {typeInfo.TypeSymbol.Name} : global::System.IEquatable<{typeInfo.TypeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>
|
|
{{");
|
|
}
|
|
|
|
protected abstract void GenerateBody();
|
|
|
|
protected virtual void GenerateTypeEnd()
|
|
{
|
|
sourceBuilder.Append($@"
|
|
}}");
|
|
}
|
|
|
|
protected virtual void GenerateNamespaceEnd()
|
|
{
|
|
sourceBuilder.Append($@"
|
|
}}");
|
|
}
|
|
}
|
|
}
|