Browse Source

Naming fix & simd else if branch

pull/1761/head
Dmitry Pentin 5 years ago
parent
commit
6532552b6b
  1. 2
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.Intrinsic.cs
  2. 10
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  3. 24
      src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.Intrinsic.cs
  4. 4
      src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs
  5. 4
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Transpose.cs
  6. 4
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs

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

@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
private void TransposeAvx()
private void Transpose_Avx()
{
// https://stackoverflow.com/questions/25622745/transpose-an-8x8-float-using-avx-avx2/25627536#25627536
Vector256<float> r0 = Avx.InsertVector128(

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

@ -612,25 +612,25 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Transpose the block inplace.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public void Transpose()
public void TransposeInplace()
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx.IsSupported)
{
this.TransposeAvx();
this.Transpose_Avx();
}
else
#endif
{
this.TransposeScalar();
this.TransposeInplace_Scalar();
}
}
/// <summary>
/// Scalar inplace transpose implementation for <see cref="Transpose"/>
/// Scalar inplace transpose implementation for <see cref="TransposeInplace"/>
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
private void TransposeScalar()
private void TransposeInplace_Scalar()
{
float tmp;
int horIndex, verIndex;

24
src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.Intrinsic.cs

@ -45,33 +45,33 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
DebugGuard.IsTrue(Avx.IsSupported || Sse.IsSupported, "Avx or at least Sse support is required to execute this operation.");
// First pass - process rows
block.Transpose();
block.TransposeInplace();
if (Avx.IsSupported)
{
FDCT8x8_avx(ref block);
FDCT8x8_Avx(ref block);
}
else if (Sse.IsSupported)
else
{
// Left part
FDCT8x4_sse(ref Unsafe.As<Vector4, Vector128<float>>(ref block.V0L));
FDCT8x4_Sse(ref Unsafe.As<Vector4, Vector128<float>>(ref block.V0L));
// Right part
FDCT8x4_sse(ref Unsafe.As<Vector4, Vector128<float>>(ref block.V0R));
FDCT8x4_Sse(ref Unsafe.As<Vector4, Vector128<float>>(ref block.V0R));
}
// Second pass - process columns
block.Transpose();
block.TransposeInplace();
if (Avx.IsSupported)
{
FDCT8x8_avx(ref block);
FDCT8x8_Avx(ref block);
}
else if (Sse.IsSupported)
else
{
// Left part
FDCT8x4_sse(ref Unsafe.As<Vector4, Vector128<float>>(ref block.V0L));
FDCT8x4_Sse(ref Unsafe.As<Vector4, Vector128<float>>(ref block.V0L));
// Right part
FDCT8x4_sse(ref Unsafe.As<Vector4, Vector128<float>>(ref block.V0R));
FDCT8x4_Sse(ref Unsafe.As<Vector4, Vector128<float>>(ref block.V0R));
}
}
@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Must be called on both 8x4 matrix parts for the full FDCT transform.
/// </remarks>
/// <param name="blockRef">Input reference to the first </param>
public static void FDCT8x4_sse(ref Vector128<float> blockRef)
public static void FDCT8x4_Sse(ref Vector128<float> blockRef)
{
DebugGuard.IsTrue(Sse.IsSupported, "Sse support is required to execute this operation.");
@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Requires Avx support.
/// </remarks>
/// <param name="block">Input matrix.</param>
public static void FDCT8x8_avx(ref Block8x8F block)
public static void FDCT8x8_Avx(ref Block8x8F block)
{
DebugGuard.IsTrue(Avx.IsSupported, "Avx support is required to execute this operation.");

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

@ -88,9 +88,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="temp">Matrix to store temporal results.</param>
public static void TransformIDCT(ref Block8x8F block, ref Block8x8F temp)
{
block.Transpose();
block.TransposeInplace();
IDCT8x8(ref block, ref temp);
temp.Transpose();
temp.TransposeInplace();
IDCT8x8(ref temp, ref block);
// TODO: This can be fused into quantization table step

4
tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Transpose.cs

@ -12,9 +12,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations
private Block8x8F source = Create8x8FloatData();
[Benchmark]
public float TransposeInto()
public float TransposeInplace()
{
this.source.Transpose();
this.source.TransposeInplace();
return this.source[0];
}

4
tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs

@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
}
[Fact]
public void Transpose()
public void TransposeInplace()
{
static void RunTest()
{
@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
var block8x8 = default(Block8x8F);
block8x8.LoadFrom(Create8x8FloatData());
block8x8.Transpose();
block8x8.TransposeInplace();
float[] actual = new float[64];
block8x8.ScaledCopyTo(actual);

Loading…
Cancel
Save