Browse Source

Vector4ConversionThreshold

pull/751/head
Anton Firszov 7 years ago
parent
commit
9fa08b2257
  1. 20
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs

20
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs

@ -17,6 +17,12 @@ namespace SixLabors.ImageSharp.PixelFormats
public partial class PixelOperations<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// It's not worth to bother the transitive pixel conversion method below this limit.
/// The value depends on the actual gain brought by the SIMD characteristics of the executing CPU and JIT.
/// </summary>
private static readonly int Vector4ConversionThreshold = CalculateVector4ConversionThreshold();
/// <summary>
/// Gets the global <see cref="PixelOperations{TPixel}"/> instance for the pixel type <typeparamref name="TPixel"/>
/// </summary>
@ -183,7 +189,7 @@ namespace SixLabors.ImageSharp.PixelFormats
int count = sourcePixels.Length;
// Not worth for small buffers:
if (count < 128)
if (count < Vector4ConversionThreshold)
{
ToVector4DefaultImpl(sourcePixels, destVectors);
return;
@ -218,7 +224,7 @@ namespace SixLabors.ImageSharp.PixelFormats
int count = sourceVectors.Length;
// Not worth for small buffers:
if (count < 128)
if (count < Vector4ConversionThreshold)
{
FromVector4DefaultImpl(sourceVectors, destPixels);
return;
@ -263,5 +269,15 @@ namespace SixLabors.ImageSharp.PixelFormats
dp = sp.ToVector4();
}
}
private static int CalculateVector4ConversionThreshold()
{
if (!Vector.IsHardwareAccelerated)
{
return int.MaxValue;
}
return SimdUtils.ExtendedIntrinsics.IsAvailable && SimdUtils.IsAvx2CompatibleArchitecture ? 256 : 128;
}
}
}
Loading…
Cancel
Save