This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Base64 encoding with simd-support #34529
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
daddd95
Optimized scalar code-path
gfoidl 144c431
Fixed label names
gfoidl 81a3c15
Implemented vectorized versions
gfoidl a46b9b2
Added reference to source of algorithm
gfoidl 2ac8aa4
Added back missing namespace
gfoidl 40d216b
Unsafe.Add instead of Unsafe.Subtract
gfoidl e7f00fb
Added THIRD-PARTY-NOTICES
gfoidl 6072958
PR Feedback
gfoidl f2067cc
THIRD-PARTY-NOTICES in repo-base instead instead in folder
gfoidl 6954802
PR Feedback
gfoidl 74e36e7
Rewritten to use raw-pointers instead of GC-tracked refs
gfoidl 294ecaa
Initialized the static fields directly (i.e. w/o cctor)
gfoidl 3016983
Added a test for decoding a (encoded) Guid
gfoidl 0343eda
EncodingMap / DecodingMap as byref instead of pointer
gfoidl a246816
PR Feedback
gfoidl d31b7e8
Debug.Fail instead throwing for the assertion
gfoidl 5c0dbee
ROSpan for static data
gfoidl 31c4741
ROS for lookup maps
gfoidl c8b6cb3
In decode avoided stack spill and hoisted zero-vector outside the loops
gfoidl d89692f
Assert assumption about destLength
gfoidl c8ee0a9
Added comments from original source and some changes to variable names
gfoidl 8c53689
Use TestZ instead of MoveMask in AVX2-path
gfoidl cf4f5ce
Fixed too complicated mask2F creation
gfoidl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
| using Internal.Runtime.CompilerServices; | ||
|
|
||
| namespace System.Buffers.Text | ||
| { | ||
| public static partial class Base64 | ||
| { | ||
| private static TVector ReadVector<TVector>(ReadOnlySpan<sbyte> data) | ||
| { | ||
| ref sbyte tmp = ref MemoryMarshal.GetReference(data); | ||
| return Unsafe.As<sbyte, TVector>(ref tmp); | ||
| } | ||
|
|
||
| [Conditional("DEBUG")] | ||
| private static unsafe void AssertRead<TVector>(byte* src, byte* srcStart, int srcLength) | ||
| { | ||
| int vectorElements = Unsafe.SizeOf<TVector>(); | ||
| byte* readEnd = src + vectorElements; | ||
| byte* srcEnd = srcStart + srcLength; | ||
|
|
||
| if (readEnd > srcEnd) | ||
| { | ||
| int srcIndex = (int)(src - srcStart); | ||
| Debug.Fail($"Read for {typeof(TVector)} is not within safe bounds. srcIndex: {srcIndex}, srcLength: {srcLength}"); | ||
| } | ||
| } | ||
|
|
||
| [Conditional("DEBUG")] | ||
| private static unsafe void AssertWrite<TVector>(byte* dest, byte* destStart, int destLength) | ||
| { | ||
| int vectorElements = Unsafe.SizeOf<TVector>(); | ||
| byte* writeEnd = dest + vectorElements; | ||
| byte* destEnd = destStart + destLength; | ||
|
|
||
| if (writeEnd > destEnd) | ||
| { | ||
| int destIndex = (int)(dest - destStart); | ||
| Debug.Fail($"Write for {typeof(TVector)} is not within safe bounds. destIndex: {destIndex}, destLength: {destLength}"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.