Skip to content

Commit

Permalink
fix(bzip2): use explicit feature defs for vectorized memory move (#635)
Browse files Browse the repository at this point in the history
* Fixed mismatched framework directives for vectorized memory move

Co-authored-by: nils måsén <nils@piksel.se>
  • Loading branch information
modio-jackson and piksel authored Aug 12, 2021
1 parent f04d973 commit cd5310f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ICSharpCode.SharpZipLib/BZip2/BZip2InputStream.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#define VECTORIZE_MEMORY_MOVE
#endif

using ICSharpCode.SharpZipLib.Checksum;
using System;
using System.IO;
Expand All @@ -19,9 +23,9 @@ 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
#if VECTORIZE_MEMORY_MOVE
private static readonly int VectorSize = System.Numerics.Vector<byte>.Count;
#endif
#endif // VECTORIZE_MEMORY_MOVE

#endregion Constants

Expand Down Expand Up @@ -717,7 +721,7 @@ cache misses.

var j = nextSym - 1;

#if !NETSTANDARD2_0 && !NETFRAMEWORK
#if VECTORIZE_MEMORY_MOVE
// 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.
Expand All @@ -729,7 +733,7 @@ cache misses.
arrayPart.CopyTo(yy, j - VectorSize + 1);
j -= VectorSize;
}
#endif
#endif // VECTORIZE_MEMORY_MOVE

while(j > 0)
{
Expand Down

0 comments on commit cd5310f

Please sign in to comment.