Skip to content

Commit f1bdfd9

Browse files
committed
more cleaning
1 parent ca1c240 commit f1bdfd9

File tree

7 files changed

+94
-97
lines changed

7 files changed

+94
-97
lines changed

src/Base64ARM.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static partial class Base64
1616
// If needed for debugging, you can do the following:
1717
/*static string VectorToString(Vector128<byte> vector)
1818
{
19-
Span<byte> bytes = new byte[16];
19+
Span<byte> bytes = stackalloc byte[16];
2020
vector.CopyTo(bytes);
2121
StringBuilder sb = new StringBuilder();
2222
foreach (byte b in bytes)
@@ -246,8 +246,8 @@ private static unsafe void Compress(Vector128<byte> data, ushort mask, byte* out
246246
// thintable_epi8[mask2] into a 128-bit register, using only
247247
// two instructions on most compilers.
248248

249-
ulong value1 = Tables.thintableEpi8[mask1];
250-
ulong value2 = Tables.thintableEpi8[mask2];
249+
ulong value1 = Tables.GetThintableEpi8(mask1);
250+
ulong value2 = Tables.GetThintableEpi8(mask2);
251251

252252
Vector128<sbyte> shufmask = Vector128.Create(value2, value1).AsSByte();
253253

@@ -259,7 +259,7 @@ private static unsafe void Compress(Vector128<byte> data, ushort mask, byte* out
259259
Vector128<sbyte> pruned = AdvSimd.Arm64.VectorTableLookup(data.AsSByte(), shufmask);
260260
// we still need to put the two halves together.
261261
// we compute the popcount of the first half:
262-
int pop1 = Tables.BitsSetTable256mul2[mask1];
262+
int pop1 = Tables.GetBitsSetTable256mul2(mask1);
263263
// then load the corresponding mask, what it does is to write
264264
// only the first pop1 bytes from the first 8 bytes, and then
265265
// it fills in with the bytes from the second 8 bytes + some filling
@@ -341,7 +341,6 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMRegular(ReadOnlySp
341341
{
342342
// translation from ASCII to 6 bit values
343343
bool isUrl = false;
344-
byte[] toBase64 = Tables.ToBase64Value;
345344
bytesConsumed = 0;
346345
bytesWritten = 0;
347346
const int blocksSize = 6;
@@ -469,7 +468,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMRegular(ReadOnlySp
469468
int lastBlockSrcCount = 0;
470469
while ((bufferPtr - startOfBuffer) % 64 != 0 && src < srcEnd)
471470
{
472-
byte val = toBase64[(int)*src];
471+
byte val = SimdBase64.Tables.GetToBase64Value((uint)*src);
473472
*bufferPtr = val;
474473
if (val > 64)
475474
{
@@ -533,7 +532,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMRegular(ReadOnlySp
533532

534533
while (leftover < 4 && src < srcEnd)
535534
{
536-
byte val = toBase64[(byte)*src];
535+
byte val = SimdBase64.Tables.GetToBase64Value((byte)*src);
537536
if (val > 64)
538537
{
539538
bytesConsumed = (int)(src - srcInit);
@@ -645,7 +644,6 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMRegular(ReadOnlySp
645644
{
646645
// translation from ASCII to 6 bit values
647646
bool isUrl = false;
648-
byte[] toBase64 = Tables.ToBase64Value;
649647
bytesConsumed = 0;
650648
bytesWritten = 0;
651649
const int blocksSize = 6;
@@ -787,7 +785,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMRegular(ReadOnlySp
787785
bytesWritten += remainderBytesWritten;
788786
return result;
789787
}
790-
byte val = toBase64[(int)*src];
788+
byte val = SimdBase64.Tables.GetToBase64Value((uint)*src);
791789
*bufferPtr = val;
792790
if (val > 64)
793791
{
@@ -858,7 +856,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMRegular(ReadOnlySp
858856
return OperationStatus.InvalidData;
859857
}
860858

861-
byte val = toBase64[(byte)*src];
859+
byte val = SimdBase64.Tables.GetToBase64Value((uint)*src);
862860
if (val > 64)
863861
{
864862
bytesConsumed = (int)(src - srcInit);
@@ -971,7 +969,6 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMUrl(ReadOnlySpan<b
971969
{
972970
// translation from ASCII to 6 bit values
973971
bool isUrl = true;
974-
byte[] toBase64 = Tables.ToBase64UrlValue;
975972
bytesConsumed = 0;
976973
bytesWritten = 0;
977974
const int blocksSize = 6;
@@ -1098,7 +1095,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMUrl(ReadOnlySpan<b
10981095
int lastBlockSrcCount = 0;
10991096
while ((bufferPtr - startOfBuffer) % 64 != 0 && src < srcEnd)
11001097
{
1101-
byte val = toBase64[(int)*src];
1098+
byte val = Tables.GetToBase64UrlValue((byte)*src);
11021099
*bufferPtr = val;
11031100
if (val > 64)
11041101
{
@@ -1163,7 +1160,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMUrl(ReadOnlySpan<b
11631160

11641161
while (leftover < 4 && src < srcEnd)
11651162
{
1166-
byte val = toBase64[(byte)*src];
1163+
byte val = Tables.GetToBase64UrlValue((byte)*src);
11671164
if (val > 64)
11681165
{
11691166
bytesConsumed = (int)(src - srcInit);
@@ -1277,7 +1274,6 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMUrl(ReadOnlySpan<c
12771274
{
12781275
// translation from ASCII to 6 bit values
12791276
bool isUrl = true;
1280-
byte[] toBase64 = Tables.ToBase64UrlValue;
12811277
bytesConsumed = 0;
12821278
bytesWritten = 0;
12831279
const int blocksSize = 6;
@@ -1424,7 +1420,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMUrl(ReadOnlySpan<c
14241420
bytesWritten += remainderBytesWritten;
14251421
return result;
14261422
}
1427-
byte val = toBase64[(int)*src];
1423+
byte val = Tables.GetToBase64UrlValue((byte)*src);
14281424
*bufferPtr = val;
14291425
if (val > 64)
14301426
{
@@ -1495,7 +1491,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64ARMUrl(ReadOnlySpan<c
14951491
bytesWritten = (int)(dst - dstInit);
14961492
return OperationStatus.InvalidData;
14971493
}
1498-
byte val = toBase64[(byte)*src];
1494+
byte val = Tables.GetToBase64UrlValue((byte)*src);
14991495
if (val > 64)
15001496
{
15011497
bytesConsumed = (int)(src - srcInit);

src/Base64AVX2UTF16.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ private unsafe static OperationStatus InnerDecodeFromBase64AVX2Regular(ReadOnlyS
2525
{
2626
// translation from ASCII to 6 bit values
2727
bool isUrl = false;
28-
byte[] toBase64 = Tables.ToBase64Value;
2928
bytesConsumed = 0;
3029
bytesWritten = 0;
3130
const int blocksSize = 6;
@@ -200,7 +199,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64AVX2Regular(ReadOnlyS
200199
bytesWritten += remainderBytesWritten;
201200
return result;
202201
}
203-
byte val = toBase64[(int)*src];
202+
byte val = SimdBase64.Tables.GetToBase64Value((uint)*src);
204203
*bufferPtr = val;
205204
if (val > 64)
206205
{
@@ -281,7 +280,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64AVX2Regular(ReadOnlyS
281280
bytesWritten = (int)(dst - dstInit);
282281
return OperationStatus.InvalidData;
283282
}
284-
byte val = toBase64[(byte)*src];
283+
byte val = SimdBase64.Tables.GetToBase64Value((byte)*src);
285284
if (val > 64)
286285
{
287286
bytesConsumed = (int)(src - srcInit);
@@ -390,7 +389,6 @@ private unsafe static OperationStatus InnerDecodeFromBase64AVX2Url(ReadOnlySpan<
390389
{
391390
// translation from ASCII to 6 bit values
392391
bool isUrl = true;
393-
byte[] toBase64 = Tables.ToBase64UrlValue;
394392
bytesConsumed = 0;
395393
bytesWritten = 0;
396394
const int blocksSize = 6;
@@ -563,7 +561,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64AVX2Url(ReadOnlySpan<
563561
bytesWritten += remainderBytesWritten;
564562
return result;
565563
}
566-
byte val = toBase64[(int)*src];
564+
byte val = Tables.GetToBase64UrlValue((byte)*src);
567565
*bufferPtr = val;
568566
if (val > 64)
569567
{
@@ -642,7 +640,7 @@ private unsafe static OperationStatus InnerDecodeFromBase64AVX2Url(ReadOnlySpan<
642640

643641
while (leftover < 4 && src < srcEnd)
644642
{
645-
byte val = toBase64[(byte)*src];
643+
byte val = Tables.GetToBase64UrlValue((byte)*src);
646644
if (val > 64)
647645
{
648646
bytesConsumed = (int)(src - srcInit);

0 commit comments

Comments
 (0)