Browse Source

Fixed division by vector length

pull/2401/head
Günther Foidl 3 years ago
parent
commit
2bbf1cb9b3
  1. 4
      src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
  2. 18
      src/ImageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs
  3. 2
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs
  4. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs
  5. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs
  6. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs
  7. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs
  8. 2
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.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. 10
      src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs
  16. 5
      tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs
  17. 4
      tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs
  18. 2
      tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_PackFromRgbPlanes.cs
  19. 10
      tests/ImageSharp.Benchmarks/General/Vectorization/UInt32ToSingle.cs
  20. 6
      tests/ImageSharp.Benchmarks/General/Vectorization/VectorFetching.cs
  21. 2
      tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs

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

@ -97,7 +97,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector<byte>.Count);
nuint n = (uint)(dest.Length / Vector<byte>.Count);
nuint n = (uint)dest.Length / (uint)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));
@ -132,7 +132,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector<byte>.Count);
nuint n = (uint)(dest.Length / Vector<byte>.Count);
nuint n = (uint)dest.Length / (uint)Vector<byte>.Count;
ref Vector<float> sourceBase =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));

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

@ -391,7 +391,7 @@ internal static partial class SimdUtils
ref Vector128<byte> destBase =
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
nuint n = (uint)(source.Length / Vector128<byte>.Count);
nuint n = (uint)source.Length / (uint)Vector128<byte>.Count;
for (nuint i = 0; i < n; i += 3)
{
@ -454,7 +454,7 @@ internal static partial class SimdUtils
ref Vector128<byte> destBase =
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
nuint n = (uint)(source.Length / Vector128<byte>.Count);
nuint n = (uint)source.Length / (uint)Vector128<byte>.Count;
for (nuint i = 0, j = 0; i < n; i += 3, j += 4)
{
@ -498,7 +498,7 @@ internal static partial class SimdUtils
ref Vector128<byte> destBase =
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
nuint n = (uint)(source.Length / Vector128<byte>.Count);
nuint n = (uint)source.Length / (uint)Vector128<byte>.Count;
for (nuint i = 0, j = 0; i < n; i += 4, j += 3)
{
@ -650,7 +650,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector256<byte>.Count);
nuint n = (uint)(dest.Length / Vector256<byte>.Count);
nuint n = (uint)dest.Length / (uint)Vector256<byte>.Count;
ref Vector256<float> destBase =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(dest));
@ -683,7 +683,7 @@ internal static partial class SimdUtils
// Sse
VerifySpanInput(source, dest, Vector128<byte>.Count);
nuint n = (uint)(dest.Length / Vector128<byte>.Count);
nuint n = (uint)dest.Length / (uint)Vector128<byte>.Count;
ref Vector128<float> destBase =
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(dest));
@ -782,7 +782,7 @@ internal static partial class SimdUtils
{
VerifySpanInput(source, dest, Vector256<byte>.Count);
nuint n = (uint)(dest.Length / Vector256<byte>.Count);
nuint n = (uint)dest.Length / (uint)Vector256<byte>.Count;
ref Vector256<float> sourceBase =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(source));
@ -821,7 +821,7 @@ internal static partial class SimdUtils
// Sse
VerifySpanInput(source, dest, Vector128<byte>.Count);
nuint n = (uint)(dest.Length / Vector128<byte>.Count);
nuint n = (uint)dest.Length / (uint)Vector128<byte>.Count;
ref Vector128<float> sourceBase =
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(source));
@ -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));
nuint count = (uint)(redChannel.Length / Vector256<byte>.Count);
nuint count = (uint)redChannel.Length / (uint)Vector256<byte>.Count;
ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32);
Vector256<uint> control1 = Unsafe.As<byte, Vector256<uint>>(ref control1Bytes);
@ -936,7 +936,7 @@ 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));
nuint count = (uint)(redChannel.Length / Vector256<byte>.Count);
nuint count = (uint)redChannel.Length / (uint)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);

2
src/ImageSharp/Formats/Jpeg/Components/Block8x8F.ScaledCopy.cs

@ -98,7 +98,7 @@ internal partial struct Block8x8F
nuint xx = x * horizontalScale;
float value = this[(int)(y8 + x)];
nuint baseIdx = (uint)((yy * areaStride) + xx);
nuint baseIdx = (yy * areaStride) + xx;
for (nuint i = 0; i < verticalScale; i++, baseIdx += areaStride)
{

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

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

10
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
nuint count = (uint)(source.Length / Vector256<float>.Count);
nuint count = (uint)source.Length / (uint)Vector256<float>.Count;
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<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));
nuint count = (uint)(source.Length / Vector<float>.Count);
nuint count = (uint)source.Length / (uint)Vector<float>.Count;
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 / Vector256<float>.Count);
nuint length = (uint)touchedCount / (uint)Vector256<float>.Count;
for (uint i = 0; i < haddIterationsCount; 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
nuint count = (uint)(target.Length / Vector256<float>.Count);
nuint count = (uint)target.Length / (uint)Vector256<float>.Count;
var multiplierVector = Vector256.Create(multiplier);
for (nuint 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));
nuint count = (uint)(target.Length / Vector<float>.Count);
nuint count = (uint)target.Length / (uint)Vector<float>.Count;
var multiplierVector = new Vector<float>(multiplier);
for (nuint i = 0; i < count; i++)
{

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

@ -103,10 +103,9 @@ 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());
nuint n = (uint)(dest.Length / Vector<byte>.Count);
nuint n = (uint)dest.Length / (uint)Vector<byte>.Count;
ref Vector256<float> sourceBase =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(src));
ref Vector256<float> sourceBase = ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(src));
ref Vector256<byte> destBase = ref Unsafe.As<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(dest));
ref byte maskBase = ref MemoryMarshal.GetReference(PermuteMaskDeinterleave8x32);

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

@ -54,7 +54,7 @@ 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());
nuint n = (uint)(dFloats.Length / Vector<byte>.Count);
nuint n = (uint)dFloats.Length / (uint)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));
@ -96,7 +96,7 @@ 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());
nuint n = (uint)(dFloats.Length / Vector<byte>.Count);
nuint n = (uint)dFloats.Length / (uint)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));

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

@ -205,7 +205,7 @@ 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]);
nuint count = (uint)(this.Count / Vector256<float>.Count);
nuint count = (uint)this.Count / (uint)Vector256<float>.Count;
ref byte control = ref MemoryMarshal.GetReference(SimdUtils.HwIntrinsics.PermuteMaskEvenOdd8x32);
Vector256<int> vcontrol = Unsafe.As<byte, Vector256<int>>(ref control);

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

@ -12,7 +12,7 @@ public class UInt32ToSingle
{
private float[] data;
private const int Count = 32;
private const uint Count = 32;
[GlobalSetup]
public void Setup()
@ -25,7 +25,7 @@ public class UInt32ToSingle
{
ref Vector<float> b = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
nuint n = (uint)(Count / Vector<float>.Count);
nuint n = Count / (uint)Vector<float>.Count;
var bVec = new Vector<float>(256.0f / 255.0f);
var magicFloat = new Vector<float>(32768.0f);
@ -50,7 +50,7 @@ public class UInt32ToSingle
[Benchmark]
public void StandardSimd()
{
nuint n = (uint)(Count / Vector<float>.Count);
nuint n = Count / (uint)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);
@ -69,7 +69,7 @@ public class UInt32ToSingle
[Benchmark]
public void StandardSimdFromInt()
{
nuint n = (uint)(Count / Vector<float>.Count);
nuint n = Count / (uint)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);
@ -88,7 +88,7 @@ public class UInt32ToSingle
[Benchmark]
public void StandardSimdFromInt_RefCast()
{
nuint n = (uint)(Count / Vector<float>.Count);
nuint n = Count / (uint)Vector<float>.Count;
ref Vector<float> bf = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
var scale = new Vector<float>(1f / 255f);

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

@ -63,7 +63,7 @@ public class VectorFetching
var v = new Vector<float>(this.testValue);
ref Vector<float> start = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
nuint n = (uint)(this.InputSize / Vector<uint>.Count);
nuint n = (uint)this.InputSize / (uint)Vector<uint>.Count;
for (nuint i = 0; i < n; i++)
{
@ -82,7 +82,7 @@ public class VectorFetching
var v = new Vector<float>(this.testValue);
ref Vector<float> start = ref Unsafe.As<float, Vector<float>>(ref this.data[0]);
nuint n = (uint)(this.InputSize / Vector<uint>.Count);
nuint n = (uint)this.InputSize / (uint)Vector<uint>.Count;
for (nuint i = 0; i < n; i++)
{
@ -100,7 +100,7 @@ public class VectorFetching
ref Vector<float> start = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(span));
nuint n = (uint)(this.InputSize / Vector<uint>.Count);
nuint n = (uint)this.InputSize / (uint)Vector<uint>.Count;
for (nuint i = 0; i < n; i++)
{

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

@ -42,7 +42,7 @@ public class WidenBytesToUInt32
[Benchmark]
public void Simd()
{
nuint n = (uint)(Count / Vector<byte>.Count);
nuint n = Count / (uint)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]);

Loading…
Cancel
Save