Browse Source

fixed ToVector4SimdAligned()

pull/174/head
Anton Firszov 9 years ago
parent
commit
0e96fd4c96
  1. 12
      src/ImageSharp/Colors/Color.BulkOperations.cs

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

@ -64,18 +64,20 @@ namespace ImageSharp
ref uint src = ref Unsafe.As<Color, uint>(ref sourceColors.DangerousGetPinnableReference()); ref uint src = ref Unsafe.As<Color, uint>(ref sourceColors.DangerousGetPinnableReference());
using (PinnedBuffer<uint> tempBuf = new PinnedBuffer<uint>(unpackedRawCount + Vector<uint>.Count)) using (PinnedBuffer<uint> tempBuf = new PinnedBuffer<uint>(
unpackedRawCount + Vector<uint>.Count))
{ {
uint* tPtr = (uint*)tempBuf.Pointer; uint* tPtr = (uint*)tempBuf.Pointer;
uint[] temp = tempBuf.Array; uint[] temp = tempBuf.Array;
float[] fTemp = Unsafe.As<float[]>(temp); float[] fTemp = Unsafe.As<float[]>(temp);
UnpackedRGBA* dst = (UnpackedRGBA*)tPtr; UnpackedRGBA* dst = (UnpackedRGBA*)tPtr;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++, dst++)
{ {
uint sVal = Unsafe.Add(ref src, i);
// This call is the bottleneck now: // This call is the bottleneck now:
ref uint sp = ref Unsafe.Add(ref src, i); dst->Load(sVal);
dst->Load(sp);
} }
for (int i = 0; i < unpackedRawCount; i += vecSize) for (int i = 0; i < unpackedRawCount; i += vecSize)
@ -90,7 +92,7 @@ namespace ImageSharp
vf.CopyTo(fTemp, i); vf.CopyTo(fTemp, i);
} }
BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount); BufferSpan.Copy(tempBuf.Span.AsBytes(), destVectors.AsBytes(), unpackedRawCount * sizeof(uint));
} }
} }

Loading…
Cancel
Save