From 0b140a4ad9f7be71f172eac4d10997bc0936844d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Wed, 29 Mar 2023 10:29:55 +0200 Subject: [PATCH] Added and used Numerics.Vector{128|256}Count extension --- src/ImageSharp/Common/Helpers/Numerics.cs | 90 +++++++++++++++++++ .../Helpers/SimdUtils.ExtendedIntrinsics.cs | 4 +- .../Common/Helpers/SimdUtils.HwIntrinsics.cs | 20 ++--- .../JpegColorConverter.CmykAvx.cs | 4 +- .../JpegColorConverter.CmykVector.cs | 4 +- .../JpegColorConverter.GrayScaleArm.cs | 4 +- .../JpegColorConverter.GrayScaleAvx.cs | 4 +- .../JpegColorConverter.GrayScaleVector.cs | 4 +- .../JpegColorConverter.RgbArm.cs | 2 +- .../JpegColorConverter.RgbAvx.cs | 2 +- .../JpegColorConverter.RgbVector.cs | 2 +- .../JpegColorConverter.YCbCrAvx.cs | 4 +- .../JpegColorConverter.YCbCrVector.cs | 4 +- .../JpegColorConverter.YccKAvx.cs | 4 +- .../JpegColorConverter.YccKVector.cs | 4 +- .../Components/Encoder/ComponentProcessor.cs | 10 +-- .../FeatureTesting/FeatureTestRunner.cs | 2 +- 17 files changed, 129 insertions(+), 39 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index 876f6e1fe6..5af5db3cda 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -949,4 +949,94 @@ public static int EvenReduceSum(Vector256 accumulator) [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 b9505ba3ef..ac122fc7d4 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs @@ -97,7 +97,7 @@ internal static void ByteToNormalizedFloat(ReadOnlySpan source, Span.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 void NormalizedFloatToByteSaturate( { 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 8ba1b09125..5b5a3493de 100644 --- a/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs +++ b/src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs @@ -222,7 +222,7 @@ private static void Shuffle4( 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 @@ private static void Shuffle3( 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 @@ private static void Pad3Shuffle4( 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 @@ private static void Shuffle4Slice3( 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 unsafe void ByteToNormalizedFloat( { 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 unsafe void ByteToNormalizedFloat( // 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 void NormalizedFloatToByteSaturate( { 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 void NormalizedFloatToByteSaturate( // 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 void PackFromRgbPlanesAvx2Reduce( 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 void PackFromRgbPlanesAvx2Reduce( 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 0283e83d0f..76d188f457 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 @@ public override void ConvertToRgbInplace(in ComponentValues values) // 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 @@ public static void ConvertFromRgb(in ComponentValues values, float maxValue, Spa 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 4cc8c0665f..a59be009b7 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 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) 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 @@ public static void ConvertFromRgbInplaceVectorized(in ComponentValues values, fl // 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 a8d5f49c24..6bb8fd7aa3 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 @@ public override void ConvertToRgbInplace(in ComponentValues values) // 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 @@ public override void ConvertFromRgb(in ComponentValues values, Span rLane 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 4efb6f8514..a9e1c5d130 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 @@ public override void ConvertToRgbInplace(in ComponentValues values) // 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 @@ public override void ConvertFromRgb(in ComponentValues values, Span rLane 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 4156a5968b..cac10636f5 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 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) 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 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span 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 8889223064..75eeb17dd3 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 @@ public override void ConvertToRgbInplace(in ComponentValues values) // 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 ae9b943aaf..b56728fa71 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 @@ public override void ConvertToRgbInplace(in ComponentValues values) // 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 5e3cf9b2b3..bd3142fa13 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 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) 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 0a2cfd084c..c5fa786e2c 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 @@ public override void ConvertToRgbInplace(in ComponentValues values) 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 @@ public override void ConvertFromRgb(in ComponentValues values, Span rLane 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 ca01aed612..a5d0c889e3 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 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) 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 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span 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 337741622a..efe40ba085 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 @@ public override void ConvertToRgbInplace(in ComponentValues values) 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 @@ public override void ConvertFromRgb(in ComponentValues values, Span rLane 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 d67fad3080..570a401adf 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 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) 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 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span 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 4815baa62f..be27385cd0 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs @@ -122,7 +122,7 @@ static void SumVertical(Span target, Span source) 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 @@ static void SumVertical(Span target, Span source) 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 @@ static void SumHorizontal(Span target, int factor) 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 @@ static void MultiplyToAverage(Span target, float multiplier) 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 @@ static void MultiplyToAverage(Span target, float multiplier) { 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 f68bfdbe6e..5a9a72f967 100644 --- a/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs +++ b/tests/ImageSharp.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs @@ -62,7 +62,7 @@ public static void RunWithHwIntrinsicsFeature( ProcessStartInfo processStartInfo = new(); if (intrinsic.Key != HwIntrinsics.AllowAll) { - processStartInfo.Environment[$"COMPlus_{intrinsic.Value}"] = "0"; + processStartInfo.Environment[$"DOTNET_{intrinsic.Value}"] = "0"; RemoteExecutor.Invoke( action,