diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs
index 876f6e1fe..5af5db3cd 100644
--- a/src/ImageSharp/Common/Helpers/Numerics.cs
+++ b/src/ImageSharp/Common/Helpers/Numerics.cs
@@ -949,4 +949,94 @@ internal static class Numerics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsOutOfRange(int value, int min, int max)
=> (uint)(value - min) > (uint)(max - min);
+
+ ///
+ /// Gets the count of vectors that safely fit into the given span.
+ ///
+ /// The type of the vector.
+ /// The given span.
+ /// Count of vectors that safely fit into the span.
+ public static nuint VectorCount(this Span span)
+ where TVector : struct
+ => (uint)span.Length / (uint)Vector.Count;
+
+ ///
+ /// Gets the count of vectors that safely fit into the given span.
+ ///
+ /// The type of the vector.
+ /// The given span.
+ /// Count of vectors that safely fit into the span.
+ public static nuint Vector128Count(this Span span)
+ where TVector : struct
+ => (uint)span.Length / (uint)Vector128.Count;
+
+ ///
+ /// Gets the count of vectors that safely fit into the given span.
+ ///
+ /// The type of the vector.
+ /// The given span.
+ /// Count of vectors that safely fit into the span.
+ public static nuint Vector128Count(this ReadOnlySpan span)
+ where TVector : struct
+ => (uint)span.Length / (uint)Vector128.Count;
+
+ ///
+ /// Gets the count of vectors that safely fit into the given span.
+ ///
+ /// The type of the vector.
+ /// The given span.
+ /// Count of vectors that safely fit into the span.
+ public static nuint Vector256Count(this Span span)
+ where TVector : struct
+ => (uint)span.Length / (uint)Vector256.Count;
+
+ ///
+ /// Gets the count of vectors that safely fit into the given span.
+ ///
+ /// The type of the vector.
+ /// The given span.
+ /// Count of vectors that safely fit into the span.
+ public static nuint Vector256Count(this ReadOnlySpan span)
+ where TVector : struct
+ => (uint)span.Length / (uint)Vector256.Count;
+
+ ///
+ /// Gets the count of vectors that safely fit into the given span.
+ ///
+ /// The type of the vector.
+ /// The given span.
+ /// Count of vectors that safely fit into the span.
+ public static nuint VectorCount(this Span span)
+ where TVector : struct
+ => (uint)span.Length / (uint)Vector.Count;
+
+ ///
+ /// Gets the count of vectors that safely fit into the given span.
+ ///
+ /// The type of the vector.
+ /// The given span.
+ /// Count of vectors that safely fit into the span.
+ public static nuint Vector128Count(this Span span)
+ where TVector : struct
+ => (uint)span.Length / (uint)Vector128.Count;
+
+ ///
+ /// Gets the count of vectors that safely fit into the given span.
+ ///
+ /// The type of the vector.
+ /// The given span.
+ /// Count of vectors that safely fit into the span.
+ public static nuint Vector256Count(this Span span)
+ where TVector : struct
+ => (uint)span.Length / (uint)Vector256.Count;
+
+ ///
+ /// Gets the count of vectors that safely fit into length.
+ ///
+ /// The type of the vector.
+ /// The given length.
+ /// Count of vectors that safely fit into the length.
+ public static nuint Vector256Count(int length)
+ where TVector : struct
+ => (uint)length / (uint)Vector256.Count;
}
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
index b9505ba3e..ac122fc7d 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
@@ -97,7 +97,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector.Count);
- nuint n = (uint)dest.Length / (uint)Vector.Count;
+ nuint n = dest.VectorCount();
ref Vector sourceBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
ref Vector destBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
@@ -132,7 +132,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector.Count);
- nuint n = (uint)dest.Length / (uint)Vector.Count;
+ nuint n = dest.VectorCount();
ref Vector sourceBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
diff --git a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
index 8ba1b0912..5b5a3493d 100644
--- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
+++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
@@ -222,7 +222,7 @@ internal static partial class SimdUtils
ref Vector256 destBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
- nint n = (nint)(uint)(dest.Length / Vector256.Count);
+ nint n = (nint)dest.Vector256Count();
nint m = Numerics.Modulo4(n);
nint u = n - m;
@@ -392,7 +392,7 @@ internal static partial class SimdUtils
ref Vector128 destBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
- nuint n = (uint)source.Length / (uint)Vector128.Count;
+ nuint n = source.Vector128Count();
for (nuint i = 0; i < n; i += 3)
{
@@ -455,7 +455,7 @@ internal static partial class SimdUtils
ref Vector128 destBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
- nuint n = (uint)source.Length / (uint)Vector128.Count;
+ nuint n = source.Vector128Count();
for (nuint i = 0, j = 0; i < n; i += 3, j += 4)
{
@@ -499,7 +499,7 @@ internal static partial class SimdUtils
ref Vector128 destBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
- nuint n = (uint)source.Length / (uint)Vector128.Count;
+ nuint n = source.Vector128Count();
for (nuint i = 0, j = 0; i < n; i += 4, j += 3)
{
@@ -679,7 +679,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector256.Count);
- nuint n = (uint)dest.Length / (uint)Vector256.Count;
+ nuint n = dest.Vector256Count();
ref Vector256 destBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
@@ -712,7 +712,7 @@ internal static partial class SimdUtils
// Sse
VerifySpanInput(source, dest, Vector128.Count);
- nuint n = (uint)dest.Length / (uint)Vector128.Count;
+ nuint n = dest.Vector128Count();
ref Vector128 destBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(dest));
@@ -811,7 +811,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector256.Count);
- nuint n = (uint)dest.Length / (uint)Vector256.Count;
+ nuint n = dest.Vector256Count();
ref Vector256 sourceBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
@@ -850,7 +850,7 @@ internal static partial class SimdUtils
// Sse
VerifySpanInput(source, dest, Vector128.Count);
- nuint n = (uint)dest.Length / (uint)Vector128.Count;
+ nuint n = dest.Vector128Count();
ref Vector128 sourceBase =
ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
@@ -893,7 +893,7 @@ internal static partial class SimdUtils
ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel));
ref byte dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(destination));
- nuint count = (uint)redChannel.Length / (uint)Vector256.Count;
+ nuint count = redChannel.Vector256Count();
ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32);
Vector256 control1 = Unsafe.As>(ref control1Bytes);
@@ -965,7 +965,7 @@ internal static partial class SimdUtils
ref Vector256 bBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(blueChannel));
ref Vector256 dBase = ref Unsafe.As>(ref MemoryMarshal.GetReference(destination));
- nuint count = (uint)redChannel.Length / (uint)Vector256.Count;
+ nuint count = redChannel.Vector256Count();
ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32);
Vector256 control1 = Unsafe.As>(ref control1Bytes);
var a = Vector256.Create((byte)255);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs
index 0283e83d0..76d188f45 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs
@@ -32,7 +32,7 @@ internal abstract partial class JpegColorConverterBase
// Used for the color conversion
var scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue));
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
ref Vector256 c = ref Unsafe.Add(ref c0Base, i);
@@ -71,7 +71,7 @@ internal abstract partial class JpegColorConverterBase
var scale = Vector256.Create(maxValue);
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
Vector256 ctmp = Avx.Subtract(scale, Unsafe.Add(ref srcR, i));
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs
index 4cc8c0665..a59be009b 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs
@@ -30,7 +30,7 @@ internal abstract partial class JpegColorConverterBase
var scale = new Vector(1 / (this.MaximumValue * this.MaximumValue));
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
ref Vector c = ref Unsafe.Add(ref cBase, i);
@@ -78,7 +78,7 @@ internal abstract partial class JpegColorConverterBase
// Used for the color conversion
var scale = new Vector(maxValue);
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
Vector ctmp = scale - Unsafe.Add(ref srcR, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs
index a8d5f49c2..6bb8fd7aa 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs
@@ -27,7 +27,7 @@ internal abstract partial class JpegColorConverterBase
// Used for the color conversion
var scale = Vector128.Create(1 / this.MaximumValue);
- nuint n = (uint)values.Component0.Length / (uint)Vector128.Count;
+ nuint n = values.Component0.Vector128Count();
for (nuint i = 0; i < n; i++)
{
ref Vector128 c0 = ref Unsafe.Add(ref c0Base, i);
@@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase
var f0587 = Vector128.Create(0.587f);
var f0114 = Vector128.Create(0.114f);
- nuint n = (uint)values.Component0.Length / (uint)Vector128.Count;
+ nuint n = values.Component0.Vector128Count();
for (nuint i = 0; i < n; i++)
{
ref Vector128 r = ref Unsafe.Add(ref srcRed, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs
index 4efb6f851..a9e1c5d13 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs
@@ -27,7 +27,7 @@ internal abstract partial class JpegColorConverterBase
// Used for the color conversion
var scale = Vector256.Create(1 / this.MaximumValue);
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
ref Vector256 c0 = ref Unsafe.Add(ref c0Base, i);
@@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase
var f0587 = Vector256.Create(0.587f);
var f0114 = Vector256.Create(0.114f);
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
ref Vector256 r = ref Unsafe.Add(ref srcRed, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs
index 4156a5968..cac10636f 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs
@@ -24,7 +24,7 @@ internal abstract partial class JpegColorConverterBase
var scale = new Vector(1 / this.MaximumValue);
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
ref Vector c0 = ref Unsafe.Add(ref cBase, i);
@@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase
var gMult = new Vector(0.587f);
var bMult = new Vector(0.114f);
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
Vector r = Unsafe.Add(ref srcR, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs
index 888922306..75eeb17dd 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs
@@ -30,7 +30,7 @@ internal abstract partial class JpegColorConverterBase
// Used for the color conversion
var scale = Vector128.Create(1 / this.MaximumValue);
- nuint n = (uint)values.Component0.Length / (uint)Vector128.Count;
+ nuint n = values.Component0.Vector128Count();
for (nuint i = 0; i < n; i++)
{
ref Vector128 r = ref Unsafe.Add(ref rBase, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs
index ae9b943aa..b56728fa7 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs
@@ -29,7 +29,7 @@ internal abstract partial class JpegColorConverterBase
// Used for the color conversion
var scale = Vector256.Create(1 / this.MaximumValue);
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
ref Vector256 r = ref Unsafe.Add(ref rBase, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs
index 5e3cf9b2b..bd3142fa1 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs
@@ -28,7 +28,7 @@ internal abstract partial class JpegColorConverterBase
var scale = new Vector(1 / this.MaximumValue);
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
ref Vector r = ref Unsafe.Add(ref rBase, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs
index 0a2cfd084..c5fa786e2 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs
@@ -38,7 +38,7 @@ internal abstract partial class JpegColorConverterBase
var bCbMult = Vector256.Create(YCbCrScalar.BCbMult);
// Walking 8 elements at one step:
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
// y = yVals[i];
@@ -98,7 +98,7 @@ internal abstract partial class JpegColorConverterBase
var fn0081312F = Vector256.Create(-0.081312F);
var f05 = Vector256.Create(0.5f);
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
Vector256 r = Unsafe.Add(ref srcR, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs
index ca01aed61..a5d0c889e 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs
@@ -35,7 +35,7 @@ internal abstract partial class JpegColorConverterBase
var gCrMult = new Vector(-YCbCrScalar.GCrMult);
var bCbMult = new Vector(YCbCrScalar.BCbMult);
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
// y = yVals[i];
@@ -103,7 +103,7 @@ internal abstract partial class JpegColorConverterBase
var gCrMult = new Vector(0.418688f);
var bCrMult = new Vector(0.081312f);
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
Vector r = Unsafe.Add(ref srcR, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs
index 337741622..efe40ba08 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs
@@ -40,7 +40,7 @@ internal abstract partial class JpegColorConverterBase
var bCbMult = Vector256.Create(YCbCrScalar.BCbMult);
// Walking 8 elements at one step:
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
// y = yVals[i];
@@ -109,7 +109,7 @@ internal abstract partial class JpegColorConverterBase
var fn0081312F = Vector256.Create(-0.081312F);
var f05 = Vector256.Create(0.5f);
- nuint n = (uint)values.Component0.Length / (uint)Vector256.Count;
+ nuint n = values.Component0.Vector256Count();
for (nuint i = 0; i < n; i++)
{
Vector256 r = Avx.Subtract(maxSampleValue, Unsafe.Add(ref srcR, i));
diff --git a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs
index d67fad308..570a401ad 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs
@@ -36,7 +36,7 @@ internal abstract partial class JpegColorConverterBase
var gCrMult = new Vector(-YCbCrScalar.GCrMult);
var bCbMult = new Vector(YCbCrScalar.BCbMult);
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
// y = yVals[i];
@@ -107,7 +107,7 @@ internal abstract partial class JpegColorConverterBase
var gCrMult = new Vector(0.418688f);
var bCrMult = new Vector(0.081312f);
- nuint n = (uint)values.Component0.Length / (uint)Vector.Count;
+ nuint n = values.Component0.VectorCount();
for (nuint i = 0; i < n; i++)
{
Vector r = maxSampleValue - Unsafe.Add(ref srcR, i);
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs
index 4815baa62..be27385cd 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs
@@ -122,7 +122,7 @@ internal class ComponentProcessor : IDisposable
ref Vector256 sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
- nuint count = (uint)source.Length / (uint)Vector256.Count;
+ nuint count = source.Vector256Count();
for (nuint i = 0; i < count; i++)
{
Unsafe.Add(ref targetVectorRef, i) = Avx.Add(Unsafe.Add(ref targetVectorRef, i), Unsafe.Add(ref sourceVectorRef, i));
@@ -133,7 +133,7 @@ internal class ComponentProcessor : IDisposable
ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target));
ref Vector sourceVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(source));
- nuint count = (uint)source.Length / (uint)Vector.Count;
+ nuint count = source.VectorCount();
for (nuint i = 0; i < count; i++)
{
Unsafe.Add(ref targetVectorRef, i) += Unsafe.Add(ref sourceVectorRef, i);
@@ -166,7 +166,7 @@ internal class ComponentProcessor : IDisposable
source = source.Slice(touchedCount);
target = target.Slice(touchedCount / factor);
- nuint length = (uint)touchedCount / (uint)Vector256.Count;
+ nuint length = Numerics.Vector256Count(touchedCount);
for (uint i = 0; i < haddIterationsCount; i++)
{
@@ -200,7 +200,7 @@ internal class ComponentProcessor : IDisposable
ref Vector256 targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target));
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
- nuint count = (uint)target.Length / (uint)Vector256.Count;
+ nuint count = target.Vector256Count();
var multiplierVector = Vector256.Create(multiplier);
for (nuint i = 0; i < count; i++)
{
@@ -211,7 +211,7 @@ internal class ComponentProcessor : IDisposable
{
ref Vector targetVectorRef = ref Unsafe.As>(ref MemoryMarshal.GetReference(target));
- nuint count = (uint)target.Length / (uint)Vector.Count;
+ nuint count = target.VectorCount();
var multiplierVector = new Vector(multiplier);
for (nuint i = 0; i < count; i++)
{
diff --git a/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs b/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs
index f68bfdbe6..5a9a72f96 100644
--- a/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs
@@ -62,7 +62,7 @@ public static class FeatureTestRunner
ProcessStartInfo processStartInfo = new();
if (intrinsic.Key != HwIntrinsics.AllowAll)
{
- processStartInfo.Environment[$"COMPlus_{intrinsic.Value}"] = "0";
+ processStartInfo.Environment[$"DOTNET_{intrinsic.Value}"] = "0";
RemoteExecutor.Invoke(
action,