Skip to content

Commit

Permalink
Add more codegen improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Dec 14, 2020
1 parent 9142e72 commit a8cae3f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/ImageSharp/Common/Helpers/Numerics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,11 @@ public static void UnPremultiply(Span<Vector4> vectors)
public static unsafe void CubePowOnXYZ(Span<Vector4> vectors)
{
ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectors);
int length = vectors.Length;
ref Vector4 endRef = ref Unsafe.Add(ref baseRef, vectors.Length);

for (int x = 0; x < length; x++)
while (Unsafe.IsAddressLessThan(ref baseRef, ref endRef))
{
ref Vector4 pixel4 = ref Unsafe.Add(ref baseRef, x);
Vector4 v = pixel4;
Vector4 v = baseRef;
float a = v.W;

// Fast path for the default gamma exposure, which is 3. In this case we can skip
Expand All @@ -573,7 +572,8 @@ public static unsafe void CubePowOnXYZ(Span<Vector4> vectors)
v = v * v * v;
v.W = a;

pixel4 = v;
baseRef = v;
baseRef = ref Unsafe.Add(ref baseRef, 1);
}
}

Expand Down Expand Up @@ -638,12 +638,12 @@ public static unsafe void CubeRootOnXYZ(Span<Vector4> vectors)
}
#endif
ref Vector4 vectorsRef = ref MemoryMarshal.GetReference(vectors);
int length = vectors.Length;
ref Vector4 vectorsEnd = ref Unsafe.Add(ref vectorsRef, vectors.Length);

// Fallback with scalar preprocessing and vectorized approximation steps
for (int x = 0; x < length; x++)
while (Unsafe.IsAddressLessThan(ref vectorsRef, ref vectorsEnd))
{
ref Vector4 v = ref Unsafe.Add(ref vectorsRef, x);
Vector4 v = vectorsRef;

double
x64 = v.X,
Expand Down Expand Up @@ -678,7 +678,8 @@ public static unsafe void CubeRootOnXYZ(Span<Vector4> vectors)
y4 = (2 / 3f * y4) + (1 / 3f * (v / (y4 * y4)));
y4.W = a;

v = y4;
vectorsRef = y4;
vectorsRef = ref Unsafe.Add(ref vectorsRef, 1);
}
}
}
Expand Down

0 comments on commit a8cae3f

Please sign in to comment.