SOURCE DUMP v1

This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit fb20299e9d
8 changed files with 768360 additions and 0 deletions

View file

@ -0,0 +1,48 @@
// <auto-generated /> - edit Matrix.access.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float4x4
{
/// <inheritdoc />
public float this[int row, int column]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get
{
if ((uint)row >= RowCount)
throw new ArgumentOutOfRangeException(nameof(row));
return Unsafe.Add(ref Unsafe.AsRef(in X), row)[column];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
if ((uint)row >= RowCount)
throw new ArgumentOutOfRangeException(nameof(row));
Unsafe.Add(ref X, row)[column] = value;
}
}
public readonly void Deconstruct(out float4 x, out float4 y, out float4 z, out float4 w)
{
x = X;
y = Y;
z = Z;
w = W;
}
public Span<float> AsSpan()
{
return MemoryMarshal.CreateSpan(ref Unsafe.As<float4x4, float>(ref this), 16);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<float> AsReadOnlySpan()
{
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<float4x4, float>(ref Unsafe.AsRef(in this)), 16);
}
}

View file

@ -0,0 +1,31 @@
// <auto-generated /> - edit Matrix.equality.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float4x4
{
/// <inheritdoc cref="Matrix4x4.Equals(object?)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override readonly bool Equals([NotNullWhen(true)] object? obj)
{
return obj is float4x4 other && Equals(other);
}
/// <inheritdoc cref="Matrix4x4.Equals(Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(float4x4 other)
{
// This function needs to account for floating-point equality around NaN
// and so must behave equivalently to the underlying float/float.Equals
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z) && W.Equals(other.W);
}
/// <inheritdoc cref="Matrix4x4.GetHashCode()" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override readonly int GetHashCode()
{
return HashCode.Combine(X, Y, Z, W);
}
}

View file

@ -0,0 +1,19 @@
// <auto-generated /> - edit Matrix.format.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float4x4
{
/// <inheritdoc />
public readonly string ToString(string? format, IFormatProvider? formatProvider)
{
return $"{{ X:{X.ToString(format, formatProvider)}, Y:{Y.ToString(format, formatProvider)}, Z:{Z.ToString(format, formatProvider)}, W:{W.ToString(format, formatProvider)} }}";
}
/// <inheritdoc />
public readonly override string ToString()
{
return $"{{ X:{X}, Y:{Y}, Z:{Z}, W:{W} }}";
}
}

View file

@ -0,0 +1,197 @@
// <auto-generated /> - edit Matrix.tt to modify
#nullable enable
namespace Brutal.Numerics;
/// <summary>
/// Implements a 4x4 matrix with float components.
/// </summary>
[DebuggerTypeProxy(typeof(DebugView))]
public partial struct float4x4 : IMatrix<float4x4, float>
, IFloatingMatrix4x4<float4x4, float, float3, float4, floatQuat>
{
internal class DebugView(float4x4 m)
{
public float4 X => m.X;
public float4 Y => m.Y;
public float4 Z => m.Z;
public float4 W => m.W;
}
/// <summary>The first row of the matrix.</summary>
[XmlIgnore]
public float4 X;
/// <summary>The second row of the matrix.</summary>
[XmlIgnore]
public float4 Y;
/// <summary>The third row of the matrix.</summary>
[XmlIgnore]
public float4 Z;
/// <summary>The fourth row of the matrix.</summary>
[XmlIgnore]
public float4 W;
/// <inheritdoc cref="Matrix4x4(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float4x4(
float m11,
float m12,
float m13,
float m14,
float m21,
float m22,
float m23,
float m24,
float m31,
float m32,
float m33,
float m34,
float m41,
float m42,
float m43,
float m44
)
{
X = new float4(m11, m12, m13, m14);
Y = new float4(m21, m22, m23, m24);
Z = new float4(m31, m32, m33, m34);
W = new float4(m41, m42, m43, m44);
}
/// <summary>Creates a matrix from the leading 16 elements of a span, row by row.</summary>
/// <param name="span">The elements to read; must contain at least 16, and any beyond that are ignored.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 16 elements.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float4x4(ReadOnlySpan<float> span)
{
if (span.Length < 16)
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 16.");
this = Unsafe.ReadUnaligned<float4x4>(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(span)));
}
/// <inheritdoc cref="Matrix4x4(Matrix3x2)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float4x4(float3x2 value)
{
X = new float4(value.X, 0, 0);
Y = new float4(value.Y, 0, 0);
Z = float4.UnitZ;
W = new float4(value.Z, 0, 1);
}
static float4x4 IMatrix<float4x4, float>.Create(ReadOnlySpan<float> span) => new(span);
/// <inheritdoc />
public static float4x4 Identity
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
float4x4 result;
result.X = float4.UnitX;
result.Y = float4.UnitY;
result.Z = float4.UnitZ;
result.W = float4.UnitW;
return result;
}
}
/// <inheritdoc />
public static int ComponentSize => sizeof(float);
/// <inheritdoc />
public static int RowCount => 4;
/// <inheritdoc />
public static int ColumnCount => 4;
/// <inheritdoc cref="Matrix4x4.IsIdentity" />
public readonly bool IsIdentity
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => X == float4.UnitX && Y == float4.UnitY && Z == float4.UnitZ && W == float4.UnitW;
}
/// <summary>The kernel view: the same 64/128 bytes as the row fields, seen as SIMD vectors.</summary>
private readonly struct Rows(Vector128<float> x, Vector128<float> y, Vector128<float> z, Vector128<float> w)
{
public readonly Vector128<float> X = x, Y = y, Z = z, W = w;
/// <summary>One row through this whole matrix: one multiply, three fused-estimate accumulations.</summary>
// fused-estimate is permitted to fuse: results may differ by an ulp between FMA and non-FMA hardware
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly Vector128<float> Transform(Vector128<float> row)
{
var result = X * row.GetElement(0);
result = Vector128.MultiplyAddEstimate(Y, Vector128.Create(row.GetElement(1)), result);
result = Vector128.MultiplyAddEstimate(Z, Vector128.Create(row.GetElement(2)), result);
result = Vector128.MultiplyAddEstimate(W, Vector128.Create(row.GetElement(3)), result);
return result;
}
}
[UnscopedRef]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private readonly ref readonly Rows AsRows()
{
return ref Unsafe.As<float4x4, Rows>(ref Unsafe.AsRef(in this));
}
/// <summary>The half-matrix view: rows 01 and 23 as one vector each - the width where a two-source lane mix is a single permute.</summary>
private readonly struct Halves(Vector256<float> lo, Vector256<float> hi)
{
public readonly Vector256<float> Lo = lo, Hi = hi;
}
/// <summary>Transpose in registers. net10 has no two-source shuffle (Zips are net11), so this rides WIDTH instead: at double the row width each transposed half is one permute per source half plus a blend.</summary>
// one index constant serves both sources - the don't-care lanes land under the blend mask;
// every arm is a JIT constant, so exactly one survives per machine
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float4x4 TransposeKernel(in float4x4 matrix)
{
if (Vector512.IsHardwareAccelerated)
{
// the whole matrix is one Vector512: transpose is ONE 16-lane permute
var whole = Unsafe.As<float4x4, Vector512<float>>(ref Unsafe.AsRef(in matrix));
var transposed = Vector512.ShuffleNative(whole, Vector512.Create(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15));
return Unsafe.BitCast<Vector512<float>, float4x4>(transposed);
}
if (Vector256.IsHardwareAccelerated)
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static ref readonly Halves AsHalves(in float4x4 value)
{
return ref Unsafe.As<float4x4, Halves>(ref Unsafe.AsRef(in value));
}
ref readonly var halves = ref AsHalves(in matrix);
var idxLo = Vector256.Create(0, 4, 0, 4, 1, 5, 1, 5);
var idxHi = Vector256.Create(2, 6, 2, 6, 3, 7, 3, 7);
var takeHi = Vector256.Create(0, 0, -1, -1, 0, 0, -1, -1).AsSingle();
var transposed = new Halves(
Vector256.ConditionalSelect(takeHi, Vector256.ShuffleNative(halves.Hi, idxLo), Vector256.ShuffleNative(halves.Lo, idxLo)),
Vector256.ConditionalSelect(takeHi, Vector256.ShuffleNative(halves.Hi, idxHi), Vector256.ShuffleNative(halves.Lo, idxHi)));
return Unsafe.BitCast<Halves, float4x4>(transposed);
}
// no accelerated width to widen into (arm64 tops out at V128): plain field shuffle
float4x4 result;
result.X = new float4(matrix.X.X, matrix.Y.X, matrix.Z.X, matrix.W.X);
result.Y = new float4(matrix.X.Y, matrix.Y.Y, matrix.Z.Y, matrix.W.Y);
result.Z = new float4(matrix.X.Z, matrix.Y.Z, matrix.Z.Z, matrix.W.Z);
result.W = new float4(matrix.X.W, matrix.Y.W, matrix.Z.W, matrix.W.W);
return result;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,100 @@
// <auto-generated /> - edit Matrix.operators.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float4x4
{
/// <inheritdoc cref="Matrix4x4.op_Addition(Matrix4x4, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float4x4 operator +(float4x4 left, float4x4 right)
{
float4x4 result;
result.X = left.X + right.X;
result.Y = left.Y + right.Y;
result.Z = left.Z + right.Z;
result.W = left.W + right.W;
return result;
}
/// <inheritdoc cref="Matrix4x4.op_Equality(Matrix4x4, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(float4x4 left, float4x4 right)
{
return left.X == right.X && left.Y == right.Y && left.Z == right.Z && left.W == right.W;
}
/// <inheritdoc cref="Matrix4x4.op_Inequality(Matrix4x4, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(float4x4 left, float4x4 right)
{
return left.X != right.X || left.Y != right.Y || left.Z != right.Z || left.W != right.W;
}
/// <inheritdoc cref="Matrix4x4.op_Multiply(Matrix4x4, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float4x4 operator *(float4x4 left, float4x4 right)
{
ref readonly var l = ref left.AsRows();
ref readonly var r = ref right.AsRows();
var result = new Rows(
r.Transform(l.X),
r.Transform(l.Y),
r.Transform(l.Z),
r.Transform(l.W));
return Unsafe.BitCast<Rows, float4x4>(result);
}
/// <inheritdoc cref="Multiply(float4x4, float4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float4 operator *(float4x4 matrix, float4 vector)
{
return Multiply(matrix, vector);
}
/// <inheritdoc cref="Matrix4x4.op_Multiply(Matrix4x4, float)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float4x4 operator *(float4x4 left, float right)
{
float4x4 result;
result.X = left.X * right;
result.Y = left.Y * right;
result.Z = left.Z * right;
result.W = left.W * right;
return result;
}
/// <inheritdoc cref="Matrix4x4.op_Subtraction(Matrix4x4, Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float4x4 operator -(float4x4 left, float4x4 right)
{
float4x4 result;
result.X = left.X - right.X;
result.Y = left.Y - right.Y;
result.Z = left.Z - right.Z;
result.W = left.W - right.W;
return result;
}
/// <inheritdoc cref="Matrix4x4.op_UnaryNegation(Matrix4x4)" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float4x4 operator -(float4x4 value)
{
float4x4 result;
result.X = -value.X;
result.Y = -value.Y;
result.Z = -value.Z;
result.W = -value.W;
return result;
}
}

View file

@ -0,0 +1,32 @@
// <auto-generated /> - edit Matrix.pack.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float4x4
{
public static float4x4 Pack(in double4x4 vector, Func<double, float> elementConverter)
{
MatrixPack.Pack(vector, out float4x4 result, elementConverter);
return result;
}
public static void Pack(
in ReadOnlySpan<double4x4> source,
Span<float4x4> destination,
Func<double, float> elementConverter
)
{
MatrixPack.Pack(source, destination, elementConverter);
}
public static float4x4 Pack(in double4x4 vector)
{
return Pack(vector, f => (float)f);
}
public static void Pack(in ReadOnlySpan<double4x4> source, Span<float4x4> destination)
{
Pack(source, destination, f => (float)f);
}
}

View file

@ -0,0 +1,135 @@
// <auto-generated /> - edit Matrix.swizzle.tt to modify
#nullable enable
namespace Brutal.Numerics;
public partial struct float4x4
{
/// <inheritdoc cref="Matrix4x4.M11" />
[XmlAttribute]
public float M11
{
readonly get => X.X;
set => X.X = value;
}
/// <inheritdoc cref="Matrix4x4.M12" />
[XmlAttribute]
public float M12
{
readonly get => X.Y;
set => X.Y = value;
}
/// <inheritdoc cref="Matrix4x4.M13" />
[XmlAttribute]
public float M13
{
readonly get => X.Z;
set => X.Z = value;
}
/// <inheritdoc cref="Matrix4x4.M14" />
[XmlAttribute]
public float M14
{
readonly get => X.W;
set => X.W = value;
}
/// <inheritdoc cref="Matrix4x4.M21" />
[XmlAttribute]
public float M21
{
readonly get => Y.X;
set => Y.X = value;
}
/// <inheritdoc cref="Matrix4x4.M22" />
[XmlAttribute]
public float M22
{
readonly get => Y.Y;
set => Y.Y = value;
}
/// <inheritdoc cref="Matrix4x4.M23" />
[XmlAttribute]
public float M23
{
readonly get => Y.Z;
set => Y.Z = value;
}
/// <inheritdoc cref="Matrix4x4.M24" />
[XmlAttribute]
public float M24
{
readonly get => Y.W;
set => Y.W = value;
}
/// <inheritdoc cref="Matrix4x4.M31" />
[XmlAttribute]
public float M31
{
readonly get => Z.X;
set => Z.X = value;
}
/// <inheritdoc cref="Matrix4x4.M32" />
[XmlAttribute]
public float M32
{
readonly get => Z.Y;
set => Z.Y = value;
}
/// <inheritdoc cref="Matrix4x4.M33" />
[XmlAttribute]
public float M33
{
readonly get => Z.Z;
set => Z.Z = value;
}
/// <inheritdoc cref="Matrix4x4.M34" />
[XmlAttribute]
public float M34
{
readonly get => Z.W;
set => Z.W = value;
}
/// <inheritdoc cref="Matrix4x4.M41" />
[XmlAttribute]
public float M41
{
readonly get => W.X;
set => W.X = value;
}
/// <inheritdoc cref="Matrix4x4.M42" />
[XmlAttribute]
public float M42
{
readonly get => W.Y;
set => W.Y = value;
}
/// <inheritdoc cref="Matrix4x4.M43" />
[XmlAttribute]
public float M43
{
readonly get => W.Z;
set => W.Z = value;
}
/// <inheritdoc cref="Matrix4x4.M44" />
[XmlAttribute]
public float M44
{
readonly get => W.W;
set => W.W = value;
}
}