Base64 encoding with simd-support (dotnet/corefx#34529)
authorGünther Foidl <gue@korporal.at>
Wed, 29 May 2019 15:29:31 +0000 (17:29 +0200)
committerTanner Gooding <tagoo@outlook.com>
Wed, 29 May 2019 15:29:31 +0000 (08:29 -0700)
commitaf1995c68f35af192b10f0735282b8768ca39337
treeb9e75bc1ca9f5a3ea4b8dd84c6c9182b4de1d6af
parent822e91ec64509a74064c248b2d7282cabbf9e278
Base64 encoding with simd-support (dotnet/corefx#34529)

* Optimized scalar code-path

* Fixed label names

* Implemented vectorized versions

* Added reference to source of algorithm

* Added back missing namespace

* Unsafe.Add instead of Unsafe.Subtract

Fixed build-failure (https://ci3.dot.net/job/dotnet_corefx/job/master/job/linux-musl-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/8247/console)
Seems like the internal Unsafe doesn't have a Subtract method, so use Add instead.

* Added THIRD-PARTY-NOTICES

* PR Feedback

* THIRD-PARTY-NOTICES in repo-base instead instead in folder

Cf. https://github.com/dotnet/corefx/pull/34529#issuecomment-453510246

* PR Feedback

* https://github.com/dotnet/corefx/pull/34529#discussion_r247200659
* https://github.com/dotnet/corefx/pull/34529#discussion_r247214904

* Rewritten to use raw-pointers instead of GC-tracked refs

Cf. https://github.com/dotnet/corefx/pull/34529#discussion_r247197669

* Initialized the static fields directly (i.e. w/o cctor)

Cf. https://github.com/dotnet/corefx/pull/34529#discussion_r247193419

* Added a test for decoding a (encoded) Guid

The case with decoding encoded 16 bytes was not covered by tests, so a wrong code got commited before, resulting
in DestinationTooSmall instead of the correct Done.

* EncodingMap / DecodingMap as byref instead of pointer

So got rid of the `rep stosd` in the prolog. Cf. https://github.com/dotnet/corefx/pull/34529#discussion_r248075157

* PR Feedback

* https://github.com/dotnet/corefx/pull/34529#discussion_r262165689

* Debug.Fail instead throwing for the assertion

Cf. https://github.com/dotnet/corefx/pull/34529#discussion_r263894301

* ROSpan for static data

* ROS for lookup maps

* In decode avoided stack spill and hoisted zero-vector outside the loops

Cf. https://github.com/dotnet/corefx/pull/34529#discussion_r287613894

* Assert assumption about destLength

Cf. https://github.com/dotnet/corefx/pull/34529#discussion_r287605561

* Added comments from original source and some changes to variable names

Cf. https://github.com/dotnet/corefx/pull/34529#discussion_r287606634 and https://github.com/dotnet/corefx/pull/34529#discussion_r287606714

* Use TestZ instead of MoveMask in AVX2-path

Cf. https://github.com/dotnet/corefx/pull/34529#discussion_r287825385

* Fixed too complicated mask2F creation

Improved the version done in dotnet/corefx@c8b6cb3387ca856f52d246ad260172c8fe1d9dcd, so the static data isn't needed and code is more compact and readable.

Commit migrated from https://github.com/dotnet/corefx/commit/036e0a64bd190e80f1685c3b267e495b03bb2962
src/libraries/System.Memory/src/System.Memory.csproj
src/libraries/System.Memory/src/System/Buffers/Text/Base64.cs [new file with mode: 0644]
src/libraries/System.Memory/src/System/Buffers/Text/Base64Decoder.cs
src/libraries/System.Memory/src/System/Buffers/Text/Base64Encoder.cs
src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs