Browse Source

if (count < 256) { no SIMD }

pull/126/head
Anton Firszov 9 years ago
parent
commit
fdf4911eb4
  1. 7
      src/ImageSharp/Colors/Color.BulkOperations.cs
  2. 2
      tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs
  3. 33
      tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs

7
src/ImageSharp/Colors/Color.BulkOperations.cs

@ -88,6 +88,13 @@ namespace ImageSharp
/// <inheritdoc />
internal override void ToVector4(BufferPointer<Color> sourceColors, BufferPointer<Vector4> destVectors, int count)
{
if (count < 256)
{
// Doesn't worth to bother with SIMD:
base.ToVector4(sourceColors, destVectors, count);
return;
}
int remainder = count % Vector<uint>.Count;
int alignedCount = count - remainder;

2
tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk
private PinnedBuffer<Vector4> destination;
[Params(16, 128, 1024)]
[Params(64, 300, 1024)]
public int Count { get; set; }
[Setup]

33
tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs

@ -1,15 +1,22 @@
// ReSharper disable InconsistentNaming
// ReSharper disable AccessToDisposedClosure
namespace ImageSharp.Tests.Colors
{
using System;
using System.Numerics;
using Xunit;
using Xunit.Abstractions;
public class BulkPixelOperationsTests
{
public class Color : BulkPixelOperationsTests<ImageSharp.Color>
{
public Color(ITestOutputHelper output)
: base(output)
{
}
// For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class:
public static new TheoryData<int> ArraySizesData => new TheoryData<int> { 7, 16, 1111 };
@ -32,19 +39,21 @@ namespace ImageSharp.Tests.Colors
);
}
[Fact]
// [Fact] // Profiling benchmark - enable manually!
public void Benchmark_ToVector4()
{
int times = 150000;
int times = 200000;
int count = 1024;
using (PinnedBuffer<ImageSharp.Color> source = new PinnedBuffer<ImageSharp.Color>(count))
using (PinnedBuffer<Vector4> dest = new PinnedBuffer<Vector4>(count))
{
for (int i = 0; i < times; i++)
{
BulkPixelOperations<ImageSharp.Color>.Instance.ToVector4(source, dest, count);
}
this.Measure(
times,
() =>
{
BulkPixelOperations<ImageSharp.Color>.Instance.ToVector4(source, dest, count);
});
}
}
}
@ -52,6 +61,11 @@ namespace ImageSharp.Tests.Colors
public class Argb : BulkPixelOperationsTests<ImageSharp.Argb>
{
// For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class:
public Argb(ITestOutputHelper output)
: base(output)
{
}
public static new TheoryData<int> ArraySizesData => new TheoryData<int> { 7, 16, 1111 };
}
@ -64,9 +78,14 @@ namespace ImageSharp.Tests.Colors
}
}
public abstract class BulkPixelOperationsTests<TColor>
public abstract class BulkPixelOperationsTests<TColor> : MeasureFixture
where TColor : struct, IPixel<TColor>
{
protected BulkPixelOperationsTests(ITestOutputHelper output)
: base(output)
{
}
public static TheoryData<int> ArraySizesData => new TheoryData<int> { 7, 16, 1111 };
private static BulkPixelOperations<TColor> Operations => BulkPixelOperations<TColor>.Instance;

Loading…
Cancel
Save