Skip to content

Commit

Permalink
Simple automatic vectorization of the rotation loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad-kruczynski committed Apr 18, 2021
1 parent 47c5478 commit 7dac297
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/ICSharpCode.SharpZipLib/BZip2/BZip2InputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public class BZip2InputStream : Stream
private const int NO_RAND_PART_B_STATE = 6;
private const int NO_RAND_PART_C_STATE = 7;

#endregion Constants
#if NETSTANDARD2_1
private static readonly int VectorSize = System.Numerics.Vector<byte>.Count;
#endif

#endregion Constants

#region Instance Fields

Expand Down Expand Up @@ -711,10 +715,22 @@ cache misses.
unzftab[seqToUnseq[tmp]]++;
ll8[last] = seqToUnseq[tmp];

for (int j = nextSym - 1; j > 0; --j)
var j = nextSym - 1;

#if !NETSTANDARD2_0 && !NETFRAMEWORK
while(j >= VectorSize)
{
var arrayPart = new System.Numerics.Vector<byte>(yy, j - VectorSize);
arrayPart.CopyTo(yy, j - VectorSize + 1);
j -= VectorSize;
}
#endif

while(j > 0)
{
yy[j] = yy[j - 1];
yy[j] = yy[--j];
}

yy[0] = tmp;

if (groupPos == 0)
Expand Down

0 comments on commit 7dac297

Please # to comment.