Skip to content

Commit 51e503d

Browse files
author
Daniel Lemire
committed
more cleaning
1 parent e6bd5b6 commit 51e503d

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ as a reference (`System.Buffers.Text.Base64.DecodeFromUtf8`).
2727

2828
| processor | SimdBase64(GB/s) | .NET speed (GB/s) | speed up |
2929
|:----------------|:------------------------|:-------------------|:-------------------|
30-
| Apple M2 processor (ARM) | 6.3 | 3.8 | 1.7 x |
31-
| Intel Ice Lake (AVX2) | 5.8 | 3.4 | 1.7 x |
32-
| Intel Ice Lake (SSSE3) | 4.7 | 3.4 | 1.4 x |
30+
| Apple M2 processor (ARM) | 6.5 | 3.8 | 1.7 x |
31+
| Intel Ice Lake (AVX2) | 6.6 | 3.4 | 1.9 x |
32+
| Intel Ice Lake (SSSE3) | 4.9 | 3.4 | 1.4 x |
3333

3434
Our results are more impressive when comparing against the standard base64 string decoding
35-
function (`Convert.FromBase64String(mystring)`), but we omit these results for simplicity.
35+
function (`Convert.FromBase64String(mystring)`), but it is explained in part by the fact
36+
that the .NET team did not accelerated them using SIMD instructions. Thus we omit them, only
37+
comparing with the SIMD-accelerated .NET functions.
3638

3739
## Requirements
3840

benchmark/Benchmark.cs

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

src/Base64Scalar.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public unsafe static OperationStatus DecodeFromBase64Scalar(ReadOnlySpan<byte> s
151151
if (MatchSystem(Endianness.BIG))
152152
{
153153
triple <<= 8;
154-
Marshal.Copy(BitConverter.GetBytes(triple), 0, (IntPtr)dst, 2);
154+
Buffer.MemoryCopy(&triple, dst, 2, 2);
155155
}
156156
else
157157
{
@@ -180,7 +180,7 @@ public unsafe static OperationStatus DecodeFromBase64Scalar(ReadOnlySpan<byte> s
180180
if (MatchSystem(Endianness.BIG))
181181
{
182182
triple <<= 8;
183-
Marshal.Copy(BitConverter.GetBytes(triple), 0, (IntPtr)dst, 3);
183+
Buffer.MemoryCopy(&triple, dst, 3, 3);
184184
}
185185
else
186186
{
@@ -300,7 +300,7 @@ public unsafe static OperationStatus DecodeFromBase64Scalar(ReadOnlySpan<char> s
300300
if (MatchSystem(Endianness.BIG))
301301
{
302302
triple <<= 8;
303-
Marshal.Copy(BitConverter.GetBytes(triple), 0, (IntPtr)dst, 2);
303+
Buffer.MemoryCopy(&triple, dst, 2, 2);
304304
}
305305
else
306306
{
@@ -329,7 +329,7 @@ public unsafe static OperationStatus DecodeFromBase64Scalar(ReadOnlySpan<char> s
329329
if (MatchSystem(Endianness.BIG))
330330
{
331331
triple <<= 8;
332-
Marshal.Copy(BitConverter.GetBytes(triple), 0, (IntPtr)dst, 3);
332+
Buffer.MemoryCopy(&triple, dst, 3, 3);
333333
}
334334
else
335335
{
@@ -457,7 +457,7 @@ public unsafe static OperationStatus SafeDecodeFromBase64Scalar(ReadOnlySpan<byt
457457
if (MatchSystem(Endianness.BIG))
458458
{
459459
triple <<= 8;
460-
Marshal.Copy(BitConverter.GetBytes(triple), 0, (IntPtr)dst, 2);
460+
Buffer.MemoryCopy(&triple, dst, 2, 2);
461461
}
462462
else
463463
{
@@ -492,7 +492,7 @@ public unsafe static OperationStatus SafeDecodeFromBase64Scalar(ReadOnlySpan<byt
492492
if (MatchSystem(Endianness.BIG))
493493
{
494494
triple <<= 8;
495-
Marshal.Copy(BitConverter.GetBytes(triple), 0, (IntPtr)dst, 3);
495+
Buffer.MemoryCopy(&triple, dst, 3, 3);
496496
}
497497
else
498498
{
@@ -548,7 +548,6 @@ public unsafe static OperationStatus SafeDecodeFromBase64Scalar(ReadOnlySpan<cha
548548
return OperationStatus.DestinationTooSmall;
549549
}
550550
Buffer.MemoryCopy(bufferPtr, dst, 3, 3);
551-
//Marshal.Copy(buffer, 0, (IntPtr)dst, 3); // optimization opportunity: copy 4 bytes
552551
dst += 3;
553552
src += 4;
554553
}
@@ -621,7 +620,7 @@ public unsafe static OperationStatus SafeDecodeFromBase64Scalar(ReadOnlySpan<cha
621620
if (MatchSystem(Endianness.BIG))
622621
{
623622
triple <<= 8;
624-
Marshal.Copy(BitConverter.GetBytes(triple), 0, (IntPtr)dst, 2);
623+
Buffer.MemoryCopy(&triple, dst, 2, 2);
625624
}
626625
else
627626
{
@@ -656,7 +655,7 @@ public unsafe static OperationStatus SafeDecodeFromBase64Scalar(ReadOnlySpan<cha
656655
if (MatchSystem(Endianness.BIG))
657656
{
658657
triple <<= 8;
659-
Marshal.Copy(BitConverter.GetBytes(triple), 0, (IntPtr)dst, 3);
658+
Buffer.MemoryCopy(&triple, dst, 3, 3);
660659
}
661660
else
662661
{

0 commit comments

Comments
 (0)