mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 21:18:24 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
8 changed files with 768360 additions and 0 deletions
|
|
@ -0,0 +1,48 @@
|
|||
// <auto-generated /> - edit Matrix.access.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct double4x4
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public double 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 double4 x, out double4 y, out double4 z, out double4 w)
|
||||
{
|
||||
x = X;
|
||||
y = Y;
|
||||
z = Z;
|
||||
w = W;
|
||||
}
|
||||
|
||||
public Span<double> AsSpan()
|
||||
{
|
||||
return MemoryMarshal.CreateSpan(ref Unsafe.As<double4x4, double>(ref this), 16);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly ReadOnlySpan<double> AsReadOnlySpan()
|
||||
{
|
||||
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<double4x4, double>(ref Unsafe.AsRef(in this)), 16);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// <auto-generated /> - edit Matrix.equality.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct double4x4
|
||||
{
|
||||
/// <inheritdoc cref="Matrix4x4.Equals(object?)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override readonly bool Equals([NotNullWhen(true)] object? obj)
|
||||
{
|
||||
return obj is double4x4 other && Equals(other);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.Equals(Matrix4x4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(double4x4 other)
|
||||
{
|
||||
// This function needs to account for floating-point equality around NaN
|
||||
// and so must behave equivalently to the underlying double/double.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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// <auto-generated /> - edit Matrix.format.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct double4x4
|
||||
{
|
||||
/// <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} }}";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
// <auto-generated /> - edit Matrix.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
/// <summary>
|
||||
/// Implements a 4x4 matrix with double components.
|
||||
/// </summary>
|
||||
[DebuggerTypeProxy(typeof(DebugView))]
|
||||
public partial struct double4x4 : IMatrix<double4x4, double>
|
||||
, IFloatingMatrix4x4<double4x4, double, double3, double4, doubleQuat>
|
||||
{
|
||||
internal class DebugView(double4x4 m)
|
||||
{
|
||||
public double4 X => m.X;
|
||||
public double4 Y => m.Y;
|
||||
public double4 Z => m.Z;
|
||||
public double4 W => m.W;
|
||||
}
|
||||
|
||||
/// <summary>The first row of the matrix.</summary>
|
||||
[XmlIgnore]
|
||||
public double4 X;
|
||||
|
||||
/// <summary>The second row of the matrix.</summary>
|
||||
[XmlIgnore]
|
||||
public double4 Y;
|
||||
|
||||
/// <summary>The third row of the matrix.</summary>
|
||||
[XmlIgnore]
|
||||
public double4 Z;
|
||||
|
||||
/// <summary>The fourth row of the matrix.</summary>
|
||||
[XmlIgnore]
|
||||
public double4 W;
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public double4x4(
|
||||
double m11,
|
||||
double m12,
|
||||
double m13,
|
||||
double m14,
|
||||
double m21,
|
||||
double m22,
|
||||
double m23,
|
||||
double m24,
|
||||
double m31,
|
||||
double m32,
|
||||
double m33,
|
||||
double m34,
|
||||
double m41,
|
||||
double m42,
|
||||
double m43,
|
||||
double m44
|
||||
)
|
||||
{
|
||||
X = new double4(m11, m12, m13, m14);
|
||||
Y = new double4(m21, m22, m23, m24);
|
||||
Z = new double4(m31, m32, m33, m34);
|
||||
W = new double4(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 double4x4(ReadOnlySpan<double> span)
|
||||
{
|
||||
if (span.Length < 16)
|
||||
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 16.");
|
||||
|
||||
this = Unsafe.ReadUnaligned<double4x4>(ref Unsafe.As<double, byte>(ref MemoryMarshal.GetReference(span)));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4(Matrix3x2)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public double4x4(double3x2 value)
|
||||
{
|
||||
X = new double4(value.X, 0, 0);
|
||||
Y = new double4(value.Y, 0, 0);
|
||||
Z = double4.UnitZ;
|
||||
W = new double4(value.Z, 0, 1);
|
||||
}
|
||||
|
||||
static double4x4 IMatrix<double4x4, double>.Create(ReadOnlySpan<double> span) => new(span);
|
||||
|
||||
/// <inheritdoc />
|
||||
public static double4x4 Identity
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
double4x4 result;
|
||||
|
||||
result.X = double4.UnitX;
|
||||
result.Y = double4.UnitY;
|
||||
result.Z = double4.UnitZ;
|
||||
result.W = double4.UnitW;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public static int ComponentSize => sizeof(double);
|
||||
|
||||
/// <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 == double4.UnitX && Y == double4.UnitY && Z == double4.UnitZ && W == double4.UnitW;
|
||||
}
|
||||
|
||||
/// <summary>The kernel view: the same 64/128 bytes as the row fields, seen as SIMD vectors.</summary>
|
||||
private readonly struct Rows(Vector256<double> x, Vector256<double> y, Vector256<double> z, Vector256<double> w)
|
||||
{
|
||||
public readonly Vector256<double> 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 Vector256<double> Transform(Vector256<double> row)
|
||||
{
|
||||
var result = X * row.GetElement(0);
|
||||
result = Vector256.MultiplyAddEstimate(Y, Vector256.Create(row.GetElement(1)), result);
|
||||
result = Vector256.MultiplyAddEstimate(Z, Vector256.Create(row.GetElement(2)), result);
|
||||
result = Vector256.MultiplyAddEstimate(W, Vector256.Create(row.GetElement(3)), result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
[UnscopedRef]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private readonly ref readonly Rows AsRows()
|
||||
{
|
||||
return ref Unsafe.As<double4x4, 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(Vector512<double> lo, Vector512<double> hi)
|
||||
{
|
||||
public readonly Vector512<double> 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 double4x4 TransposeKernel(in double4x4 matrix)
|
||||
{
|
||||
if (Vector512.IsHardwareAccelerated)
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static ref readonly Halves AsHalves(in double4x4 value)
|
||||
{
|
||||
return ref Unsafe.As<double4x4, Halves>(ref Unsafe.AsRef(in value));
|
||||
}
|
||||
|
||||
ref readonly var halves = ref AsHalves(in matrix);
|
||||
|
||||
var idxLo = Vector512.Create(0, 4, 0, 4, 1, 5, 1, 5);
|
||||
var idxHi = Vector512.Create(2, 6, 2, 6, 3, 7, 3, 7);
|
||||
var takeHi = Vector512.Create(0, 0, -1, -1, 0, 0, -1, -1).AsDouble();
|
||||
|
||||
var transposed = new Halves(
|
||||
Vector512.ConditionalSelect(takeHi, Vector512.ShuffleNative(halves.Hi, idxLo), Vector512.ShuffleNative(halves.Lo, idxLo)),
|
||||
Vector512.ConditionalSelect(takeHi, Vector512.ShuffleNative(halves.Hi, idxHi), Vector512.ShuffleNative(halves.Lo, idxHi)));
|
||||
return Unsafe.BitCast<Halves, double4x4>(transposed);
|
||||
}
|
||||
|
||||
// no accelerated width to widen into (arm64 tops out at V128): plain field shuffle
|
||||
double4x4 result;
|
||||
|
||||
result.X = new double4(matrix.X.X, matrix.Y.X, matrix.Z.X, matrix.W.X);
|
||||
result.Y = new double4(matrix.X.Y, matrix.Y.Y, matrix.Z.Y, matrix.W.Y);
|
||||
result.Z = new double4(matrix.X.Z, matrix.Y.Z, matrix.Z.Z, matrix.W.Z);
|
||||
result.W = new double4(matrix.X.W, matrix.Y.W, matrix.Z.W, matrix.W.W);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,100 @@
|
|||
// <auto-generated /> - edit Matrix.operators.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct double4x4
|
||||
{
|
||||
/// <inheritdoc cref="Matrix4x4.op_Addition(Matrix4x4, Matrix4x4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double4x4 operator +(double4x4 left, double4x4 right)
|
||||
{
|
||||
double4x4 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 ==(double4x4 left, double4x4 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 !=(double4x4 left, double4x4 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 double4x4 operator *(double4x4 left, double4x4 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, double4x4>(result);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Multiply(double4x4, double4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double4 operator *(double4x4 matrix, double4 vector)
|
||||
{
|
||||
return Multiply(matrix, vector);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.op_Multiply(Matrix4x4, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double4x4 operator *(double4x4 left, double right)
|
||||
{
|
||||
double4x4 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 double4x4 operator -(double4x4 left, double4x4 right)
|
||||
{
|
||||
double4x4 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 double4x4 operator -(double4x4 value)
|
||||
{
|
||||
double4x4 result;
|
||||
|
||||
result.X = -value.X;
|
||||
result.Y = -value.Y;
|
||||
result.Z = -value.Z;
|
||||
result.W = -value.W;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// <auto-generated /> - edit Matrix.pack.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct double4x4
|
||||
{
|
||||
public static double4x4 Unpack(in float4x4 vector, Func<float, double> elementConverter)
|
||||
{
|
||||
MatrixPack.Pack(vector, out double4x4 result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void Unpack(
|
||||
in ReadOnlySpan<float4x4> source,
|
||||
Span<double4x4> destination,
|
||||
Func<float, double> elementConverter
|
||||
)
|
||||
{
|
||||
MatrixPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static double4x4 Unpack(in float4x4 vector)
|
||||
{
|
||||
return Unpack(vector, f => f);
|
||||
}
|
||||
|
||||
public static void Unpack(in ReadOnlySpan<float4x4> source, Span<double4x4> destination)
|
||||
{
|
||||
Unpack(source, destination, f => f);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
// <auto-generated /> - edit Matrix.swizzle.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct double4x4
|
||||
{
|
||||
/// <inheritdoc cref="Matrix4x4.M11" />
|
||||
[XmlAttribute]
|
||||
public double M11
|
||||
{
|
||||
readonly get => X.X;
|
||||
set => X.X = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M12" />
|
||||
[XmlAttribute]
|
||||
public double M12
|
||||
{
|
||||
readonly get => X.Y;
|
||||
set => X.Y = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M13" />
|
||||
[XmlAttribute]
|
||||
public double M13
|
||||
{
|
||||
readonly get => X.Z;
|
||||
set => X.Z = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M14" />
|
||||
[XmlAttribute]
|
||||
public double M14
|
||||
{
|
||||
readonly get => X.W;
|
||||
set => X.W = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M21" />
|
||||
[XmlAttribute]
|
||||
public double M21
|
||||
{
|
||||
readonly get => Y.X;
|
||||
set => Y.X = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M22" />
|
||||
[XmlAttribute]
|
||||
public double M22
|
||||
{
|
||||
readonly get => Y.Y;
|
||||
set => Y.Y = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M23" />
|
||||
[XmlAttribute]
|
||||
public double M23
|
||||
{
|
||||
readonly get => Y.Z;
|
||||
set => Y.Z = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M24" />
|
||||
[XmlAttribute]
|
||||
public double M24
|
||||
{
|
||||
readonly get => Y.W;
|
||||
set => Y.W = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M31" />
|
||||
[XmlAttribute]
|
||||
public double M31
|
||||
{
|
||||
readonly get => Z.X;
|
||||
set => Z.X = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M32" />
|
||||
[XmlAttribute]
|
||||
public double M32
|
||||
{
|
||||
readonly get => Z.Y;
|
||||
set => Z.Y = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M33" />
|
||||
[XmlAttribute]
|
||||
public double M33
|
||||
{
|
||||
readonly get => Z.Z;
|
||||
set => Z.Z = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M34" />
|
||||
[XmlAttribute]
|
||||
public double M34
|
||||
{
|
||||
readonly get => Z.W;
|
||||
set => Z.W = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M41" />
|
||||
[XmlAttribute]
|
||||
public double M41
|
||||
{
|
||||
readonly get => W.X;
|
||||
set => W.X = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M42" />
|
||||
[XmlAttribute]
|
||||
public double M42
|
||||
{
|
||||
readonly get => W.Y;
|
||||
set => W.Y = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M43" />
|
||||
[XmlAttribute]
|
||||
public double M43
|
||||
{
|
||||
readonly get => W.Z;
|
||||
set => W.Z = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Matrix4x4.M44" />
|
||||
[XmlAttribute]
|
||||
public double M44
|
||||
{
|
||||
readonly get => W.W;
|
||||
set => W.W = value;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue