Günther Foidl 3 years ago
parent
commit
6ae2eb9eb2
  1. 12
      src/ImageSharp/Common/Helpers/Numerics.cs
  2. 8
      src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
  3. 84
      src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
  4. 4
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  5. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs
  6. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs
  7. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs
  8. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs
  9. 2
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs
  10. 2
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs
  11. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs
  12. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs
  13. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs
  14. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs
  15. 8
      src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs
  16. 4
      tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs
  17. 12
      tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs
  18. 4
      tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs
  19. 16
      tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs
  20. 18
      tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs
  21. 4
      tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs

12
src/ImageSharp/Common/Helpers/Numerics.cs

@ -55,6 +55,12 @@ internal static class Numerics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Modulo4(int x) => x & 3;
/// <summary>
/// Calculates <paramref name="x"/> % 4
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static nint Modulo4(nint x) => x & 3;
/// <summary>
/// Calculates <paramref name="x"/> % 8
/// </summary>
@ -430,9 +436,9 @@ internal static class Numerics
var vmin = new Vector<T>(min);
var vmax = new Vector<T>(max);
int n = span.Length / Vector<T>.Count;
int m = Modulo4(n);
int u = n - m;
nint n = (nint)(uint)span.Length / Vector<T>.Count;
nint m = Modulo4(n);
nint u = n - m;
ref Vector<T> vs0 = ref Unsafe.As<T, Vector<T>>(ref MemoryMarshal.GetReference(span));
ref Vector<T> vs1 = ref Unsafe.Add(ref vs0, 1);

8
src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs

@ -97,12 +97,12 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector<byte>.Count);
int n = dest.Length / Vector<byte>.Count;
nint n = (nint)(uint)dest.Length / Vector<byte>.Count;
ref Vector<byte> sourceBase = ref Unsafe.As<byte, Vector<byte>>(ref MemoryMarshal.GetReference(source));
ref Vector<float> destBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(dest));
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
Vector<byte> b = Unsafe.Add(ref sourceBase, i);
@ -132,13 +132,13 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector<byte>.Count);
int n = dest.Length / Vector<byte>.Count;
nint n = (nint)(uint)dest.Length / Vector<byte>.Count;
ref Vector<float> sourceBase =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));
ref Vector<byte> destBase = ref Unsafe.As<byte, Vector<byte>>(ref MemoryMarshal.GetReference(dest));
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector<float> s = ref Unsafe.Add(ref sourceBase, i * 4);

84
src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs

@ -221,11 +221,11 @@ internal static partial class SimdUtils
ref Vector256<float> destBase =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(dest));
int n = dest.Length / Vector256<float>.Count;
int m = Numerics.Modulo4(n);
int u = n - m;
nint n = (nint)(uint)dest.Length / Vector256<float>.Count;
nint m = Numerics.Modulo4(n);
nint u = n - m;
for (int i = 0; i < u; i += 4)
for (nint i = 0; i < u; i += 4)
{
ref Vector256<float> vd0 = ref Unsafe.Add(ref destBase, i);
ref Vector256<float> vs0 = ref Unsafe.Add(ref sourceBase, i);
@ -238,7 +238,7 @@ internal static partial class SimdUtils
if (m > 0)
{
for (int i = u; i < n; i++)
for (nint i = u; i < n; i++)
{
Unsafe.Add(ref destBase, i) = Avx.Permute(Unsafe.Add(ref sourceBase, i), control);
}
@ -253,11 +253,11 @@ internal static partial class SimdUtils
ref Vector128<float> destBase =
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(dest));
int n = dest.Length / Vector128<float>.Count;
int m = Numerics.Modulo4(n);
int u = n - m;
nint n = (nint)(uint)dest.Length / Vector128<float>.Count;
nint m = Numerics.Modulo4(n);
nint u = n - m;
for (int i = 0; i < u; i += 4)
for (nint i = 0; i < u; i += 4)
{
ref Vector128<float> vd0 = ref Unsafe.Add(ref destBase, i);
ref Vector128<float> vs0 = ref Unsafe.Add(ref sourceBase, i);
@ -276,7 +276,7 @@ internal static partial class SimdUtils
if (m > 0)
{
for (int i = u; i < n; i++)
for (nint i = u; i < n; i++)
{
Vector128<float> vs = Unsafe.Add(ref sourceBase, i);
Unsafe.Add(ref destBase, i) = Sse.Shuffle(vs, vs, control);
@ -306,11 +306,11 @@ internal static partial class SimdUtils
ref Vector256<byte> destBase =
ref Unsafe.As<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(dest));
int n = dest.Length / Vector256<byte>.Count;
int m = Numerics.Modulo4(n);
int u = n - m;
nint n = (nint)(uint)dest.Length / Vector256<byte>.Count;
nint m = Numerics.Modulo4(n);
nint u = n - m;
for (int i = 0; i < u; i += 4)
for (nint i = 0; i < u; i += 4)
{
ref Vector256<byte> vs0 = ref Unsafe.Add(ref sourceBase, i);
ref Vector256<byte> vd0 = ref Unsafe.Add(ref destBase, i);
@ -323,7 +323,7 @@ internal static partial class SimdUtils
if (m > 0)
{
for (int i = u; i < n; i++)
for (nint i = u; i < n; i++)
{
Unsafe.Add(ref destBase, i) = Avx2.Shuffle(Unsafe.Add(ref sourceBase, i), vshuffle);
}
@ -342,11 +342,11 @@ internal static partial class SimdUtils
ref Vector128<byte> destBase =
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
int n = dest.Length / Vector128<byte>.Count;
int m = Numerics.Modulo4(n);
int u = n - m;
nint n = (nint)(uint)dest.Length / Vector128<byte>.Count;
nint m = Numerics.Modulo4(n);
nint u = n - m;
for (int i = 0; i < u; i += 4)
for (nint i = 0; i < u; i += 4)
{
ref Vector128<byte> vs0 = ref Unsafe.Add(ref sourceBase, i);
ref Vector128<byte> vd0 = ref Unsafe.Add(ref destBase, i);
@ -359,7 +359,7 @@ internal static partial class SimdUtils
if (m > 0)
{
for (int i = u; i < n; i++)
for (nint i = u; i < n; i++)
{
Unsafe.Add(ref destBase, i) = Ssse3.Shuffle(Unsafe.Add(ref sourceBase, i), vshuffle);
}
@ -391,9 +391,9 @@ internal static partial class SimdUtils
ref Vector128<byte> destBase =
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
int n = source.Length / Vector128<byte>.Count;
nint n = (nint)(uint)source.Length / Vector128<byte>.Count;
for (int i = 0; i < n; i += 3)
for (nint i = 0; i < n; i += 3)
{
ref Vector128<byte> vs = ref Unsafe.Add(ref sourceBase, i);
@ -454,9 +454,9 @@ internal static partial class SimdUtils
ref Vector128<byte> destBase =
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
int n = source.Length / Vector128<byte>.Count;
nint n = (nint)(uint)source.Length / Vector128<byte>.Count;
for (int i = 0, j = 0; i < n; i += 3, j += 4)
for (nint i = 0, j = 0; i < n; i += 3, j += 4)
{
ref Vector128<byte> v0 = ref Unsafe.Add(ref sourceBase, i);
Vector128<byte> v1 = Unsafe.Add(ref v0, 1);
@ -498,9 +498,9 @@ internal static partial class SimdUtils
ref Vector128<byte> destBase =
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
int n = source.Length / Vector128<byte>.Count;
nint n = (nint)(uint)source.Length / Vector128<byte>.Count;
for (int i = 0, j = 0; i < n; i += 4, j += 3)
for (nint i = 0, j = 0; i < n; i += 4, j += 3)
{
ref Vector128<byte> vs = ref Unsafe.Add(ref sourceBase, i);
@ -650,16 +650,16 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector256<byte>.Count);
int n = dest.Length / Vector256<byte>.Count;
nint n = (nint)(uint)dest.Length / Vector256<byte>.Count;
ref Vector256<float> destBase =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(dest));
var scale = Vector256.Create(1 / (float)byte.MaxValue);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
int si = Vector256<byte>.Count * i;
nint si = Vector256<byte>.Count * i;
Vector256<int> i0 = Avx2.ConvertToVector256Int32(sourceBase + si);
Vector256<int> i1 = Avx2.ConvertToVector256Int32(sourceBase + si + Vector256<int>.Count);
Vector256<int> i2 = Avx2.ConvertToVector256Int32(sourceBase + si + (Vector256<int>.Count * 2));
@ -683,7 +683,7 @@ internal static partial class SimdUtils
// Sse
VerifySpanInput(source, dest, Vector128<byte>.Count);
int n = dest.Length / Vector128<byte>.Count;
nint n = (nint)(uint)dest.Length / Vector128<byte>.Count;
ref Vector128<float> destBase =
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(dest));
@ -691,9 +691,9 @@ internal static partial class SimdUtils
var scale = Vector128.Create(1 / (float)byte.MaxValue);
Vector128<byte> zero = Vector128<byte>.Zero;
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
int si = Vector128<byte>.Count * i;
nint si = Vector128<byte>.Count * i;
Vector128<int> i0, i1, i2, i3;
if (Sse41.IsSupported)
@ -782,7 +782,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector256<byte>.Count);
int n = dest.Length / Vector256<byte>.Count;
nint n = (nint)(uint)dest.Length / Vector256<byte>.Count;
ref Vector256<float> sourceBase =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(source));
@ -794,7 +794,7 @@ internal static partial class SimdUtils
ref byte maskBase = ref MemoryMarshal.GetReference(PermuteMaskDeinterleave8x32);
Vector256<int> mask = Unsafe.As<byte, Vector256<int>>(ref maskBase);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector256<float> s = ref Unsafe.Add(ref sourceBase, i * 4);
@ -821,7 +821,7 @@ internal static partial class SimdUtils
// Sse
VerifySpanInput(source, dest, Vector128<byte>.Count);
int n = dest.Length / Vector128<byte>.Count;
nint n = (nint)(uint)dest.Length / Vector128<byte>.Count;
ref Vector128<float> sourceBase =
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(source));
@ -831,7 +831,7 @@ internal static partial class SimdUtils
var scale = Vector128.Create((float)byte.MaxValue);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector128<float> s = ref Unsafe.Add(ref sourceBase, i * 4);
@ -864,7 +864,7 @@ internal static partial class SimdUtils
ref Vector256<byte> bBase = ref Unsafe.As<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(blueChannel));
ref byte dBase = ref Unsafe.As<Rgb24, byte>(ref MemoryMarshal.GetReference(destination));
int count = redChannel.Length / Vector256<byte>.Count;
nint count = (nint)(uint)redChannel.Length / Vector256<byte>.Count;
ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32);
Vector256<uint> control1 = Unsafe.As<byte, Vector256<uint>>(ref control1Bytes);
@ -875,7 +875,7 @@ internal static partial class SimdUtils
Vector256<byte> shuffleAlpha = Unsafe.As<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(ShuffleMaskShiftAlpha));
for (int i = 0; i < count; i++)
for (nint i = 0; i < count; i++)
{
Vector256<byte> r0 = Unsafe.Add(ref rBase, i);
Vector256<byte> g0 = Unsafe.Add(ref gBase, i);
@ -918,7 +918,7 @@ internal static partial class SimdUtils
Unsafe.As<byte, Vector256<byte>>(ref d4) = rgb4;
}
int slice = count * Vector256<byte>.Count;
int slice = (int)count * Vector256<byte>.Count;
redChannel = redChannel[slice..];
greenChannel = greenChannel[slice..];
blueChannel = blueChannel[slice..];
@ -936,12 +936,12 @@ internal static partial class SimdUtils
ref Vector256<byte> bBase = ref Unsafe.As<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(blueChannel));
ref Vector256<byte> dBase = ref Unsafe.As<Rgba32, Vector256<byte>>(ref MemoryMarshal.GetReference(destination));
int count = redChannel.Length / Vector256<byte>.Count;
nint count = (nint)(uint)redChannel.Length / Vector256<byte>.Count;
ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32);
Vector256<uint> control1 = Unsafe.As<byte, Vector256<uint>>(ref control1Bytes);
var a = Vector256.Create((byte)255);
for (int i = 0; i < count; i++)
for (nint i = 0; i < count; i++)
{
Vector256<byte> r0 = Unsafe.Add(ref rBase, i);
Vector256<byte> g0 = Unsafe.Add(ref gBase, i);
@ -970,7 +970,7 @@ internal static partial class SimdUtils
Unsafe.Add(ref d0, 3) = rgb4;
}
int slice = count * Vector256<byte>.Count;
int slice = (int)count * Vector256<byte>.Count;
redChannel = redChannel[slice..];
greenChannel = greenChannel[slice..];
blueChannel = blueChannel[slice..];

4
src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs

@ -425,7 +425,7 @@ internal partial struct Block8x8F : IEquatable<Block8x8F>
Vector256<int> targetVector = Vector256.Create(value);
ref Vector256<float> blockStride = ref this.V0;
for (int i = 0; i < RowCount; i++)
for (nint i = 0; i < RowCount; i++)
{
Vector256<int> areEqual = Avx2.CompareEqual(Avx.ConvertToVector256Int32WithTruncation(Unsafe.Add(ref this.V0, i)), targetVector);
if (Avx2.MoveMask(areEqual.AsByte()) != equalityMask)
@ -439,7 +439,7 @@ internal partial struct Block8x8F : IEquatable<Block8x8F>
ref float scalars = ref Unsafe.As<Block8x8F, float>(ref this);
for (int i = 0; i < Size; i++)
for (nint i = 0; i < Size; i++)
{
if ((int)Unsafe.Add(ref scalars, i) != value)
{

4
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));
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint i = 0; i < n; i++)
{
ref Vector256<float> c = ref Unsafe.Add(ref c0Base, i);
@ -71,7 +71,7 @@ internal abstract partial class JpegColorConverterBase
var scale = Vector256.Create(maxValue);
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint i = 0; i < n; i++)
{
Vector256<float> ctmp = Avx.Subtract(scale, Unsafe.Add(ref srcR, i));

4
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs

@ -30,7 +30,7 @@ internal abstract partial class JpegColorConverterBase
var scale = new Vector<float>(1 / (this.MaximumValue * this.MaximumValue));
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
ref Vector<float> 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<float>(maxValue);
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
Vector<float> ctmp = scale - Unsafe.Add(ref srcR, i);

4
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);
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint i = 0; i < n; i++)
{
ref Vector256<float> 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);
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint i = 0; i < n; i++)
{
ref Vector256<float> r = ref Unsafe.Add(ref srcRed, i);

4
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs

@ -24,7 +24,7 @@ internal abstract partial class JpegColorConverterBase
var scale = new Vector<float>(1 / this.MaximumValue);
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
ref Vector<float> c0 = ref Unsafe.Add(ref cBase, i);
@ -53,7 +53,7 @@ internal abstract partial class JpegColorConverterBase
var gMult = new Vector<float>(0.587f);
var bMult = new Vector<float>(0.114f);
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
Vector<float> r = Unsafe.Add(ref srcR, i);

2
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);
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint i = 0; i < n; i++)
{
ref Vector256<float> r = ref Unsafe.Add(ref rBase, i);

2
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs

@ -28,7 +28,7 @@ internal abstract partial class JpegColorConverterBase
var scale = new Vector<float>(1 / this.MaximumValue);
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
ref Vector<float> r = ref Unsafe.Add(ref rBase, i);

4
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:
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint 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);
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint i = 0; i < n; i++)
{
Vector256<float> r = Unsafe.Add(ref srcR, i);

4
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs

@ -35,7 +35,7 @@ internal abstract partial class JpegColorConverterBase
var gCrMult = new Vector<float>(-YCbCrScalar.GCrMult);
var bCbMult = new Vector<float>(YCbCrScalar.BCbMult);
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
// y = yVals[i];
@ -103,7 +103,7 @@ internal abstract partial class JpegColorConverterBase
var gCrMult = new Vector<float>(0.418688f);
var bCrMult = new Vector<float>(0.081312f);
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
Vector<float> r = Unsafe.Add(ref srcR, i);

4
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:
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint 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);
nint n = values.Component0.Length / Vector256<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector256<float>.Count;
for (nint i = 0; i < n; i++)
{
Vector256<float> r = Avx.Subtract(maxSampleValue, Unsafe.Add(ref srcR, i));

4
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs

@ -36,7 +36,7 @@ internal abstract partial class JpegColorConverterBase
var gCrMult = new Vector<float>(-YCbCrScalar.GCrMult);
var bCbMult = new Vector<float>(YCbCrScalar.BCbMult);
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
// y = yVals[i];
@ -107,7 +107,7 @@ internal abstract partial class JpegColorConverterBase
var gCrMult = new Vector<float>(0.418688f);
var bCrMult = new Vector<float>(0.081312f);
nint n = values.Component0.Length / Vector<float>.Count;
nint n = (nint)(uint)values.Component0.Length / Vector<float>.Count;
for (nint i = 0; i < n; i++)
{
Vector<float> r = maxSampleValue - Unsafe.Add(ref srcR, i);

8
src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs

@ -122,7 +122,7 @@ internal class ComponentProcessor : IDisposable
ref Vector256<float> sourceVectorRef = ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(source));
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
nint count = source.Length / Vector256<float>.Count;
nint count = (nint)(uint)source.Length / Vector256<float>.Count;
for (nint 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<float> targetVectorRef = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(target));
ref Vector<float> sourceVectorRef = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));
nint count = source.Length / Vector<float>.Count;
nint count = (nint)(uint)source.Length / Vector<float>.Count;
for (nint i = 0; i < count; i++)
{
Unsafe.Add(ref targetVectorRef, i) += Unsafe.Add(ref sourceVectorRef, i);
@ -200,7 +200,7 @@ internal class ComponentProcessor : IDisposable
ref Vector256<float> targetVectorRef = ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(target));
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
nint count = target.Length / Vector256<float>.Count;
nint count = (nint)(uint)target.Length / Vector256<float>.Count;
var multiplierVector = Vector256.Create(multiplier);
for (nint i = 0; i < count; i++)
{
@ -211,7 +211,7 @@ internal class ComponentProcessor : IDisposable
{
ref Vector<float> targetVectorRef = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(target));
nint count = target.Length / Vector<float>.Count;
nint count = (nint)(uint)target.Length / Vector<float>.Count;
var multiplierVector = new Vector<float>(multiplier);
for (nint i = 0; i < count; i++)
{

4
tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

@ -103,7 +103,7 @@ public class FromVector4Rgba32 : FromVector4<Rgba32>
Span<float> src = MemoryMarshal.Cast<Vector4, float>(this.source.GetSpan());
Span<byte> dest = MemoryMarshal.Cast<Rgba32, byte>(this.destination.GetSpan());
int n = dest.Length / Vector<byte>.Count;
nint n = (nint)(uint)dest.Length / Vector<byte>.Count;
ref Vector256<float> sourceBase =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(src));
@ -114,7 +114,7 @@ public class FromVector4Rgba32 : FromVector4<Rgba32>
var maxBytes = Vector256.Create(255f);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector256<float> s = ref Unsafe.Add(ref sourceBase, i * 4);

12
tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs

@ -54,13 +54,13 @@ public class ToVector4_Rgba32 : ToVector4<Rgba32>
Span<byte> sBytes = MemoryMarshal.Cast<Rgba32, byte>(this.source.GetSpan());
Span<float> dFloats = MemoryMarshal.Cast<Vector4, float>(this.destination.GetSpan());
int n = dFloats.Length / Vector<byte>.Count;
nint n = (nint)(uint)dFloats.Length / Vector<byte>.Count;
ref Vector<byte> sourceBase = ref Unsafe.As<byte, Vector<byte>>(ref MemoryMarshal.GetReference((ReadOnlySpan<byte>)sBytes));
ref Vector<float> destBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(dFloats));
ref Vector<uint> destBaseU = ref Unsafe.As<Vector<float>, Vector<uint>>(ref destBase);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
Vector<byte> b = Unsafe.Add(ref sourceBase, i);
@ -75,10 +75,10 @@ public class ToVector4_Rgba32 : ToVector4<Rgba32>
Unsafe.Add(ref d, 3) = w3;
}
n = dFloats.Length / Vector<float>.Count;
n = (nint)(uint)dFloats.Length / Vector<float>.Count;
var scale = new Vector<float>(1f / 255f);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector<float> dRef = ref Unsafe.Add(ref destBase, i);
@ -96,13 +96,13 @@ public class ToVector4_Rgba32 : ToVector4<Rgba32>
Span<byte> sBytes = MemoryMarshal.Cast<Rgba32, byte>(this.source.GetSpan());
Span<float> dFloats = MemoryMarshal.Cast<Vector4, float>(this.destination.GetSpan());
int n = dFloats.Length / Vector<byte>.Count;
nint n = (nint)(uint)dFloats.Length / Vector<byte>.Count;
ref Vector<byte> sourceBase = ref Unsafe.As<byte, Vector<byte>>(ref MemoryMarshal.GetReference((ReadOnlySpan<byte>)sBytes));
ref Vector<float> destBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(dFloats));
var scale = new Vector<float>(1f / 255f);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
Vector<byte> b = Unsafe.Add(ref sourceBase, i);

4
tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs

@ -205,14 +205,14 @@ public unsafe class PixelConversion_PackFromRgbPlanes
ref Vector256<float> bBase = ref Unsafe.As<float, Vector256<float>>(ref this.bFloat[0]);
ref Vector256<float> resultBase = ref Unsafe.As<float, Vector256<float>>(ref this.rgbaFloat[0]);
int count = this.Count / Vector256<float>.Count;
nint count = (nint)(uint)this.Count / Vector256<float>.Count;
ref byte control = ref MemoryMarshal.GetReference(SimdUtils.HwIntrinsics.PermuteMaskEvenOdd8x32);
Vector256<int> vcontrol = Unsafe.As<byte, Vector256<int>>(ref control);
var va = Vector256.Create(1F);
for (int i = 0; i < count; i++)
for (nint i = 0; i < count; i++)
{
Vector256<float> r = Unsafe.Add(ref rBase, i);
Vector256<float> g = Unsafe.Add(ref gBase, i);

16
tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs

@ -25,14 +25,14 @@ public class UInt32ToSingle
{
ref Vector<float> b = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
int n = Count / Vector<float>.Count;
nint n = Count / Vector<float>.Count;
var bVec = new Vector<float>(256.0f / 255.0f);
var magicFloat = new Vector<float>(32768.0f);
var magicInt = new Vector<uint>(1191182336); // reinterpreted value of 32768.0f
var mask = new Vector<uint>(255);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector<float> df = ref Unsafe.Add(ref b, i);
@ -50,14 +50,14 @@ public class UInt32ToSingle
[Benchmark]
public void StandardSimd()
{
int n = Count / Vector<float>.Count;
nint n = Count / Vector<float>.Count;
ref Vector<float> bf = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
ref Vector<uint> bu = ref Unsafe.As<Vector<float>, Vector<uint>>(ref bf);
var scale = new Vector<float>(1f / 255f);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
Vector<uint> u = Unsafe.Add(ref bu, i);
Vector<float> v = Vector.ConvertToSingle(u);
@ -69,14 +69,14 @@ public class UInt32ToSingle
[Benchmark]
public void StandardSimdFromInt()
{
int n = Count / Vector<float>.Count;
nint n = Count / Vector<float>.Count;
ref Vector<float> bf = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
ref Vector<int> bu = ref Unsafe.As<Vector<float>, Vector<int>>(ref bf);
var scale = new Vector<float>(1f / 255f);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
Vector<int> u = Unsafe.Add(ref bu, i);
Vector<float> v = Vector.ConvertToSingle(u);
@ -88,12 +88,12 @@ public class UInt32ToSingle
[Benchmark]
public void StandardSimdFromInt_RefCast()
{
int n = Count / Vector<float>.Count;
nint n = Count / Vector<float>.Count;
ref Vector<float> bf = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
var scale = new Vector<float>(1f / 255f);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector<float> fRef = ref Unsafe.Add(ref bf, i);

18
tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs

@ -63,14 +63,14 @@ public class VectorFetching
var v = new Vector<float>(this.testValue);
ref Vector<float> start = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
int n = this.InputSize / Vector<uint>.Count;
nint n = (nint)(uint)this.InputSize / Vector<uint>.Count;
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector<float> p = ref Unsafe.Add(ref start, i);
Vector<float> a = p;
a = a * v;
a *= v;
p = a;
}
@ -82,12 +82,12 @@ public class VectorFetching
var v = new Vector<float>(this.testValue);
ref Vector<float> start = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
int n = this.InputSize / Vector<uint>.Count;
nint n = (nint)(uint)this.InputSize / Vector<uint>.Count;
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector<float> a = ref Unsafe.Add(ref start, i);
a = a * v;
a *= v;
}
}
@ -100,12 +100,12 @@ public class VectorFetching
ref Vector<float> start = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(span));
int n = this.InputSize / Vector<uint>.Count;
nint n = (nint)(uint)this.InputSize / Vector<uint>.Count;
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
ref Vector<float> a = ref Unsafe.Add(ref start, i);
a = a * v;
a *= v;
}
}
}

4
tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs

@ -42,12 +42,12 @@ public class WidenBytesToUInt32
[Benchmark]
public void Simd()
{
int n = Count / Vector<byte>.Count;
nint n = Count / Vector<byte>.Count;
ref Vector<byte> sBase = ref Unsafe.As<byte, Vector<byte>>(ref this.source[0]);
ref Vector<uint> dBase = ref Unsafe.As<uint, Vector<uint>>(ref this.dest[0]);
for (int i = 0; i < n; i++)
for (nint i = 0; i < n; i++)
{
Vector<byte> b = Unsafe.Add(ref sBase, i);

Loading…
Cancel
Save