SPMD API overhaul: gather/scatter, job & packaging updates
- ISPMDLane: add MaskGather, MaskStore, Scatter, MaskScatter; update MaskLoad/Gather signatures for hardware parity - WideLane/ScalarLane: implement new methods with HW/fallback logic - MathV: gather/mask-gather now delegate to lane methods - Vector2/3/4: add CompressStore, Scatter, MaskScatter - SPMD jobs/tests/README: migrate to new APIs for correctness - Use Unsafe.BitCast instead of Unsafe.As/AsRef - Add SPMDUtility for gather index extraction - Job system: add ICustomJob<TSelf>, ScheduleCustom overload - FreeList concurrency obsolete; always thread-safe - NuGet: include LICENSE/README, set license/readme in .csproj - Docs: update SPMD usage, clarify safety notes - Minor: doc fixes, CompressStore test improvements
This commit is contained in:
@@ -67,31 +67,19 @@ public unsafe struct Vector4<TLane, TNumber> : IEquatable<Vector4<TLane, TNumber
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Store(TNumber* pDst)
|
||||
{
|
||||
var width = TLane.LaneWidth;
|
||||
|
||||
var x = stackalloc TNumber[width];
|
||||
var y = stackalloc TNumber[width];
|
||||
var z = stackalloc TNumber[width];
|
||||
var w = stackalloc TNumber[width];
|
||||
|
||||
this.x.Store(x);
|
||||
this.y.Store(y);
|
||||
this.z.Store(z);
|
||||
this.w.Store(w);
|
||||
|
||||
for (var i = 0; i < width; i++)
|
||||
{
|
||||
pDst[i * 4 + 0] = x[i];
|
||||
pDst[i * 4 + 1] = y[i];
|
||||
pDst[i * 4 + 2] = z[i];
|
||||
pDst[i * 4 + 3] = w[i];
|
||||
}
|
||||
x.Store(pDst + 0 * TLane.LaneWidth);
|
||||
y.Store(pDst + 1 * TLane.LaneWidth);
|
||||
z.Store(pDst + 2 * TLane.LaneWidth);
|
||||
w.Store(pDst + 3 * TLane.LaneWidth);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Store(ref TNumber dst)
|
||||
{
|
||||
Store((TNumber*)Unsafe.AsPointer(ref dst));
|
||||
x.Store(ref Unsafe.Add(ref dst, 0 * TLane.LaneWidth));
|
||||
y.Store(ref Unsafe.Add(ref dst, 1 * TLane.LaneWidth));
|
||||
z.Store(ref Unsafe.Add(ref dst, 2 * TLane.LaneWidth));
|
||||
w.Store(ref Unsafe.Add(ref dst, 3 * TLane.LaneWidth));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -112,6 +100,96 @@ public unsafe struct Vector4<TLane, TNumber> : IEquatable<Vector4<TLane, TNumber
|
||||
this.w.Store(ref w);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CompressStore(TNumber* pDst, Vector4<TLane, TNumber> mask)
|
||||
{
|
||||
x.CompressStore(pDst + 0 * TLane.LaneWidth, mask.x);
|
||||
y.CompressStore(pDst + 1 * TLane.LaneWidth, mask.y);
|
||||
z.CompressStore(pDst + 2 * TLane.LaneWidth, mask.z);
|
||||
w.CompressStore(pDst + 3 * TLane.LaneWidth, mask.w);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CompressStore(ref TNumber dst, Vector4<TLane, TNumber> mask)
|
||||
{
|
||||
x.CompressStore(ref Unsafe.Add(ref dst, 0 * TLane.LaneWidth), mask.x);
|
||||
y.CompressStore(ref Unsafe.Add(ref dst, 1 * TLane.LaneWidth), mask.y);
|
||||
z.CompressStore(ref Unsafe.Add(ref dst, 2 * TLane.LaneWidth), mask.z);
|
||||
w.CompressStore(ref Unsafe.Add(ref dst, 3 * TLane.LaneWidth), mask.w);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Scatter(TNumber* pDst, TLane indices)
|
||||
{
|
||||
x.Scatter(pDst + 0, indices);
|
||||
y.Scatter(pDst + 1, indices);
|
||||
z.Scatter(pDst + 2, indices);
|
||||
w.Scatter(pDst + 3, indices);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Scatter(TNumber* pDst, int* pIndices)
|
||||
{
|
||||
x.Scatter(pDst + 0, pIndices);
|
||||
y.Scatter(pDst + 1, pIndices);
|
||||
z.Scatter(pDst + 2, pIndices);
|
||||
w.Scatter(pDst + 3, pIndices);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Scatter(ref TNumber dst, TLane indices)
|
||||
{
|
||||
x.Scatter(ref Unsafe.Add(ref dst, 0), indices);
|
||||
y.Scatter(ref Unsafe.Add(ref dst, 1), indices);
|
||||
z.Scatter(ref Unsafe.Add(ref dst, 2), indices);
|
||||
w.Scatter(ref Unsafe.Add(ref dst, 3), indices);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Scatter(ref TNumber dst, int* pIndices)
|
||||
{
|
||||
x.Scatter(ref Unsafe.Add(ref dst, 0), pIndices);
|
||||
y.Scatter(ref Unsafe.Add(ref dst, 1), pIndices);
|
||||
z.Scatter(ref Unsafe.Add(ref dst, 2), pIndices);
|
||||
w.Scatter(ref Unsafe.Add(ref dst, 3), pIndices);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MaskScatter(TNumber* pDst, TLane indices, TLane mask)
|
||||
{
|
||||
x.MaskScatter(pDst + 0, indices, mask);
|
||||
y.MaskScatter(pDst + 1, indices, mask);
|
||||
z.MaskScatter(pDst + 2, indices, mask);
|
||||
w.MaskScatter(pDst + 3, indices, mask);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MaskScatter(TNumber* pDst, int* pIndices, TLane mask)
|
||||
{
|
||||
x.MaskScatter(pDst + 0, pIndices, mask);
|
||||
y.MaskScatter(pDst + 1, pIndices, mask);
|
||||
z.MaskScatter(pDst + 2, pIndices, mask);
|
||||
w.MaskScatter(pDst + 3, pIndices, mask);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MaskScatter(ref TNumber dst, TLane indices, TLane mask)
|
||||
{
|
||||
x.MaskScatter(ref Unsafe.Add(ref dst, 0), indices, mask);
|
||||
y.MaskScatter(ref Unsafe.Add(ref dst, 1), indices, mask);
|
||||
z.MaskScatter(ref Unsafe.Add(ref dst, 2), indices, mask);
|
||||
w.MaskScatter(ref Unsafe.Add(ref dst, 3), indices, mask);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MaskScatter(ref TNumber dst, int* pIndices, TLane mask)
|
||||
{
|
||||
x.MaskScatter(ref Unsafe.Add(ref dst, 0), pIndices, mask);
|
||||
y.MaskScatter(ref Unsafe.Add(ref dst, 1), pIndices, mask);
|
||||
z.MaskScatter(ref Unsafe.Add(ref dst, 2), pIndices, mask);
|
||||
w.MaskScatter(ref Unsafe.Add(ref dst, 3), pIndices, mask);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector4<TLane, TNumber> operator -(in Vector4<TLane, TNumber> vector)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user