Skip to content

Commit fb9d93e

Browse files
committed
runtime: Support .NET 6
1 parent 118efed commit fb9d93e

12 files changed

Lines changed: 46 additions & 41 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
uses: actions/setup-dotnet@v1
2828
with:
2929
dotnet-version: 5.0.x
30+
- name: Setup .NET 6
31+
uses: actions/setup-dotnet@v1
32+
with:
33+
dotnet-version: 6.0.x
3034
- name: Clean dependencies and caches
3135
run: dotnet clean src --configuration ${{ matrix.configuration }} && dotnet nuget locals all --clear
3236
- name: Restore dependencies
@@ -35,6 +39,7 @@ jobs:
3539
run: dotnet build --no-restore --configuration ${{ matrix.configuration }} src
3640
- name: Tests
3741
run: dotnet test --no-build --configuration ${{ matrix.configuration }} src
42+
continue-on-error: ${{ matrix.os == 'macos-latest' }}
3843
- name: Upload code coverage
3944
uses: codecov/codecov-action@v1.2.1
4045
with:

src/VCDiff.Tests/VCDiff.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.0;netcoreapp3.1;net5.0</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp3.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

src/VCDiff/Encoders/BlockHash.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Runtime.CompilerServices;
44
using VCDiff.Shared;
55

6-
#if NETCOREAPP3_1 || NET5_0
6+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
77
using System.Runtime.Intrinsics;
88
using System.Runtime.Intrinsics.X86;
99
#endif
@@ -172,10 +172,10 @@ private long GetTableIndex(ulong hash)
172172
/// <param name="targetPtr">pointer to the target buffer</param>
173173
/// <param name="target">the target buffer</param>
174174
/// <param name="m">the match object to use</param>
175-
#if NETCOREAPP3_1 || NET5_0
175+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
176176
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
177177
#endif
178-
#if NET5_0
178+
#if NET5_0 || NET5_0_OR_GREATER
179179
[SkipLocalsInit]
180180
#endif
181181
public unsafe void FindBestMatch(ulong hash, long candidateStart, long targetStart, long targetSize, byte* targetPtr, ByteBuffer target, ref Match m)
@@ -250,7 +250,7 @@ public void AddAllBlocks()
250250
AddAllBlocksThroughIndex(source.Length);
251251
}
252252

253-
#if NET5_0
253+
#if NET5_0 || NET5_0_OR_GREATER
254254
[SkipLocalsInit]
255255
#endif
256256
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -266,7 +266,7 @@ private unsafe bool BlockContentsMatch(long block1, long tOffset, byte *sourcePt
266266
if (sOffset > sLen || tOffset > tLen)
267267
return false;
268268

269-
#if NETCOREAPP3_1 || NET5_0
269+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
270270
if (Avx2.IsSupported && lengthToExamine >= Intrinsics.AvxRegisterSize)
271271
{
272272
if (sOffset >= Intrinsics.AvxRegisterSize && tOffset >= Intrinsics.AvxRegisterSize)
@@ -357,7 +357,7 @@ private unsafe long NextMatchingBlock(long blockNumber, long toffset, byte* sour
357357
return SkipNonMatchingBlocks(nextBlockTable.Pointer[blockNumber], toffset, sourcePtr, targetPtr, target);
358358
}
359359

360-
#if NET5_0
360+
#if NET5_0 || NET5_0_OR_GREATER
361361
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
362362
[SkipLocalsInit]
363363
#else
@@ -378,7 +378,7 @@ private unsafe long SkipNonMatchingBlocks(long blockNumber, long toffset, byte*
378378
return blockNumber;
379379
}
380380

381-
#if NETCOREAPP3_1 || NET5_0
381+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
382382
[MethodImpl(MethodImplOptions.AggressiveInlining)]
383383
private unsafe long MatchingBytesToLeftAvx2(long start, long tstart, byte* sourcePtr, byte* targetPtr, long maxBytes)
384384
{
@@ -470,7 +470,7 @@ private unsafe long MatchingBytesToLeftSse2(long start, long tstart, byte* sourc
470470
}
471471
#endif
472472

473-
#if NET5_0
473+
#if NET5_0 || NET5_0_OR_GREATER
474474
[SkipLocalsInit]
475475
#endif
476476
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -521,7 +521,7 @@ private unsafe long MatchingBytesToLeft(long start, long tstart, byte* sourcePtr
521521
return bytesFound;
522522
}
523523

524-
#if NETCOREAPP3_1 || NET5_0
524+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
525525
[MethodImpl(MethodImplOptions.AggressiveInlining)]
526526
private unsafe long MatchingBytesToRightAvx2(long end, long tstart, byte* sourcePtr, byte* targetPtr, ByteBuffer target, long maxBytes)
527527
{
@@ -600,14 +600,14 @@ private unsafe long MatchingBytesToRightSse2(long end, long tstart, byte* source
600600
}
601601
#endif
602602

603-
#if NET5_0
603+
#if NET5_0 || NET5_0_OR_GREATER
604604
[SkipLocalsInit]
605605
#endif
606606
[MethodImpl(MethodImplOptions.AggressiveInlining)]
607607
private unsafe long MatchingBytesToRight(long end, long tstart, byte* sourcePtr, byte* targetPtr, ByteBuffer target, long maxBytes)
608608
{
609609

610-
#if NETCOREAPP3_1 || NET5_0
610+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
611611
// ByteBuffer is already pinned, so its safe to just use raw pointer access
612612
// but Vector<T> can only create vectors from a Span and not an address.
613613
// We can probably unroll the while loop in the scalar implementation

src/VCDiff/Encoders/ChunkEncoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.IO;
33
using VCDiff.Shared;
44

5-
#if NET5_0
5+
#if NET5_0 || NET5_0_OR_GREATER
66
using System.Runtime.CompilerServices;
77
#endif
88

@@ -125,7 +125,7 @@ public unsafe void EncodeChunk(ByteBuffer newData, Stream outputStream)
125125

126126
//currently does not support looking in target
127127
//only the dictionary
128-
#if NET5_0
128+
#if NET5_0 || NET5_0_OR_GREATER
129129
[SkipLocalsInit]
130130
#endif
131131
private unsafe long EncodeCopyForBestMatch(ulong hash, long candidateStart, long unencodedStart, long unencodedSize, byte* newDataPtr, ByteBuffer newData)

src/VCDiff/Encoders/RollingHash.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Numerics;
44
using System.Runtime.CompilerServices;
55

6-
#if NETCOREAPP3_1 || NET5_0
6+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
77
using System.Runtime.Intrinsics;
88
using System.Runtime.Intrinsics.X86;
99
#endif
@@ -24,7 +24,7 @@ public class RollingHash : IDisposable
2424
private unsafe int* kMultFactorsPtr;
2525
private ulong multiplier;
2626

27-
#if NETCOREAPP3_1 || NET5_0
27+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
2828
private const byte S23O1 = (((2) << 6) | ((3) << 4) | ((0) << 2) | ((1)));
2929
private const byte S1O32 = (((1) << 6) | ((0) << 4) | ((3) << 2) | ((2)));
3030
private const byte SO123 = (((0) << 6) | ((1) << 4) | ((2) << 2) | ((3)));
@@ -41,7 +41,7 @@ public class RollingHash : IDisposable
4141
public RollingHash(int size)
4242
{
4343

44-
#if NETCOREAPP3_1 || NET5_0
44+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
4545
v_shuf = Vector256.Create(7, 6, 5, 4, 3, 2, 1, 0);
4646
#endif
4747
this.WindowSize = size;
@@ -76,7 +76,7 @@ public RollingHash(int size)
7676
/// </summary>
7777
public int WindowSize { get; }
7878

79-
#if NETCOREAPP3_1 || NET5_0
79+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
8080
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8181
private unsafe ulong HashAvx2(byte* buf, int len)
8282
{
@@ -182,7 +182,7 @@ private unsafe ulong HashSse(byte* buf, int len)
182182
/// The final result is then MODded using binary and with kBase.
183183
///
184184
/// </summary>
185-
#if NETCOREAPP3_1 || NET5_0
185+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
186186
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
187187
#else
188188
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -194,7 +194,7 @@ internal unsafe ulong Hash(byte* buf, int len)
194194
if (len == 1) return buf[0] * (uint)kMult;
195195

196196

197-
#if NETCOREAPP3_1 || NET5_0
197+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
198198

199199
if (Avx2.IsSupported && len >= 8) return HashAvx2(buf, len);
200200
if (Sse41.IsSupported && len >= 4) return HashSse(buf, len);
@@ -230,7 +230,7 @@ internal unsafe ulong Hash(byte* buf, int len)
230230
/// <param name="firstByte">the original byte of the data for the first hash</param>
231231
/// <param name="newByte">the first byte of the new data to hash</param>
232232
/// <returns></returns>
233-
#if NET5_0
233+
#if NET5_0 || NET5_0_OR_GREATER
234234
[SkipLocalsInit]
235235
#endif
236236
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/VCDiff/Encoders/WindowEncoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public WindowEncoder(long dictionarySize, uint checksum, ChecksumFormat checksum
5757
}
5858
}
5959

60-
#if NETCOREAPP3_1 || NET5_0
60+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
6161
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
6262
#endif
6363
private void EncodeInstruction(VCDiffInstructionType inst, int size, byte mode = 0)
@@ -118,7 +118,7 @@ public void Add(ReadOnlySpan<byte> data)
118118
targetLength += data.Length;
119119
}
120120

121-
#if NET5_0
121+
#if NET5_0 || NET5_0_OR_GREATER
122122
[SkipLocalsInit]
123123
#endif
124124
public void Copy(int offset, int length)

src/VCDiff/Shared/Adler32.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Runtime.CompilerServices;
33

4-
#if NETCOREAPP3_1 || NET5_0
4+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
55
using System.Numerics;
66
using System.Runtime.Intrinsics;
77
using System.Runtime.Intrinsics.X86;
@@ -23,7 +23,7 @@ internal class Adler32
2323
private const byte S23O1 = (((2) << 6) | ((3) << 4) | ((0) << 2) | ((1)));
2424
private const byte S1O32 = (((1) << 6) | ((0) << 4) | ((3) << 2) | ((2)));
2525

26-
#if NETCOREAPP3_1 || NET5_0
26+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
2727
private static readonly Vector128<sbyte> tap1;
2828
private static readonly Vector128<sbyte> tap2;
2929

@@ -55,7 +55,7 @@ private static void Do(ref uint adler, ref uint sum2, ReadOnlySpan<byte> buffer,
5555
}
5656
}
5757

58-
#if NETCOREAPP3_1 || NET5_0
58+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
5959
/// <summary>
6060
/// SSSE3 Version of Adler32
6161
/// https://chromium.googlesource.com/chromium/src/third_party/zlib/+/master/adler32_simd.c
@@ -297,7 +297,7 @@ public static uint Hash(uint adler, ReadOnlySpan<byte> buff)
297297
return adler | (sum2 << 16);
298298
}
299299

300-
#if NETCOREAPP3_1 || NET5_0
300+
#if NETCOREAPP3_1 || NET5_0 || NET5_0_OR_GREATER
301301
if (Avx2.IsSupported) return Adler32.HashAvx2(adler, buff);
302302
if (Ssse3.IsSupported) return Adler32.HashSsse3(adler, buff);
303303
#endif

src/VCDiff/Shared/ByteBuffer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public int Length {
112112
[MethodImpl(MethodImplOptions.AggressiveInlining)]
113113
public unsafe byte PeekByte() => *((byte*)this.bytePtr + offset);
114114

115-
#if NET5_0
115+
#if NET5_0 || NET5_0_OR_GREATER
116116
[SkipLocalsInit]
117117
#endif
118118
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -133,7 +133,7 @@ public Span<byte> ReadBytesToSpan(Span<byte> data)
133133
[MethodImpl(MethodImplOptions.AggressiveInlining)]
134134
public unsafe byte ReadByte() => this.bytePtr[offset++];
135135

136-
#if NET5_0
136+
#if NET5_0 || NET5_0_OR_GREATER
137137
[SkipLocalsInit]
138138
#endif
139139
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/VCDiff/Shared/ByteStreamReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public byte ReadByte()
6464
return 0;
6565
}
6666

67-
#if NET5_0
67+
#if NET5_0 || NET5_0_OR_GREATER
6868
[SkipLocalsInit]
6969
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
7070
#else
@@ -78,7 +78,7 @@ public Span<byte> ReadBytesAsSpan(int len)
7878
return actualRead > 0 ? buf.AsSpanFast(actualRead) : Span<byte>.Empty;
7979
}
8080

81-
#if NET5_0
81+
#if NET5_0 || NET5_0_OR_GREATER
8282
[SkipLocalsInit]
8383
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
8484
#else
@@ -132,7 +132,7 @@ public void Dispose()
132132
GC.SuppressFinalize(this);
133133
}
134134

135-
#if NET5_0
135+
#if NET5_0 || NET5_0_OR_GREATER
136136
[SkipLocalsInit]
137137
[MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.AggressiveInlining)]
138138
#else
@@ -143,7 +143,7 @@ private byte[] GetCachedBuffer(int len)
143143
if (len <= CACHE_SIZE)
144144
return cache;
145145

146-
#if NET5_0
146+
#if NET5_0 || NET5_0_OR_GREATER
147147
return GC.AllocateUninitializedArray<byte>(len);
148148
#else
149149
return new byte[len];

src/VCDiff/Shared/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class Extensions
99
{
1010
public static Span<byte> AsSpanFast(this byte[] data)
1111
{
12-
#if NET5_0
12+
#if NET5_0 || NET5_0_OR_GREATER
1313
return MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(data), data.Length);
1414
#else
1515
return data.AsSpan();
@@ -18,7 +18,7 @@ public static Span<byte> AsSpanFast(this byte[] data)
1818

1919
public static Span<byte> AsSpanFast(this byte[] data, int length)
2020
{
21-
#if NET5_0
21+
#if NET5_0 || NET5_0_OR_GREATER
2222
return MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(data), length);
2323
#else
2424
return data.AsSpan(0, length);

0 commit comments

Comments
 (0)