Skip to content

Commit 2bbf1cb

Browse files
committed
Fixed division by vector length
1 parent 84bad73 commit 2bbf1cb

21 files changed

+50
-51
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal static void ByteToNormalizedFloat(ReadOnlySpan<byte> source, Span<float
9797
{
9898
VerifySpanInput(source, dest, Vector<byte>.Count);
9999

100-
nuint n = (uint)(dest.Length / Vector<byte>.Count);
100+
nuint n = (uint)dest.Length / (uint)Vector<byte>.Count;
101101

102102
ref Vector<byte> sourceBase = ref Unsafe.As<byte, Vector<byte>>(ref MemoryMarshal.GetReference(source));
103103
ref Vector<float> destBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(dest));
@@ -132,7 +132,7 @@ internal static void NormalizedFloatToByteSaturate(
132132
{
133133
VerifySpanInput(source, dest, Vector<byte>.Count);
134134

135-
nuint n = (uint)(dest.Length / Vector<byte>.Count);
135+
nuint n = (uint)dest.Length / (uint)Vector<byte>.Count;
136136

137137
ref Vector<float> sourceBase =
138138
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private static void Shuffle3(
391391
ref Vector128<byte> destBase =
392392
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
393393

394-
nuint n = (uint)(source.Length / Vector128<byte>.Count);
394+
nuint n = (uint)source.Length / (uint)Vector128<byte>.Count;
395395

396396
for (nuint i = 0; i < n; i += 3)
397397
{
@@ -454,7 +454,7 @@ private static void Pad3Shuffle4(
454454
ref Vector128<byte> destBase =
455455
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
456456

457-
nuint n = (uint)(source.Length / Vector128<byte>.Count);
457+
nuint n = (uint)source.Length / (uint)Vector128<byte>.Count;
458458

459459
for (nuint i = 0, j = 0; i < n; i += 3, j += 4)
460460
{
@@ -498,7 +498,7 @@ private static void Shuffle4Slice3(
498498
ref Vector128<byte> destBase =
499499
ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(dest));
500500

501-
nuint n = (uint)(source.Length / Vector128<byte>.Count);
501+
nuint n = (uint)source.Length / (uint)Vector128<byte>.Count;
502502

503503
for (nuint i = 0, j = 0; i < n; i += 4, j += 3)
504504
{
@@ -650,7 +650,7 @@ internal static unsafe void ByteToNormalizedFloat(
650650
{
651651
VerifySpanInput(source, dest, Vector256<byte>.Count);
652652

653-
nuint n = (uint)(dest.Length / Vector256<byte>.Count);
653+
nuint n = (uint)dest.Length / (uint)Vector256<byte>.Count;
654654

655655
ref Vector256<float> destBase =
656656
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(dest));
@@ -683,7 +683,7 @@ internal static unsafe void ByteToNormalizedFloat(
683683
// Sse
684684
VerifySpanInput(source, dest, Vector128<byte>.Count);
685685

686-
nuint n = (uint)(dest.Length / Vector128<byte>.Count);
686+
nuint n = (uint)dest.Length / (uint)Vector128<byte>.Count;
687687

688688
ref Vector128<float> destBase =
689689
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(dest));
@@ -782,7 +782,7 @@ internal static void NormalizedFloatToByteSaturate(
782782
{
783783
VerifySpanInput(source, dest, Vector256<byte>.Count);
784784

785-
nuint n = (uint)(dest.Length / Vector256<byte>.Count);
785+
nuint n = (uint)dest.Length / (uint)Vector256<byte>.Count;
786786

787787
ref Vector256<float> sourceBase =
788788
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(source));
@@ -821,7 +821,7 @@ internal static void NormalizedFloatToByteSaturate(
821821
// Sse
822822
VerifySpanInput(source, dest, Vector128<byte>.Count);
823823

824-
nuint n = (uint)(dest.Length / Vector128<byte>.Count);
824+
nuint n = (uint)dest.Length / (uint)Vector128<byte>.Count;
825825

826826
ref Vector128<float> sourceBase =
827827
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(source));
@@ -864,7 +864,7 @@ internal static void PackFromRgbPlanesAvx2Reduce(
864864
ref Vector256<byte> bBase = ref Unsafe.As<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(blueChannel));
865865
ref byte dBase = ref Unsafe.As<Rgb24, byte>(ref MemoryMarshal.GetReference(destination));
866866

867-
nuint count = (uint)(redChannel.Length / Vector256<byte>.Count);
867+
nuint count = (uint)redChannel.Length / (uint)Vector256<byte>.Count;
868868

869869
ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32);
870870
Vector256<uint> control1 = Unsafe.As<byte, Vector256<uint>>(ref control1Bytes);
@@ -936,7 +936,7 @@ internal static void PackFromRgbPlanesAvx2Reduce(
936936
ref Vector256<byte> bBase = ref Unsafe.As<byte, Vector256<byte>>(ref MemoryMarshal.GetReference(blueChannel));
937937
ref Vector256<byte> dBase = ref Unsafe.As<Rgba32, Vector256<byte>>(ref MemoryMarshal.GetReference(destination));
938938

939-
nuint count = (uint)(redChannel.Length / Vector256<byte>.Count);
939+
nuint count = (uint)redChannel.Length / (uint)Vector256<byte>.Count;
940940
ref byte control1Bytes = ref MemoryMarshal.GetReference(PermuteMaskEvenOdd8x32);
941941
Vector256<uint> control1 = Unsafe.As<byte, Vector256<uint>>(ref control1Bytes);
942942
var a = Vector256.Create((byte)255);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void CopyArbitraryScale(ref float areaOrigin, uint areaStride, uint hori
9898
nuint xx = x * horizontalScale;
9999

100100
float value = this[(int)(y8 + x)];
101-
nuint baseIdx = (uint)((yy * areaStride) + xx);
101+
nuint baseIdx = (yy * areaStride) + xx;
102102

103103
for (nuint i = 0; i < verticalScale; i++, baseIdx += areaStride)
104104
{

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
3232
// Used for the color conversion
3333
var scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue));
3434

35-
nuint n = (uint)(values.Component0.Length / Vector256<float>.Count);
35+
nuint n = (uint)values.Component0.Length / (uint)Vector256<float>.Count;
3636
for (nuint i = 0; i < n; i++)
3737
{
3838
ref Vector256<float> c = ref Unsafe.Add(ref c0Base, i);
@@ -71,7 +71,7 @@ public static void ConvertFromRgb(in ComponentValues values, float maxValue, Spa
7171

7272
var scale = Vector256.Create(maxValue);
7373

74-
nuint n = (uint)(values.Component0.Length / Vector256<float>.Count);
74+
nuint n = (uint)values.Component0.Length / (uint)Vector256<float>.Count;
7575
for (nuint i = 0; i < n; i++)
7676
{
7777
Vector256<float> ctmp = Avx.Subtract(scale, Unsafe.Add(ref srcR, i));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
3030

3131
var scale = new Vector<float>(1 / (this.MaximumValue * this.MaximumValue));
3232

33-
nuint n = (uint)(values.Component0.Length / Vector<float>.Count);
33+
nuint n = (uint)values.Component0.Length / (uint)Vector<float>.Count;
3434
for (nuint i = 0; i < n; i++)
3535
{
3636
ref Vector<float> c = ref Unsafe.Add(ref cBase, i);
@@ -78,7 +78,7 @@ public static void ConvertFromRgbInplaceVectorized(in ComponentValues values, fl
7878
// Used for the color conversion
7979
var scale = new Vector<float>(maxValue);
8080

81-
nuint n = (uint)(values.Component0.Length / Vector<float>.Count);
81+
nuint n = (uint)values.Component0.Length / (uint)Vector<float>.Count;
8282
for (nuint i = 0; i < n; i++)
8383
{
8484
Vector<float> ctmp = scale - Unsafe.Add(ref srcR, i);

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
2727
// Used for the color conversion
2828
var scale = Vector256.Create(1 / this.MaximumValue);
2929

30-
nuint n = (uint)(values.Component0.Length / Vector256<float>.Count);
30+
nuint n = (uint)values.Component0.Length / (uint)Vector256<float>.Count;
3131
for (nuint i = 0; i < n; i++)
3232
{
3333
ref Vector256<float> c0 = ref Unsafe.Add(ref c0Base, i);
@@ -53,7 +53,7 @@ public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane
5353
var f0587 = Vector256.Create(0.587f);
5454
var f0114 = Vector256.Create(0.114f);
5555

56-
nuint n = (uint)(values.Component0.Length / Vector256<float>.Count);
56+
nuint n = (uint)values.Component0.Length / (uint)Vector256<float>.Count;
5757
for (nuint i = 0; i < n; i++)
5858
{
5959
ref Vector256<float> r = ref Unsafe.Add(ref srcRed, i);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
2424

2525
var scale = new Vector<float>(1 / this.MaximumValue);
2626

27-
nuint n = (uint)(values.Component0.Length / Vector<float>.Count);
27+
nuint n = (uint)values.Component0.Length / (uint)Vector<float>.Count;
2828
for (nuint i = 0; i < n; i++)
2929
{
3030
ref Vector<float> c0 = ref Unsafe.Add(ref cBase, i);
@@ -53,7 +53,7 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span
5353
var gMult = new Vector<float>(0.587f);
5454
var bMult = new Vector<float>(0.114f);
5555

56-
nuint n = (uint)(values.Component0.Length / Vector<float>.Count);
56+
nuint n = (uint)values.Component0.Length / (uint)Vector<float>.Count;
5757
for (nuint i = 0; i < n; i++)
5858
{
5959
Vector<float> r = Unsafe.Add(ref srcR, i);

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
3030

3131
// Used for the color conversion
3232
var scale = Vector128.Create(1 / this.MaximumValue);
33-
nuint n = (uint)(values.Component0.Length / Vector128<float>.Count);
33+
nuint n = (uint)values.Component0.Length / (uint)Vector128<float>.Count;
3434
for (nuint i = 0; i < n; i++)
3535
{
3636
ref Vector128<float> r = ref Unsafe.Add(ref rBase, i);

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override void ConvertToRgbInplace(in ComponentValues values)
2929

3030
// Used for the color conversion
3131
var scale = Vector256.Create(1 / this.MaximumValue);
32-
nuint n = (uint)(values.Component0.Length / Vector256<float>.Count);
32+
nuint n = (uint)values.Component0.Length / (uint)Vector256<float>.Count;
3333
for (nuint i = 0; i < n; i++)
3434
{
3535
ref Vector256<float> r = ref Unsafe.Add(ref rBase, i);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
2828

2929
var scale = new Vector<float>(1 / this.MaximumValue);
3030

31-
nuint n = (uint)(values.Component0.Length / Vector<float>.Count);
31+
nuint n = (uint)values.Component0.Length / (uint)Vector<float>.Count;
3232
for (nuint i = 0; i < n; i++)
3333
{
3434
ref Vector<float> r = ref Unsafe.Add(ref rBase, i);

0 commit comments

Comments
 (0)