Skip to content

Commit 2f5926c

Browse files
author
Daniel Lemire
committed
some trimming
1 parent 908e031 commit 2f5926c

File tree

3 files changed

+33
-43
lines changed

3 files changed

+33
-43
lines changed

benchmark/Benchmark.cs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,15 @@ public unsafe void RunSSEDecodingBenchmarkUTF16(string[] data, int[] lengths)
305305
}
306306
}
307307

308-
309-
310308
public unsafe void RunSSEDecodingBenchmarkWithAllocUTF8(string[] data, int[] lengths)
311309
{
312310
for (int i = 0; i < FileContent.Length; i++)
313311
{
314-
byte[] base64 = input[i];
315-
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<byte>(base64.AsSpan())];
312+
Span<byte> base64 = input[i].AsSpan();
313+
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<byte>(base64)];
316314
int bytesConsumed = 0;
317315
int bytesWritten = 0;
318-
SimdBase64.SSE.Base64.DecodeFromBase64SSE(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
316+
SimdBase64.SSE.Base64.DecodeFromBase64SSE(base64, dataoutput, out bytesConsumed, out bytesWritten, false);
319317
if (bytesWritten != lengths[i])
320318
{
321319
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
@@ -330,11 +328,11 @@ public unsafe void RunSSEDecodingBenchmarkWithAllocUTF16(string[] data, int[] le
330328
for (int i = 0; i < FileContent.Length; i++)
331329
{
332330
string s = FileContent[i];
333-
char[] base64 = input16[i];
334-
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<char>(base64.AsSpan())];
331+
Span<char> base64 = input16[i].AsSpan();
332+
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<char>(base64)];
335333
int bytesConsumed = 0;
336334
int bytesWritten = 0;
337-
SimdBase64.SSE.Base64.DecodeFromBase64SSE(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
335+
SimdBase64.SSE.Base64.DecodeFromBase64SSE(base64, dataoutput, out bytesConsumed, out bytesWritten, false);
338336
if (bytesWritten != lengths[i])
339337
{
340338
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
@@ -382,17 +380,15 @@ public unsafe void RunAVX2DecodingBenchmarkUTF16(string[] data, int[] lengths)
382380
}
383381
}
384382

385-
386-
387383
public unsafe void RunAVX2DecodingBenchmarkWithAllocUTF8(string[] data, int[] lengths)
388384
{
389385
for (int i = 0; i < FileContent.Length; i++)
390386
{
391-
byte[] base64 = input[i];
392-
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<byte>(base64.AsSpan())];
387+
Span<byte> base64 = input[i].AsSpan();
388+
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<byte>(base64)];
393389
int bytesConsumed = 0;
394390
int bytesWritten = 0;
395-
SimdBase64.AVX2.Base64.DecodeFromBase64AVX2(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
391+
SimdBase64.AVX2.Base64.DecodeFromBase64AVX2(base64, dataoutput, out bytesConsumed, out bytesWritten, false);
396392
if (bytesWritten != lengths[i])
397393
{
398394
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
@@ -407,11 +403,11 @@ public unsafe void RunAVX2DecodingBenchmarkWithAllocUTF16(string[] data, int[] l
407403
for (int i = 0; i < FileContent.Length; i++)
408404
{
409405
string s = FileContent[i];
410-
char[] base64 = input16[i];
411-
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<char>(base64.AsSpan())];
406+
Span<char> base64 = input16[i].AsSpan();
407+
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<char>(base64)];
412408
int bytesConsumed = 0;
413409
int bytesWritten = 0;
414-
SimdBase64.AVX2.Base64.DecodeFromBase64AVX2(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
410+
SimdBase64.AVX2.Base64.DecodeFromBase64AVX2(base64, dataoutput, out bytesConsumed, out bytesWritten, false);
415411
if (bytesWritten != lengths[i])
416412
{
417413
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
@@ -460,17 +456,15 @@ public unsafe void RunARMDecodingBenchmarkUTF16(string[] data, int[] lengths)
460456
}
461457
}
462458

463-
464-
465459
public unsafe void RunARMDecodingBenchmarkWithAllocUTF8(string[] data, int[] lengths)
466460
{
467461
for (int i = 0; i < FileContent.Length; i++)
468462
{
469-
byte[] base64 = input[i];
470-
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<byte>(base64.AsSpan())];
463+
Span<byte> base64 = input[i].AsSpan();
464+
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<byte>(base64)];
471465
int bytesConsumed = 0;
472466
int bytesWritten = 0;
473-
SimdBase64.Arm.Base64.DecodeFromBase64ARM(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
467+
SimdBase64.Arm.Base64.DecodeFromBase64ARM(base64, dataoutput, out bytesConsumed, out bytesWritten, false);
474468
if (bytesWritten != lengths[i])
475469
{
476470
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
@@ -485,11 +479,11 @@ public unsafe void RunARMDecodingBenchmarkWithAllocUTF16(string[] data, int[] le
485479
for (int i = 0; i < FileContent.Length; i++)
486480
{
487481
string s = FileContent[i];
488-
char[] base64 = input16[i];
489-
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<char>(base64.AsSpan())];
482+
Span<char> base64 = input16[i].AsSpan();
483+
byte[] dataoutput = new byte[SimdBase64.Scalar.Base64.MaximalBinaryLengthFromBase64Scalar<char>(base64)];
490484
int bytesConsumed = 0;
491485
int bytesWritten = 0;
492-
SimdBase64.Arm.Base64.DecodeFromBase64ARM(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
486+
SimdBase64.Arm.Base64.DecodeFromBase64ARM(base64, dataoutput, out bytesConsumed, out bytesWritten, false);
493487
if (bytesWritten != lengths[i])
494488
{
495489
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
@@ -551,8 +545,8 @@ public unsafe void DotnetRuntimeSIMDBase64RealDataUTF8()
551545
RunRuntimeSIMDDecodingBenchmarkUTF8(FileContent, DecodedLengths);
552546
}
553547

554-
[Benchmark]
555-
[BenchmarkCategory("default", "runtime")]
548+
//[Benchmark]
549+
//[BenchmarkCategory("default", "runtime")]
556550
public unsafe void DotnetRuntimeSIMDBase64RealDataWithAllocUTF8()
557551
{
558552
RunRuntimeSIMDDecodingBenchmarkWithAllocUTF8(FileContent, DecodedLengths);
@@ -572,8 +566,8 @@ public unsafe void SSEDecodingRealDataUTF8()
572566
RunSSEDecodingBenchmarkUTF8(FileContent, DecodedLengths);
573567
}
574568

575-
[Benchmark]
576-
[BenchmarkCategory("SSE")]
569+
//[Benchmark]
570+
//[BenchmarkCategory("SSE")]
577571
public unsafe void SSEDecodingRealDataWithAllocUTF8()
578572
{
579573
RunSSEDecodingBenchmarkWithAllocUTF8(FileContent, DecodedLengths);
@@ -586,25 +580,23 @@ public unsafe void AVX2DecodingRealDataUTF8()
586580
RunAVX2DecodingBenchmarkUTF8(FileContent, DecodedLengths);
587581
}
588582

589-
[Benchmark]
590-
[BenchmarkCategory("AVX")]
583+
//[Benchmark]
584+
//[BenchmarkCategory("AVX")]
591585
public unsafe void AVX2DecodingRealDataWithAllocUTF8()
592586
{
593587
RunAVX2DecodingBenchmarkWithAllocUTF8(FileContent, DecodedLengths);
594-
}
595-
596-
597-
598-
588+
}
589+
590+
599591
[Benchmark]
600592
[BenchmarkCategory("arm64")]
601593
public unsafe void ARMDecodingRealDataUTF8()
602594
{
603595
RunARMDecodingBenchmarkUTF8(FileContent, DecodedLengths);
604596
}
605597

606-
[Benchmark]
607-
[BenchmarkCategory("arm64")]
598+
//[Benchmark]
599+
//[BenchmarkCategory("arm64")]
608600
public unsafe void ARMDecodingRealDataWithAllocUTF8()
609601
{
610602
RunARMDecodingBenchmarkWithAllocUTF8(FileContent, DecodedLengths);

src/Base64AVX2UTF8.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ private static UInt64 ToBase64Mask(bool base64Url, ref Vector256<byte> src, ref
115115
0x00, 0x10, 0xC3, 0xBF, 0xBF,
116116
0xB9, 0xB9);
117117

118-
119-
120118
Vector256<sbyte> checkAsso = base64Url
121119
? Vector256.Create(0xD, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x3, 0x7, 0xB, 0xE, 0xB, 0x6, 0xD, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x3, 0x7, 0xB, 0xE, 0xB, 0x6)
122120
: Vector256.Create(

src/Base64Scalar.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public unsafe static OperationStatus DecodeFromBase64Scalar(ReadOnlySpan<byte> s
7171
UInt32 x;
7272
uint triple;
7373
int idx;
74-
byte[] buffer = new byte[4];
74+
byte[] buffer = [0, 0, 0, 0];
7575

7676
while (true)
7777
{
@@ -217,7 +217,7 @@ public unsafe static OperationStatus DecodeFromBase64Scalar(ReadOnlySpan<char> s
217217
UInt32 x;
218218
uint triple;
219219
int idx;
220-
byte[] buffer = new byte[4];
220+
byte[] buffer = [0, 0, 0, 0];
221221

222222
while (true)
223223
{
@@ -372,7 +372,7 @@ public unsafe static OperationStatus SafeDecodeFromBase64Scalar(ReadOnlySpan<byt
372372
uint x;
373373
uint triple;
374374
int idx;
375-
byte[] buffer = new byte[4];
375+
byte[] buffer = [0, 0, 0, 0];
376376

377377
while (true)
378378
{
@@ -547,7 +547,7 @@ public unsafe static OperationStatus SafeDecodeFromBase64Scalar(ReadOnlySpan<cha
547547
uint x;
548548
uint triple;
549549
int idx;
550-
byte[] buffer = new byte[4];
550+
byte[] buffer = [0, 0, 0, 0];
551551

552552
while (true)
553553
{

0 commit comments

Comments
 (0)