Skip to content

Commit

Permalink
deps,src: use SIMD for normal base64 encoding
Browse files Browse the repository at this point in the history
PR-URL: #39775
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
mscdex authored and danielleadams committed Jul 26, 2022
1 parent 9b53a69 commit 2ec8092
Show file tree
Hide file tree
Showing 78 changed files with 7,161 additions and 0 deletions.
32 changes: 32 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -1839,3 +1839,35 @@ The externally maintained libraries used by Node.js are:
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

- base64, located at deps/base64/base64/, is licensed as follows:
"""
Copyright (c) 2005-2007, Nick Galbreath
Copyright (c) 2013-2019, Alfred Klomp
Copyright (c) 2015-2017, Wojciech Mula
Copyright (c) 2016-2017, Matthieu Darbois
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
14 changes: 14 additions & 0 deletions deps/base64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# base64

This project boosts base64 encoding/decoding performance by utilizing SIMD
operations where possible.

The source is pulled from: https://github.com/aklomp/base64

Active development occurs in the default branch (currently named `master`).

## Updating

```sh
$ git clone https://github.com/aklomp/base64
```
191 changes: 191 additions & 0 deletions deps/base64/base64.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
{
'variables': {
'arm_fpu%': '',
'target_arch%': '',
},
'targets': [
{
'target_name': 'base64',
'type': 'static_library',
'include_dirs': [ 'base64/include', 'base64/lib' ],
'direct_dependent_settings': {
'include_dirs': [ 'base64/include' ],
'defines': [ 'BASE64_STATIC_DEFINE' ],
},
'defines': [ 'BASE64_STATIC_DEFINE' ],
'sources': [
'base64/include/libbase64.h',
'base64/lib/arch/generic/codec.c',
'base64/lib/tables/tables.c',
'base64/lib/codec_choose.c',
'base64/lib/codecs.h',
'base64/lib/lib.c',
],

'conditions': [
[ 'arm_fpu=="neon" and target_arch=="arm"', {
'defines': [ 'HAVE_NEON32=1' ],
'dependencies': [ 'base64_neon32' ],
}, {
'sources': [ 'base64/lib/arch/neon32/codec.c' ],
}],

# arm64 requires NEON, so it's safe to always use it
[ 'target_arch=="arm64"', {
'defines': [ 'HAVE_NEON64=1' ],
'dependencies': [ 'base64_neon64' ],
}, {
'sources': [ 'base64/lib/arch/neon64/codec.c' ],
}],

# Runtime detection will happen for x86 CPUs
[ 'target_arch in "ia32 x64 x32"', {
'defines': [
'HAVE_SSSE3=1',
'HAVE_SSE41=1',
'HAVE_SSE42=1',
'HAVE_AVX=1',
'HAVE_AVX2=1',
],
'dependencies': [
'base64_ssse3',
'base64_sse41',
'base64_sse42',
'base64_avx',
'base64_avx2',
],
}, {
'sources': [
'base64/lib/arch/ssse3/codec.c',
'base64/lib/arch/sse41/codec.c',
'base64/lib/arch/sse42/codec.c',
'base64/lib/arch/avx/codec.c',
'base64/lib/arch/avx2/codec.c',
],
}],
],
},

{
'target_name': 'base64_ssse3',
'type': 'static_library',
'include_dirs': [ 'base64/include', 'base64/lib' ],
'sources': [ 'base64/lib/arch/ssse3/codec.c' ],
'defines': [ 'BASE64_STATIC_DEFINE', 'HAVE_SSSE3=1' ],
'conditions': [
[ 'OS!="win"', {
'cflags': [ '-mssse3' ],
'xcode_settings': {
'OTHER_CFLAGS': [ '-mssse3' ]
},
}],
],
},

{
'target_name': 'base64_sse41',
'type': 'static_library',
'include_dirs': [ 'base64/include', 'base64/lib' ],
'sources': [ 'base64/lib/arch/sse41/codec.c' ],
'defines': [ 'BASE64_STATIC_DEFINE', 'HAVE_SSE41=1' ],
'conditions': [
[ 'OS!="win"', {
'cflags': [ '-msse4.1' ],
'xcode_settings': {
'OTHER_CFLAGS': [ '-msse4.1' ]
},
}],
],
},

{
'target_name': 'base64_sse42',
'type': 'static_library',
'include_dirs': [ 'base64/include', 'base64/lib' ],
'sources': [ 'base64/lib/arch/sse42/codec.c' ],
'defines': [ 'BASE64_STATIC_DEFINE', 'HAVE_SSE42=1' ],
'conditions': [
[ 'OS!="win"', {
'cflags': [ '-msse4.2' ],
'xcode_settings': {
'OTHER_CFLAGS': [ '-msse4.2' ]
},
}],
],
},

{
'target_name': 'base64_avx',
'type': 'static_library',
'include_dirs': [ 'base64/include', 'base64/lib' ],
'sources': [ 'base64/lib/arch/avx/codec.c' ],
'defines': [ 'BASE64_STATIC_DEFINE', 'HAVE_AVX=1' ],
'conditions': [
[ 'OS!="win"', {
'cflags': [ '-mavx' ],
'xcode_settings': {
'OTHER_CFLAGS': [ '-mavx' ]
},
}, {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [
'/arch:AVX'
],
},
},
}],
],
},

{
'target_name': 'base64_avx2',
'type': 'static_library',
'include_dirs': [ 'base64/include', 'base64/lib' ],
'sources': [ 'base64/lib/arch/avx2/codec.c' ],
'defines': [ 'BASE64_STATIC_DEFINE', 'HAVE_AVX2=1' ],
'conditions': [
[ 'OS!="win"', {
'cflags': [ '-mavx2' ],
'xcode_settings': {
'OTHER_CFLAGS': [ '-mavx2' ]
},
}, {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [
'/arch:AVX2'
],
},
},
}],
],
},

{
'target_name': 'base64_neon32',
'type': 'static_library',
'include_dirs': [ 'base64/include', 'base64/lib' ],
'sources': [ 'base64/lib/arch/neon32/codec.c' ],
'defines': [ 'BASE64_STATIC_DEFINE', 'HAVE_NEON32=1' ],
'conditions': [
[ 'OS!="win"', {
'cflags': [ '-mfpu=neon' ],
'xcode_settings': {
'OTHER_CFLAGS': [ '-mfpu=neon' ]
},
}],
],
},

{
'target_name': 'base64_neon64',
'type': 'static_library',
'include_dirs': [ 'base64/include', 'base64/lib' ],
'sources': [ 'base64/lib/arch/neon64/codec.c' ],
'defines': [ 'BASE64_STATIC_DEFINE', 'HAVE_NEON64=1' ],
# NEON is required in arm64, so no -mfpu flag is needed
}

]
}
22 changes: 22 additions & 0 deletions deps/base64/base64/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://EditorConfig.org
root = true

[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

indent_style = tab
tab_width = 8
indent_size = 8

[CMakeLists.txt]
tab_width = 4
indent_style = space
[*.cmake]
tab_width = 4
indent_style = space

[*.py]
tab_width = 4
indent_style = space
133 changes: 133 additions & 0 deletions deps/base64/base64/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Test

on: [push, pull_request]

jobs:
makefile-test:
name: makefile-${{ matrix.runner }}-amd64-${{ matrix.compiler }} ${{ ((matrix.openmp == 1) && '+openmp') || '' }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner: ["ubuntu-18.04"]
compiler: ["gcc", "clang"]
openmp: ["0", "1"]
include:
- runner: "macos-11"
compiler: "clang"
openmp: "0"
env:
OPENMP: ${{ matrix.openmp }}
OMP_NUM_THREADS: ${{ ((matrix.openmp == 1) && '2') || '0' }}
CC: ${{ matrix.compiler }}
OBJCOPY: ${{ (startsWith(matrix.runner, 'macos') && 'echo') || 'objcopy' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run tests
run: ./test/ci/test.sh

cmake-test:
name: cmake-${{ matrix.runner }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner: ["ubuntu-18.04", "macos-11", "windows-2019"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: CMake Configure
run: >
cmake
-B out
-Werror=dev
-DBASE64_BUILD_TESTS=ON
${{ runner.os != 'Windows' && '-DCMAKE_BUILD_TYPE=Release' || '' }}
${{ runner.os == 'macOS' && '-DBASE64_WITH_AVX2=OFF' || '' }}
- name: CMake Build
run: cmake --build out --config Release --verbose
- name: CTest
run: ctest --no-tests=error --test-dir out -VV --build-config Release

alpine-makefile-test:
name: makefile-alpine-amd64-gcc
runs-on: ubuntu-latest
container:
image: alpine:3.12
env:
CC: gcc
steps:
- name: Install deps
run: apk add --update bash build-base git
- name: Checkout
uses: actions/checkout@v3
- name: Run tests
run: ./test/ci/test.sh

alpine-cmake-test:
name: cmake-alpine-amd64-gcc
runs-on: ubuntu-latest
container:
image: alpine:3.12
steps:
- name: Install deps
run: apk add --update bash build-base cmake git
- name: Checkout
uses: actions/checkout@v3
- name: CMake Configure
run: cmake -B out -Werror=dev -DBASE64_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
- name: CMake Build
run: cmake --build out --config Release --verbose
- name: CTest
run: ctest --no-tests=error -VV --build-config Release
working-directory: ./out

alpine-alt-arch-makefile-test:
name: makefile-alpine-${{matrix.arch}}-${{matrix.cc}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [armv7, aarch64, s390x, ppc64le]
cc: [gcc, clang]
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: uraimo/run-on-arch-action@v2
with:
arch: ${{matrix.arch}}
distro: alpine_latest
env: |
CC: ${{matrix.cc}}
install: apk add --update bash build-base cmake git ${{matrix.cc}}
run: ./test/ci/test.sh

alpine-alt-arch-cmake-test:
name: cmake-alpine-${{matrix.arch}}-${{matrix.cc}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [armv7, aarch64, s390x, ppc64le]
cc: [gcc, clang]
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: uraimo/run-on-arch-action@v2
with:
arch: ${{matrix.arch}}
distro: alpine_latest
env: |
CC: ${{matrix.cc}}
install: apk add --update bash build-base cmake git ${{matrix.cc}}
run: |
echo "::group::CMake Configure"
cmake -B out -Werror=dev -DBASE64_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
echo "::endgroup::CMake Configure"
echo "::group::CMake Build"
cmake --build out --config Release --verbose
echo "::endgroup::CMake Build"
echo "::group::CTest"
ctest --no-tests=error --test-dir out -VV --build-config Release
echo "::endgroup::CTest"
Loading

0 comments on commit 2ec8092

Please sign in to comment.