Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HowToDoThis committed Aug 11, 2021
1 parent 045aba6 commit fa2b3f8
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/ICSharpCode.SharpZipLib/BZip2/BZip2InputStream.cs
Expand Up @@ -19,6 +19,10 @@ public class BZip2InputStream : Stream
private const int NO_RAND_PART_B_STATE = 6;
private const int NO_RAND_PART_C_STATE = 7;

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

#endregion Constants

#region Instance Fields
Expand Down Expand Up @@ -677,10 +681,27 @@ 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
// This is vectorized memory move. Going from the back, we're taking chunks of array
// and write them at the new location shifted by one. Since chunks are VectorSize long,
// at the end we have to move "tail" (or head actually) of the array using a plain loop.
// If System.Numerics.Vector API is not available, the plain loop is used to do the whole copying.

while (j >= VectorSize)
{
yy[j] = yy[j - 1];
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];
}

yy[0] = tmp;

if (groupPos == 0)
Expand Down

0 comments on commit fa2b3f8

Please sign in to comment.