Skip to content

Commit

Permalink
Merge pull request #2401 from gfoidl/codegen-optimizations
Browse files Browse the repository at this point in the history
Low-hanging fruit codegen optimizations
  • Loading branch information
JimBobSquarePants authored Mar 24, 2023
2 parents d7cd46f + 2bbf1cb commit 0a1f05b
Show file tree
Hide file tree
Showing 182 changed files with 1,854 additions and 1,793 deletions.
4 changes: 2 additions & 2 deletions src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static unsafe void CompandAvx2(Span<Vector4> vectors, float[] table)

// Divide by 2 as 4 elements per Vector4 and 8 per Vector256<float>
ref Vector256<float> vectorsBase = ref Unsafe.As<Vector4, Vector256<float>>(ref MemoryMarshal.GetReference(vectors));
ref Vector256<float> vectorsLast = ref Unsafe.Add(ref vectorsBase, (IntPtr)((uint)vectors.Length / 2u));
ref Vector256<float> vectorsLast = ref Unsafe.Add(ref vectorsBase, (uint)vectors.Length / 2u);

while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
{
Expand Down Expand Up @@ -204,7 +204,7 @@ private static unsafe void CompandScalar(Span<Vector4> vectors, float[] table)
Vector4 zero = Vector4.Zero;
var scale = new Vector4(Scale);
ref Vector4 vectorsBase = ref MemoryMarshal.GetReference(vectors);
ref Vector4 vectorsLast = ref Unsafe.Add(ref vectorsBase, vectors.Length);
ref Vector4 vectorsLast = ref Unsafe.Add(ref vectorsBase, (uint)vectors.Length);

while (Unsafe.IsAddressLessThan(ref vectorsBase, ref vectorsLast))
{
Expand Down
26 changes: 13 additions & 13 deletions src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Convert(ReadOnlySpan<CieLch> source, Span<CieLab> destination)
ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -70,7 +70,7 @@ public void Convert(ReadOnlySpan<CieLchuv> source, Span<CieLab> destination)
ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -103,7 +103,7 @@ public void Convert(ReadOnlySpan<CieLuv> source, Span<CieLab> destination)
ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -136,7 +136,7 @@ public void Convert(ReadOnlySpan<CieXyy> source, Span<CieLab> destination)
ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -169,7 +169,7 @@ public void Convert(ReadOnlySpan<CieXyz> source, Span<CieLab> destination)
ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -201,7 +201,7 @@ public void Convert(ReadOnlySpan<Cmyk> source, Span<CieLab> destination)
ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -234,7 +234,7 @@ public void Convert(ReadOnlySpan<Hsl> source, Span<CieLab> destination)
ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -266,7 +266,7 @@ public void Convert(ReadOnlySpan<Hsv> source, Span<CieLab> destination)
ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -299,7 +299,7 @@ public void Convert(ReadOnlySpan<HunterLab> source, Span<CieLab> destination)
ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -332,7 +332,7 @@ public void Convert(ReadOnlySpan<Lms> source, Span<CieLab> destination)
ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -365,7 +365,7 @@ public void Convert(ReadOnlySpan<LinearRgb> source, Span<CieLab> destination)
ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -398,7 +398,7 @@ public void Convert(ReadOnlySpan<Rgb> source, Span<CieLab> destination)
ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -431,7 +431,7 @@ public void Convert(ReadOnlySpan<YCbCr> source, Span<CieLab> destination)
ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLab dp = ref Unsafe.Add(ref destRef, i);
Expand Down
26 changes: 13 additions & 13 deletions src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Convert(ReadOnlySpan<CieLab> source, Span<CieLch> destination)
ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -69,7 +69,7 @@ public void Convert(ReadOnlySpan<CieLchuv> source, Span<CieLch> destination)
ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLchuv sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -102,7 +102,7 @@ public void Convert(ReadOnlySpan<CieLuv> source, Span<CieLch> destination)
ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -135,7 +135,7 @@ public void Convert(ReadOnlySpan<CieXyy> source, Span<CieLch> destination)
ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -168,7 +168,7 @@ public void Convert(ReadOnlySpan<CieXyz> source, Span<CieLch> destination)
ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -200,7 +200,7 @@ public void Convert(ReadOnlySpan<Cmyk> source, Span<CieLch> destination)
ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -233,7 +233,7 @@ public void Convert(ReadOnlySpan<Hsl> source, Span<CieLch> destination)
ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -266,7 +266,7 @@ public void Convert(ReadOnlySpan<Hsv> source, Span<CieLch> destination)
ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -299,7 +299,7 @@ public void Convert(ReadOnlySpan<HunterLab> source, Span<CieLch> destination)
ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -332,7 +332,7 @@ public void Convert(ReadOnlySpan<LinearRgb> source, Span<CieLch> destination)
ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -365,7 +365,7 @@ public void Convert(ReadOnlySpan<Lms> source, Span<CieLch> destination)
ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -398,7 +398,7 @@ public void Convert(ReadOnlySpan<Rgb> source, Span<CieLch> destination)
ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -431,7 +431,7 @@ public void Convert(ReadOnlySpan<YCbCr> source, Span<CieLch> destination)
ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLch destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLch dp = ref Unsafe.Add(ref destRef, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Convert(ReadOnlySpan<CieLab> source, Span<CieLchuv> destination)
ref CieLab sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLab sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -69,7 +69,7 @@ public void Convert(ReadOnlySpan<CieLch> source, Span<CieLchuv> destination)
ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLch sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -102,7 +102,7 @@ public void Convert(ReadOnlySpan<CieLuv> source, Span<CieLchuv> destination)
ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieLuv sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -135,7 +135,7 @@ public void Convert(ReadOnlySpan<CieXyy> source, Span<CieLchuv> destination)
ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieXyy sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -168,7 +168,7 @@ public void Convert(ReadOnlySpan<CieXyz> source, Span<CieLchuv> destination)
ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref CieXyz sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -201,7 +201,7 @@ public void Convert(ReadOnlySpan<Cmyk> source, Span<CieLchuv> destination)
ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Cmyk sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -234,7 +234,7 @@ public void Convert(ReadOnlySpan<Hsl> source, Span<CieLchuv> destination)
ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Hsl sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -267,7 +267,7 @@ public void Convert(ReadOnlySpan<Hsv> source, Span<CieLchuv> destination)
ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Hsv sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -300,7 +300,7 @@ public void Convert(ReadOnlySpan<HunterLab> source, Span<CieLchuv> destination)
ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref HunterLab sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -333,7 +333,7 @@ public void Convert(ReadOnlySpan<LinearRgb> source, Span<CieLchuv> destination)
ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref LinearRgb sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -366,7 +366,7 @@ public void Convert(ReadOnlySpan<Lms> source, Span<CieLchuv> destination)
ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Lms sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -399,7 +399,7 @@ public void Convert(ReadOnlySpan<Rgb> source, Span<CieLchuv> destination)
ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref Rgb sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down Expand Up @@ -431,7 +431,7 @@ public void Convert(ReadOnlySpan<YCbCr> source, Span<CieLchuv> destination)
ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLchuv destRef = ref MemoryMarshal.GetReference(destination);

for (int i = 0; i < count; i++)
for (nuint i = 0; i < (uint)count; i++)
{
ref YCbCr sp = ref Unsafe.Add(ref sourceRef, i);
ref CieLchuv dp = ref Unsafe.Add(ref destRef, i);
Expand Down
Loading

0 comments on commit 0a1f05b

Please sign in to comment.