Browse Source

Removed excess code, added benchmarks

pull/1761/head
Dmitry Pentin 5 years ago
parent
commit
9973e8da3b
  1. 30
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  2. 3
      src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.Intrinsic.cs
  3. 3
      src/ImageSharp/Formats/Jpeg/Components/FastFloatingPointDCT.cs
  4. 23
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Quantize.cs
  5. 16
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Transpose.cs
  6. 11
      tests/ImageSharp.Benchmarks/Program.cs

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

@ -424,32 +424,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
else else
#endif #endif
{ {
Multiply(ref block, ref qt); for (int i = 0; i < Size; i++)
block.RoundInto(ref dest); {
int idx = ZigZag.ZigZagOrder[i];
float quantizedVal = block[idx] * qt[idx];
quantizedVal += quantizedVal < 0 ? -0.5f : 0.5f;
dest[i] = (short)quantizedVal;
}
} }
} }
[MethodImpl(InliningOptions.ShortMethod)]
private static void Multiply(ref Block8x8F a, ref Block8x8F b)
{
a.V0L *= b.V0L;
a.V0R *= b.V0R;
a.V1L *= b.V1L;
a.V1R *= b.V1R;
a.V2L *= b.V2L;
a.V2R *= b.V2R;
a.V3L *= b.V3L;
a.V3R *= b.V3R;
a.V4L *= b.V4L;
a.V4R *= b.V4R;
a.V5L *= b.V5L;
a.V5R *= b.V5R;
a.V6L *= b.V6L;
a.V6R *= b.V6R;
a.V7L *= b.V7L;
a.V7R *= b.V7R;
}
public void RoundInto(ref Block8x8 dest) public void RoundInto(ref Block8x8 dest)
{ {
for (int i = 0; i < Size; i++) for (int i = 0; i < Size; i++)

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

@ -3,12 +3,11 @@
#if SUPPORTS_RUNTIME_INTRINSICS #if SUPPORTS_RUNTIME_INTRINSICS
using System; using System;
using System.Collections.Generic; using System.Diagnostics;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics; using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
using System.Text;
namespace SixLabors.ImageSharp.Formats.Jpeg.Components namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{ {

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

@ -1,11 +1,8 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
#if SUPPORTS_RUNTIME_INTRINSICS #if SUPPORTS_RUNTIME_INTRINSICS
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
#endif #endif

23
tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Quantize.cs

@ -0,0 +1,23 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Formats.Jpeg.Components;
namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations
{
[Config(typeof(Config.HwIntrinsics_SSE_AVX))]
public class Block8x8F_Quantize
{
private Block8x8F block = default;
private Block8x8F quant = default;
private Block8x8 result = default;
[Benchmark]
public short Quantize()
{
Block8x8F.Quantize(ref this.block, ref this.result, ref this.quant);
return this.result[0];
}
}
}

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

@ -9,25 +9,27 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations
[Config(typeof(Config.HwIntrinsics_SSE_AVX))] [Config(typeof(Config.HwIntrinsics_SSE_AVX))]
public class Block8x8F_Transpose public class Block8x8F_Transpose
{ {
private static readonly Block8x8F Source = Create8x8FloatData(); private Block8x8F source = Create8x8FloatData();
[Benchmark] [Benchmark]
public void TransposeInto() => Source.Transpose(); public float TransposeInto()
{
this.source.Transpose();
return this.source[0];
}
private static Block8x8F Create8x8FloatData() private static Block8x8F Create8x8FloatData()
{ {
float[] result = new float[64]; Block8x8F block = default;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
{ {
result[(i * 8) + j] = (i * 10) + j; block[(i * 8) + j] = (i * 10) + j;
} }
} }
var source = default(Block8x8F); return block;
source.LoadFrom(result);
return source;
} }
} }
} }

11
tests/ImageSharp.Benchmarks/Program.cs

@ -1,8 +1,6 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Reflection;
using BenchmarkDotNet.Running; using BenchmarkDotNet.Running;
namespace SixLabors.ImageSharp.Benchmarks namespace SixLabors.ImageSharp.Benchmarks
@ -15,9 +13,8 @@ namespace SixLabors.ImageSharp.Benchmarks
/// <param name="args"> /// <param name="args">
/// The arguments to pass to the program. /// The arguments to pass to the program.
/// </param> /// </param>
public static void Main(string[] args) public static void Main(string[] args) => BenchmarkSwitcher
{ .FromAssembly(typeof(Program).Assembly)
new BenchmarkSwitcher(typeof(Program).GetTypeInfo().Assembly).Run(args); .Run(args);
}
} }
} }

Loading…
Cancel
Save