Upgrade to .net9
This commit is contained in:
parent
eb97cfb57c
commit
a1cb6592eb
15 changed files with 395 additions and 54 deletions
|
|
@ -20,6 +20,7 @@ public static class Utils
|
|||
return (a + b - 1) / b;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public static (int Column, int Row) GetSBSCoordinate(string coordinate)
|
||||
{
|
||||
var column = coordinate[^1] - '0';
|
||||
|
|
@ -33,7 +34,13 @@ public static class Utils
|
|||
return (column, row);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Performs a SIMD-accelerated calculation that generates a buffer of bounded, scaled indices.
|
||||
/// </summary>
|
||||
/// <param name="scaleFactor">The amount by which to scale the sequence values.</param>
|
||||
/// <param name="length">The total number of scalar values to generate.</param>
|
||||
/// <param name="max">Upper limit (exclusive) for clamping values.</param>
|
||||
/// <param name="offset">The offset to apply before clamping.</param>
|
||||
public static IBuffer<int> BoundsMatrix(float scaleFactor, int length, int max, int offset)
|
||||
{
|
||||
var vectorSize = DivCeil(length, Vector<float>.Count);
|
||||
|
|
@ -45,14 +52,13 @@ public static class Utils
|
|||
var vectorMax = new Vector<int>(max - 1);
|
||||
var vectorScale = new Vector<float>(scaleFactor);
|
||||
|
||||
var vectorSequence = SequenceVector(0f, 1f);
|
||||
var vectorSequence = Vector.CreateSequence(0f, 1f);
|
||||
|
||||
var seq = 0f;
|
||||
for (var i = 0; i < vectorSize; i++, seq += Vector<float>.Count)
|
||||
{
|
||||
var sequence = new Vector<float>(seq) + vectorSequence;
|
||||
span[i] = Vector.Multiply(sequence, vectorScale);
|
||||
span[i] = Vector.Add(span[i], vectorScale);
|
||||
span[i] = Vector.FusedMultiplyAdd(sequence, vectorScale, vectorScale);
|
||||
span[i] = Vector.Ceiling(span[i]);
|
||||
}
|
||||
|
||||
|
|
@ -62,23 +68,9 @@ public static class Utils
|
|||
{
|
||||
resultSpan[i] = Vector.ConvertToInt32(span[i]);
|
||||
resultSpan[i] = Vector.Add(resultSpan[i], vectorOffset);
|
||||
resultSpan[i] = Vector.Min(resultSpan[i], vectorMax);
|
||||
resultSpan[i] = Vector.Max(resultSpan[i], vectorMin);
|
||||
resultSpan[i] = Vector.ClampNative(resultSpan[i], vectorMin, vectorMax);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Vector<float> SequenceVector(float start, float step)
|
||||
{
|
||||
var vector = Vector<float>.Zero;
|
||||
ref var reference = ref Unsafe.As<Vector<float>, float>(ref vector);
|
||||
for (var i = 0; i < Vector<float>.Count; i++)
|
||||
{
|
||||
ref var current = ref Unsafe.Add(ref reference, i);
|
||||
current = start + step * i;
|
||||
}
|
||||
|
||||
return vector;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue