Skip to content

Commit d1716ab

Browse files
committed
using trick
1 parent f1bdfd9 commit d1716ab

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

benchmark/Benchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ public Config()
153153
}
154154
// Parameters and variables for real data
155155
[Params(
156-
@"data/email/" //,
157-
//@"data/dns/swedenzonebase.txt"
156+
@"data/email/" //,
157+
//@"data/dns/swedenzonebase.txt"
158158
)]
159159
#pragma warning disable CA1051
160160
public string? FileName;

src/Base64AVX2UTF8.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ private static unsafe void CopyBlock(Block64* b, byte* output)
246246
private static unsafe void Base64DecodeBlockSafe(byte* outPtr, Block64* b)
247247
{
248248
Base64Decode(outPtr, b->chunk0);
249-
Span<byte> buffer = stackalloc byte[32];
249+
// Should be:
250+
// Span<byte> buffer = stackalloc byte[32];
251+
Span<byte> buffer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
250252

251253
// Safe memory copy for the last part of the data
252254
fixed (byte* bufferStart = buffer)
@@ -296,10 +298,12 @@ private static unsafe void Base64DecodeBlock(byte* output, Block64* block)
296298
private static unsafe void Base64DecodeBlockSafe(byte* outPtr, byte* srcPtr)
297299
{
298300
Base64Decode(outPtr, Avx2.LoadVector256(srcPtr));
299-
Base64Decode(outPtr + 24, Avx2.LoadVector256(srcPtr + 32));
300-
Span<byte> buffer = stackalloc byte[32];
301+
// should be:
302+
// Span<byte> buffer = stackalloc byte[32];
303+
Span<byte> buffer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
301304
fixed (byte* bufferPtr = buffer)
302305
{
306+
Base64Decode(bufferPtr, Avx2.LoadVector256(srcPtr + 32));
303307
// Copy only the first 12 bytes of the decoded fourth block into the output buffer, offset by 36 bytes.
304308
// This step is necessary because the fourth block may not need all 16 bytes if it contains padding characters.
305309
Buffer.MemoryCopy(bufferPtr, outPtr + 24, 24, 24);

src/Base64SSEUTF8.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ private static unsafe void Base64DecodeBlockSafe(byte* outPtr, Block64* b)
200200
Base64Decode(outPtr, b->chunk0);
201201
Base64Decode(outPtr + 12, b->chunk1);
202202
Base64Decode(outPtr + 24, b->chunk2);
203-
Span<byte> buffer = stackalloc byte[16];
203+
// should be:
204+
//Span<byte> buffer = stackalloc byte[16];
205+
Span<byte> buffer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
204206

205207
// Safe memory copy for the last part of the data
206208
fixed (byte* bufferStart = buffer)
@@ -258,7 +260,9 @@ private static unsafe void Base64DecodeBlockSafe(byte* outPtr, byte* srcPtr)
258260
Base64Decode(outPtr + 12, Sse2.LoadVector128(srcPtr + 16));
259261
Base64Decode(outPtr + 24, Sse2.LoadVector128(srcPtr + 32));
260262
Vector128<byte> tempBlock = Sse2.LoadVector128(srcPtr + 48);
261-
Span<byte> buffer = stackalloc byte[16];
263+
// should be:
264+
// Span<byte> buffer = stackalloc byte[16];
265+
Span<byte> buffer = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
262266
fixed (byte* bufferPtr = buffer)
263267
{
264268
Base64Decode(bufferPtr, tempBlock);

0 commit comments

Comments
 (0)