Enhance mathematical capabilities and job system

Added new numeric types for unsigned integers, including uint2, uint3, and uint4, along with their matrix types.
Added a new `quaternion` struct with constructors and methods for creating and manipulating quaternions.
Added methods for projecting and reflecting vectors, enhancing geometric operations.
Added utility functions for generating orthonormal bases and changing vector signs.
Added comprehensive unit tests for new mathematical functions and quaternion operations.
Added a high-performance job scheduling system with job management features and worker thread management.
Added new structs for job execution, allowing efficient job scheduling and execution.
Added utility functions for job execution, including methods for obtaining unique job IDs.

Changed access modifiers and property definitions in several files for improved clarity and maintainability.
Changed property definitions and method implementations in `ImageInfo.cs`, `ImageResult.cs`, and `ImageResultFloat.cs` for better readability.
Changed memory management functions in `CRuntime.cs` and improved memory allocation tracking in `MemoryStats.cs`.
Changed the project file to include references to necessary projects and enable unsafe code blocks.

Removed the `WorkerThreadPool.cs` file, integrating worker thread management directly into the `JobScheduler`.
Removed the `float4` struct and its associated methods and properties, transitioning to a new code generation strategy.
Removed the `float4.tt` template and other related files, indicating a shift in code generation approach.
Removed the `Vectorize.cs` file, indicating a change in how vector operations are handled.

Updated the `.gitignore` file to include IDE-specific settings.
Updated various XML files to define project components and structure.
Updated the `AllocationManager.cs` to improve memory allocation management and introduce new strategies.
Updated the `UnsafeArray.cs`, `UnsafeHashMap.cs`, and `UnsafeList.cs` to enhance performance and safety in unsafe contexts.
Updated error handling and function pointer management in `MemoryLeakException.cs` and `FunctionPointer.cs`.
Updated the `AssemblyInfo.cs` file to include global using directives for better code organization.
This commit is contained in:
2025-09-06 12:07:02 +09:00
parent eeff3313b5
commit a2a760594e
114 changed files with 20826 additions and 7217 deletions

View File

@@ -1,186 +1,188 @@
using System;
using System.Runtime.InteropServices;
namespace Misaki.HighPerformance.Image.Runtime
namespace Misaki.HighPerformance.Image.Runtime;
internal static unsafe class CRuntime
{
internal static unsafe class CRuntime
private static readonly string numbers = "0123456789";
public static void* malloc(ulong size)
{
private static readonly string numbers = "0123456789";
return malloc((long)size);
}
public static void* malloc(ulong size)
public static void* malloc(long size)
{
var ptr = NativeMemory.Alloc((nuint)size);
MemoryStats.Allocated();
return ptr;
}
public static void free(void* ptr)
{
if (ptr == null)
return;
NativeMemory.Free(ptr);
MemoryStats.Freed();
}
public static void memcpy(void* a, void* b, long size)
{
NativeMemory.Copy(b, a, (nuint)size);
}
public static void memcpy(void* a, void* b, ulong size)
{
memcpy(a, b, (long)size);
}
public static void memmove(void* a, void* b, long size)
{
void* temp = null;
try
{
return malloc((long)size);
temp = malloc(size);
memcpy(temp, b, size);
memcpy(a, temp, size);
}
public static void* malloc(long size)
finally
{
var ptr = NativeMemory.Alloc((nuint)size);
MemoryStats.Allocated();
return ptr;
}
public static void free(void* ptr)
{
if (ptr == null)
return;
NativeMemory.Free(ptr);
MemoryStats.Freed();
}
public static void memcpy(void* a, void* b, long size)
{
NativeMemory.Copy(b, a, (nuint)size);
}
public static void memcpy(void* a, void* b, ulong size)
{
memcpy(a, b, (long)size);
}
public static void memmove(void* a, void* b, long size)
{
void* temp = null;
try
{
temp = malloc(size);
memcpy(temp, b, size);
memcpy(a, temp, size);
}
finally
{
if (temp != null)
free(temp);
}
}
public static int memcmp(void* a, void* b, long size)
{
var result = 0;
var ap = (byte*)a;
var bp = (byte*)b;
for (long i = 0; i < size; ++i)
{
if (*ap != *bp)
result += 1;
ap++;
bp++;
}
return result;
}
public static void memset(void* ptr, int value, long size)
{
NativeMemory.Fill(ptr, (nuint)size, (byte)value);
}
public static void memset(void* ptr, int value, ulong size)
{
memset(ptr, value, (long)size);
}
public static uint _lrotl(uint x, int y)
{
return x << y | x >> 32 - y;
}
public static void* realloc(void* ptr, long newSize)
{
if (ptr == null)
return malloc(newSize);
var result = NativeMemory.Realloc(ptr, (nuint)newSize);
return result;
}
public static void* realloc(void* a, ulong newSize)
{
return realloc(a, (long)newSize);
}
public static int abs(int v)
{
return Math.Abs(v);
}
public static double pow(double a, double b)
{
return Math.Pow(a, b);
}
public static double ldexp(double number, int exponent)
{
return number * Math.Pow(2, exponent);
}
public static int strcmp(sbyte* src, string token)
{
var result = 0;
for (var i = 0; i < token.Length; ++i)
{
if (src[i] != token[i])
{
++result;
}
}
return result;
}
public static int strncmp(sbyte* src, string token, ulong size)
{
var result = 0;
for (var i = 0; i < Math.Min(token.Length, (int)size); ++i)
{
if (src[i] != token[i])
{
++result;
}
}
return result;
}
public static long strtol(sbyte* start, sbyte** end, int radix)
{
// First step - determine length
var length = 0;
var ptr = start;
while (numbers.IndexOf((char)*ptr) != -1)
{
++ptr;
++length;
}
long result = 0;
// Now build up the number
ptr = start;
while (length > 0)
{
long num = numbers.IndexOf((char)*ptr);
var pow = (long)Math.Pow(10, length - 1);
result += num * pow;
++ptr;
--length;
}
if (end != null)
{
*end = ptr;
}
return result;
if (temp != null)
free(temp);
}
}
public static int memcmp(void* a, void* b, long size)
{
var result = 0;
var ap = (byte*)a;
var bp = (byte*)b;
for (long i = 0; i < size; ++i)
{
if (*ap != *bp)
result += 1;
ap++;
bp++;
}
return result;
}
public static void memset(void* ptr, int value, long size)
{
var bptr = (byte*)ptr;
var bval = (byte)value;
for (long i = 0; i < size; ++i)
*bptr++ = bval;
}
public static void memset(void* ptr, int value, ulong size)
{
memset(ptr, value, (long)size);
}
public static uint _lrotl(uint x, int y)
{
return (x << y) | (x >> (32 - y));
}
public static void* realloc(void* ptr, long newSize)
{
if (ptr == null)
return malloc(newSize);
var result = NativeMemory.Realloc(ptr, (nuint)newSize);
return result;
}
public static void* realloc(void* a, ulong newSize)
{
return realloc(a, (long)newSize);
}
public static int abs(int v)
{
return Math.Abs(v);
}
public static double pow(double a, double b)
{
return Math.Pow(a, b);
}
public static double ldexp(double number, int exponent)
{
return number * Math.Pow(2, exponent);
}
public static int strcmp(sbyte* src, string token)
{
var result = 0;
for (var i = 0; i < token.Length; ++i)
{
if (src[i] != token[i])
{
++result;
}
}
return result;
}
public static int strncmp(sbyte* src, string token, ulong size)
{
var result = 0;
for (var i = 0; i < Math.Min(token.Length, (int)size); ++i)
{
if (src[i] != token[i])
{
++result;
}
}
return result;
}
public static long strtol(sbyte* start, sbyte** end, int radix)
{
// First step - determine length
var length = 0;
var ptr = start;
while (numbers.IndexOf((char)*ptr) != -1)
{
++ptr;
++length;
}
long result = 0;
// Now build up the number
ptr = start;
while (length > 0)
{
long num = numbers.IndexOf((char)*ptr);
var pow = (long)Math.Pow(10, length - 1);
result += num * pow;
++ptr;
--length;
}
if (end != null)
{
*end = ptr;
}
return result;
}
}

View File

@@ -2,26 +2,26 @@
namespace Misaki.HighPerformance.Image.Runtime
{
internal unsafe static class MemoryStats
{
private static int _allocations;
public static int Allocations
{
get
{
return _allocations;
}
}
internal unsafe static class MemoryStats
{
private static int _allocations;
internal static void Allocated()
{
Interlocked.Increment(ref _allocations);
}
public static int Allocations
{
get
{
return _allocations;
}
}
internal static void Freed()
{
Interlocked.Decrement(ref _allocations);
}
}
internal static void Allocated()
{
Interlocked.Increment(ref _allocations);
}
internal static void Freed()
{
Interlocked.Decrement(ref _allocations);
}
}
}

View File

@@ -1,16 +1,16 @@
namespace Misaki.HighPerformance.Image.Runtime
{
internal class Utility
{
public static T[][] CreateArray<T>(int d1, int d2)
{
var result = new T[d1][];
for (var i = 0; i < d1; i++)
{
result[i] = new T[d2];
}
internal class Utility
{
public static T[][] CreateArray<T>(int d1, int d2)
{
var result = new T[d1][];
for (var i = 0; i < d1; i++)
{
result[i] = new T[d2];
}
return result;
}
}
return result;
}
}
}