Skip to content

Commit 4880435

Browse files
committed
remove roslyn bug workaround (fixed in VS 15.8 and Core SDK 2.1.400)
1 parent 287a4aa commit 4880435

7 files changed

Lines changed: 133 additions & 133 deletions

File tree

src/Blake2Fast/Blake2bContext.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ unsafe internal partial struct Blake2bContext : IBlake2Incremental
4747
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4848
private void addLength(uint len)
4949
{
50-
this.t[0] += len;
51-
if (this.t[0] < len)
52-
this.t[1]++;
50+
t[0] += len;
51+
if (t[0] < len)
52+
t[1]++;
5353
}
5454

5555
unsafe private static void compress(Blake2bContext* s, byte* input)
@@ -93,20 +93,20 @@ public void Init(int digestLength = HashBytes, ByteSpan key = default)
9393
throw new ArgumentException($"Key must be between 0 and {MaxKeyBytes} bytes in length", nameof(key));
9494

9595
outlen = (uint)digestLength;
96-
Unsafe.CopyBlock(ref Unsafe.As<ulong, byte>(ref this.h[0]), ref Unsafe.As<ulong, byte>(ref iv[0]), HashBytes);
97-
this.h[0] ^= 0x01010000u ^ (keylen << 8) ^ outlen;
96+
Unsafe.CopyBlock(ref Unsafe.As<ulong, byte>(ref h[0]), ref Unsafe.As<ulong, byte>(ref iv[0]), HashBytes);
97+
h[0] ^= 0x01010000u ^ (keylen << 8) ^ outlen;
9898

9999
#if USE_INTRINSICS
100-
Unsafe.CopyBlock(ref Unsafe.As<ulong, byte>(ref this.viv[0]), ref Unsafe.As<ulong, byte>(ref iv[0]), HashBytes);
101-
Unsafe.CopyBlock(ref this.vrm[0], ref rormask[0], 32);
100+
Unsafe.CopyBlock(ref Unsafe.As<ulong, byte>(ref viv[0]), ref Unsafe.As<ulong, byte>(ref iv[0]), HashBytes);
101+
Unsafe.CopyBlock(ref vrm[0], ref rormask[0], 32);
102102
#endif
103103

104104
if (keylen > 0)
105105
{
106106
#if FAST_SPAN
107-
Unsafe.CopyBlock(ref this.b[0], ref MemoryMarshal.GetReference(key), keylen);
107+
Unsafe.CopyBlock(ref b[0], ref MemoryMarshal.GetReference(key), keylen);
108108
#else
109-
Unsafe.CopyBlock(ref this.b[0], ref key.Array[key.Offset], keylen);
109+
Unsafe.CopyBlock(ref b[0], ref key.Array[key.Offset], keylen);
110110
#endif
111111
c = BlockBytes;
112112
}
@@ -127,9 +127,9 @@ public void Update(ByteSpan input)
127127
if (blockrem > 0)
128128
{
129129
#if FAST_SPAN
130-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref MemoryMarshal.GetReference(input), blockrem);
130+
Unsafe.CopyBlockUnaligned(ref b[c], ref MemoryMarshal.GetReference(input), blockrem);
131131
#else
132-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref input.Array[input.Offset], blockrem);
132+
Unsafe.CopyBlockUnaligned(ref b[c], ref input.Array[input.Offset], blockrem);
133133
#endif
134134
}
135135
addLength(BlockBytes);
@@ -163,40 +163,40 @@ public void Update(ByteSpan input)
163163
if (inlen > 0)
164164
{
165165
#if FAST_SPAN
166-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref MemoryMarshal.GetReference(input.Slice((int)clen)), inlen);
166+
Unsafe.CopyBlockUnaligned(ref b[c], ref MemoryMarshal.GetReference(input.Slice((int)clen)), inlen);
167167
#else
168-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref input.Array[input.Offset + clen], inlen);
168+
Unsafe.CopyBlockUnaligned(ref b[c], ref input.Array[input.Offset + clen], inlen);
169169
#endif
170170
c += inlen;
171171
}
172172
}
173173

174174
private void finish(WriteableByteSpan hash)
175175
{
176-
if (this.f[0] != 0)
176+
if (f[0] != 0)
177177
throw new InvalidOperationException("Hash has already been finalized.");
178178

179179
if (c < BlockBytes)
180-
Unsafe.InitBlockUnaligned(ref this.b[c], 0, BlockBytes - c);
180+
Unsafe.InitBlockUnaligned(ref b[c], 0, BlockBytes - c);
181181

182182
addLength(c);
183-
this.f[0] = unchecked((ulong)~0);
183+
f[0] = unchecked((ulong)~0);
184184
fixed (Blake2bContext* s = &this)
185185
compress(s, s->b);
186186

187187
#if FAST_SPAN
188188
if (!BitConverter.IsLittleEndian)
189189
{
190-
var span = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<ulong, byte>(ref this.h[0]), HashBytes);
190+
var span = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<ulong, byte>(ref h[0]), HashBytes);
191191
for (int i = 0; i < HashWords; i++)
192-
this.h[i] = BinaryPrimitives.ReadUInt64LittleEndian(span.Slice(i * WordSize, WordSize));
192+
h[i] = BinaryPrimitives.ReadUInt64LittleEndian(span.Slice(i * WordSize, WordSize));
193193
}
194194
#endif
195195

196196
#if FAST_SPAN
197-
Unsafe.CopyBlock(ref hash[0], ref Unsafe.As<ulong, byte>(ref this.h[0]), outlen);
197+
Unsafe.CopyBlock(ref hash[0], ref Unsafe.As<ulong, byte>(ref h[0]), outlen);
198198
#else
199-
Unsafe.CopyBlock(ref hash.Array[hash.Offset], ref Unsafe.As<ulong, byte>(ref this.h[0]), outlen);
199+
Unsafe.CopyBlock(ref hash.Array[hash.Offset], ref Unsafe.As<ulong, byte>(ref h[0]), outlen);
200200
#endif
201201
}
202202

src/Blake2Fast/Blake2sContext.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ unsafe internal partial struct Blake2sContext : IBlake2Incremental
4747
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4848
private void addLength(uint len)
4949
{
50-
this.t[0] += len;
51-
if (this.t[0] < len)
52-
this.t[1]++;
50+
t[0] += len;
51+
if (t[0] < len)
52+
t[1]++;
5353
}
5454

5555
unsafe private static void compress(Blake2sContext* s, byte* input)
@@ -93,20 +93,20 @@ public void Init(int digestLength = HashBytes, ByteSpan key = default)
9393
throw new ArgumentException($"Key must be between 0 and {MaxKeyBytes} bytes in length", nameof(key));
9494

9595
outlen = (uint)digestLength;
96-
Unsafe.CopyBlock(ref Unsafe.As<uint, byte>(ref this.h[0]), ref Unsafe.As<uint, byte>(ref iv[0]), HashBytes);
97-
this.h[0] ^= 0x01010000u ^ (keylen << 8) ^ outlen;
96+
Unsafe.CopyBlock(ref Unsafe.As<uint, byte>(ref h[0]), ref Unsafe.As<uint, byte>(ref iv[0]), HashBytes);
97+
h[0] ^= 0x01010000u ^ (keylen << 8) ^ outlen;
9898

9999
#if USE_INTRINSICS
100-
Unsafe.CopyBlock(ref Unsafe.As<uint, byte>(ref this.viv[0]), ref Unsafe.As<uint, byte>(ref iv[0]), HashBytes);
101-
Unsafe.CopyBlock(ref this.vrm[0], ref rormask[0], 32);
100+
Unsafe.CopyBlock(ref Unsafe.As<uint, byte>(ref viv[0]), ref Unsafe.As<uint, byte>(ref iv[0]), HashBytes);
101+
Unsafe.CopyBlock(ref vrm[0], ref rormask[0], 32);
102102
#endif
103103

104104
if (keylen > 0)
105105
{
106106
#if FAST_SPAN
107-
Unsafe.CopyBlock(ref this.b[0], ref MemoryMarshal.GetReference(key), keylen);
107+
Unsafe.CopyBlock(ref b[0], ref MemoryMarshal.GetReference(key), keylen);
108108
#else
109-
Unsafe.CopyBlock(ref this.b[0], ref key.Array[key.Offset], keylen);
109+
Unsafe.CopyBlock(ref b[0], ref key.Array[key.Offset], keylen);
110110
#endif
111111
c = BlockBytes;
112112
}
@@ -127,9 +127,9 @@ public void Update(ByteSpan input)
127127
if (blockrem > 0)
128128
{
129129
#if FAST_SPAN
130-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref MemoryMarshal.GetReference(input), blockrem);
130+
Unsafe.CopyBlockUnaligned(ref b[c], ref MemoryMarshal.GetReference(input), blockrem);
131131
#else
132-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref input.Array[input.Offset], blockrem);
132+
Unsafe.CopyBlockUnaligned(ref b[c], ref input.Array[input.Offset], blockrem);
133133
#endif
134134
}
135135
addLength(BlockBytes);
@@ -163,40 +163,40 @@ public void Update(ByteSpan input)
163163
if (inlen > 0)
164164
{
165165
#if FAST_SPAN
166-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref MemoryMarshal.GetReference(input.Slice((int)clen)), inlen);
166+
Unsafe.CopyBlockUnaligned(ref b[c], ref MemoryMarshal.GetReference(input.Slice((int)clen)), inlen);
167167
#else
168-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref input.Array[input.Offset + clen], inlen);
168+
Unsafe.CopyBlockUnaligned(ref b[c], ref input.Array[input.Offset + clen], inlen);
169169
#endif
170170
c += inlen;
171171
}
172172
}
173173

174174
private void finish(WriteableByteSpan hash)
175175
{
176-
if (this.f[0] != 0)
176+
if (f[0] != 0)
177177
throw new InvalidOperationException("Hash has already been finalized.");
178178

179179
if (c < BlockBytes)
180-
Unsafe.InitBlockUnaligned(ref this.b[c], 0, BlockBytes - c);
180+
Unsafe.InitBlockUnaligned(ref b[c], 0, BlockBytes - c);
181181

182182
addLength(c);
183-
this.f[0] = unchecked((uint)~0);
183+
f[0] = unchecked((uint)~0);
184184
fixed (Blake2sContext* s = &this)
185185
compress(s, s->b);
186186

187187
#if FAST_SPAN
188188
if (!BitConverter.IsLittleEndian)
189189
{
190-
var span = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<uint, byte>(ref this.h[0]), HashBytes);
190+
var span = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<uint, byte>(ref h[0]), HashBytes);
191191
for (int i = 0; i < HashWords; i++)
192-
this.h[i] = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(i * WordSize, WordSize));
192+
h[i] = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(i * WordSize, WordSize));
193193
}
194194
#endif
195195

196196
#if FAST_SPAN
197-
Unsafe.CopyBlock(ref hash[0], ref Unsafe.As<uint, byte>(ref this.h[0]), outlen);
197+
Unsafe.CopyBlock(ref hash[0], ref Unsafe.As<uint, byte>(ref h[0]), outlen);
198198
#else
199-
Unsafe.CopyBlock(ref hash.Array[hash.Offset], ref Unsafe.As<uint, byte>(ref this.h[0]), outlen);
199+
Unsafe.CopyBlock(ref hash.Array[hash.Offset], ref Unsafe.As<uint, byte>(ref h[0]), outlen);
200200
#endif
201201
}
202202

src/Blake2Fast/_Blake2Main.ttinclude

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ namespace SauceControl.Blake2Fast
5151
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5252
private void addLength(uint len)
5353
{
54-
this.t[0] += len;
55-
if (this.t[0] < len)
56-
this.t[1]++;
54+
t[0] += len;
55+
if (t[0] < len)
56+
t[1]++;
5757
}
5858

5959
unsafe private static void compress(Blake2<#= alg.suffix #>Context* s, byte* input)
@@ -97,12 +97,12 @@ namespace SauceControl.Blake2Fast
9797
throw new ArgumentException($"Key must be between 0 and {MaxKeyBytes} bytes in length", nameof(key));
9898

9999
outlen = (uint)digestLength;
100-
Unsafe.CopyBlock(ref Unsafe.As<<#= alg.wtype #>, byte>(ref this.h[0]), ref Unsafe.As<<#= alg.wtype #>, byte>(ref iv[0]), HashBytes);
101-
this.h[0] ^= 0x01010000u ^ (keylen << 8) ^ outlen;
100+
Unsafe.CopyBlock(ref Unsafe.As<<#= alg.wtype #>, byte>(ref h[0]), ref Unsafe.As<<#= alg.wtype #>, byte>(ref iv[0]), HashBytes);
101+
h[0] ^= 0x01010000u ^ (keylen << 8) ^ outlen;
102102

103103
#if USE_INTRINSICS
104-
Unsafe.CopyBlock(ref Unsafe.As<<#= alg.wtype #>, byte>(ref this.viv[0]), ref Unsafe.As<<#= alg.wtype #>, byte>(ref iv[0]), HashBytes);
105-
Unsafe.CopyBlock(ref this.vrm[0], ref rormask[0], 32);
104+
Unsafe.CopyBlock(ref Unsafe.As<<#= alg.wtype #>, byte>(ref viv[0]), ref Unsafe.As<<#= alg.wtype #>, byte>(ref iv[0]), HashBytes);
105+
Unsafe.CopyBlock(ref vrm[0], ref rormask[0], 32);
106106
#endif
107107

108108
<#
@@ -112,24 +112,24 @@ namespace SauceControl.Blake2Fast
112112
if ((salt.Length > 0)
113113
{
114114
ref [#= alg.wtype #] rs = ref Unsafe.As<byte, [#= alg.wtype #]>(ref salt[0]);
115-
this.h[4] ^= rs;
116-
this.h[5] ^= Unsafe.Add(ref rs, 1);
115+
h[4] ^= rs;
116+
h[5] ^= Unsafe.Add(ref rs, 1);
117117
}
118118
if ((personalization.Length > 0)
119119
{
120120
ref [#= alg.wtype #] rp = ref Unsafe.As<byte, [#= alg.wtype #]>(ref personalization[0]);
121-
this.h[6] ^= rp;
122-
this.h[7] ^= Unsafe.Add(ref rp, 1);
121+
h[6] ^= rp;
122+
h[7] ^= Unsafe.Add(ref rp, 1);
123123
}
124124
*/
125125

126126
#>
127127
if (keylen > 0)
128128
{
129129
#if FAST_SPAN
130-
Unsafe.CopyBlock(ref this.b[0], ref MemoryMarshal.GetReference(key), keylen);
130+
Unsafe.CopyBlock(ref b[0], ref MemoryMarshal.GetReference(key), keylen);
131131
#else
132-
Unsafe.CopyBlock(ref this.b[0], ref key.Array[key.Offset], keylen);
132+
Unsafe.CopyBlock(ref b[0], ref key.Array[key.Offset], keylen);
133133
#endif
134134
c = BlockBytes;
135135
}
@@ -150,9 +150,9 @@ namespace SauceControl.Blake2Fast
150150
if (blockrem > 0)
151151
{
152152
#if FAST_SPAN
153-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref MemoryMarshal.GetReference(input), blockrem);
153+
Unsafe.CopyBlockUnaligned(ref b[c], ref MemoryMarshal.GetReference(input), blockrem);
154154
#else
155-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref input.Array[input.Offset], blockrem);
155+
Unsafe.CopyBlockUnaligned(ref b[c], ref input.Array[input.Offset], blockrem);
156156
#endif
157157
}
158158
addLength(BlockBytes);
@@ -186,40 +186,40 @@ namespace SauceControl.Blake2Fast
186186
if (inlen > 0)
187187
{
188188
#if FAST_SPAN
189-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref MemoryMarshal.GetReference(input.Slice((int)clen)), inlen);
189+
Unsafe.CopyBlockUnaligned(ref b[c], ref MemoryMarshal.GetReference(input.Slice((int)clen)), inlen);
190190
#else
191-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref input.Array[input.Offset + clen], inlen);
191+
Unsafe.CopyBlockUnaligned(ref b[c], ref input.Array[input.Offset + clen], inlen);
192192
#endif
193193
c += inlen;
194194
}
195195
}
196196

197197
private void finish(WriteableByteSpan hash)
198198
{
199-
if (this.f[0] != 0)
199+
if (f[0] != 0)
200200
throw new InvalidOperationException("Hash has already been finalized.");
201201

202202
if (c < BlockBytes)
203-
Unsafe.InitBlockUnaligned(ref this.b[c], 0, BlockBytes - c);
203+
Unsafe.InitBlockUnaligned(ref b[c], 0, BlockBytes - c);
204204

205205
addLength(c);
206-
this.f[0] = unchecked((<#= alg.wtype #>)~0);
206+
f[0] = unchecked((<#= alg.wtype #>)~0);
207207
fixed (Blake2<#= alg.suffix #>Context* s = &this)
208208
compress(s, s->b);
209209

210210
#if FAST_SPAN
211211
if (!BitConverter.IsLittleEndian)
212212
{
213-
var span = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<<#= alg.wtype #>, byte>(ref this.h[0]), HashBytes);
213+
var span = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<<#= alg.wtype #>, byte>(ref h[0]), HashBytes);
214214
for (int i = 0; i < HashWords; i++)
215-
this.h[i] = BinaryPrimitives.ReadUInt<#= alg.bits #>LittleEndian(span.Slice(i * WordSize, WordSize));
215+
h[i] = BinaryPrimitives.ReadUInt<#= alg.bits #>LittleEndian(span.Slice(i * WordSize, WordSize));
216216
}
217217
#endif
218218

219219
#if FAST_SPAN
220-
Unsafe.CopyBlock(ref hash[0], ref Unsafe.As<<#= alg.wtype #>, byte>(ref this.h[0]), outlen);
220+
Unsafe.CopyBlock(ref hash[0], ref Unsafe.As<<#= alg.wtype #>, byte>(ref h[0]), outlen);
221221
#else
222-
Unsafe.CopyBlock(ref hash.Array[hash.Offset], ref Unsafe.As<<#= alg.wtype #>, byte>(ref this.h[0]), outlen);
222+
Unsafe.CopyBlock(ref hash.Array[hash.Offset], ref Unsafe.As<<#= alg.wtype #>, byte>(ref h[0]), outlen);
223223
#endif
224224
}
225225

tests/JitRegression/Blake2b.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ unsafe internal partial struct Blake2bContext
3838
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3939
private void addLength(uint len)
4040
{
41-
this.t[0] += len;
42-
if (this.t[0] < len)
43-
this.t[1]++;
41+
t[0] += len;
42+
if (t[0] < len)
43+
t[1]++;
4444
}
4545

4646
private void compress(byte* data)
@@ -74,13 +74,13 @@ public void Init(int outlen = HashBytes, byte[] key = null)
7474
if (keylen > MaxKeyBytes)
7575
throw new ArgumentException($"Key must be between 0 and {MaxKeyBytes} bytes in length", nameof(key));
7676

77-
Unsafe.CopyBlock(ref Unsafe.As<ulong, byte>(ref this.h[0]), ref Unsafe.As<ulong, byte>(ref iv[0]), HashBytes);
78-
this.h[0] ^= 0x01010000u ^ (keylen << 8) ^ (uint)outlen;
77+
Unsafe.CopyBlock(ref Unsafe.As<ulong, byte>(ref h[0]), ref Unsafe.As<ulong, byte>(ref iv[0]), HashBytes);
78+
h[0] ^= 0x01010000u ^ (keylen << 8) ^ (uint)outlen;
7979
this.outlen = (uint)outlen;
8080

8181
if (keylen > 0)
8282
{
83-
Unsafe.CopyBlock(ref this.b[0], ref key[0], keylen);
83+
Unsafe.CopyBlock(ref b[0], ref key[0], keylen);
8484
c = BlockBytes;
8585
}
8686
}
@@ -95,7 +95,7 @@ public void Update(byte[] data)
9595
if ((c > 0u) && (inlen > blockrem))
9696
{
9797
if (blockrem > 0)
98-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref data[0], blockrem);
98+
Unsafe.CopyBlockUnaligned(ref b[c], ref data[0], blockrem);
9999

100100
addLength(BlockBytes);
101101
fixed (Blake2bContext* s = &this)
@@ -122,26 +122,26 @@ public void Update(byte[] data)
122122

123123
if (inlen > 0)
124124
{
125-
Unsafe.CopyBlockUnaligned(ref this.b[c], ref data[clen], inlen);
125+
Unsafe.CopyBlockUnaligned(ref b[c], ref data[clen], inlen);
126126
c += inlen;
127127
}
128128
}
129129

130130
public byte[] Finish()
131131
{
132-
if (this.f[0] != 0)
132+
if (f[0] != 0)
133133
throw new InvalidOperationException(nameof(Finish) + " has already been used. It cannot be called again on this instance.");
134134

135135
if (c < BlockBytes)
136-
Unsafe.InitBlockUnaligned(ref this.b[c], 0, BlockBytes - c);
136+
Unsafe.InitBlockUnaligned(ref b[c], 0, BlockBytes - c);
137137

138138
addLength(c);
139-
this.f[0] = unchecked((ulong)~0);
139+
f[0] = unchecked((ulong)~0);
140140
fixed (Blake2bContext* s = &this)
141141
compress(s->b);
142142

143143
var hash = new byte[outlen];
144-
Unsafe.CopyBlock(ref hash[0], ref Unsafe.As<ulong, byte>(ref this.h[0]), outlen);
144+
Unsafe.CopyBlock(ref hash[0], ref Unsafe.As<ulong, byte>(ref h[0]), outlen);
145145

146146
this = default;
147147
return hash;

0 commit comments

Comments
 (0)