* 增加xsimd库

This commit is contained in:
2026-02-05 20:57:57 +08:00
parent 5b3ed1d1e4
commit 085cb83ae4
245 changed files with 59823 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
---
BasedOnStyle: WebKit
AlignAfterOpenBracket: Align
AlignConsecutiveDeclarations: 'false'
BreakBeforeBraces: Allman
NamespaceIndentation: All
...
+7
View File
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.19)
project(test VERSION 0.0.1)
find_package(xsimd REQUIRED)
add_executable(test main.cpp)
target_link_libraries(test PUBLIC xsimd)
+6
View File
@@ -0,0 +1,6 @@
#include "xsimd/xsimd.hpp"
int main()
{
return 0;
}
@@ -0,0 +1,4 @@
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(triple aarch64-linux-gnu)
include(${CMAKE_CURRENT_LIST_DIR}/clang.cmake)
@@ -0,0 +1,4 @@
set(CMAKE_SYSTEM_PROCESSOR armv7-a)
set(triple arm-linux-gnueabihf)
include(${CMAKE_CURRENT_LIST_DIR}/clang.cmake)
@@ -0,0 +1,4 @@
set(CMAKE_SYSTEM_PROCESSOR riscv64)
set(triple riscv64-linux-gnu)
include(${CMAKE_CURRENT_LIST_DIR}/clang.cmake)
+11
View File
@@ -0,0 +1,11 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
@@ -0,0 +1,4 @@
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(triple aarch64-linux-gnu)
include(${CMAKE_CURRENT_LIST_DIR}/gcc.cmake)
@@ -0,0 +1,4 @@
set(CMAKE_SYSTEM_PROCESSOR armv7-a)
set(triple arm-linux-gnueabihf)
include(${CMAKE_CURRENT_LIST_DIR}/gcc.cmake)
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_PROCESSOR powerpc64)
set(triple powerpc64-linux-gnu)
include(${CMAKE_CURRENT_LIST_DIR}/gcc.cmake)
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_PROCESSOR powerpc64le)
set(triple powerpc64le-linux-gnu)
include(${CMAKE_CURRENT_LIST_DIR}/gcc.cmake)
@@ -0,0 +1,4 @@
set(CMAKE_SYSTEM_PROCESSOR riscv64)
set(triple riscv64-linux-gnu)
include(${CMAKE_CURRENT_LIST_DIR}/gcc.cmake)
+9
View File
@@ -0,0 +1,9 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER ${triple}-gcc)
set(CMAKE_CXX_COMPILER ${triple}-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+36
View File
@@ -0,0 +1,36 @@
name: Android build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
target:
- armeabi-v7a
- arm64-v8a
- x86
- x86_64
api:
- 16
- 18
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build script
env:
TARGET: ${{ matrix.target }}
API: ${{ matrix.api }}
run: |
mkdir _build
NDK="$($ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --list_installed | sed -E 's/( +[|] +)/|/g;s/ +$//' | grep '^ ndk' | cut -d '|' -f 4 | sort | head -n1)"
cd _build && \
cmake .. -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/$NDK/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=$ABI \
-DANDROID_PLATFORM=android-$API \
-DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DCMAKE_BUILD_TYPE=Release
cmake --build . --verbose
@@ -0,0 +1,15 @@
name: Arch consistency check
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt install g++
- name: Check architecture consistency
run: cd test && sh ./check_arch.sh
+22
View File
@@ -0,0 +1,22 @@
name: benchmark & examples
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt install g++
- name: Setup
run: |
mkdir _build
cd _build && cmake .. -DBUILD_BENCHMARK=ON -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release
- name: Build
run: cmake --build _build
- name: Testing sequential
run: cmake --build _build --target xbenchmark
+29
View File
@@ -0,0 +1,29 @@
name: CMake integration
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash -l {0}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Configure build
run: |
mkdir _build && cd _build
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=_install
- name: Build
run: cmake --build _build --target install
- name: Check install
run: |
mkdir _install_build && cd _install_build
cp ${{ github.workspace }}/.github/cmake-test/* .
ls $PWD/../_build/_install/share/cmake/xsimd
cmake . -DCMAKE_PREFIX_PATH=$PWD/../_build/_install/share/cmake/xsimd
cmake --build .
+45
View File
@@ -0,0 +1,45 @@
name: Arm cross-compilation build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
name: '${{ matrix.target.arch }}, ${{ matrix.sys.compiler }} ${{ matrix.sys.version }}'
strategy:
matrix:
target:
- { platform: 'arm', arch: 'armv7-a', dir: 'arm-linux-gnueabihf', flags: '-mfpu=neon', full: 'ON'}
- { platform: 'arm', arch: 'armv7-a', dir: 'arm-linux-gnueabihf', flags: '-mfpu=vfpv3-d16', full: 'OFF' } # no neon
- { platform: 'aarch64', arch: 'armv8-a', dir: 'aarch64-linux-gnu', flags: '', full: 'ON' }
sys:
- { compiler: 'gcc', version: '10' }
steps:
- name: Setup compiler
if: ${{ matrix.sys.compiler == 'gcc' }}
run: |
sudo apt-get update || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install g++-${{ matrix.sys.version }}-${{ matrix.target.dir }} g++-${{ matrix.sys.version }}-multilib || exit 1
sudo update-alternatives --remove-all ${{ matrix.target.dir }}-gcc || true
sudo update-alternatives --remove-all ${{ matrix.target.dir }}-g++ || true
sudo update-alternatives --install /usr/bin/${{ matrix.target.dir }}-gcc ${{ matrix.target.dir }}-gcc /usr/bin/${{ matrix.target.dir }}-gcc-${{ matrix.sys.version }} 20
sudo update-alternatives --install /usr/bin/${{ matrix.target.dir }}-g++ ${{ matrix.target.dir }}-g++ /usr/bin/${{ matrix.target.dir }}-g++-${{ matrix.sys.version }} 20
- name: Setup QEMU
run: |
sudo apt-get --no-install-suggests --no-install-recommends install qemu-user
- name: Setup Ninja
run: |
sudo apt-get install ninja-build
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Setup
run: |
mkdir _build
cd _build && cmake .. -DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DBUILD_BENCHMARK=${{ matrix.target.full }} -DBUILD_EXAMPLES=${{ matrix.target.full }} -DCMAKE_BUILD_TYPE=Release -DTARGET_ARCH=generic -DCMAKE_C_FLAGS="-march=${{ matrix.target.arch }} ${{ matrix.target.flags }}" -DCMAKE_CXX_FLAGS="-march=${{ matrix.target.arch }} ${{ matrix.target.flags }}" -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/.github/toolchains/${{ matrix.sys.compiler }}-${{ matrix.target.dir }}.cmake
- name: Build
run: cmake --build _build
- name: Testing xsimd
run: |
qemu-${{ matrix.target.platform }} -L /usr/${{ matrix.target.dir}}/ ./test/test_xsimd
working-directory: ${{ github.workspace }}/_build
+44
View File
@@ -0,0 +1,44 @@
name: PowerPC cross-compilation build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
name: '${{ matrix.target.arch }}, ${{ matrix.sys.compiler }} ${{ matrix.sys.version }}'
strategy:
matrix:
target:
- { platform: 'ppc64le', dir: 'powerpc64le-linux-gnu', flags: '-maltivec -mvsx -mcpu=power10', full: 'OFF' }
- { platform: 'ppc64', dir: 'powerpc64-linux-gnu', flags: '-maltivec -mvsx -mcpu=power10', full: 'OFF' }
sys:
- { compiler: 'gcc', version: '12' }
steps:
- name: Setup compiler
if: ${{ matrix.sys.compiler == 'gcc' }}
run: |
sudo apt-get update || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install g++-${{ matrix.sys.version }}-${{ matrix.target.dir }} g++-${{ matrix.sys.version }}-multilib || exit 1
sudo update-alternatives --remove-all ${{ matrix.target.dir }}-gcc || true
sudo update-alternatives --remove-all ${{ matrix.target.dir }}-g++ || true
sudo update-alternatives --install /usr/bin/${{ matrix.target.dir }}-gcc ${{ matrix.target.dir }}-gcc /usr/bin/${{ matrix.target.dir }}-gcc-${{ matrix.sys.version }} 20
sudo update-alternatives --install /usr/bin/${{ matrix.target.dir }}-g++ ${{ matrix.target.dir }}-g++ /usr/bin/${{ matrix.target.dir }}-g++-${{ matrix.sys.version }} 20
- name: Setup QEMU
run: |
sudo apt-get --no-install-suggests --no-install-recommends install qemu-user
- name: Setup Ninja
run: |
sudo apt-get install ninja-build
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Setup
run: |
mkdir _build
cd _build && cmake .. -DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DBUILD_BENCHMARK=${{ matrix.target.full }} -DBUILD_EXAMPLES=${{ matrix.target.full }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="${{ matrix.target.flags }}" -DCMAKE_CXX_FLAGS="${{ matrix.target.flags }}" -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/.github/toolchains/${{ matrix.sys.compiler }}-${{ matrix.target.dir }}.cmake
- name: Build
run: cmake --build _build --verbose -j1
- name: Testing xsimd
run: |
qemu-${{ matrix.target.platform }} -cpu power10 -L /usr/${{ matrix.target.dir}}/ ./test/test_xsimd
working-directory: ${{ github.workspace }}/_build
+64
View File
@@ -0,0 +1,64 @@
name: RISC-V RVV cross-compilation build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ matrix.sys.compiler }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
name: 'RISC-V RVV${{ matrix.vector_bits }}'
strategy:
matrix:
sys:
- { compiler: 'gcc', gcc_runtime: '14'}
- { compiler: 'clang', version: '17', gcc_runtime: '14'}
- { compiler: 'clang', version: '18', gcc_runtime: '14'}
vector_bits:
- 128
- 256
- 512
steps:
- name: Setup GCC
run: |
sudo apt-get -y -qq update
sudo apt-get -y -qq --no-install-suggests --no-install-recommends install gcc-${{ matrix.sys.gcc_runtime }}-riscv64-linux-gnu g++-${{ matrix.sys.gcc_runtime }}-riscv64-linux-gnu
sudo update-alternatives --install /usr/bin/riscv64-linux-gnu-gcc riscv64-linux-gnu-gcc /usr/bin/riscv64-linux-gnu-gcc-${{ matrix.sys.gcc_runtime }} 20
sudo update-alternatives --install /usr/bin/riscv64-linux-gnu-g++ riscv64-linux-gnu-g++ /usr/bin/riscv64-linux-gnu-g++-${{ matrix.sys.gcc_runtime }} 20
- name: Setup LLVM
if: ${{ matrix.sys.compiler == 'clang' }}
run: |
# Install given LLVM version
curl -o llvm.sh https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh ${{ matrix.sys.version }}
sudo ln -srf $(which clang-${{ matrix.sys.version }}) /usr/bin/clang
sudo ln -srf $(which clang++-${{ matrix.sys.version }}) /usr/bin/clang++
rm llvm.sh
- name: Setup QEMU
uses: docker/setup-qemu-action@v3.0.0
with:
platforms: riscv64
- name: Setup Ninja
run: |
sudo apt-get -y -qq install ninja-build
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Setup
run: >
cmake -S . -B _build
-GNinja
-DBUILD_TESTS=ON
-DDOWNLOAD_DOCTEST=ON
-DCMAKE_BUILD_TYPE=Release
-DTARGET_ARCH=generic
-DCMAKE_C_FLAGS="-march=rv64gcv_zvl${{ matrix.vector_bits }}b_zba_zbb_zbs -mrvv-vector-bits=zvl"
-DCMAKE_CXX_FLAGS="-march=rv64gcv_zvl${{ matrix.vector_bits }}b_zba_zbb_zbs -mrvv-vector-bits=zvl"
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/.github/toolchains/${{ matrix.sys.compiler }}-riscv64-linux-gnu.cmake
- name: Build
run: cmake --build _build
- name: Testing xsimd
run: >
QEMU_CPU="rv64,zba=true,zbb=true,zbs=true,v=true,vlen=${{ matrix.vector_bits }},elen=64,vext_spec=v1.0"
QEMU_LD_PREFIX="/usr/riscv64-linux-gnu"
./test/test_xsimd
working-directory: ${{ github.workspace }}/_build
+40
View File
@@ -0,0 +1,40 @@
name: Arm-SVE cross-compilation build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
name: 'Arm SVE${{ matrix.vector_bits }}'
strategy:
matrix:
vector_bits:
- 128
- 256
- 512
steps:
- name: Setup compiler
run: |
sudo apt-get update || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install g++-10-aarch64-linux-gnu || exit 1
sudo update-alternatives --install /usr/bin/aarch64-linux-gnu-gcc aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-gnu-gcc-10 20
sudo update-alternatives --install /usr/bin/aarch64-linux-gnu-g++ aarch64-linux-gnu-g++ /usr/bin/aarch64-linux-gnu-g++-10 20
- name: Setup QEMU
run: |
sudo apt-get --no-install-suggests --no-install-recommends install qemu-user
- name: Setup Ninja
run: |
sudo apt-get install ninja-build
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Setup
run: |
mkdir _build
cd _build && cmake .. -GNinja -DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DCMAKE_BUILD_TYPE=Release -DTARGET_ARCH=generic -DCMAKE_C_FLAGS="-march=armv8-a+sve -msve-vector-bits=${{ matrix.vector_bits }}" -DCMAKE_CXX_FLAGS="-march=armv8-a+sve -msve-vector-bits=${{ matrix.vector_bits }}" -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/.github/toolchains/gcc-aarch64-linux-gnu.cmake
- name: Build
run: cmake --build _build
- name: Testing xsimd
run: |
qemu-aarch64 --cpu max,sve${{ matrix.vector_bits }}=on -L /usr/aarch64-linux-gnu/ ./test/test_xsimd
working-directory: ${{ github.workspace }}/_build
+17
View File
@@ -0,0 +1,17 @@
name: C++ -fno-except compatibility
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt install g++
- name: Setup
run: |
mkdir _build
cd _build && cmake .. -DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-fno-exceptions
- name: Build
run: cmake --build _build
+23
View File
@@ -0,0 +1,23 @@
name: C++ compatibility build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
cxx-version: [11, 14, 17, 20]
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt install g++
- name: Setup
run: |
mkdir _build
cd _build && cmake .. -DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=${{matrix.cxx-version}}
- name: Build
run: cmake --build _build
+14
View File
@@ -0,0 +1,14 @@
name: doc
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt install doxygen python3-breathe python3-sphinx-rtd-theme
- name: Render
run: make -C docs
+27
View File
@@ -0,0 +1,27 @@
name: Emscripten build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: mamba-org/setup-micromamba@v2
with:
environment-name: xsimd
create-args: >-
microsoft::playwright=1.50.0
python
init-shell: bash
- name: Build script
shell: bash -el {0}
run: |
echo "Build script for wasm"
playwright install
./test/test_wasm/test_wasm.sh
+71
View File
@@ -0,0 +1,71 @@
name: Linux emulated build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash -l {0}
jobs:
build:
runs-on: ubuntu-latest
name: '${{ matrix.sys.compiler }} ${{ matrix.sys.version }} - emulated'
strategy:
matrix:
sys:
- { compiler: 'gcc', version: '14'}
- { compiler: 'clang', version: '18'}
steps:
- name: Setup compiler
if: ${{ matrix.sys.compiler == 'gcc' }}
run: |
GCC_VERSION=${{ matrix.sys.version }}
sudo apt-get update
sudo apt-get --no-install-suggests --no-install-recommends install g++-$GCC_VERSION
CC=gcc-$GCC_VERSION
echo "CC=$CC" >> $GITHUB_ENV
CXX=g++-$GCC_VERSION
echo "CXX=$CXX" >> $GITHUB_ENV
CXXFLAGS="-Wno-noexcept-type -Wno-stringop-overflow -Wno-maybe-uninitialized"
echo "CXXFLAGS=$CXXFLAGS" >> $GITHUB_ENV
- name: Setup compiler
if: ${{ matrix.sys.compiler == 'clang' }}
run: |
LLVM_VERSION=${{ matrix.sys.version }}
sudo apt-get update || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install clang-$LLVM_VERSION || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install g++ g++-multilib || exit 1
sudo ln -s /usr/include/asm-generic /usr/include/asm
CC=clang-$LLVM_VERSION
echo "CC=$CC" >> $GITHUB_ENV
CXX=clang++-$LLVM_VERSION
echo "CXX=$CXX" >> $GITHUB_ENV
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Install mamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
- name: Configure build
env:
CC: ${{ env.CC }}
CXX: ${{ env.CXX }}
run: |
mkdir _build
cd _build
cmake .. -DBUILD_TESTS=ON \
-DBUILD_BENCHMARK=ON \
-DBUILD_EXAMPLES=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DXSIMD_ENABLE_WERROR=ON \
-DCMAKE_CXX_FLAGS="-DXSIMD_DEFAULT_ARCH=emulated\<128\> -DXSIMD_WITH_EMULATED=1 ${CXXFLAGS}" \
-G Ninja
- name: Build
run: ninja -C _build
- name: Test
run: |
cd _build/test
./test_xsimd
+128
View File
@@ -0,0 +1,128 @@
name: Linux build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash -l {0}
jobs:
build:
runs-on: ubuntu-latest
name: '${{ matrix.sys.compiler }} ${{ matrix.sys.version }} - ${{ matrix.sys.flags }}'
strategy:
matrix:
sys:
- { compiler: 'gcc', version: '12', flags: 'force_no_instr_set' }
- { compiler: 'gcc', version: '13', flags: 'enable_xtl_complex' }
- { compiler: 'gcc', version: '14', flags: 'avx' }
- { compiler: 'gcc', version: '13', flags: 'avx512' }
- { compiler: 'gcc', version: '12', flags: 'i386' }
- { compiler: 'gcc', version: '13', flags: 'avx512pf' }
- { compiler: 'gcc', version: '13', flags: 'avx512vbmi' }
- { compiler: 'gcc', version: '14', flags: 'avx512vbmi2' }
- { compiler: 'gcc', version: '13', flags: 'avx512vnni' }
- { compiler: 'clang', version: '16', flags: 'force_no_instr_set' }
- { compiler: 'clang', version: '16', flags: 'enable_xtl_complex' }
- { compiler: 'clang', version: '17', flags: 'avx' }
- { compiler: 'clang', version: '17', flags: 'sse3' }
- { compiler: 'clang', version: '18', flags: 'avx512' }
steps:
- name: Setup compiler
if: ${{ matrix.sys.compiler == 'gcc' }}
run: |
GCC_VERSION=${{ matrix.sys.version }}
sudo apt-get update
sudo apt-get --no-install-suggests --no-install-recommends install g++-$GCC_VERSION
sudo dpkg --add-architecture i386
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get --no-install-suggests --no-install-recommends install gcc-$GCC_VERSION-multilib g++-$GCC_VERSION-multilib linux-libc-dev:i386
CC=gcc-$GCC_VERSION
echo "CC=$CC" >> $GITHUB_ENV
CXX=g++-$GCC_VERSION
echo "CXX=$CXX" >> $GITHUB_ENV
- name: Setup compiler
if: ${{ matrix.sys.compiler == 'clang' }}
run: |
LLVM_VERSION=${{ matrix.sys.version }}
sudo apt-get update || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install clang-$LLVM_VERSION || exit 1
sudo apt-get --no-install-suggests --no-install-recommends install g++ g++-multilib || exit 1
sudo ln -s /usr/include/asm-generic /usr/include/asm
CC=clang-$LLVM_VERSION
echo "CC=$CC" >> $GITHUB_ENV
CXX=clang++-$LLVM_VERSION
echo "CXX=$CXX" >> $GITHUB_ENV
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Install mamba
uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment.yml
- name: Setup SDE
if: startswith(matrix.sys.flags, 'avx512')
run: sh install_sde.sh
- name: Configure build
env:
CC: ${{ env.CC }}
CXX: ${{ env.CXX }}
run: |
if [[ '${{ matrix.sys.flags }}' == 'enable_xtl_complex' ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DENABLE_XTL_COMPLEX=ON"
fi
if [[ '${{ matrix.sys.flags }}' == 'avx' ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DTARGET_ARCH=sandybridge"
fi
if [[ '${{ matrix.sys.flags }}' == 'sse3' ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DTARGET_ARCH=nocona"
fi
if [[ '${{ matrix.sys.flags }}' == 'avx512' ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DTARGET_ARCH=skylake-avx512"
fi
if [[ '${{ matrix.sys.flags }}' == 'avx512pf' ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DTARGET_ARCH=knl"
fi
if [[ '${{ matrix.sys.flags }}' == 'avx512vbmi' ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DTARGET_ARCH=cannonlake"
fi
if [[ '${{ matrix.sys.flags }}' == 'avx512vbmi2' ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DTARGET_ARCH=icelake-server"
fi
if [[ '${{ matrix.sys.flags }}' == 'avx512vnni' ]]; then
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DTARGET_ARCH=knm"
fi
if [[ '${{ matrix.sys.flags }}' == 'i386' ]]; then
CXX_FLAGS="$CXX_FLAGS -m32"
fi
if [[ '${{ matrix.sys.flags }}' == 'force_no_instr_set' ]]; then
:
else
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DXSIMD_ENABLE_WERROR=ON"
fi
# Cheap way of spotting uninitialized read
CXX_FLAGS="$CXX_FLAGS -ftrivial-auto-var-init=pattern"
mkdir _build
cd _build
cmake .. -DBUILD_TESTS=ON \
-DBUILD_BENCHMARK=ON \
-DBUILD_EXAMPLES=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
$CMAKE_EXTRA_ARGS \
-DCMAKE_CXX_FLAGS='$CXX_FLAGS' \
-G Ninja
- name: Build
run: ninja -C _build
- name: Test
run: |
cd _build
cd test
if echo '${{ matrix.sys.flags }}' | grep -q 'avx512' ; then
../../sde-external-9.48.0-2024-11-25-lin/sde64 -tgl -- ./test_xsimd
else
./test_xsimd
fi
+27
View File
@@ -0,0 +1,27 @@
name: macOS build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
strategy:
matrix:
os:
- 14
- 15
- 15-intel
runs-on: macos-${{ matrix.os }}
name: 'macos-${{ matrix.os }}'
steps:
- uses: actions/checkout@v3
- name: Setup
run: |
mkdir _build
cd _build && cmake .. -DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DBUILD_BENCHMARK=ON -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
- name: Build
run: cmake --build _build --verbose
- name: Testing sequential
run: cmake --build _build --target xbenchmark --verbose
- name: Testing xsimd
run: ${{github.workspace}}/_build/test/test_xsimd
+47
View File
@@ -0,0 +1,47 @@
name: sanitizer
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash -l {0}
jobs:
build:
runs-on: ubuntu-latest
name: 'sanitizer - ${{ matrix.flags }}'
strategy:
matrix:
flags:
- sanitize=address
- sanitize=undefined
- fast-math -fsanitize=undefined
llvm-version: [20]
env:
CC: clang-${{ matrix.llvm-version }}
CXX: clang++-${{ matrix.llvm-version }}
steps:
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Setup compiler
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh ${{ matrix.llvm-version }}
- name: Configure build
run: |
mkdir _build
cd _build
cmake .. -DBUILD_TESTS=ON \
-DBUILD_BENCHMARK=ON \
-DBUILD_EXAMPLES=ON \
-DDOWNLOAD_DOCTEST=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS='-f${{ matrix.flags }} -O0 -g -fno-inline' \
-G Ninja
- name: Build
run: ninja -C _build
- name: Test
run: |
cd _build/test
./test_xsimd
+24
View File
@@ -0,0 +1,24 @@
name: style check
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
formatting-check:
name: Format check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/clang-format-action@v4.11.0
with:
clang-format-version: '17'
exclude-regex: 'doctest.h'
inlining-check:
runs-on: ubuntu-latest
name: Check inline keyword usage
steps:
- uses: actions/checkout@v2
- run: sudo apt install clang-tools
- run: sh ./test/check_inline_specifier.sh .
+93
View File
@@ -0,0 +1,93 @@
name: Windows build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: 'MSVC ${{ matrix.os }}, ${{ matrix.target }} ${{ matrix.sys.set }}'
defaults:
run:
shell: bash {0}
strategy:
matrix:
os:
- 2022
- 2025
target:
- x86
- x64
sys:
- { set: SSE, flags: "/arch:SSE2" }
- { set: AVX, flags: "/arch:AVX" }
- { set: AVX2, flags: "/arch:AVX2" }
- { set: AVX512, flags: "/arch:AVX512" }
exclude:
# AVX on both platforms has a codegen error
# On 2019 in _mm256_rsqrt_ps, on 2022 in _mm256_blend_p*
- { sys: { set: AVX } }
# On both platforms x86 + AVX512 triggers a compiler crash
- { target: x86, sys: { set: AVX512 } }
# /arch:SSE2 is not available on x64 platforms (SSE2 is enabled by default)
- { target: x64, sys: { set: SSE} }
runs-on: windows-${{ matrix.os }}
steps:
- name: Setup compiler
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.target }}
- name: Setup Ninja
run: |
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install ninja
- name: Checkout xsimd
uses: actions/checkout@v3
- name: Setup
run: |
mkdir _build
cd _build && cmake .. -DBUILD_TESTS=ON -DDOWNLOAD_DOCTEST=ON -DBUILD_BENCHMARK=ON -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="${{ matrix.sys.flags }}" -G Ninja
- name: Build
run: |
cd _build && cmake --build .
- name: Testing xsimd
if: ${{ !startsWith(matrix.sys.set, 'AVX512') }}
run: |
cd _build && ./test/test_xsimd
build-windows-mingw:
name: 'MSYS2 ${{ matrix.msystem }}'
runs-on: windows-2022
defaults:
run:
shell: msys2 {0}
strategy:
matrix:
# Temporarily remove MINGW64 and UCRT64 builds because
# GCC 12 gives an unexpected overflow warning for __builtin_memmove
# see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106199
msystem: [ MINGW32, CLANG64 ]
#msystem: [ MINGW32, MINGW64, UCRT64, CLANG32, CLANG64 ]
fail-fast: false
steps:
- name: Use MinGW from MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.msystem }}
update: true
path-type: minimal
pacboy: >-
cc:p
cmake:p
ninja:p
- name: Checkout xsimd
uses: actions/checkout@v2
- name: Configure
run: |
mkdir _build
cd _build
cmake .. -DBUILD_TESTS=ON -DBUILD_BENCHMARK=ON -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release -DDOWNLOAD_DOCTEST=ON -G Ninja
- name: Build
run: ninja -C _build
- name: Test
run: |
cd _build && ./test/test_xsimd
+49
View File
@@ -0,0 +1,49 @@
# Generated pkg-config files
*.pc
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# Vim tmp files
*.swp
# Build folder
build/
# Documentation build artefacts
docs/CMakeCache.txt
docs/xml/
docs/build/
# VSCode / clangd IntelliSense
.vscode/
.cache/
# CLion / IDEA
.idea/
+169
View File
@@ -0,0 +1,169 @@
############################################################################
# Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and #
# Martin Renou #
# Copyright (c) QuantStack #
# Copyright (c) Serge Guelton #
# #
# Distributed under the terms of the BSD 3-Clause License. #
# #
# The full license is in the file LICENSE, distributed with this software. #
############################################################################
cmake_minimum_required(VERSION 3.10)
project(xsimd)
option(XSIMD_REFACTORING ON)
set(XSIMD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Versioning
# ==========
file(STRINGS "${XSIMD_INCLUDE_DIR}/xsimd/config/xsimd_config.hpp" xsimd_version_defines
REGEX "#define XSIMD_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${xsimd_version_defines})
if(ver MATCHES "#define XSIMD_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(XSIMD_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(${PROJECT_NAME}_VERSION
${XSIMD_VERSION_MAJOR}.${XSIMD_VERSION_MINOR}.${XSIMD_VERSION_PATCH})
message(STATUS "xsimd v${${PROJECT_NAME}_VERSION}")
# Build
# =====
set(XSIMD_HEADERS
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_constants.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_fma3_avx.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_fma3_avx2.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_fma3_sse.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_fma4.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_common.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_isa.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_neon.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_neon64.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_rvv.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_scalar.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_sse2.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_sse3.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_sse4_1.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_sse4_2.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_ssse3.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_vsx.hpp
${XSIMD_INCLUDE_DIR}/xsimd/arch/xsimd_sve.hpp
${XSIMD_INCLUDE_DIR}/xsimd/config/xsimd_arch.hpp
${XSIMD_INCLUDE_DIR}/xsimd/config/xsimd_config.hpp
${XSIMD_INCLUDE_DIR}/xsimd/config/xsimd_cpuid.hpp
${XSIMD_INCLUDE_DIR}/xsimd/memory/xsimd_aligned_allocator.hpp
${XSIMD_INCLUDE_DIR}/xsimd/memory/xsimd_alignment.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_all_registers.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_api.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_neon_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_neon64_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_avx2_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_avx512f_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_avx_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_batch.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_batch_constant.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_fma3_avx_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_fma3_avx2_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_fma3_sse_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_fma4_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_common_arch.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_vsx_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_rvv_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_sse2_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_sse3_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_sse4_1_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_sse4_2_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_ssse3_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_sve_register.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_traits.hpp
${XSIMD_INCLUDE_DIR}/xsimd/types/xsimd_utils.hpp
${XSIMD_INCLUDE_DIR}/xsimd/xsimd.hpp
)
add_library(xsimd INTERFACE)
target_include_directories(xsimd INTERFACE
$<BUILD_INTERFACE:${XSIMD_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
OPTION(ENABLE_XTL_COMPLEX "enables support for xcomplex defined in xtl" OFF)
OPTION(BUILD_TESTS "xsimd test suite" OFF)
if(ENABLE_XTL_COMPLEX)
find_package(xtl 0.8.0 REQUIRED)
target_compile_features(xsimd INTERFACE cxx_std_14)
target_compile_definitions(xsimd INTERFACE XSIMD_ENABLE_XTL_COMPLEX=1)
target_link_libraries(xsimd INTERFACE xtl)
else()
target_compile_features(xsimd INTERFACE cxx_std_11)
endif()
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
OPTION(BUILD_BENCHMARK "xsimd benchmarks" OFF)
if(BUILD_BENCHMARK)
add_subdirectory(benchmark)
endif()
OPTION(BUILD_EXAMPLES "xsimd examples" OFF)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Installation
# ============
OPTION(XSIMD_SKIP_INSTALL "Skip installation or not. By default it is OFF" OFF)
if(${XSIMD_SKIP_INSTALL})
return() # skip installation
endif ()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(JoinPaths)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS xsimd
EXPORT ${PROJECT_NAME}-targets)
# Makes the project importable from the build directory
export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
install(DIRECTORY ${XSIMD_INCLUDE_DIR}/xsimd
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
set(XSIMD_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xsimdConfig.cmake")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${XSIMD_CMAKECONFIG_INSTALL_DIR})
# xsimd is header-only and does not depend on the architecture.
# Remove CMAKE_SIZEOF_VOID_P from xtensorConfigVersion.cmake so that an xtensorConfig.cmake
# generated for a 64 bit target can be used for 32 bit targets and vice versa.
set(_XTENSOR_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${${PROJECT_NAME}_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${XSIMD_CMAKECONFIG_INSTALL_DIR})
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${XSIMD_CMAKECONFIG_INSTALL_DIR})
configure_file(${PROJECT_NAME}.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig/")
+25
View File
@@ -0,0 +1,25 @@
# Contributing to xsimd
First, thanks for being there! Welcome on board, we will try to make your
contributing journey as good an experience as it can be.
# Submitting patches
Patches should be submitted through Github PR. We did put some effort to setup a
decent Continuous Integration coverage, please try to make it green ;-)
We use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to keep
the coding style consistent, a ``.clang-format`` file is shipped within the
source, feel free to use it!
# Extending the API
We are open to extending the API, as long as it has been discussed either in an
Issue or a PR. The only constraint is to add testing for new functions, and make
sure they work on all supported architectures, not only your favorite one!
# Licensing
We use a shared copyright model that enables all contributors to maintain the
copyright on their contributions. Stated otherwise, there's no copyright
assignment.
+405
View File
@@ -0,0 +1,405 @@
.. Copyright (c) Serge Guelton and Johan Mabille
Copyright (c) QuantStack
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Changelog
=========
14.0.0
------
* **New architecture**: VMX with VSX extension
* [API] Add ``xsimd::bitwise_[l|r]shift<N>(...)`` and ``xsimd::rot[l|r]<N>(...)``
* [API] Add ``xsimd::widen`` to widen a batch to a batch twice as big
* [API] Add ``xsimd::first()`` function to extract the first lane from a batch
* [API] Reorder ``xsimd::make_batch_constant`` and ``xsimd::make_batch_bool_constant`` template
arguments
* Bump CMake requirement to 3.10
* Provide generic and specialize implementation of ``xsimd::reduce_mul``
* Have ``xsimd::max`` / ``min`` behave as ``std::max`` / ``min`` when one argument is NaN
* Optimize batch_bool load/store from/to array of booleans
* Cleaner error when trying to instantiate a batch while no arch is
supported
* Fix ``XSIMD_INLINE`` for compilers that don't have always_inline
* Rename ``xsimd::generic`` in ``xsimd::common``
* Fix ``xsimd::log10`` implementation under ``-ffast-math``, and add ``-fast-math-support`` to
generic math algorithm and tests
* Bump xtl dependency requirement
* Provide a generic implementation of ``swizzle`` with constant mask
* Enable xsimd with only emulated arch
* Rename ``avx512vnni<vbmi>`` in ``avx512vnni<vbmi2>``
* [SSE2] Fix and improve ``xsimd::swizzle`` on ``[u]int16``
* [AVX512x] Specialize ``xsimd::insert``, ``xsimd::incr_if``, ``xsimd::decr_if``
* [AVX512F,AVX512VBMI] Sepcialize ``xsimd::slide_left`` and ``xsimd::slide_right``
* [AVX512F] Fix ``batch_bool`` xor
* [WASM] Fix neq for ``batch_bool``
* [AVX/AVX2/AVX512/ARM32] Improve implementation of ``xsimd::swizzle``
* [AVX512VBMI2] Speciliaze ``xsimd::compress`` and ``xsimd::expand``
* [SSE/AVX/AVX512] Improve ``xsimd::reduce_add``
* [SSSE3/AVX2] Fix ``xsimd::rotate_left`` implementation for ``[u]int16`` and optimize
the ``[u]int8`` implementation
* [AVX2] Fix implementation of ``xsimd::rotate_left``
* [AVX512] Disable faulty implementation of ``xsimd::rotate_left``
* [ARM64] Improve implementation of comparison operator for 64 bit integers
* [AVX512BW] Optimize ``xsimd::shift_left`` and ``xsimd::shift_right``
* [AVX512F] Fix ``batch_const`` with 16b and 8b integers
13.2.0
------
* Added broadcast overload for bool
* Fixed kernel::store for booleans
* Explicitly verify dependency between architectures (like sse2 implies sse2)
* Use default arch alignment as default alignment for xsimd::aligned_allocator
* sse2 version of xsimd::swizzle on [u]int16_t
* avx implementation of transpose for [u]int[8|16]
* Implement [u]int8 and [u]int16 matrix transpose for 128 bit registers
* Fix minor warning
* Fix fma4 support
13.1.0
------
* Fix rotate_left and rotate_right behavior (it was swapped!)
* Fix compress implementation on RISC-V
* Improve RISC-V CI
* Fix clang-17 compilation on RISC-V
* Validate cmake integration
* Provide xsimd::transpose on 64 and 32 bits on most platforms
* Improve documentation
* Provide xsimd::batch_bool::count
* Fix interaction between xsimd::make_sized_batch_t and
xsimd::batch<std::complex, ...>
* Fix vbmi, sve and rvv detection through xsimd::available_architectures
* Fix compilation on MS targets where ``small`` can be defined.
* Change default install directory for installed headers.
* Support mixed-complex implementations of xsimd::pow()
* Improve xsimd::pow implementation for complex numbers
* Fix uninitialized read in lgamma implementation
13.0.0
------
* Most xsimd functions are flagged as always_inline
* Fix some xsimd scalar version (abs, bitofsign, signbit, bitwise_cast, exp10)
* Move from batch_constant<batch<T, A>, Csts...> to batch_constant<T, A, Csts...>
* Move from batch_bool_constant<batch<T, A>, Csts...> to batch_bool_constant<T, A, Csts...>
* Provide an as_batch() method (resp. as_batch_bool) method for batch_constant (resp. batch_bool_constant)
* New architecture emulated<N> for batches of N bits emulated using scalar operations.
* Remove the version method from all architectures
* Support xsimd::avg and xsimd::avgr vector operation
* Model i8mm arm extension
* Fix dispatching mechanism
12.1.1
------
* Update readme with a section on adoption, and a section on the history of the project
* Fix/avx512vnni implementation
* Fix regression on XSIMD_NO_SUPPORTED_ARCHITECTURE
12.1.0
------
* Fix various problems with architecture version handling
* Specialize xsimd::compress for riscv
* Provide stubs for various avx512xx architectures
12.0.0
------
* Fix sincos implementation to cope with Emscripten
* Upgraded minimal version of cmake to remove deprecation warning
* Fixed constants::signmask for GCC when using ffast-math
* Add RISC-V Vector support
* Generic, simple implementation fox xsimd::compress
* Disable batch of bools, and suggest using batch_bool instead
* Add an option to skip installation
11.2.0
------
* Provide shuffle operations of floating point batches
* Provide a generic implementation of xsimd::swizzle with dynamic indices
* Implement rotl, rotr, rotate_left and rotate_right
* Let CMake figure out pkgconfig directories
* Add missing boolean operators in xsimd_api.hpp
* Initial Implementation for the new WASM based instruction set
* Provide a generic version for float to uint32_t conversion
11.1.0
------
* Introduce XSIMD_DEFAULT_ARCH to force default architecture (if any)
* Remove C++ requirement on xsimd::exp10 scalar implementation
* Improve and test documentation
11.0.0
------
* Provide a generic reducer
* Fix ``find_package(xsimd)`` for xtl enabled xsimd, reloaded
* Cleanup benchmark code
* Provide avx512f implementation of FMA and variant
* Hexadecimal floating points are not a C++11 feature
* back to slow implementation of exp10 on Windows
* Changed bitwise_cast API
* Provide generic signed /unsigned type conversion
* Fixed sde location
* Feature/incr decr
* Cleanup documentation
10.0.0
------
* Fix potential ABI issue in SVE support
* Disable fast exp10 on OSX
* Assert on unaligned memory when calling aligned load/store
* Fix warning about uninitialized storage
* Always forward arch parameter
* Do not specialize the behavior of ``simd_return_type`` for char
* Support broadcasting of complex batches
* Make xsimd compatible with -fno-exceptions
* Provide and test comparison operators overloads that accept scalars
9.0.1
-----
* Fix potential ABI issue in SVE support, making ``xsimd::sve`` a type alias to
size-dependent type.
9.0.0
-----
* Support fixed size SVE
* Fix a bug in SSSE3 ``xsimd::swizzle`` implementation for ``int8`` and ``int16``
* Rename ``xsimd::hadd`` into ``xsimd::reduce_add``, provide ``xsimd::reduce_min`` and ``xsimd::reduce_max``
* Properly report unsupported double for neon on arm32
* Fill holes in xsimd scalar api
* Fix ``find_package(xsimd)`` for xtl enabled xsimd
* Replace ``xsimd::bool_cast`` by ``xsimd::batch_bool_cast``
* Native ``xsimd::hadd`` for float on arm64
* Properly static_assert when trying to instantiate an ``xsimd::batch`` of xtl complex
* Introduce ``xsimd::batch_bool::mask()`` and ``batch_bool::from_mask(...)``
* Flag some function with ``[[nodiscard]]``
* Accept both relative and absolute libdir and include dir in xsimd.pc
* Implement ``xsimd::nearbyint_as_int`` for NEON
* Add ``xsimd::polar``
* Speedup double -> F32/I32 gathers
* Add ``xsimd::slide_left`` and ``xsimd::slide_right``
* Support integral ``xsimd::swizzles`` on AVX
8.1.0
-----
* Add ``xsimd::gather`` and ``xsimd::scatter``
* Add ``xsimd::nearbyint_as_int``
* Add ``xsimd::none``
* Add ``xsimd::reciprocal``
* Remove batch constructor from memory adress, use ``xsimd::batch<...>::load_(un)aligned`` instead
* Leave to msvc users the opportunity to manually disable FMA3 on AVX
* Provide ``xsimd::insert`` to modify a single value from a vector
* Make ``xsimd::pow`` implementation resilient to ``FE_INVALID``
* Reciprocal square root support through ``xsimd::rsqrt``
* NEON: Improve ``xsimd::any`` and ``xsimd::all``
* Provide type utility to explicitly require a batch of given size and type
* Implement ``xsimd::swizzle`` on x86, neon and neon64
* Avx support for ``xsimd::zip_lo`` and ``xsimd::zip_hi``
* Only use ``_mm256_unpacklo_epi<N>`` on AVX2
* Provide neon/neon64 conversion function from ``uint(32|64)_t`` to ``(float|double)``
* Provide SSE/AVX/AVX2 conversion function from ``uint32_t`` to ``float``
* Provide AVX2 conversion function from ``(u)int64_t`` to ``double``
* Provide better SSE conversion function from ``uint64_t`` to ``double``
* Provide better SSE conversion function to ``double``
* Support logical xor for ``xsimd::batch_bool``
* Clarify fma support:
- FMA3 + SSE -> ``xsimd::fma3<sse4_2>``
- FMA3 + AVX -> ``xsimd::fma3<avx>``
- FMA3 + AVX2 -> ``xsimd::fma3<avx2>``
- FMA4 -> ``xsimd::fma4``
* Allow ``xsimd::transform`` to work with complex types
* Add missing scalar version of ``xsimd::norm`` and ``xsimd::conj``
8.0.5
-----
* Fix neon ``xsimd::hadd`` implementation
* Detect unsupported architectures and set ``XSIMD_NO_SUPPORTED_ARCHITECTURE``
if needs be
8.0.4
-----
* Provide some conversion operators for ``float`` -> ``uint32``
* Improve code generated for AVX2 signed integer comparisons
* Enable detection of avx512cd and avx512dq, and fix avx512bw detection
* Enable detection of AVX2+FMA
* Pick the best compatible architecture in ``xsimd::dispatch``
* Enables support for FMA when AVX2 is detected on Windows
* Add missing includes / forward declaration
* Mark all functions inline and noexcept
* Assert when using incomplete ``std::initializer_list``
8.0.3
-----
* Improve CI & testing, no functional change
8.0.2
-----
* Do not use ``_mm256_srai_epi32`` under AVX, it's an AVX2 instruction
8.0.1
-----
* Fix invalid constexpr ``std::make_tuple`` usage in neon64
+29
View File
@@ -0,0 +1,29 @@
Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou
Copyright (c) 2016, QuantStack
Copyright (c) 2018, Serge Guelton
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.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
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.
+238
View File
@@ -0,0 +1,238 @@
# ![xsimd](docs/source/xsimd.svg)
[![GHA android](https://github.com/xtensor-stack/xsimd/actions/workflows/android.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/android.yml)
[![GHA cross-rvv](https://github.com/xtensor-stack/xsimd/actions/workflows/cross-rvv.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/cross-rvv.yml)
[![GHA cross-sve](https://github.com/xtensor-stack/xsimd/actions/workflows/cross-sve.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/cross-sve.yml)
[![GHA cross](https://github.com/xtensor-stack/xsimd/actions/workflows/cross.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/cross.yml)
[![GHA cxx-no-exceptions](https://github.com/xtensor-stack/xsimd/actions/workflows/cxx-no-exceptions.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/cxx-no-exceptions.yml)
[![GHA cxx-versions](https://github.com/xtensor-stack/xsimd/actions/workflows/cxx-versions.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/cxx-versions.yml)
[![GHA emscripten](https://github.com/xtensor-stack/xsimd/actions/workflows/emscripten.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/emscripten.yml)
[![GHA linux](https://github.com/xtensor-stack/xsimd/actions/workflows/linux.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/linux.yml)
[![GHA macos](https://github.com/xtensor-stack/xsimd/actions/workflows/macos.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/macos.yml)
[![GHA windows](https://github.com/xtensor-stack/xsimd/actions/workflows/windows.yml/badge.svg)](https://github.com/xtensor-stack/xsimd/actions/workflows/windows.yml)
[![Documentation Status](http://readthedocs.org/projects/xsimd/badge/?version=latest)](https://xsimd.readthedocs.io/en/latest/?badge=latest)
[![Zulip](https://img.shields.io/badge/social_chat-zulip-blue.svg)](https://xtensor.zulipchat.com/#narrow/channel/539553-Ask-anything)
C++ wrappers for SIMD intrinsics
## Introduction
SIMD (Single Instruction, Multiple Data) is a feature of microprocessors that has been available for many years. SIMD instructions perform a single operation
on a batch of values at once, and thus provide a way to significantly accelerate code execution. However, these instructions differ between microprocessor
vendors and compilers.
`xsimd` provides a unified means for using these features for library authors. Namely, it enables manipulation of batches of numbers with the same arithmetic operators as for single values. It also provides accelerated implementation of common mathematical functions operating on batches.
## Adoption
Beyond Xtensor, Xsimd has been adopted by major open-source projects, such as Mozilla Firefox, Apache Arrow, Pythran, and Krita.
## History
The XSimd project started with a series of blog articles by Johan Mabille on how to implement wrappers for SIMD intrinsicts.
The archives of the blog can be found here: [The C++ Scientist](http://johanmabille.github.io/blog/archives/). The design described in
the articles remained close to the actual architecture of XSimd up until Version 8.0.
The mathematical functions are a lightweight implementation of the algorithms originally implemented in the now deprecated [boost.SIMD](https://github.com/NumScale/boost.simd) project.
## Requirements
`xsimd` requires a C++11 compliant compiler. The following C++ compilers are supported:
Compiler | Version
------------------------|-------------------------------
Microsoft Visual Studio | MSVC 2015 update 2 and above
g++ | 4.9 and above
clang | 4.0 and above
The following SIMD instruction set extensions are supported:
Architecture | Instruction set extensions
-------------|-----------------------------------------------------
x86 | SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, FMA3+SSE, FMA3+AVX, FMA3+AVX2
x86 | AVX512BW, AVX512CD, AVX512DQ, AVX512F (gcc7 and higher)
x86 AMD | FMA4
ARM | NEON, NEON64, SVE128/256/512 (fixed vector size)
WebAssembly | WASM
powerpc64 | VSX
RISC-V | RISC-V128/256/512 (fixed vector size)
## Installation
### Install from conda-forge
A package for xsimd is available on the mamba (or conda) package manager.
```bash
mamba install -c conda-forge xsimd
```
### Install with Spack
A package for xsimd is available on the Spack package manager.
```bash
spack install xsimd
spack load xsimd
```
### Install from sources
You can directly install it from the sources with cmake:
```bash
cmake -D CMAKE_INSTALL_PREFIX=your_install_prefix .
make install
```
## Documentation
To get started with using `xsimd`, check out the full documentation
http://xsimd.readthedocs.io/
## Dependencies
`xsimd` has an optional dependency on the [xtl](https://github.com/xtensor-stack/xtl) library:
| `xsimd` | `xtl` (optional) |
|---------|------------------|
| master | ^0.7.0 |
| 12.x | ^0.7.0 |
| 11.x | ^0.7.0 |
| 10.x | ^0.7.0 |
| 9.x | ^0.7.0 |
| 8.x | ^0.7.0 |
The dependency on `xtl` is required if you want to support vectorization for `xtl::xcomplex`. In this case, you must build your project with C++14 support enabled.
## Usage
The version 8 of the library is a complete rewrite and there are some slight differences with 7.x versions.
A migration guide will be available soon. In the meanwhile, the following examples show how to use both versions
7 and 8 of the library?
### Explicit use of an instruction set extension
Here is an example that computes the mean of two sets of 4 double floating point values, assuming AVX extension is supported:
```cpp
#include <iostream>
#include "xsimd/xsimd.hpp"
namespace xs = xsimd;
int main(int argc, char* argv[])
{
xs::batch<double, xs::avx2> a = {1.5, 2.5, 3.5, 4.5};
xs::batch<double, xs::avx2> b = {2.5, 3.5, 4.5, 5.5};
auto mean = (a + b) / 2;
std::cout << mean << std::endl;
return 0;
}
```
Do not forget to enable AVX extension when building the example. With gcc or clang, this is done with the `-mavx` flag,
on MSVC you have to pass the `/arch:AVX` option.
This example outputs:
```cpp
(2.0, 3.0, 4.0, 5.0)
```
### Auto detection of the instruction set extension to be used
The same computation operating on vectors and using the most performant instruction set available at compile time, based on the provided compiler flags (e.g. ``-mavx2`` for GCC and Clang to target AVX2):
```cpp
#include <cstddef>
#include <vector>
#include "xsimd/xsimd.hpp"
namespace xs = xsimd;
using vector_type = std::vector<double, xsimd::aligned_allocator<double>>;
void mean(const vector_type& a, const vector_type& b, vector_type& res)
{
std::size_t size = a.size();
constexpr std::size_t simd_size = xsimd::simd_type<double>::size;
std::size_t vec_size = size - size % simd_size;
for(std::size_t i = 0; i < vec_size; i += simd_size)
{
auto ba = xs::load_aligned(&a[i]);
auto bb = xs::load_aligned(&b[i]);
auto bres = (ba + bb) / 2.;
bres.store_aligned(&res[i]);
}
for(std::size_t i = vec_size; i < size; ++i)
{
res[i] = (a[i] + b[i]) / 2.;
}
}
```
## Building and Running the Tests
Building the tests requires [cmake](https://cmake.org).
`cmake` is available as a package for most linux distributions. Besides, they can also be installed with the `conda` package manager (even on windows):
```bash
conda install -c conda-forge cmake
```
Once `cmake` is installed, you can build and run the tests:
```bash
mkdir build
cd build
cmake ../ -DBUILD_TESTS=ON
make xtest
```
In the context of continuous integration with Travis CI, tests are run in a `conda` environment, which can be activated with
```bash
cd test
conda env create -f ./test-environment.yml
source activate test-xsimd
cd ..
cmake . -DBUILD_TESTS=ON
make xtest
```
## Building the HTML Documentation
xsimd's documentation is built with three tools
- [doxygen](http://www.doxygen.org)
- [sphinx](http://www.sphinx-doc.org)
- [breathe](https://breathe.readthedocs.io)
While doxygen must be installed separately, you can install breathe by typing
```bash
pip install breathe
```
Breathe can also be installed with `conda`
```bash
conda install -c conda-forge breathe
```
Finally, build the documentation with
```bash
make html
```
from the `docs` subdirectory.
## License
We use a shared copyright model that enables all contributors to maintain the
copyright on their contributions.
This software is licensed under the BSD-3-Clause license. See the [LICENSE](LICENSE) file for details.
+81
View File
@@ -0,0 +1,81 @@
############################################################################
# Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and #
# Martin Renou #
# Copyright (c) QuantStack #
# Copyright (c) Serge Guelton #
# #
# Distributed under the terms of the BSD 3-Clause License. #
# #
# The full license is in the file LICENSE, distributed with this software. #
############################################################################
cmake_minimum_required(VERSION 3.10)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
project(xsimd-benchmark)
find_package(xsimd REQUIRED CONFIG)
set(XSIMD_INCLUDE_DIR ${xsimd_INCLUDE_DIRS})
endif ()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting tests build type to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
else()
message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}")
endif()
include(CheckCXXCompilerFlag)
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
if(NOT CMAKE_CXX_FLAGS MATCHES "-march" AND NOT CMAKE_CXX_FLAGS MATCHES "-arch" AND NOT CMAKE_OSX_ARCHITECTURES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
if(NOT MSVC)
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG)
if (ENABLE_XTL_COMPLEX)
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
if (NOT HAS_CPP14_FLAG)
message(FATAL_ERROR "Unsupported compiler -- xsimd requires C++14 support when xtl complex support is enabled")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG)
if (NOT HAS_CPP11_FLAG)
message(FATAL_ERROR "Unsupported compiler -- xsimd requires C++11 support!")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()
endif()
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
endforeach()
endif()
include_directories(${XSIMD_INCLUDE_DIR})
set(XSIMD_BENCHMARK
main.cpp
xsimd_benchmark.hpp
)
set(XSIMD_BENCHMARK_TARGET benchmark_xsimd)
add_executable(${XSIMD_BENCHMARK_TARGET} ${XSIMD_BENCHMARK} ${XSIMD_HEADERS})
if(ENABLE_XTL_COMPLEX)
target_link_libraries(benchmark_xsimd PRIVATE xtl)
endif()
add_custom_target(xbenchmark COMMAND benchmark_xsimd DEPENDS ${XSIMD_BENCHMARK_TARGET})
+159
View File
@@ -0,0 +1,159 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#include "xsimd_benchmark.hpp"
#include <map>
void benchmark_operation()
{
// std::size_t size = 9984;
std::size_t size = 20000;
xsimd::run_benchmark_2op(xsimd::add_fn(), std::cout, size, 1000);
xsimd::run_benchmark_2op(xsimd::sub_fn(), std::cout, size, 1000);
xsimd::run_benchmark_2op(xsimd::mul_fn(), std::cout, size, 1000);
xsimd::run_benchmark_2op(xsimd::div_fn(), std::cout, size, 1000);
}
void benchmark_exp_log()
{
std::size_t size = 20000;
xsimd::run_benchmark_1op(xsimd::exp_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::exp2_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op(xsimd::expm1_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::log_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::log2_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op(xsimd::log10_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::log1p_fn(), std::cout, size, 1000);
}
void benchmark_trigo()
{
std::size_t size = 20000;
xsimd::run_benchmark_1op(xsimd::sin_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::cos_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::tan_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::asin_fn(), std::cout, size, 1000, xsimd::init_method::arctrigo);
xsimd::run_benchmark_1op(xsimd::acos_fn(), std::cout, size, 1000, xsimd::init_method::arctrigo);
xsimd::run_benchmark_1op(xsimd::atan_fn(), std::cout, size, 1000, xsimd::init_method::arctrigo);
}
void benchmark_hyperbolic()
{
std::size_t size = 20000;
xsimd::run_benchmark_1op(xsimd::sinh_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::cosh_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::tanh_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::asinh_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op(xsimd::acosh_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op(xsimd::atanh_fn(), std::cout, size, 100);
}
void benchmark_power()
{
std::size_t size = 20000;
xsimd::run_benchmark_2op(xsimd::pow_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::sqrt_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::cbrt_fn(), std::cout, size, 100);
xsimd::run_benchmark_2op(xsimd::hypot_fn(), std::cout, size, 1000);
}
void benchmark_rounding()
{
std::size_t size = 20000;
xsimd::run_benchmark_1op(xsimd::ceil_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::floor_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::trunc_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::round_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op(xsimd::nearbyint_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op(xsimd::rint_fn(), std::cout, size, 100);
}
#ifdef XSIMD_POLY_BENCHMARKS
void benchmark_poly_evaluation()
{
std::size_t size = 20000;
xsimd::run_benchmark_1op(xsimd::horner_5_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::estrin_5_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::horner_10_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::estrin_10_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::horner_12_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::estrin_12_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::horner_14_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::estrin_14_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::horner_16_fn(), std::cout, size, 1000);
xsimd::run_benchmark_1op(xsimd::estrin_16_fn(), std::cout, size, 1000);
}
#endif
void benchmark_basic_math()
{
std::size_t size = 20000;
xsimd::run_benchmark_2op(xsimd::fmod_fn(), std::cout, size, 1000);
xsimd::run_benchmark_2op(xsimd::remainder_fn(), std::cout, size, 1000);
xsimd::run_benchmark_2op(xsimd::fdim_fn(), std::cout, size, 1000);
xsimd::run_benchmark_3op(xsimd::clip_fn(), std::cout, size, 1000);
#if 0
xsimd::run_benchmark_1op_pred(xsimd::isfinite_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op_pred(xsimd::isinf_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op_pred(xsimd::is_flint_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op_pred(xsimd::is_odd_fn(), std::cout, size, 100);
xsimd::run_benchmark_1op_pred(xsimd::is_even_fn(), std::cout, size, 100);
#endif
}
int main(int argc, char* argv[])
{
const std::map<std::string, std::pair<std::string, void (*)()>> fn_map = {
{ "op", { "arithmetic", benchmark_operation } },
{ "exp", { "exponential and logarithm", benchmark_exp_log } },
{ "trigo", { "trigonometric", benchmark_trigo } },
{ "hyperbolic", { "hyperbolic", benchmark_hyperbolic } },
{ "power", { "power", benchmark_power } },
{ "basic_math", { "basic math", benchmark_basic_math } },
{ "rounding", { "rounding", benchmark_rounding } },
#ifdef XSIMD_POLY_BENCHMARKS
{ "utils", { "polynomial evaluation", benchmark_poly_evaluation } },
#endif
};
if (argc > 1)
{
if (std::string(argv[1]) == "--help" || std::string(argv[1]) == "-h")
{
std::cout << "Available options:" << std::endl;
for (auto const& kv : fn_map)
{
std::cout << kv.first << ": run benchmark on " << kv.second.first << " functions" << std::endl;
}
}
else
{
std::cout << "############################" << std::endl
<< "# " << xsimd::default_arch::name() << std::endl
<< "############################" << std::endl;
for (int i = 1; i < argc; ++i)
{
fn_map.at(argv[i]).second();
}
}
}
else
{
std::cout << "############################" << std::endl
<< "# " << xsimd::default_arch::name() << std::endl
<< "############################" << std::endl;
for (auto const& kv : fn_map)
{
kv.second.second();
}
}
return 0;
}
+565
View File
@@ -0,0 +1,565 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_BENCHMARK_HPP
#define XSIMD_BENCHMARK_HPP
#include "xsimd/arch/xsimd_scalar.hpp"
#include "xsimd/xsimd.hpp"
#include <chrono>
#include <iostream>
#include <string>
#include <vector>
namespace xsimd
{
using duration_type = std::chrono::duration<double, std::milli>;
template <class T>
using bench_vector = std::vector<T, xsimd::aligned_allocator<T>>;
template <class T>
void init_benchmark(bench_vector<T>& lhs, bench_vector<T>& rhs, bench_vector<T>& res, size_t size)
{
lhs.resize(size);
rhs.resize(size);
res.resize(size);
for (size_t i = 0; i < size; ++i)
{
lhs[i] = T(0.5) + std::sqrt(T(i)) * T(9.) / T(size);
rhs[i] = T(10.2) / T(i + 2) + T(0.25);
}
}
template <class T>
void init_benchmark(bench_vector<T>& op0, bench_vector<T>& op1, bench_vector<T>& op2, bench_vector<T>& res, size_t size)
{
op0.resize(size);
op1.resize(size);
op2.resize(size);
res.resize(size);
for (size_t i = 0; i < size; ++i)
{
op0[i] = T(0.5) + std::sqrt(T(i)) * T(9.) / T(size);
op1[i] = T(10.2) / T(i + 3) + T(0.25);
op2[i] = T(20.1) / T(i + 2) + T(0.65);
}
}
template <class T>
void init_benchmark_arctrigo(bench_vector<T>& lhs, bench_vector<T>& rhs, bench_vector<T>& res, size_t size)
{
lhs.resize(size);
rhs.resize(size);
res.resize(size);
for (size_t i = 0; i < size; ++i)
{
lhs[i] = T(-1.) + T(2.) * T(i) / T(size);
rhs[i] = T(i) / T(i + 2) + T(0.25);
}
}
enum class init_method
{
classic,
arctrigo
};
template <class F, class V>
duration_type benchmark_scalar(F f, V& lhs, V& res, std::size_t number)
{
size_t s = lhs.size();
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (size_t i = 0; i < s; ++i)
{
res[i] = f(lhs[i]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class F, class V>
duration_type benchmark_scalar(F f, V& lhs, V& rhs, V& res, std::size_t number)
{
size_t s = lhs.size();
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (size_t i = 0; i < s; ++i)
{
res[i] = f(lhs[i], rhs[i]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class F, class V>
duration_type benchmark_scalar(F f, V& op0, V& op1, V& op2, V& res, std::size_t number)
{
size_t s = op0.size();
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (size_t i = 0; i < s; ++i)
{
res[i] = f(op0[i], op1[i], op2[i]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class B, class F, class V>
duration_type benchmark_simd(F f, V& lhs, V& res, std::size_t number)
{
std::size_t s = lhs.size();
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (std::size_t i = 0; i <= (s - B::size); i += B::size)
{
B blhs = B::load_aligned(&lhs[i]);
B bres = f(blhs);
bres.store_aligned(&res[i]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class B, class F, class V>
duration_type benchmark_simd_unrolled(F f, V& lhs, V& res, std::size_t number)
{
std::size_t s = lhs.size();
std::size_t inc = 4 * B::size;
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (std::size_t i = 0; i <= (s - inc); i += inc)
{
size_t j = i + B::size;
size_t k = j + B::size;
size_t l = k + B::size;
B blhs = B::load_aligned(&lhs[i]),
blhs2 = B::load_aligned(&lhs[j]),
blhs3 = B::load_aligned(&lhs[k]),
blhs4 = B::load_aligned(&lhs[l]);
B bres = f(blhs);
B bres2 = f(blhs2);
B bres3 = f(blhs3);
B bres4 = f(blhs4);
bres.store_aligned(&res[i]);
bres2.store_aligned(&res[j]);
bres3.store_aligned(&res[k]);
bres4.store_aligned(&res[l]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class B, class F, class V>
duration_type benchmark_simd(F f, V& lhs, V& rhs, V& res, std::size_t number)
{
std::size_t s = lhs.size();
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (std::size_t i = 0; i <= (s - B::size); i += B::size)
{
B blhs = B::load_aligned(&lhs[i]),
brhs = B::load_aligned(&rhs[i]);
B bres = f(blhs, brhs);
bres.store_aligned(&res[i]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class B, class F, class V>
duration_type benchmark_simd_unrolled(F f, V& lhs, V& rhs, V& res, std::size_t number)
{
std::size_t s = lhs.size();
std::size_t inc = 4 * B::size;
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (std::size_t i = 0; i <= (s - inc); i += inc)
{
size_t j = i + B::size;
size_t k = j + B::size;
size_t l = k + B::size;
B blhs = B::load_aligned(&lhs[i]),
brhs = B::load_aligned(&rhs[i]),
blhs2 = B::load_aligned(&lhs[j]),
brhs2 = B::load_aligned(&rhs[j]);
B blhs3 = B::load_aligned(&lhs[k]),
brhs3 = B::load_aligned(&rhs[k]),
blhs4 = B::load_aligned(&lhs[l]),
brhs4 = B::load_aligned(&rhs[l]);
B bres = f(blhs, brhs);
B bres2 = f(blhs2, brhs2);
B bres3 = f(blhs3, brhs3);
B bres4 = f(blhs4, brhs4);
bres.store_aligned(&res[i]);
bres2.store_aligned(&res[j]);
bres3.store_aligned(&res[k]);
bres4.store_aligned(&res[l]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class B, class F, class V>
duration_type benchmark_simd(F f, V& op0, V& op1, V& op2, V& res, std::size_t number)
{
std::size_t s = op0.size();
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (std::size_t i = 0; i <= (s - B::size); i += B::size)
{
B bop0 = B::load_aligned(&op0[i]),
bop1 = B::load_aligned(&op1[i]),
bop2 = B::load_aligned(&op2[i]);
B bres = f(bop0, bop1, bop2);
bres.store_aligned(&res[i]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class B, class F, class V>
duration_type benchmark_simd_unrolled(F f, V& op0, V& op1, V& op2, V& res, std::size_t number)
{
std::size_t s = op0.size();
std::size_t inc = 4 * B::size;
duration_type t_res = duration_type::max();
for (std::size_t count = 0; count < number; ++count)
{
auto start = std::chrono::steady_clock::now();
for (std::size_t i = 0; i <= (s - inc); i += inc)
{
size_t j = i + B::size;
size_t k = j + B::size;
size_t l = k + B::size;
B bop0_i = B::load_aligned(&op0[i]),
bop1_i = B::load_aligned(&op1[i]),
bop2_i = B::load_aligned(&op2[i]);
B bop0_j = B::load_aligned(&op0[j]),
bop1_j = B::load_aligned(&op1[j]),
bop2_j = B::load_aligned(&op2[j]);
B bop0_k = B::load_aligned(&op0[k]),
bop1_k = B::load_aligned(&op1[k]),
bop2_k = B::load_aligned(&op2[k]);
B bop0_l = B::load_aligned(&op0[l]),
bop1_l = B::load_aligned(&op1[l]),
bop2_l = B::load_aligned(&op2[l]);
B bres_i = f(bop0_i, bop1_i, bop2_i);
B bres_j = f(bop0_j, bop1_j, bop2_j);
B bres_k = f(bop0_k, bop1_k, bop2_k);
B bres_l = f(bop0_l, bop1_l, bop2_l);
bres_i.store_aligned(&res[i]);
bres_j.store_aligned(&res[j]);
bres_k.store_aligned(&res[k]);
bres_l.store_aligned(&res[l]);
}
auto end = std::chrono::steady_clock::now();
auto tmp = end - start;
t_res = tmp < t_res ? tmp : t_res;
}
return t_res;
}
template <class F, class OS>
void run_benchmark_1op(F f, OS& out, std::size_t size, std::size_t iter, init_method init = init_method::classic)
{
bench_vector<float> f_lhs, f_rhs, f_res;
bench_vector<double> d_lhs, d_rhs, d_res;
switch (init)
{
case init_method::classic:
init_benchmark(f_lhs, f_rhs, f_res, size);
init_benchmark(d_lhs, d_rhs, d_res, size);
break;
case init_method::arctrigo:
init_benchmark_arctrigo(f_lhs, f_rhs, f_res, size);
init_benchmark_arctrigo(d_lhs, d_rhs, d_res, size);
break;
default:
init_benchmark(f_lhs, f_rhs, f_res, size);
init_benchmark(d_lhs, d_rhs, d_res, size);
break;
}
#ifndef XSIMD_POLY_BENCHMARKS
duration_type t_float_scalar = benchmark_scalar(f, f_lhs, f_res, iter);
duration_type t_double_scalar = benchmark_scalar(f, d_lhs, d_res, iter);
#endif
duration_type t_float_vector = benchmark_simd<batch<float>>(f, f_lhs, f_res, iter);
duration_type t_float_vector_u = benchmark_simd_unrolled<batch<float>>(f, f_lhs, f_res, iter);
#if !XSIMD_WITH_NEON || XSIMD_WITH_NEON64
duration_type t_double_vector = benchmark_simd<batch<double>>(f, d_lhs, d_res, iter);
duration_type t_double_vector_u = benchmark_simd_unrolled<batch<double>>(f, d_lhs, d_res, iter);
#endif
out << "============================" << std::endl;
out << f.name() << std::endl;
#ifndef XSIMD_POLY_BENCHMARKS
out << "scalar float : " << t_float_scalar.count() << "ms" << std::endl;
#endif
out << "vector float : " << t_float_vector.count() << "ms" << std::endl;
out << "vector float unr : " << t_float_vector_u.count() << "ms" << std::endl;
#ifndef XSIMD_POLY_BENCHMARKS
out << "scalar double : " << t_double_scalar.count() << "ms" << std::endl;
#endif
#if !XSIMD_WITH_NEON || XSIMD_WITH_NEON64
out << "vector double : " << t_double_vector.count() << "ms" << std::endl;
out << "vector double unr : " << t_double_vector_u.count() << "ms" << std::endl;
#endif
out << "============================" << std::endl;
}
template <class F, class OS>
void run_benchmark_2op(F f, OS& out, std::size_t size, std::size_t iter)
{
bench_vector<float> f_lhs, f_rhs, f_res;
bench_vector<double> d_lhs, d_rhs, d_res;
init_benchmark(f_lhs, f_rhs, f_res, size);
init_benchmark(d_lhs, d_rhs, d_res, size);
duration_type t_float_scalar = benchmark_scalar(f, f_lhs, f_rhs, f_res, iter);
duration_type t_float_vector = benchmark_simd<batch<float>>(f, f_lhs, f_rhs, f_res, iter);
duration_type t_float_vector_u = benchmark_simd_unrolled<batch<float>>(f, f_lhs, f_rhs, f_res, iter);
duration_type t_double_scalar = benchmark_scalar(f, d_lhs, d_rhs, d_res, iter);
#if !XSIMD_WITH_NEON || XSIMD_WITH_NEON64
duration_type t_double_vector = benchmark_simd<batch<double>>(f, d_lhs, d_rhs, d_res, iter);
duration_type t_double_vector_u = benchmark_simd_unrolled<batch<double>>(f, d_lhs, d_rhs, d_res, iter);
#endif
out << "============================" << std::endl;
out << f.name() << std::endl;
out << "scalar float : " << t_float_scalar.count() << "ms" << std::endl;
out << "vector float : " << t_float_vector.count() << "ms" << std::endl;
out << "vector float unr : " << t_float_vector_u.count() << "ms" << std::endl;
out << "scalar double : " << t_double_scalar.count() << "ms" << std::endl;
#if !XSIMD_WITH_NEON || XSIMD_WITH_NEON64
out << "vector double : " << t_double_vector.count() << "ms" << std::endl;
out << "vector double unr : " << t_double_vector_u.count() << "ms" << std::endl;
#endif
out << "============================" << std::endl;
}
template <class F, class OS>
void run_benchmark_3op(F f, OS& out, std::size_t size, std::size_t iter)
{
bench_vector<float> f_op0, f_op1, f_op2, f_res;
bench_vector<double> d_op0, d_op1, d_op2, d_res;
init_benchmark(f_op0, f_op1, f_op2, f_res, size);
init_benchmark(d_op0, d_op1, d_op2, d_res, size);
duration_type t_float_scalar = benchmark_scalar(f, f_op0, f_op1, f_op2, f_res, iter);
duration_type t_float_vector = benchmark_simd<batch<float>>(f, f_op0, f_op1, f_op2, f_res, iter);
duration_type t_float_vector_u = benchmark_simd_unrolled<batch<float>>(f, f_op0, f_op1, f_op2, f_res, iter);
duration_type t_double_scalar = benchmark_scalar(f, d_op0, d_op1, d_op2, d_res, iter);
#if !XSIMD_WITH_NEON || XSIMD_WITH_NEON64
duration_type t_double_vector = benchmark_simd<batch<double>>(f, d_op0, d_op1, d_op2, d_res, iter);
duration_type t_double_vector_u = benchmark_simd_unrolled<batch<double>>(f, d_op0, d_op1, d_op2, d_res, iter);
#endif
out << "============================" << std::endl;
out << f.name() << std::endl;
out << "scalar float : " << t_float_scalar.count() << "ms" << std::endl;
out << "vector float : " << t_float_vector.count() << "ms" << std::endl;
out << "vector float unr : " << t_float_vector_u.count() << "ms" << std::endl;
out << "scalar double : " << t_double_scalar.count() << "ms" << std::endl;
#if !XSIMD_WITH_NEON || XSIMD_WITH_NEON64
out << "vector double : " << t_double_vector.count() << "ms" << std::endl;
out << "vector double unr : " << t_double_vector_u.count() << "ms" << std::endl;
#endif
out << "============================" << std::endl;
}
#define DEFINE_OP_FUNCTOR_2OP(OP, NAME) \
struct NAME##_fn \
{ \
template <class T> \
inline T operator()(const T& lhs, const T& rhs) const \
{ \
return lhs OP rhs; \
} \
inline std::string name() const \
{ \
return #NAME; \
} \
}
#define DEFINE_FUNCTOR_1OP(FN) \
struct FN##_fn \
{ \
template <class T> \
inline T operator()(const T& x) const \
{ \
using xsimd::FN; \
return FN(x); \
} \
inline std::string name() const \
{ \
return #FN; \
} \
}
#define DEFINE_FUNCTOR_1OP_TEMPLATE(NAME, FN, N, ...) \
struct NAME##_##N##_fn \
{ \
template <class T> \
inline T operator()(const T& x) const \
{ \
using xsimd::FN; \
return FN<T, __VA_ARGS__>(x); \
} \
inline std::string name() const \
{ \
return #FN " " #N; \
} \
}
#define DEFINE_FUNCTOR_2OP(FN) \
struct FN##_fn \
{ \
template <class T> \
inline T operator()(const T& lhs, const T& rhs) const \
{ \
using xsimd::FN; \
return FN(lhs, rhs); \
} \
inline std::string name() const \
{ \
return #FN; \
} \
}
#define DEFINE_FUNCTOR_3OP(FN) \
struct FN##_fn \
{ \
template <class T> \
inline T operator()(const T& op0, const T& op1, const T& op2) const \
{ \
using xsimd::FN; \
return FN(op0, op1, op2); \
} \
inline std::string name() const \
{ \
return #FN; \
} \
}
DEFINE_OP_FUNCTOR_2OP(+, add);
DEFINE_OP_FUNCTOR_2OP(-, sub);
DEFINE_OP_FUNCTOR_2OP(*, mul);
DEFINE_OP_FUNCTOR_2OP(/, div);
DEFINE_FUNCTOR_1OP(exp);
DEFINE_FUNCTOR_1OP(exp2);
DEFINE_FUNCTOR_1OP(expm1);
DEFINE_FUNCTOR_1OP(log);
DEFINE_FUNCTOR_1OP(log10);
DEFINE_FUNCTOR_1OP(log2);
DEFINE_FUNCTOR_1OP(log1p);
DEFINE_FUNCTOR_1OP(sin);
DEFINE_FUNCTOR_1OP(cos);
DEFINE_FUNCTOR_1OP(tan);
DEFINE_FUNCTOR_1OP(asin);
DEFINE_FUNCTOR_1OP(acos);
DEFINE_FUNCTOR_1OP(atan);
DEFINE_FUNCTOR_1OP(sinh);
DEFINE_FUNCTOR_1OP(cosh);
DEFINE_FUNCTOR_1OP(tanh);
DEFINE_FUNCTOR_1OP(asinh);
DEFINE_FUNCTOR_1OP(acosh);
DEFINE_FUNCTOR_1OP(atanh);
DEFINE_FUNCTOR_2OP(pow);
DEFINE_FUNCTOR_1OP(sqrt);
DEFINE_FUNCTOR_1OP(cbrt);
DEFINE_FUNCTOR_2OP(hypot);
DEFINE_FUNCTOR_1OP(ceil);
DEFINE_FUNCTOR_1OP(floor);
DEFINE_FUNCTOR_1OP(trunc);
DEFINE_FUNCTOR_1OP(round);
DEFINE_FUNCTOR_1OP(nearbyint);
DEFINE_FUNCTOR_1OP(rint);
DEFINE_FUNCTOR_2OP(fmod);
DEFINE_FUNCTOR_2OP(remainder);
DEFINE_FUNCTOR_2OP(fdim);
DEFINE_FUNCTOR_3OP(clip);
#if 0
DEFINE_FUNCTOR_1OP(isfinite);
DEFINE_FUNCTOR_1OP(isinf);
DEFINE_FUNCTOR_1OP(is_flint);
DEFINE_FUNCTOR_1OP(is_odd);
DEFINE_FUNCTOR_1OP(is_even);
#endif
DEFINE_FUNCTOR_1OP_TEMPLATE(horner, kernel::horner, 5, 1, 2, 3, 4, 5);
DEFINE_FUNCTOR_1OP_TEMPLATE(estrin, kernel::estrin, 5, 1, 2, 3, 4, 5);
DEFINE_FUNCTOR_1OP_TEMPLATE(horner, kernel::horner, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
DEFINE_FUNCTOR_1OP_TEMPLATE(estrin, kernel::estrin, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
DEFINE_FUNCTOR_1OP_TEMPLATE(horner, kernel::horner, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
DEFINE_FUNCTOR_1OP_TEMPLATE(estrin, kernel::estrin, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
DEFINE_FUNCTOR_1OP_TEMPLATE(horner, kernel::horner, 14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
DEFINE_FUNCTOR_1OP_TEMPLATE(estrin, kernel::estrin, 14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
DEFINE_FUNCTOR_1OP_TEMPLATE(horner, kernel::horner, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
DEFINE_FUNCTOR_1OP_TEMPLATE(estrin, kernel::estrin, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
}
#endif
+26
View File
@@ -0,0 +1,26 @@
# This module provides function for joining paths
# known from from most languages
#
# Original license:
# SPDX-License-Identifier: (MIT OR CC0-1.0)
# Explicit permission given to distribute this module under
# the terms of the project as described in /LICENSE.rst.
# Copyright 2020 Jan Tojnar
# https://github.com/jtojnar/cmake-snips
#
# Modelled after Python’s os.path.join
# https://docs.python.org/3.7/library/os.path.html#os.path.join
# Windows not supported
function(join_paths joined_path first_path_segment)
set(temp_path "${first_path_segment}")
foreach(current_segment IN LISTS ARGN)
if(NOT ("${current_segment}" STREQUAL ""))
if(IS_ABSOLUTE "${current_segment}")
set(temp_path "${current_segment}")
else()
set(temp_path "${temp_path}/${current_segment}")
endif()
endif()
endforeach()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()
+50
View File
@@ -0,0 +1,50 @@
PROJECT_NAME = "xsimd"
XML_OUTPUT = xml
INPUT = ../include/xsimd/types/xsimd_api.hpp \
../include/xsimd/types/xsimd_batch.hpp \
../include/xsimd/types/xsimd_batch_constant.hpp \
../include/xsimd/config/xsimd_arch.hpp \
../include/xsimd/config/xsimd_config.hpp \
../include/xsimd/memory/xsimd_alignment.hpp \
../include/xsimd/memory/xsimd_aligned_allocator.hpp \
../include/xsimd/types/xsimd_common_arch.hpp \
../include/xsimd/types/xsimd_traits.hpp \
../include/xsimd/types/xsimd_vsx_register.hpp \
../include/xsimd/types/xsimd_avx2_register.hpp \
../include/xsimd/types/xsimd_avx512bw_register.hpp \
../include/xsimd/types/xsimd_avx512cd_register.hpp \
../include/xsimd/types/xsimd_avx512dq_register.hpp \
../include/xsimd/types/xsimd_avx512f_register.hpp \
../include/xsimd/types/xsimd_avx_register.hpp \
../include/xsimd/types/xsimd_fma3_avx_register.hpp \
../include/xsimd/types/xsimd_fma3_avx2_register.hpp \
../include/xsimd/types/xsimd_fma3_sse_register.hpp \
../include/xsimd/types/xsimd_fma4_register.hpp \
../include/xsimd/types/xsimd_neon64_register.hpp \
../include/xsimd/types/xsimd_neon_register.hpp \
../include/xsimd/types/xsimd_rvv_register.hpp \
../include/xsimd/types/xsimd_sse2_register.hpp \
../include/xsimd/types/xsimd_sse3_register.hpp \
../include/xsimd/types/xsimd_sse4_1_register.hpp \
../include/xsimd/types/xsimd_sse4_2_register.hpp \
../include/xsimd/types/xsimd_ssse3_register.hpp \
../include/xsimd/types/xsimd_sve_register.hpp
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
GENERATE_HTML = NO
GENERATE_XML = YES
RECURSIVE = YES
QUIET = YES
JAVADOC_AUTOBRIEF = YES
WARN_IF_UNDOCUMENTED = NO
WARN_AS_ERROR = NO
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
PREDEFINED = XSIMD_NO_DISCARD= \
XSIMD_INLINE=inline \
DOXYGEN_SHOULD_SKIP_THIS=
+186
View File
@@ -0,0 +1,186 @@
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext api
default: html
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " applehelp to make an Apple Help Book"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " coverage to run coverage check of the documentation (if enabled)"
clean:
rm -rf $(BUILDDIR)/*
html:
doxygen
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
doxygen
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
doxygen
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
doxygen
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
doxygen
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
doxygen
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
epub:
doxygen
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
doxygen
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
doxygen
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
latexpdfja:
doxygen
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
doxygen
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
doxygen
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
doxygen
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
doxygen
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
doxygen
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
doxygen
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
doxygen
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
doxygen
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
coverage:
doxygen
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
@echo "Testing of coverage in the sources finished, look at the " \
"results in $(BUILDDIR)/coverage/python.txt."
xml:
doxygen
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
pseudoxml:
doxygen
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
+9
View File
@@ -0,0 +1,9 @@
name: xsimd-docs
channels:
- conda-forge
dependencies:
- breathe
- sphinx_rtd_theme
- sphinx=6.*
+264
View File
@@ -0,0 +1,264 @@
@ECHO OFF
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=build
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
set I18NSPHINXOPTS=%SPHINXOPTS% source
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^<target^>` where ^<target^> is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. singlehtml to make a single large HTML file
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. devhelp to make HTML files and a Devhelp project
echo. epub to make an epub
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. text to make text files
echo. man to make manual pages
echo. texinfo to make Texinfo files
echo. gettext to make PO message catalogs
echo. changes to make an overview over all changed/added/deprecated items
echo. xml to make Docutils-native XML files
echo. pseudoxml to make pseudoxml-XML files for display purposes
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
echo. coverage to run coverage check of the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
goto end
)
REM Check if sphinx-build is available and fallback to Python version if any
%SPHINXBUILD% 1>NUL 2>NUL
if errorlevel 9009 goto sphinx_python
goto sphinx_ok
:sphinx_python
set SPHINXBUILD=python -m sphinx.__init__
%SPHINXBUILD% 2> nul
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
:sphinx_ok
if "%1" == "html" (
doxygen
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
goto end
)
if "%1" == "singlehtml" (
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\packagename.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\packagename.ghc
goto end
)
if "%1" == "devhelp" (
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished.
goto end
)
if "%1" == "epub" (
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The epub file is in %BUILDDIR%/epub.
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
if errorlevel 1 exit /b 1
echo.
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "latexpdf" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
cd %BUILDDIR%/latex
make all-pdf
cd %~dp0
echo.
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "latexpdfja" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
cd %BUILDDIR%/latex
make all-pdf-ja
cd %~dp0
echo.
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "text" (
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The text files are in %BUILDDIR%/text.
goto end
)
if "%1" == "man" (
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The manual pages are in %BUILDDIR%/man.
goto end
)
if "%1" == "texinfo" (
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
goto end
)
if "%1" == "gettext" (
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
if errorlevel 1 exit /b 1
echo.
echo.The overview file is in %BUILDDIR%/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
if errorlevel 1 exit /b 1
echo.
echo.Link check complete; look for any errors in the above output ^
or in %BUILDDIR%/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
if errorlevel 1 exit /b 1
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in %BUILDDIR%/doctest/output.txt.
goto end
)
if "%1" == "coverage" (
%SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage
if errorlevel 1 exit /b 1
echo.
echo.Testing of coverage in the sources finished, look at the ^
results in %BUILDDIR%/coverage/python.txt.
goto end
)
if "%1" == "xml" (
%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The XML files are in %BUILDDIR%/xml.
goto end
)
if "%1" == "pseudoxml" (
%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
goto end
)
:end
+4
View File
@@ -0,0 +1,4 @@
.wy-nav-content{
max-width: 1000px;
margin: auto;
}
+21
View File
@@ -0,0 +1,21 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Alignment Manipulation
======================
Aligned Memory Allocator
------------------------
.. doxygenclass:: xsimd::aligned_allocator
:project: xsimd
:members:
Alignement Checker
------------------
.. doxygenfunction:: xsimd::is_aligned
:project: xsimd
+28
View File
@@ -0,0 +1,28 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Architecture Manipulation
=========================
xsimd provides an high level description of the instruction sets it manipulates.
The mentioned types are primarily used as template parameters for :ref:`batch
<xsimd-batch-ref>`, and when interacting with :cpp:func:`xsimd::dispatch()`.
The best available architecture is available at compile time through
``xsimd::best_arch`` which also happens to be ``xsimd::default_arch``.
.. doxygengroup:: architectures
:project: xsimd
:members:
Emulated Mode
-------------
When compiled with the macro ``XSIMD_WITH_EMULATED`` set to ``1``, xsimd also
exhibits a specific architecture ``xsimd::emulated<N>``, which consists of a
vector of ``N`` bits emulated using scalar mode.
It is mostly available for testing and debugging.
+98
View File
@@ -0,0 +1,98 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
.. _Arithmetic Operations:
Arithmetic Operations
=====================
Binary operations:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`add` | per slot addition |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`sub` | per slot subtraction |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`mul` | per slot multiply |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`div` | per slot division |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`mod` | per slot modulo |
+---------------------------------------+----------------------------------------------------+
Unary operations:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`neg` | per slot negate |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`pos` | per slot positive |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`reciprocal` | per slot reciprocal |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`decr` | per slot decrement |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`decr_if` | per slot decrement, based on a mask |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`incr` | per slot increment |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`incr_if` | per slot increment, based on a mask |
+---------------------------------------+----------------------------------------------------+
Saturated arithmetic:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`sadd` | per slot saturated addition |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`ssub` | per slot saturated subtraction |
+---------------------------------------+----------------------------------------------------+
Fused operations:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fma` | fused multiply add |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fms` | fused multiply sub |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fnma` | fused negate multiply add |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fnms` | fused negate multiply sub |
+---------------------------------------+----------------------------------------------------+
Average computation:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`avg` | per slot average |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`avgr` | per slot rounded average |
+---------------------------------------+----------------------------------------------------+
----
.. doxygengroup:: batch_arithmetic
:project: xsimd
:content-only:
+18
View File
@@ -0,0 +1,18 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. _Batch Types:
Batch Types
===========
.. toctree::
:maxdepth: 1
xsimd_batch
xsimd_batch_bool
xsimd_batch_complex
xsimd_batch_constant
+23
View File
@@ -0,0 +1,23 @@
.. Copyright (c) 2021, Serge Guelton
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Conditional Expression
======================
+------------------------------+-------------------------------------------+
| :cpp:func:`select` | conditional selection with mask |
+------------------------------+-------------------------------------------+
----
.. doxygengroup:: batch_cond
:project: xsimd
:content-only:
In the specific case when one needs to conditionnaly increment or decrement a
batch based on a mask, :cpp:func:`incr_if` and
:cpp:func:`decr_if` provide specialized version.
+57
View File
@@ -0,0 +1,57 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
Bitwise Operators
=================
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitwise_not` | per slot bitwise not |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitwise_or` | per slot bitwise or |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitwise_xor` | per slot bitwise xor |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitwise_and` | per slot bitwise and |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitwise_andnot` | per slot bitwise and not |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitwise_lshift` | per slot bitwise left shift |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitwise_rshift` | per slot bitwise right shift |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`rotr` | per slot rotate right |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`rotl` | per slot rotate left |
+---------------------------------------+----------------------------------------------------+
----
.. doxygengroup:: batch_bitwise
:project: xsimd
:content-only:
+57
View File
@@ -0,0 +1,57 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
Type Conversion
===============
Cast:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`batch_cast` | ``static_cast`` on batch types |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitwise_cast` | ``reinterpret_cast`` on batch types |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`batch_bool_cast` | ``static_cast`` on batch predicate types |
+---------------------------------------+----------------------------------------------------+
Conversion:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`to_float` | per slot conversion to floating point |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`to_int` | per slot conversion to integer |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`widen` | per slot conversion to twice as big type |
+---------------------------------------+----------------------------------------------------+
----
.. doxygengroup:: batch_conversion
:project: xsimd
:content-only:
+72
View File
@@ -0,0 +1,72 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
Comparison Operators
====================
Ordering:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`eq` | per slot equals to comparison |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`neq` | per slot different from comparison |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`gt` | per slot strictly greater than comparison |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`lt` | per slot strictly lower than comparison |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`ge` | per slot greater or equal to comparison |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`le` | per slot lower or equal to comparison |
+---------------------------------------+----------------------------------------------------+
Parity check:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`is_even` | per slot check for evenness |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`is_odd` | per slot check for oddness |
+---------------------------------------+----------------------------------------------------+
Floating point number check:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`isinf` | per slot check for infinity |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`isnan` | per slot check for NaN |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`isfinite` | per slot check for finite number |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`is_flint` | per slot check for float representing an integer |
+---------------------------------------+----------------------------------------------------+
----
.. doxygengroup:: batch_logical
:project: xsimd
:content-only:
+86
View File
@@ -0,0 +1,86 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. _Data Transfer:
Data Transfers
==============
From memory:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`load` | load values from memory (optionally masked) |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`load_aligned` | load values from aligned memory |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`load_unaligned` | load values from unaligned memory |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`load_as` | load values, forcing a type conversion |
+---------------------------------------+----------------------------------------------------+
From a scalar:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`broadcast` | broadcasting a value to all slots |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`broadcast_as` | broadcasting a value, forcing a type conversion |
+---------------------------------------+----------------------------------------------------+
To memory:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`store` | store values to memory (optionally masked) |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`store_aligned` | store values to aligned memory |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`store_unaligned` | store values to unaligned memory |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`store_as` | store values, forcing a type conversion |
+---------------------------------------+----------------------------------------------------+
In place:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`swizzle` | rearrange slots within the batch |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`slide_left` | bitwise shift the whole batch to the left |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`slide_right` | bitwise shift the whole batch to the right |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`rotate_left` | bitwise rotate the whole batch to the left |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`rotate_right` | bitwise rotate the whole batch to the right |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`insert` | modify a single batch slot |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`compress` | pack elements according to a mask |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`expand` | select contiguous elements from the batch |
+---------------------------------------+----------------------------------------------------+
Between batches:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`transpose` | tranpose a matrix as an array of batches |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`zip_lo` | interleave low halves of two batches |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`zip_hi` | interleave high halves of two batches |
+---------------------------------------+----------------------------------------------------+
----
.. doxygengroup:: batch_data_transfer
:project: xsimd
:content-only:
The following empty types are used for tag dispatching:
.. doxygenstruct:: xsimd::aligned_mode
:project: xsimd
.. doxygenstruct:: xsimd::unaligned_mode
:project: xsimd
+69
View File
@@ -0,0 +1,69 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
.. _Arch Dispatching:
Arch Dispatching
================
`xsimd` provides a generic way to dispatch a function call based on the architecture the code was compiled for and the architectures available at runtime.
The :cpp:func:`xsimd::dispatch` function takes a functor whose call operator takes an architecture parameter as first operand, followed by any number of arguments ``Args...`` and turn it into a
dispatching functor that takes ``Args...`` as arguments.
.. doxygenfunction:: xsimd::dispatch
:project: xsimd
Following code showcases a usage of the :cpp:func:`xsimd::dispatch` function:
.. code-block:: c++
#include "sum.hpp"
// Create the dispatching function, specifying the architecture we want to
// target.
auto dispatched = xsimd::dispatch<xsimd::arch_list<xsimd::avx2, xsimd::sse2>>(sum{});
// Call the appropriate implementation based on runtime information.
float res = dispatched(data, 17);
This code does *not* require any architecture-specific flags. The architecture
specific details follow.
The ``sum.hpp`` header contains the function being actually called, in an
architecture-agnostic description:
.. literalinclude:: ../../../test/doc/sum.hpp
The SSE2 and AVX2 version needs to be provided in other compilation units, compiled with the appropriate flags, for instance:
.. literalinclude:: ../../../test/doc/sum_avx2.cpp
.. literalinclude:: ../../../test/doc/sum_sse2.cpp
+45
View File
@@ -0,0 +1,45 @@
.. Copyright (c) 2016, Johan Mabille and Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
Instruction Set Macros
======================
Each of these macros corresponds to an instruction set supported by XSIMD. They
can be used to filter arch-specific code.
.. doxygengroup:: xsimd_config_macro
:project: xsimd
:content-only:
Changing Default Architecture
*****************************
You can change the default instruction set used by xsimd (when none is provided
explicitely) by setting the ``XSIMD_DEFAULT_ARCH`` macro to, say, ``xsimd::avx2``.
A common usage is to set it to ``xsimd::unsupported`` as a way to detect
instantiation of batches with the default architecture.
+172
View File
@@ -0,0 +1,172 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
Mathematical Functions
======================
Basic functions:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`abs` | absolute value |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fabs` | absolute value of floating point values |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fmod` | remainder of the floating point division operation |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`remainder` | signed remainder of the division operation |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`min` | smaller of two batches |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`max` | larger of two batches |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fmin` | smaller of two batches of floating point values |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fmax` | larger of two batches of floating point values |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`fdim` | positive difference |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`clip` | clipping operation |
+---------------------------------------+----------------------------------------------------+
Exponential functions:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`exp` | natural exponential function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`exp2` | base 2 exponential function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`exp10` | base 10 exponential function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`expm1` | natural exponential function, minus one |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`log` | natural logarithm function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`log2` | base 2 logarithm function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`log10` | base 10 logarithm function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`log1p` | natural logarithm of one plus function |
+---------------------------------------+----------------------------------------------------+
Power functions:
+-----------------------------------------+----------------------------------------------------+
| :cpp:func:`pow` | power function |
+-----------------------------------------+----------------------------------------------------+
| :cpp:func:`rsqrt` | reciprocal square root function |
+-----------------------------------------+----------------------------------------------------+
| :cpp:func:`sqrt` | square root function |
+-----------------------------------------+----------------------------------------------------+
| :cpp:func:`cbrt` | cubic root function |
+-----------------------------------------+----------------------------------------------------+
| :cpp:func:`hypot` | hypotenuse function |
+-----------------------------------------+----------------------------------------------------+
Trigonometric functions:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`sin` | sine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`cos` | cosine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`sincos` | sine and cosine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`tan` | tangent function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`asin` | arc sine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`acos` | arc cosine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`atan` | arc tangent function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`atan2` | arc tangent function, determining quadrants |
+---------------------------------------+----------------------------------------------------+
Hyperbolic functions:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`sinh` | hyperbolic sine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`cosh` | hyperbolic cosine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`tanh` | hyperbolic tangent function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`asinh` | inverse hyperbolic sine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`acosh` | inverse hyperbolic cosine function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`atanh` | inverse hyperbolic tangent function |
+---------------------------------------+----------------------------------------------------+
Error functions:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`erf` | error function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`erfc` | complementary error function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`tgamma` | gamma function |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`lgamma` | natural logarithm of the gamma function |
+---------------------------------------+----------------------------------------------------+
Nearint operations:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`ceil` | nearest integers not less |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`floor` | nearest integers not greater |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`trunc` | nearest integers not greater in magnitude |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`round` | nearest integers, rounding away from zero |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`nearbyint` | nearest integers using current rounding mode |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`rint` | nearest integers using current rounding mode |
+---------------------------------------+----------------------------------------------------+
----
.. doxygengroup:: batch_math
:project: xsimd
:content-only:
.. doxygengroup:: batch_trigo
:project: xsimd
:content-only:
.. doxygengroup:: batch_rounding
:project: xsimd
:content-only:
.. doxygengroup:: batch_math_extra
:project: xsimd
:content-only:
+55
View File
@@ -0,0 +1,55 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
Miscellaneous
=============
Sign manipulation:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`sign` | per slot sign extraction |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`signnz` | per slot sign extraction on non null elements |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`bitofsign` | per slot sign bit extraction |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`copysign` | per slot sign copy |
+---------------------------------------+----------------------------------------------------+
Stream operation:
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`operator<<` | batch pretty-printing |
+---------------------------------------+----------------------------------------------------+
----
.. doxygengroup:: batch_miscellaneous
:project: xsimd
:content-only:
+52
View File
@@ -0,0 +1,52 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
Reduction Operators
===================
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`reduce` | generic batch reduction |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`reduce_add` | sum of each batch element |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`reduce_max` | max of the batch elements |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`reduce_min` | min of the batch elements |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`reduce_mul` | product of the batch elements |
+---------------------------------------+----------------------------------------------------+
| :cpp:func:`haddp` | horizontal sum across batches |
+---------------------------------------+----------------------------------------------------+
Also see the `batch_bool` :ref:`xsimd-batch-bool-reducers`.
----
.. doxygengroup:: batch_reducers
:project: xsimd
:content-only:
+66
View File
@@ -0,0 +1,66 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content table.docutils {
width: 100%;
table-layout: fixed;
}
table.docutils .line-block {
margin-left: 0;
margin-bottom: 0;
}
table.docutils code.literal {
color: initial;
}
code.docutils {
background: initial;
}
</style>
.. _Type Traits:
Type Traits
===========
`xsimd` provides a few type traits to interact with scalar and batch types in an
uniform manner.
Combined traits:
+---------------------------------------+----------------------------------------------------+
| :cpp:class:`batch_traits` | batch types and proprties |
+---------------------------------------+----------------------------------------------------+
Type check:
+---------------------------------------+----------------------------------------------------+
| :cpp:class:`is_batch` | batch type detection |
+---------------------------------------+----------------------------------------------------+
| :cpp:class:`is_batch_bool` | mask batch type detection |
+---------------------------------------+----------------------------------------------------+
| :cpp:class:`is_batch_complex` | complex batch type detection |
+---------------------------------------+----------------------------------------------------+
Type access:
+---------------------------------------+----------------------------------------------------+
| :cpp:class:`scalar_type` | batch element type |
+---------------------------------------+----------------------------------------------------+
| :cpp:class:`mask_type` | batch mask type |
+---------------------------------------+----------------------------------------------------+
----
.. doxygengroup:: batch_traits
:project: xsimd
:content-only:
+19
View File
@@ -0,0 +1,19 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Batch of Scalars
================
.. _xsimd-batch-ref:
.. doxygenclass:: xsimd::batch
:project: xsimd
:members:
.. doxygenstruct:: xsimd::make_sized_batch
:project: xsimd
:members:
+31
View File
@@ -0,0 +1,31 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Batch of Conditions
===================
.. _xsimd-batch-bool-ref:
.. doxygenclass:: xsimd::batch_bool
:project: xsimd
:members:
Logical Operators
-----------------
.. doxygengroup:: batch_bool_logical
:project: xsimd
:content-only:
.. _xsimd-batch-bool-reducers:
Reducers
--------
.. doxygengroup:: batch_bool_reducers
:project: xsimd
:content-only:
+29
View File
@@ -0,0 +1,29 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Batch of Complex Numbers
========================
.. doxygenclass:: xsimd::batch< std::complex< T >, A >
:project: xsimd
:members:
Operations Specific to Batches of Complex Numbers
-------------------------------------------------
.. doxygengroup:: batch_complex
:project: xsimd
:content-only:
XTL Complex Support
-------------------
If the preprocessor token ``XSIMD_ENABLE_XTL_COMPLEX`` is defined, ``xsimd``
provides constructors of ``xsimd::batch< std::complex< T >, A >`` from
``xtl::xcomplex``, similar to those for ``std::complex``. This requires `XTL`_
to be installed.
.. _XTL: https://github.com/xtensor-stack/xtl
+32
View File
@@ -0,0 +1,32 @@
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Batch of Constants
==================
.. _xsimd-batch-constant-ref:
.. doxygenstruct:: xsimd::batch_constant
:project: xsimd
:members:
.. doxygenstruct:: xsimd::batch_bool_constant
:project: xsimd
:members:
.. doxygenfunction:: xsimd::make_batch_constant
:project: xsimd
.. doxygenfunction:: xsimd::make_batch_bool_constant
:project: xsimd
.. note::
:cpp:func:`make_batch_constant` and :cpp:func:`make_batch_bool_constant` also
accept a scalar value instead of a generator. In that case, that value is
broadcast to each slot of the constant batch.
+62
View File
@@ -0,0 +1,62 @@
.. Copyright (c) 2016, Johan Mabille and Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Basic Usage
===========
Manipulating Abstract Batches
-----------------------------
Here is an example that computes the mean of two batches, using the best
architecture available, based on compile time informations:
.. literalinclude:: ../../test/doc/manipulating_abstract_batches.cpp
There is no explicit architectural information available in the code, those are
deduced from the compiler target and its vector instruction support. If several
vector instructions sets are supported, the one with widest register width and
most operations is picked (e.g. AVX2 over AVX over SSE4.1).
There is no explicit register size information available in the code, those
solely depend on the architecture picked, as stated above. The batch can be a
batch of 4 single precision floating point numbers (e.g. on Neon) or a batch of
8 (e.g. on AVX2).
Manipulating Parametric Batches
-------------------------------
The implicit architectural information from previous example can be made
explicit, and the type used can be parametric. This is achieved as described in
the following example:
.. literalinclude:: ../../test/doc/manipulating_parametric_batches.cpp
At its core, a :cpp:class:`xsimd::batch` is bound to the scalar type it contains, and to the
instruction set it can use to operate on its values.
Explicit Use of an Instruction Set Extension
--------------------------------------------
Here is an example that loads two batches of 4 double floating point values, and
computes their mean, explicitly using the AVX extension:
.. literalinclude:: ../../test/doc/explicit_use_of_an_instruction_set.cpp
Note that in that case, the instruction set is explicilty specified in the batch
type. The flag passed down to the compiler need to make it possible for this
architecture to be used.
This example outputs:
.. code::
(2.0, 3.0, 4.0, 5.0)
.. warning::
If you allow your compiler to generate AVX2 instructions (e.g. through
``-mavx2``) there is nothing preventing it from optimizing the above code
using AVX2 instructions.
+493
View File
@@ -0,0 +1,493 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="svg2816"
version="1.1"
inkscape:version="0.47 r22583"
width="2072"
height="2072"
sodipodi:docname="Cmake.svg">
<metadata
id="metadata2822">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs2820">
<linearGradient
id="linearGradient4276">
<stop
style="stop-color:#32691d;stop-opacity:1"
offset="0"
id="stop4278" />
<stop
id="stop4280"
offset="0.02012207"
style="stop-color:#01d200;stop-opacity:0" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop4282" />
</linearGradient>
<linearGradient
id="linearGradient4227">
<stop
style="stop-color:#ebebec;stop-opacity:1"
offset="0"
id="stop4229" />
<stop
id="stop4231"
offset="0.00518292"
style="stop-color:#d3d3d3;stop-opacity:0" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop4233" />
</linearGradient>
<linearGradient
id="linearGradient4129">
<stop
id="stop4131"
offset="0"
style="stop-color:#cbf595;stop-opacity:1" />
<stop
style="stop-color:#01da00;stop-opacity:0"
offset="0.01826929"
id="stop4133" />
<stop
id="stop4135"
offset="1"
style="stop-color:#ffffff;stop-opacity:0;" />
</linearGradient>
<linearGradient
id="linearGradient4039">
<stop
style="stop-color:#321e1d;stop-opacity:1"
offset="0"
id="stop4041" />
<stop
id="stop4043"
offset="0.01546729"
style="stop-color:#555548;stop-opacity:0" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop4045" />
</linearGradient>
<linearGradient
id="linearGradient3990">
<stop
style="stop-color:#321e1d;stop-opacity:1"
offset="0"
id="stop3992" />
<stop
id="stop3994"
offset="0.02012207"
style="stop-color:#5a5bd7;stop-opacity:0" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop3996" />
</linearGradient>
<linearGradient
id="linearGradient3941">
<stop
id="stop3943"
offset="0"
style="stop-color:#f6b1b2;stop-opacity:1" />
<stop
style="stop-color:#c51f1f;stop-opacity:0"
offset="0.02821624"
id="stop3945" />
<stop
id="stop3947"
offset="1"
style="stop-color:#ffffff;stop-opacity:0;" />
</linearGradient>
<linearGradient
id="linearGradient3851">
<stop
id="stop3853"
offset="0"
style="stop-color:#321e1d;stop-opacity:1" />
<stop
style="stop-color:#555548;stop-opacity:0"
offset="0.02012207"
id="stop3855" />
<stop
id="stop3857"
offset="1"
style="stop-color:#ffffff;stop-opacity:0;" />
</linearGradient>
<linearGradient
id="linearGradient3800">
<stop
style="stop-color:#cbcaf2;stop-opacity:1"
offset="0"
id="stop3802" />
<stop
id="stop3808"
offset="0.02636753"
style="stop-color:#5555d2;stop-opacity:0" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop3804" />
</linearGradient>
<linearGradient
inkscape:collect="always"
id="linearGradient3715">
<stop
style="stop-color:#848484;stop-opacity:1"
offset="0"
id="stop3717" />
<stop
style="stop-color:#d2d2d2;stop-opacity:1"
offset="1"
id="stop3719" />
</linearGradient>
<linearGradient
inkscape:collect="always"
id="linearGradient3669">
<stop
style="stop-color:#01a300;stop-opacity:1"
offset="0"
id="stop3671" />
<stop
style="stop-color:#01df00;stop-opacity:1"
offset="1"
id="stop3673" />
</linearGradient>
<linearGradient
inkscape:collect="always"
id="linearGradient3653">
<stop
style="stop-color:#b40e0e;stop-opacity:1"
offset="0"
id="stop3655" />
<stop
style="stop-color:#ff5959;stop-opacity:1"
offset="1"
id="stop3657" />
</linearGradient>
<linearGradient
inkscape:collect="always"
id="linearGradient3645">
<stop
style="stop-color:#1011a1;stop-opacity:1"
offset="0"
id="stop3647" />
<stop
style="stop-color:#6969e1;stop-opacity:1"
offset="1"
id="stop3649" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3645"
id="linearGradient3651"
x1="-1527.3507"
y1="1387.5206"
x2="-1086.1161"
y2="454.13968"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(2104,48)" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3653"
id="linearGradient3659"
x1="-933.38092"
y1="680.41388"
x2="-316.78384"
y2="1721.275"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(2104,48)" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3669"
id="linearGradient3675"
x1="-678.82251"
y1="1794.8141"
x2="-1549.978"
y2="1721.275"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(2104,48)" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3715"
id="linearGradient3721"
x1="-984.2926"
y1="1472.3735"
x2="-995.60632"
y2="1093.3643"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(2104,48)" />
<filter
inkscape:collect="always"
id="filter3777">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="9.0766588"
id="feGaussianBlur3779" />
</filter>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3800"
id="linearGradient3806"
x1="-1238.0465"
y1="919.71448"
x2="-555.82379"
y2="917.51282"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.9188939,0.98349385,-0.45611308,0.88992183,3476.0418,1285.266)" />
<linearGradient
y2="913.40582"
x2="-552.84039"
y1="919.71448"
x1="-1238.0465"
gradientTransform="matrix(-1.9407023,0.93972781,-0.43581582,-0.90003588,-412.21511,3168.6506)"
gradientUnits="userSpaceOnUse"
id="linearGradient3828"
xlink:href="#linearGradient3851"
inkscape:collect="always" />
<linearGradient
id="linearGradient3851-6">
<stop
id="stop3853-2"
offset="0"
style="stop-color:#321e1d;stop-opacity:1" />
<stop
style="stop-color:#555548;stop-opacity:0"
offset="0.02012207"
id="stop3855-4" />
<stop
id="stop3857-5"
offset="1"
style="stop-color:#ffffff;stop-opacity:0;" />
</linearGradient>
<linearGradient
y2="915.30005"
x2="-555.83728"
y1="919.71448"
x1="-1238.0465"
gradientTransform="matrix(0.02700295,-2.1560608,0.90368745,0.01314507,114.37039,-755.42907)"
gradientUnits="userSpaceOnUse"
id="linearGradient3877"
xlink:href="#linearGradient3851-6"
inkscape:collect="always" />
<linearGradient
y2="917.6181"
x2="-554.89746"
y1="919.71448"
x1="-1238.0465"
gradientTransform="matrix(3.1362513,0.00261809,0.06431073,0.7601511,4936.1356,68.133286)"
gradientUnits="userSpaceOnUse"
id="linearGradient3918"
xlink:href="#linearGradient3941"
inkscape:collect="always" />
<linearGradient
y2="917.51282"
x2="-555.82379"
y1="918.44379"
x1="-1229.327"
gradientTransform="matrix(-2.1510215,-0.07025797,-0.03821188,-0.48210687,-1498.469,1058.0104)"
gradientUnits="userSpaceOnUse"
id="linearGradient3967"
xlink:href="#linearGradient3990"
inkscape:collect="always" />
<linearGradient
y2="917.51282"
x2="-555.82379"
y1="920.41797"
x1="-1237.1112"
gradientTransform="matrix(-1.3798164,-1.6569612,0.7684458,-0.63991489,-2195.6367,413.8935)"
gradientUnits="userSpaceOnUse"
id="linearGradient4016"
xlink:href="#linearGradient4039"
inkscape:collect="always" />
<linearGradient
id="linearGradient3851-62">
<stop
id="stop3853-38"
offset="0"
style="stop-color:#321e1d;stop-opacity:1" />
<stop
style="stop-color:#555548;stop-opacity:0"
offset="0.01739271"
id="stop3855-2" />
<stop
id="stop3857-62"
offset="1"
style="stop-color:#ffffff;stop-opacity:0;" />
</linearGradient>
<linearGradient
y2="910.64618"
x2="-551.12549"
y1="915.73645"
x1="-1242.2334"
gradientTransform="matrix(0.85312044,-1.9803029,0.91840135,0.39565006,2182.2918,-885.93458)"
gradientUnits="userSpaceOnUse"
id="linearGradient4065"
xlink:href="#linearGradient3851-62"
inkscape:collect="always" />
<linearGradient
y2="915.4801"
x2="-555.86682"
y1="919.71448"
x1="-1238.0465"
gradientTransform="matrix(1.3829904,1.654313,-0.7672176,0.6413869,2529.8389,3432.8719)"
gradientUnits="userSpaceOnUse"
id="linearGradient4106"
xlink:href="#linearGradient4129"
inkscape:collect="always" />
<linearGradient
y2="917.18665"
x2="-866.86804"
y1="918.09875"
x1="-1242.5582"
gradientTransform="matrix(1.3829904,1.654313,-0.7672176,0.6413869,2930.535,3096.9376)"
gradientUnits="userSpaceOnUse"
id="linearGradient4196"
xlink:href="#linearGradient4227"
inkscape:collect="always" />
<linearGradient
y2="917.51282"
x2="-555.82379"
y1="919.71448"
x1="-1238.0465"
gradientTransform="matrix(-0.83179183,1.989334,-0.83312221,-0.35033011,1447.5752,4603.6836)"
gradientUnits="userSpaceOnUse"
id="linearGradient4253"
xlink:href="#linearGradient4276"
inkscape:collect="always" />
</defs>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1280"
inkscape:window-height="750"
id="namedview2818"
showgrid="false"
inkscape:zoom="0.25"
inkscape:cx="668.45545"
inkscape:cy="769.26341"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg2816"
showguides="true"
inkscape:guide-bbox="true" />
<g
id="g3668">
<path
sodipodi:nodetypes="ccccccc"
id="path2831-1"
d="m 1971.5575,1939.9137 -1797.08691,-0.1258 c -11.0291,-1.2221 -8.5403,-6.713 -5.9958,-12.2215 L 1069.3546,128.0808 c 3.3139,-5.2772 6.2883,-4.4372 9.0861,-0.4108 l 900.8561,1799.4363 c 4.5781,9.1667 1.5811,13.1503 -7.7393,12.8074 z"
style="fill:none;stroke:#3a393b;stroke-width:22.50000000000000000;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;filter:url(#filter3777);opacity:0.53974895" />
<path
sodipodi:nodetypes="cccc"
id="path2828"
d="M 1143.3083,1084.3217 158.69119,1926.0618 1060.5107,124.10214 1143.3083,1084.3217 z"
style="fill:url(#linearGradient3651);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-opacity:1" />
<path
sodipodi:nodetypes="ccccc"
id="rect3781"
d="m 1060.5637,125.61959 c 13.4152,80.71591 11.94,94.79031 -18.0349,140.07316 L 245.92029,1844.832 161.31739,1921.7588 1060.5637,125.61959 z"
style="fill:url(#linearGradient3806);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
sodipodi:nodetypes="cccccc"
id="rect3781-0-9"
d="m 1147.188,1083.1536 -50.1671,40.0537 -52.7887,-888.7261 c -4.0533,-47.4341 -6.2416,-43.17076 -6.5492,-68.17004 l 25.1004,-48.95208 84.4046,965.79452 z"
style="fill:url(#linearGradient3967);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
sodipodi:nodetypes="cccc"
id="path2828-4"
d="M 1188.9362,1609.9939 1060.9788,123.94021 1963.9529,1926.2261 1188.9362,1609.9939 z"
style="fill:url(#linearGradient3659);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-opacity:1" />
<path
sodipodi:nodetypes="ccccc"
id="rect3781-9"
d="m 1060.9071,120.07731 c 24.1749,30.04558 39.608,75.93991 48.9654,112.17843 l 179.3742,1415.10436 -98.4276,-38.4391 -129.912,-1488.84369 z"
style="fill:url(#linearGradient3918);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
sodipodi:nodetypes="cccc"
id="path2828-1"
d="M 743.40929,1423.8349 1964.8794,1926.0085 158.92799,1925.81 743.40929,1423.8349 z"
style="fill:url(#linearGradient3675);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-opacity:1" />
<path
sodipodi:nodetypes="cccccc"
id="rect3781-0"
d="m 1963.6891,1926.5277 -56.7139,-24.6169 -795.9854,-1603.05217 c -21.9472,-24.37845 -34.3449,-39.62306 -41.2192,-51.95192 -1.1264,-32.3188 -2.943,-61.0813 -9.9138,-126.2626 l 903.8323,1805.88359 z"
style="fill:url(#linearGradient3828);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
sodipodi:nodetypes="cccc"
id="path2828-4-7"
d="m 745.26609,1425.0475 397.42281,-339.0381 55.3298,523.5716 -452.75261,-184.5335 z"
style="fill:url(#linearGradient3721);fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:4;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<path
inkscape:transform-center-y="624.859"
inkscape:transform-center-x="758.12355"
sodipodi:nodetypes="cccccc"
id="rect3781-8"
d="m 742.72829,1426.2554 c 17.4821,6.7504 20.8419,8.2827 35.806,14.4205 -16.1593,13.8305 -69.88,86.4885 -91.4281,103.8499 l -428.4072,362.6992 -98.8195,18.3883 582.8488,-499.3579 z"
style="fill:url(#linearGradient4106);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
inkscape:transform-center-y="347.22075"
inkscape:transform-center-x="-821.22079"
sodipodi:nodetypes="cccccc"
id="rect3781-0-8-6"
d="m 1962.8676,1925.4594 -68.0643,-1.0486 -1174.86681,-479.6332 23.5048,-18.7167 470.76241,191.9416 748.6639,307.4569 z"
style="fill:url(#linearGradient4253);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
sodipodi:nodetypes="ccccc"
id="rect3781-0-8"
d="m 159.98259,1925.4405 50.2958,-42.8864 1643.00831,0.1531 110.3276,42.727 -1803.63171,0.01 z"
style="fill:url(#linearGradient3877);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
inkscape:transform-center-y="369.96725"
inkscape:transform-center-x="-887.51544"
sodipodi:nodetypes="ccccccc"
id="rect3781-0-7"
d="m 1199.8469,1610.9874 -2.1608,-22.3386 610.5884,235.1678 c 39.4555,18.7661 69.1058,27.2993 88.8249,43.327 12.6947,5.2081 34.7241,12.6345 46.1135,16.4736 13.9264,9.2219 11.5065,23.9583 20.3177,41.5431 l -763.6837,-314.1729 z"
style="fill:url(#linearGradient4065);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
sodipodi:nodetypes="ccccccc"
id="path2831"
d="m 1958.5868,1931.807 -1797.08691,-0.1258 c -11.0291,-1.2221 -8.5403,-6.713 -5.9958,-12.2215 L 1056.3839,119.97408 c 3.3139,-5.27718 6.2883,-4.43721 9.0861,-0.4108 l 900.8561,1799.43632 c 4.5781,9.1667 1.5811,13.1503 -7.7393,12.8074 z"
style="fill:none;stroke:#000000;stroke-width:12.19999981;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
<path
sodipodi:nodetypes="cccccc"
id="rect3781-0-98"
d="m 160.09059,1924.1505 25.5248,-54.5322 52.0681,-38.5691 899.32641,-780.8749 c 4.7998,18.518 1.8803,6.9336 6.1315,33.989 l -983.05081,839.9872 z"
style="fill:url(#linearGradient4016);fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
inkscape:transform-center-y="624.859"
inkscape:transform-center-x="758.12355"
sodipodi:nodetypes="ccccc"
id="rect3781-8-2"
d="m 1141.0494,1090.571 c -7.8922,86.6075 -17.7158,81.5443 -53.2471,118.0205 l -263.40721,244.6992 -74.9445,-29.2367 391.59881,-333.483 z"
style="fill:url(#linearGradient4196);fill-opacity:1;fill-rule:nonzero;stroke:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 17 KiB

+1
View File
@@ -0,0 +1 @@
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 127 127"><style>.st0{fill:#43b02a}</style><path class="st0" d="M13.8 81.2c-2.1 4.2-3.8 8.6-5.2 13.1 4.7 1.3 9.4 2.2 14.2 2.6.1-3.8.4-7.4.9-11-3.4-1.3-6.7-2.9-9.9-4.7zM33 32.8c-2.8 0-5.5.2-8.3.6.4 2.8.8 5.5 1.5 8.3 1.9-3.2 4.2-6.1 6.8-8.7v-.2zM10.5 98.7c3.6 5.5 8.1 10.4 13.2 14.5-.5-4.3-.9-8.4-.9-12.5-4.2-.4-8.3-1.1-12.3-2zM43 3.4c-5 1.7-9.6 4-14 6.8 3.3.6 6.5 1.3 9.7 2.3 1.2-3.1 2.7-6.1 4.3-9.1zM63.6 0c-2.5 0-4.9.2-7.3.4 3.4 2.4 6.6 4.9 9.7 7.7l2.5 2.3-2.5 2.5c-2.1 2-4.1 4.1-6 6.4v.1s-.4.4-1 1.1c1.5-.2 3-.2 4.6-.2 23.9 0 43.3 19.4 43.3 43.3s-19.4 43.3-43.3 43.3c-8.3 0-16.1-2.3-22.7-6.4-3.3.4-6.5.6-9.8.6-1.5 0-3 0-4.6-.1.1 4.9.6 10 1.4 15.3 10.2 6.9 22.4 10.9 35.6 10.9 35.1 0 63.6-28.5 63.6-63.6C127.2 28.5 98.7 0 63.6 0z"/><path class="st0" d="M55.1 15c1.3-1.5 2.6-3 3.9-4.4-3-2.5-6.1-4.9-9.4-6.9-2 3.4-3.8 7-5.3 10.6 2.9 1.1 5.7 2.3 8.4 3.6 1.3-1.6 2.2-2.6 2.4-2.9zM19.4 34.1c-4.7.8-9.3 2.1-13.8 3.7 1.8 4.6 4.1 9.1 6.7 13.3 3-2.1 6.1-4.1 9.3-5.8-1-3.7-1.7-7.4-2.2-11.2zM11.1 58.1c-3.4 2.8-6.6 5.8-9.6 9.2 3.3 2.9 6.8 5.5 10.5 7.9 1.7-3 3.6-6 5.6-8.8-2.2-2.6-4.4-5.4-6.5-8.3zM27.3 87.3c-.4 3.2-.7 6.5-.8 9.9 3.2.2 6.4.2 9.6 0-3.4-2.8-6.4-6.1-8.8-9.9zM36.6 18.1c-4-1.1-8.1-2-12.2-2.5-.4 4.2-.4 8.3-.1 12.4 3.3-.4 6.5-.6 9.8-.6.6-3.2 1.5-6.3 2.5-9.3zM42.3 19.9c-.8 2.4-1.5 4.8-2.1 7.2 2.8-1.8 5.8-3.3 8.9-4.4-2.2-1-4.5-1.9-6.8-2.8zM.5 72.1c.8 6.2 2.5 12.1 5 17.5C6.8 86 8.3 82.4 10 79c-3.3-2.1-6.4-4.4-9.5-6.9zM18.8 18.5c-3.8 3.8-7.1 8-9.9 12.6 3.3-1 6.6-1.8 10-2.4-.2-3.4-.3-6.8-.1-10.2zM15 55.2c1.6 2.3 3.4 4.6 5.3 6.8.2-4 .8-7.8 2-11.5-2.5 1.4-5 3-7.3 4.7zM15.8 77.3c2.7 1.5 5.4 2.9 8.3 4.1-1.7-3.7-2.8-7.6-3.4-11.8-1.8 2.5-3.4 5.1-4.9 7.7zM8.4 54.1c-2-3.2-3.8-6.5-5.4-10C1.2 49.7.1 55.7 0 61.8c2.7-2.8 5.5-5.4 8.4-7.7z"/></svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import subprocess
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
if on_rtd:
subprocess.check_call('cd ..; doxygen', shell=True)
import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
def setup(app):
app.add_css_file("main_stylesheet.css")
extensions = ['breathe', 'sphinx_rtd_theme']
breathe_projects = { 'xsimd': '../xml' }
templates_path = ['_templates']
html_static_path = ['_static']
source_suffix = '.rst'
master_doc = 'index'
project = 'xsimd'
copyright = '2016, Johan Mabille and Sylvain Corlay'
author = 'Johan Mabille and Sylvain Corlay'
html_logo = 'quantstack-white.svg'
exclude_patterns = []
highlight_language = 'c++'
pygments_style = 'sphinx'
todo_include_todos = False
htmlhelp_basename = 'xsimddoc'
+139
View File
@@ -0,0 +1,139 @@
.. Copyright (c) 2016, Johan Mabille and Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. image:: xsimd.svg
:alt: xsimd
C++ wrappers for SIMD intrinsics.
Introduction
------------
`SIMD`_ (Single Instruction, Multiple Data) is a feature of microprocessors that has been available for many years. SIMD instructions perform a single operation
on a batch of values at once, and thus provide a way to significantly accelerate code execution. However, these instructions differ between microprocessor
vendors and compilers.
`xsimd` provides a unified means for using these features for library authors.
The core of the library consist in a parametrized vector type, :ref:`Batch Types`,
and a set of operations to perform :ref:`Arithmetic Operations`,
:ref:`Data Transfer`, and many common mathemtical functions, as for single
values.
There are several ways to use `xsimd` using those :ref:`Batch Types` and
operations:
- one can write a generic, vectorized, algorithm and compile it as part of their
application build, with the right architecture flag;
- one can write a generic, vectorized, algorithm and compile several version of
it by just changing the architecture flags, then pick the best version at
runtime;
- one can write a vectorized algorithm specialized for a given architecture and
still benefit from the high-level abstraction proposed by `xsimd`.
Of course, nothing prevents the combination of several of those approach, but
more about this in section :ref:`Writing vectorized code`.
You can find out more about this implementation of C++ wrappers for SIMD
intrinsics at the `The C++ Scientist`_. The mathematical functions are a
lightweight implementation of the algorithms also used in `boost.SIMD`_.
Compiler and Architecture Support
---------------------------------
The following SIMD instruction set extensions are supported:
+--------------+---------------------------------------------------------+
| Architecture | Instruction set extensions |
+==============+=========================================================+
| x86 | SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, FMA3, AVX2 |
+--------------+---------------------------------------------------------+
| x86 | AVX512 (gcc7 and higher) |
+--------------+---------------------------------------------------------+
| x86 AMD | same as above + FMA4 |
+--------------+---------------------------------------------------------+
| ARM | ARMv7, ARMv8 |
+--------------+---------------------------------------------------------+
| WebAssembly | WASM |
+--------------+---------------------------------------------------------+
| Risc-V | Vector ISA |
+--------------+---------------------------------------------------------+
| PowerPC | VSX |
+--------------+---------------------------------------------------------+
`xsimd` requires a C++11 compliant compiler. The following C++ compilers are supported:
+-------------------------+-------------------------------+
| Compiler | Version |
+=========================+===============================+
| Microsoft Visual Studio | MSVC 2015 update 2 and above |
+-------------------------+-------------------------------+
| g++ | 4.9 and above |
+-------------------------+-------------------------------+
| clang | 3.7 and above |
+-------------------------+-------------------------------+
Licensing
---------
We use a shared copyright model that enables all contributors to maintain the
copyright on their contributions.
This software is licensed under the BSD-3-Clause license. See the LICENSE file for details.
.. toctree::
:caption: INSTALLATION
:maxdepth: 2
installation
.. toctree::
:caption: USAGE
:maxdepth: 2
basic_usage
vectorized_code
integration
.. toctree::
:caption: API REFERENCE
:maxdepth: 1
api/instr_macros
api/batch_index
api/data_transfer
api/arithmetic_index
api/comparison_index
api/bitwise_operators_index
api/math_index
api/reducer_index
api/cast_index
api/type_traits
api/batch_manip
api/misc_index
api/aligned_allocator
api/arch
api/dispatching
.. toctree::
:caption: MIGRATION GUIDE
:maxdepth: 1
migration_guide
.. _SIMD: https://fr.wikipedia.org/wiki/Single_instruction_multiple_data
.. _The C++ Scientist: http://johanmabille.github.io/blog/archives/
.. _boost.SIMD: https://github.com/NumScale/boost.simd
+74
View File
@@ -0,0 +1,74 @@
.. Copyright (c) 2016, Johan Mabille and Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content .section>img {
width: 30px;
margin-bottom: 0;
margin-top: 0;
margin-right: 15px;
margin-left: 15px;
float: left;
}
</style>
Installation
============
`xsimd` is a header-only library, so installing it is just a matter of copying the ``include/xsimd`` directory.
However we provide standardized means to install it, with package managers or with cmake.
Besides the `xsimd` headers, all these methods place the ``cmake`` project configuration file in the right location so that third-party projects can use cmake's ``find_package`` to locate `xsimd` headers.
.. image:: conda.svg
Using the conda-forge Package
-----------------------------
A package for `xsimd` is available for the `mamba <https://mamba.readthedocs.io>`_ (or `conda <https://conda.io>`_) package manager.
.. code::
mamba install -c conda-forge xsimd
.. image:: spack.svg
Using the Spack Package
-----------------------
A package for `xsimd` is available on the `Spack <https://spack.io>`_ package manager.
.. code::
spack install xsimd
spack load xsimd
.. image:: cmake.svg
From Source with cmake
----------------------
You can install `xsimd` from source with `cmake <https://cmake.org/>`_. On Unix platforms, from the source directory:
.. code::
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/path/to/prefix ..
make install
On Windows platforms, from the source directory:
.. code::
mkdir build
cd build
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/prefix ..
nmake
nmake install
+37
View File
@@ -0,0 +1,37 @@
.. Copyright (c) 2025, Serge Guelton
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
Integration
===========
When Targeting a Single Architecture
------------------------------------
If you compile your whole project for a single architecture, you can rely on the
implicit architecture parameter for :cpp:class:`xsimd::batch`. Just add your
source using `xsimd` to your project build system, pass down the
appropriate flags and the magic should happen.
It's very common though to have a base application with minimal architectural
constraints, while still wanting to benefit from the acceleration of better
instruction sets if those are available.
When Targeting Multiple Architectures
-------------------------------------
It's very common, especially when targeting Intel hardware, to set a minimal
baseline, say SSE2, for the base application, while still shipping computation
kernels specialized for SSE4.2, AVX2 or AVX512BF.
In that case one can write specific kernels for each targeted instruction set
(or a generic one that's instantiated for each targeted instruction set). Those
kernels must then be compiled with the appropriate flags independently, and
linked into the application.
`xsimd` provides a generic dispatch mechanism that can be used from the *base
application* to pick the best kernel *at runtime* based on runtime detection of the
supported architectures, as described more in detailed in :ref:`Arch
Dispatching`.
+90
View File
@@ -0,0 +1,90 @@
.. Copyright (c) 2016, Johan Mabille and Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. raw:: html
<style>
.rst-content .section>img {
width: 30px;
margin-bottom: 0;
margin-top: 0;
margin-right: 15px;
margin-left: 15px;
float: left;
}
</style>
From 7.x to 8.x
===============
Version 8.x introduces a lot of API difference compared to version 7.x. This
section motivates the version bump and details the most notable changes.
Why 8.x
-------
Version 8.x introduces a new concept in `xsimd`: all batch types are now
parametrized by a type, say ``double``, and an optional architecture, say
``avx512``, as in ``batch<double, avx512>``. It is still possible to just
require a batch of doubles and let the library pick the most appropriate
architecture, as in ``batch<double>``.
This new design make it possible to target multiple architecture from the same
code, as detailed in the :ref:`Arch Dispatching` section.
As a side effect of this (almost full) rewrite of the library code, `xsimd` is
now twice as fast to compile, and its source code size as been (roughly) divided
by two. The `xsimd` developers also took this as an opportnuity to significantly
improve test coverage.
Most Notable Changes
--------------------
Batch Types
***********
The second argument of :cpp:class:`xsimd::batch` is now a type that represents
an architecture, instead of an integer.
The previous behavior can be emulated through the
:cpp:class:`xsimd::make_sized_batch` utility.
Batch of Complex Types
**********************
Loading a batch of complex from an ``xtl::xcomplex<T>`` now yields an
``xsimd::batch<std::complex<T>>`` instead of an ``xtl::xcomplex<T>``. It is still
possible to store an ``xsimd::batch<std::complex<T>>`` to an
``xtl::xcomplex<T>``.
Loading Batches
***************
``xsimd::batch<T>::load*`` are now static functions. It is no longer supported
to update an existing batch through its ``load`` method. The regular assign
operator can be used instead.
Indexing Batches
****************
``xsimd::batch<T>::operator[](size_t)`` has been replaced with
``xsimd::batch<T>::get(size_t)``. Keep in mind that this method implies a register
load *for each call*, so it's wise not to use it in performance-critical
section. When needed, do an explicit store of the batch into an array and work
from there.
Architecture Detection
**********************
Many macros have been replaced by more elaborated constructs.
``XSIMD_INSTR_SET_AVAILABLE`` has been replaced by the type alias ``xsimd::default_arch``.
Likewise architecture-specific macros like ``XSIMD_X86_INSTR_SET_AVAILABLE`` has
been replaced by ``xsimd::upported_architectures::contains<xsimd::sse3>()``. Macro like ``XSIMD_WITH_SSE3`` are still
defined to ``0`` or ``1`` to guard architecture-specific code.
+52
View File
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 19.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Calque_1"
x="0px"
y="0px"
viewBox="0 0 408.70001 84.5"
xml:space="preserve"
inkscape:version="0.91 r13725"
sodipodi:docname="quantstack-white.svg"
width="408.70001"
height="84.5"><metadata
id="metadata9"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs7" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1847"
inkscape:window-height="1056"
id="namedview5"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:zoom="0.69383003"
inkscape:cx="204.25"
inkscape:cy="41.75"
inkscape:window-x="73"
inkscape:window-y="24"
inkscape:window-maximized="1"
inkscape:current-layer="Calque_1" /><path
d="m 85.3,16 c 1.2,0.6 2.4,1.3 3.4,2.2 l 0,22.2 c 0,9.2 -1.8,19.7 -14.2,19.7 l -1.9,0 C 60.1,60.1 58.4,49.6 58.4,40.4 l 0,-22.2 c 1,-0.9 2.2,-1.6 3.4,-2.2 l 0,23.4 c 0,10.4 1.5,17.7 11.4,17.7 l 0.9,0 c 9.8,0 11.4,-7.3 11.4,-17.7 L 85.5,16 Z M 133,38.1 c 0,15 -5.1,22.1 -18.1,22.1 -0.1,0 -0.6,0 -0.7,0 -11,0 -14.2,-5.1 -14.2,-12.4 0,-10.2 9.7,-12.6 29.5,-13.4 -0.6,-9.3 -3.7,-15.2 -14.6,-15.2 -3,0 -5.8,0.5 -8.6,1.8 l -1.5,-2.9 c 3.3,-1.7 6.7,-2.1 10.1,-2.1 13,0 18.1,7 18.1,22.1 z m -3.4,-0.7 c -16.6,0.8 -26.1,2.2 -26.1,10.5 0,2.8 0.5,4.9 1.9,6.4 0.4,0.5 1,0.9 1.7,1.2 2.6,1.1 5.2,1.5 7.9,1.5 12.2,0 14.7,-7.4 14.7,-18.9 -0.1,-0.3 -0.1,-0.5 -0.1,-0.7 z m 201.7,0.7 c 0,15 -5.1,22.1 -18.1,22.1 -0.1,0 -0.6,0 -0.7,0 -11,0 -14.2,-5.1 -14.2,-12.4 0,-10.2 9.7,-12.6 29.5,-13.4 -0.6,-9.3 -3.7,-15.2 -14.6,-15.2 -3,0 -5.8,0.5 -8.6,1.8 l -1.5,-2.9 c 3.3,-1.7 6.7,-2.1 10.1,-2.1 13,0 18.1,7 18.1,22.1 z m -3.4,-0.7 c -16.6,0.8 -26.1,2.2 -26.1,10.5 0,2.8 0.5,4.9 1.9,6.4 0.4,0.5 1,0.9 1.7,1.2 2.6,1.1 5.2,1.5 7.9,1.5 12.2,0 14.7,-7.4 14.7,-18.9 -0.1,-0.3 -0.1,-0.5 -0.1,-0.7 z M 57.2,82.2 c -0.9,0.9 -1.8,1.7 -2.9,2.3 C 45,79.7 38.3,71.4 34.9,60.6 31.7,62.2 27.8,63 23.1,63 6.5,63 0,53.3 0,32.3 0,11.4 6.5,1.6 23.1,1.6 c 16.6,0 23.1,9.7 23.1,30.7 0,13 -2.5,21.6 -8.4,26.4 3.2,10.9 10,19 19.4,23.5 z M 42.7,32.3 C 42.7,15.9 39.4,4.8 23,4.8 6.6,4.8 3.3,15.8 3.3,32.3 c 0,16.4 3.3,27.5 19.7,27.5 16.4,0 19.7,-11 19.7,-27.5 z m 366,-10.4 C 408,21 407.2,20.2 406.3,19.5 l -18.3,18.2 0,-22 -0.4,0 c -1.1,0.2 -2,0.5 -3,0.8 l 0,42.6 c 1.1,0.4 2.2,0.6 3.4,0.9 l 0,-21.3 17.8,17.8 c 0.9,-0.7 1.7,-1.4 2.5,-2.3 l -16,-16 16.4,-16.3 z M 360.6,57 c -12.2,0 -14.7,-7.4 -14.7,-18.9 0,-11.5 2.5,-18.9 14.7,-18.9 3.1,0 6,0.5 8.8,1.9 l 1.5,-2.9 c -3.4,-1.7 -6.9,-2.1 -10.2,-2.1 -13,0 -18.1,7 -18.1,22.1 0,15 5.1,22.1 18.1,22.1 3.4,0 6.9,-0.4 10.3,-2.1 l -1.5,-2.9 c -3,1.2 -5.9,1.7 -8.9,1.7 z m -198,-41.1 -1.9,0 c -12.5,0 -14.2,10.5 -14.2,19.7 l 0,22.2 c 1,0.9 2.2,1.6 3.4,2.2 l 0,-23.3 c 0,-10.4 1.5,-17.7 11.4,-17.7 l 0.9,0 c 9.8,0 11.4,7.3 11.4,17.7 l 0,23.4 c 1.2,-0.6 2.4,-1.3 3.4,-2.2 l 0,-22.2 c -0.2,-9.3 -2,-19.8 -14.4,-19.8 z m 127.7,4.3 -1.6,-3.1 -10.4,0 0,-10.9 -3.3,0 0,10.8 -10.5,0 -1.6,3.1 12.1,0 c 0,0 0,22.4 0,23.7 l 0,0 c -0.1,2.6 0.3,5.1 1.2,7.3 0,0.1 1,2.2 2.6,4.1 0.8,0.9 2.4,2.3 4.6,3.8 l 1.5,-3.1 c -1.7,-1.2 -2.9,-2.2 -3.5,-2.9 -1.3,-1.5 -2,-3.2 -2,-3.2 -0.7,-1.6 -1,-3.3 -1,-5 0,-1.2 0,-24.7 0,-24.7 l 11.9,0 z M 197.8,6 l -3.3,0 0,10.8 -12,0 1.6,3.1 10.4,0 c 0,0 0,12.2 0,13.5 l 0,0 c -0.1,2.6 0.3,5.1 1.2,7.3 0,0.1 1,2.2 2.6,4.1 0.8,0.9 2.3,2.2 4.4,3.7 l 1.6,-3.1 c -1.7,-1.2 -2.9,-2.2 -3.4,-2.9 -1.3,-1.5 -2,-3.2 -2,-3.2 -0.7,-1.6 -1,-3.3 -1,-5 0,-1.2 0,-14.5 0,-14.5 l 10.4,0 1.6,-3.1 -12.1,0 0,-10.7 z m 40.3,22.2 c -1.9,-0.7 -3.6,-1.3 -5.3,-2.1 l 0,0 c -5.1,-2.1 -8.7,-4.8 -8.7,-10.8 0,-9.2 6.4,-12.1 14.5,-12.1 3.8,0 7.5,0.4 11.2,1.7 L 251.3,2 c -4,-1.5 -8.3,-2 -12.8,-2 -9.4,0 -17.7,4.1 -17.7,15.4 0,6.7 3.4,10.4 8.6,12.9 l 0,0 c 0.8,0.3 1.4,0.6 2.1,0.9 0,0 0,0 0,0 l 0,0 c 1.9,0.8 3.3,1.4 5.1,2 8.4,3 12.3,3.5 15.1,6.6 0.2,0.2 4.1,4.8 3.1,10.4 -0.5,2.9 -2.2,5.5 -4.9,7.8 -6.2,5.1 -15.9,4 -25.2,0.9 l -1.6,3.1 c 5.1,1.8 10.4,3 15.4,3 5.1,0 9.7,-1.2 13.5,-4.3 4.2,-3.5 5.7,-7.2 6.1,-9.8 1.3,-7.1 -3.3,-12.6 -3.8,-13.2 -2.7,-2.9 -7.6,-4.4 -16.2,-7.5 z"
id="path3"
inkscape:connector-curvature="0"
style="fill:#ffffff" /></svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="256" height="256"
viewBox="-128 -128 256 256"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events">
<style>
.diamond { fill:#0f3a80; }
circle.back { fill:#ffa600; stroke:#0f3a80; stroke-width:6; }
circle.front { fill:#ffffff; stroke:#0f3a80; stroke-width:6; }
line.back { stroke:#ffa600; stroke-width:7; }
line.front { stroke:#ffffff; stroke-width:7; }
line.shadow { stroke:#0f3a80; stroke-width:7; }
</style>
<defs>
<!-- need two arrows b/c we can't sync color with the marked element -->
<marker id="barrow" markerWidth="4" markerHeight="3" refX=".05" refY="1.5"
orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,3 L4,1.5 z" fill="#ffa600"/>
</marker>
<marker id="farrow" markerWidth="4" markerHeight="3" refX=".05" refY="1.5"
orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,3 L4,1.5 z" fill="#ffffff"/>
</marker>
</defs>
<!-- rounded diamond shape -->
<rect x="-97" y="-97" width="194" height="194" rx="26" ry="26"
transform="rotate(45)" class="diamond"/>
<!-- background dependency structure -->
<line x1="-11" y1="-80" x2="-11" y2="-29" transform="rotate(42 -11 -80)"
class="back" marker-end="url(#barrow)"/>
<line x1="-80" y1="0" x2="-80" y2="57" transform="rotate(-45 -80 0)"
class="back" marker-end="url(#barrow)"/>
<line x1="-11" y1="-80" x2="-11" y2="28" class="back"
marker-end="url(#barrow)"/>
<circle cx="-11" cy="-80" r="23" class="back"/>
<circle cx="0" cy="80" r="23" class="back"/>
<circle cx="-80" cy="0" r="23" class="back"/>
<!-- foreground dependency structure -->
<line x1="18" y1="-80" x2="18" y2="0" transform="rotate(42 17 -80)"
class="shadow"/>
<line x1="13" y1="-80" x2="13" y2="-5" transform="rotate(42 11 -80)"
class="front" marker-end="url(#farrow)"/>
<line x1="11" y1="-80" x2="11" y2="-29" transform="rotate(-42 11 -80)"
class="front" marker-end="url(#farrow)"/>
<line x1="80" y1="0" x2="80" y2="57" transform="rotate(45 80 0)"
class="front" marker-end="url(#farrow)"/>
<line x1="11" y1="-80" x2="11" y2="28" class="front"
marker-end="url(#farrow)"/>
<circle cx="11" cy="-80" r="23" class="front"/>
<circle cx="80" cy="0" r="23" class="front"/>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

+83
View File
@@ -0,0 +1,83 @@
.. Copyright (c) 2016, Johan Mabille and Sylvain Corlay
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
.. _Writing Vectorized Code:
Writing Vectorized Code
=======================
Assume that we have a simple function that computes the mean of two vectors, something like:
.. literalinclude:: ../../test/doc/writing_vectorized_code.cpp
How can we use `xsimd` to take advantage of vectorization?
Explicit Use of an Instruction Set
----------------------------------
`xsimd` provides the template class :cpp:class:`xsimd::batch` parametrized by ``T`` and ``A`` types where ``T`` is the type of the values involved in SIMD
instructions and ``A`` is the target architecture. If you know which instruction set is available on your machine, you can directly use the corresponding specialization
of ``batch``. For instance, assuming the AVX instruction set is available, the previous code can be vectorized the following way:
.. literalinclude:: ../../test/doc/explicit_use_of_an_instruction_set_mean.cpp
Note that the code is written in a form that's independent from the actual
vector register width.
However, if you want to write code that is portable, you cannot rely on the use of ``batch<double, xsimd::avx>``.
Indeed this won't compile on a CPU where only SSE2 instruction set is available for instance. Fortunately, if you don't set the second template parameter, `xsimd` picks the best architecture among the one available, based on the compiler flag you use.
Aligned vs Unaligned Memory
---------------------------
In the previous example, you may have noticed the :cpp:func:`xsimd::batch::load_unaligned` and :cpp:func:`xsimd::batch::store_unaligned` functions. These
are meant for loading values from contiguous dynamically allocated memory into SIMD registers and
reciprocally. When dealing with memory transfer operations, some instructions sets required the memory
to be aligned by a given amount, others can handle both aligned and unaligned modes. In that latter case,
operating on aligned memory is generally faster than operating on unaligned memory.
`xsimd` provides an aligned memory allocator, namely :cpp:class:`xsimd::aligned_allocator` which follows the standard requirements, so it can be used
with STL containers. Let's change the previous code so it can take advantage of this allocator:
.. literalinclude:: ../../test/doc/explicit_use_of_an_instruction_set_mean_aligned.cpp
Memory Alignment and Tag Dispatching
------------------------------------
You may need to write code that can operate on any type of vectors or arrays, not only the STL ones. In that
case, you cannot make assumption on the memory alignment of the container. `xsimd` provides a tag dispatching
mechanism that allows you to easily write such a generic code:
.. literalinclude:: ../../test/doc/explicit_use_of_an_instruction_set_mean_tag_dispatch.cpp
Here, the ``Tag`` template parameter can be :cpp:class:`xsimd::aligned_mode` or :cpp:class:`xsimd::unaligned_mode`. Assuming the existence
of a ``get_alignment_tag`` meta-function in the code, the previous code can be invoked this way:
.. code::
mean(a, b, res, get_alignment_tag<decltype(a)>());
Writing Arch-Independent Code
-----------------------------
If your code may target either SSE2, AVX2 or AVX512 instruction set, `xsimd`
make it possible to make your code even more generic by using the architecture
as a template parameter:
.. literalinclude:: ../../test/doc/explicit_use_of_an_instruction_set_mean_arch_independent.cpp
Then you just need to ``#include`` that file, force instantiation for a specific
architecture and pass the appropriate flag to the compiler. For instance:
.. literalinclude:: ../../test/doc/sum_sse2.cpp
This can be useful to implement runtime dispatching, based on the instruction set detected at runtime. `xsimd` provides a generic machinery :cpp:func:`xsimd::dispatch()` to implement
this pattern. Based on the above example, instead of calling ``mean{}(arch, a, b, res, tag)``, one can use ``xsimd::dispatch(mean{})(a, b, res, tag)``. More about this can be found in the :ref:`Arch Dispatching` section.
+30
View File
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Calque_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 173.4 52.4" style="enable-background:new 0 0 173.4 52.4;" width="554.584222" height="167.590618" xml:space="preserve">
<style type="text/css">
.st0{fill:#D8E448;}
.st1{opacity:0.28;fill:#D8E448;enable-background:new ;}
</style>
<path class="st0" d="M42.8,8.5c0.8-0.3,2.2-0.5,4-0.7v44.6H4.9c0.2,0,0.4-0.1,0.5-0.1c2.5-0.8,4.5-2,4.6-2.1c2-1.3,3.6-3.1,4.9-5.1
c0.4-0.6,5.2-7.8,8.6-12.9c3.4,5.1,8.2,12.3,8.6,12.9c1.2,2,2.9,3.8,4.9,5.1c0,0.1,2.1,1.3,4.6,2.1c0.2,0,0.4,0.1,0.5,0.1h4.8v-2.2
c-1.8-0.2-3.2-0.4-4-0.7c-2-0.6-3.5-1.6-3.5-1.6c-1.5-0.9-2.6-2.1-3.5-3.4c-0.4-0.7-6.6-9.9-10.1-15.3c0,0-0.1-0.1-0.1-0.2
s0.1-0.1,0.1-0.2c3.5-5.3,9.7-14.6,10.1-15.3c0.9-1.3,2-2.5,3.5-3.4C39.2,10.2,40.7,9.2,42.8,8.5z M65.4,30.1
c-4.6-1.3-7.4-2.5-7.4-6.3c0-4.4,3.1-5.7,7-5.7c2.6,0,5,0.4,7.2,1.5l0.9-2C70.5,16.3,67.7,16,65,16c-4.7,0-9.2,2.2-9.2,7.7
s4,7.2,8.7,8.5c4.5,1.2,8.1,2.1,8.1,6.2c0,4.9-3.5,6.5-7.4,6.5c-2.6,0-5.2-0.5-7.4-1.5l-1,1.9c2.5,1.1,5.4,1.6,8.5,1.6
c5.1,0,9.6-2.3,9.6-8.5C74.9,32.8,70.6,31.5,65.4,30.1z M11,44.5c0.4-0.7,6.6-9.9,10.1-15.3c0-0.1,0.1-0.1,0.1-0.2s-0.1-0.1-0.1-0.2
c-3.5-5.3-9.7-14.6-10.1-15.3c-0.9-1.3-2-2.5-3.5-3.4c0,0-1.5-1-3.5-1.6C3.2,8.3,1.8,8,0,7.8v42.4c1.8-0.2,3.2-0.4,4-0.7
c2-0.6,3.5-1.6,3.5-1.6C9,46.9,10.2,45.8,11,44.5z M9.9,7.9c2,1.3,3.6,3.1,4.9,5.1c0.4,0.6,5.2,7.8,8.6,12.9
c3.4-5.1,8.2-12.3,8.6-12.9c1.2-2,2.9-3.8,4.9-5.1c0-0.1,2.1-1.3,4.6-2.1c0.2,0,0.4-0.1,0.5-0.1H5c0.2,0,0.4,0.1,0.5,0.2
C7.8,6.6,9.9,7.8,9.9,7.9z M173.4,0v46.9c-0.8-0.1-1.6-0.3-2.3-0.5v-4c-1.9,3.1-5.2,4.6-10,4.6c-8.9,0-12.4-5-12.4-15.5
S152.2,16,161,16c4.9,0,8.1,1.5,10,4.6V0.5C171.8,0.3,172.6,0.1,173.4,0z M171.1,31.5c0-8-1.7-13.4-10-13.4c-8.4,0-10,5.3-10,13.4
s1.7,13.4,10,13.4C169.4,44.9,171.1,39.6,171.1,31.5z M86.2,47l2.3-1.2V16.5h-2.3V47z M130.4,15.9h-1.3c-5.1,0-7.6,2.5-8.9,5.8
c-1.3-3.4-3.8-5.8-8.9-5.8H110c-8.8,0-10,7.4-10,13.8v15.6c0.7,0.6,1.5,1.1,2.4,1.5V30.5c0-7.3,1.1-12.4,8-12.4h0.6
c6.9,0,8,5.1,8,12.4v14.7l2.4-0.1V30.5c0-7.3,1.1-12.4,8-12.4h0.6c6.9,0,8,5.1,8,12.4V47c0.8-0.4,1.7-0.9,2.4-1.5V29.8
C140.4,23.3,139.1,15.9,130.4,15.9z M86.2,12.3h2.3V9.9h-2.3V12.3z"/>
<path class="st1" d="M46.7,50.2v2.2h-4.8c-0.2,0-0.4-0.1-0.5-0.1c-2.5-0.8-4.5-2-4.6-2.1c-2-1.3-3.6-3.1-4.9-5.1
c-0.4-0.6-5.2-7.8-8.6-12.9c0.8-1.2,1.5-2.3,2.1-3.1c0,0.1,0.1,0.1,0.1,0.2c3.5,5.3,9.7,14.6,10.1,15.3c0.9,1.3,2,2.5,3.5,3.4
c0,0,1.5,1,3.5,1.6C43.5,49.7,44.9,50,46.7,50.2z M9.9,7.9c0-0.1-2.1-1.3-4.6-2.1C5.2,5.7,5,5.7,4.8,5.7H0v2.2C1.8,8,3.2,8.3,4,8.5
c2,0.6,3.5,1.6,3.5,1.6C9,11,10.1,12.2,11,13.5c0.4,0.7,6.6,9.9,10.1,15.3c0,0.1,0.1,0.1,0.1,0.2c0.6-0.8,1.3-1.9,2.1-3.1
c-3.4-5.1-8.2-12.3-8.6-12.9C13.5,11,11.9,9.2,9.9,7.9z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

+7
View File
@@ -0,0 +1,7 @@
name: xsimd
channels:
- conda-forge
dependencies:
- ninja
- xtl
- doctest
+44
View File
@@ -0,0 +1,44 @@
############################################################################
# Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and #
# Martin Renou #
# Copyright (c) QuantStack #
# Copyright (c) Serge Guelton #
# #
# Distributed under the terms of the BSD 3-Clause License. #
# #
# The full license is in the file LICENSE, distributed with this software. #
############################################################################
cmake_minimum_required(VERSION 3.10)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
project(xsimd-examples)
find_package(xsimd REQUIRED CONFIG)
set(XSIMD_INCLUDE_DIR ${xsimd_INCLUDE_DIR})
endif ()
include_directories(${XSIMD_INCLUDE_DIR})
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting examples build type to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
else()
message(STATUS "Tests build type is ${CMAKE_BUILD_TYPE}")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
if (NOT CMAKE_CXX_FLAGS MATCHES "-march" AND NOT CMAKE_CXX_FLAGS MATCHES "-arch" AND NOT CMAKE_OSX_ARCHITECTURES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mtune=native")
endif()
if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) # We are using clang-cl
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif()
endif()
add_executable(mandelbrot mandelbrot.cpp ${XSIMD_HEADERS})
set_property(TARGET mandelbrot PROPERTY CXX_STANDARD 14)
if(ENABLE_XTL_COMPLEX)
target_link_libraries(mandelbrot PRIVATE xtl)
endif()
add_custom_target(xmandelbrot COMMAND mandelbrot DEPENDS mandelbrot)
+330
View File
@@ -0,0 +1,330 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
// This file is derived from tsimd (MIT License)
// https://github.com/ospray/tsimd/blob/master/benchmarks/mandelbrot.cpp
// Author Jefferson Amstutz / intel
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include "pico_bench.hpp"
#include <xsimd/xsimd.hpp>
// helper function to write the rendered image as PPM file
inline void writePPM(const std::string& fileName,
const int sizeX,
const int sizeY,
const int* pixel)
{
FILE* file = fopen(fileName.c_str(), "wb");
fprintf(file, "P6\n%i %i\n255\n", sizeX, sizeY);
unsigned char* out = (unsigned char*)alloca(3 * sizeX);
for (int y = 0; y < sizeY; y++)
{
const unsigned char* in = (const unsigned char*)&pixel[(sizeY - 1 - y) * sizeX];
for (int x = 0; x < sizeX; x++)
{
out[3 * x + 0] = in[4 * x + 0];
out[3 * x + 1] = in[4 * x + 1];
out[3 * x + 2] = in[4 * x + 2];
}
fwrite(out, 3 * sizeX, sizeof(char), file);
}
fprintf(file, "\n");
fclose(file);
}
namespace xsimd
{
template <class arch>
inline batch<int, arch> mandel(const batch_bool<float, arch>& _active,
const batch<float, arch>& c_re,
const batch<float, arch>& c_im,
int maxIters)
{
using float_batch_type = batch<float, arch>;
using int_batch_type = batch<int, arch>;
constexpr std::size_t N = float_batch_type::size;
float_batch_type z_re = c_re;
float_batch_type z_im = c_im;
int_batch_type vi(0);
for (int i = 0; i < maxIters; ++i)
{
auto active = _active & ((z_re * z_re + z_im * z_im) <= float_batch_type(4.f));
if (!xsimd::any(active))
{
break;
}
float_batch_type new_re = z_re * z_re - z_im * z_im;
float_batch_type new_im = 2.f * z_re * z_im;
z_re = c_re + new_re;
z_im = c_im + new_im;
vi = select(batch_bool_cast<int>(active), vi + 1, vi);
}
return vi;
}
template <class arch>
void mandelbrot(float x0,
float y0,
float x1,
float y1,
int width,
int height,
int maxIters,
int output[])
{
using float_batch_type = batch<float, arch>;
using int_batch_type = batch<int, arch>;
constexpr std::size_t N = float_batch_type::size;
float dx = (x1 - x0) / width;
float dy = (y1 - y0) / height;
float arange[N];
std::iota(&arange[0], &arange[N], 0.f);
// float_batch_type programIndex(&arange[0], xsimd::aligned_mode());
auto programIndex = float_batch_type::load(&arange[0], xsimd::aligned_mode());
// std::iota(programIndex.begin(), programIndex.end(), 0.f);
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i += N)
{
float_batch_type x(x0 + (i + programIndex) * dx);
float_batch_type y(y0 + j * dy);
auto active = x < float_batch_type(width);
int base_index = (j * width + i);
auto result = mandel<arch>(active, x, y, maxIters);
// implement masked store!
// xsimd::store_aligned(result, output + base_index, active);
int_batch_type prev_data = int_batch_type::load_unaligned(output + base_index);
select(batch_bool_cast<int>(active), result, prev_data)
.store_aligned(output + base_index);
}
}
}
} // namespace xsimd
// omp version ////////////////////////////////////////////////////////////////
namespace omp
{
#pragma omp declare simd
template <typename T>
inline int mandel(T c_re, T c_im, int count)
{
T z_re = c_re, z_im = c_im;
int i;
for (i = 0; i < count; ++i)
{
if (z_re * z_re + z_im * z_im > 4.f)
{
break;
}
T new_re = z_re * z_re - z_im * z_im;
T new_im = 2.f * z_re * z_im;
z_re = c_re + new_re;
z_im = c_im + new_im;
}
return i;
}
void mandelbrot(float x0, float y0, float x1, float y1, int width,
int height, int maxIterations, int output[])
{
float dx = (x1 - x0) / width;
float dy = (y1 - y0) / height;
for (int j = 0; j < height; j++)
{
#pragma omp simd
for (int i = 0; i < width; ++i)
{
float x = x0 + i * dx;
float y = y0 + j * dy;
int index = (j * width + i);
output[index] = mandel<float>(x, y, maxIterations);
}
}
}
} // namespace omp
// scalar version /////////////////////////////////////////////////////////////
namespace scalar
{
inline int mandel(float c_re, float c_im, int count)
{
float z_re = c_re, z_im = c_im;
int i;
for (i = 0; i < count; ++i)
{
if (z_re * z_re + z_im * z_im > 4.f)
{
break;
}
float new_re = z_re * z_re - z_im * z_im;
float new_im = 2.f * z_re * z_im;
z_re = c_re + new_re;
z_im = c_im + new_im;
}
return i;
}
void mandelbrot(float x0, float y0, float x1, float y1,
int width, int height, int maxIterations, int output[])
{
float dx = (x1 - x0) / width;
float dy = (y1 - y0) / height;
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; ++i)
{
float x = x0 + i * dx;
float y = y0 + j * dy;
int index = (j * width + i);
output[index] = mandel(x, y, maxIterations);
}
}
}
} // namespace scalar
// run simd version of mandelbrot benchmark for a specific arch
template <class arch, class bencher_t, size_t Align>
void run_arch(
bencher_t& bencher,
float x0,
float y0,
float x1,
float y1,
int width,
int height,
int maxIters,
std::vector<int, xsimd::aligned_allocator<int, Align>>& buffer)
{
std::fill(buffer.begin(), buffer.end(), 0);
auto stats = bencher([&]()
{ xsimd::mandelbrot<arch>(x0, y0, x1, y1, width, height, maxIters, buffer.data()); });
const float scalar_min = stats.min().count();
std::cout << '\n'
<< arch::name() << " " << stats << '\n';
auto filename = std::string("mandelbrot_") + std::string(arch::name()) + std::string(".ppm");
writePPM(filename.c_str(), width, height, buffer.data());
}
template <class T>
struct run_archlist;
// run simd version of mandelbrot benchmark for a list
// of archs
template <class... Arch>
struct run_archlist<xsimd::arch_list<Arch...>>
{
template <class bencher_t, size_t Align>
static void run(
bencher_t& bencher,
float x0,
float y0,
float x1,
float y1,
int width,
int height,
int maxIters,
std::vector<int, xsimd::aligned_allocator<int, Align>>& buffer)
{
(void)std::initializer_list<int> { (run_arch<Arch>(bencher, x0, y0, x1, x1, width, height, maxIters, buffer), 0)... };
}
};
int main()
{
using namespace std::chrono;
const unsigned int width = 1024;
const unsigned int height = 768;
const float x0 = -2;
const float x1 = 1;
const float y0 = -1;
const float y1 = 1;
const int maxIters = 256;
std::vector<int, xsimd::aligned_allocator<int>> buf(width * height);
auto bencher = pico_bench::Benchmarker<milliseconds> { 64, seconds { 10 } };
std::cout << "starting benchmarks (results in 'ms')... " << '\n';
// scalar run ///////////////////////////////////////////////////////////////
std::fill(buf.begin(), buf.end(), 0);
auto stats_scalar = bencher([&]()
{ scalar::mandelbrot(x0, y0, x1, y1, width, height, maxIters, buf.data()); });
const float scalar_min = stats_scalar.min().count();
std::cout << '\n'
<< "scalar " << stats_scalar << '\n';
writePPM("mandelbrot_scalar.ppm", width, height, buf.data());
// omp run //////////////////////////////////////////////////////////////////
std::fill(buf.begin(), buf.end(), 0);
auto stats_omp = bencher([&]()
{ omp::mandelbrot(x0, y0, x1, y1, width, height, maxIters, buf.data()); });
const float omp_min = stats_omp.min().count();
std::cout << '\n'
<< "omp " << stats_omp << '\n';
writePPM("mandelbrot_omp.ppm", width, height, buf.data());
run_archlist<xsimd::supported_architectures>::run(bencher, x0, y0, x1, y1, width, height, maxIters, buf);
return 0;
}
+246
View File
@@ -0,0 +1,246 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
// This file is derived from tsimd (MIT License)
// https://github.com/ospray/tsimd/blob/master/benchmarks/pico_bench.h
// Author Jefferson Amstutz / intel
#ifndef PICO_BENCH_H
#define PICO_BENCH_H
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <iterator>
#include <numeric>
#include <ostream>
#include <type_traits>
#include <utility>
#include <vector>
namespace pico_bench
{
/* Statistics on some time measurement value T, e.g. T =
* std::chrono::milliseconds T must be some std::chrono::duration type
*/
template <typename T>
class Statistics
{
using rep = typename T::rep;
std::vector<T> samples;
public:
std::string time_suffix;
Statistics(std::vector<T> s)
: samples(s)
{
std::sort(std::begin(samples), std::end(samples));
}
T percentile(const float p) const
{
return percentile(p, samples);
}
// Winsorize the data, sets all entries above 100 - limit percentile and
// below limit percentile to the value of that percentile
void winsorize(const float limit)
{
winsorize(limit, samples);
}
T median() const
{
return percentile(50.0, samples);
}
T median_abs_dev() const
{
const auto m = median();
std::vector<T> deviations;
deviations.reserve(samples.size());
std::transform(std::begin(samples),
std::end(samples),
std::back_inserter(deviations),
[&m](const T& t)
{ return T { std::abs((t - m).count()) }; });
std::sort(std::begin(deviations), std::end(deviations));
return percentile(50.0, deviations);
}
T mean() const
{
const auto m = std::accumulate(std::begin(samples), std::end(samples), T { 0 });
return m / samples.size();
}
T std_dev() const
{
const auto m = mean();
auto val = std::accumulate(
std::begin(samples), std::end(samples), T { 0 }, [&m](const T& p, const T& t)
{ return T { static_cast<rep>(p.count() + std::pow((t - m).count(), 2)) }; });
return T { static_cast<rep>(std::sqrt(1.0 / static_cast<double>(samples.size())
* static_cast<double>(val.count()))) };
}
T min() const
{
return samples.front();
}
T max() const
{
return samples.back();
}
std::size_t size() const
{
return samples.size();
}
const T& operator[](size_t i) const
{
return samples[i];
}
private:
// Winsorize the data, sets all entries above 100 - limit percentile and
// below limit percentile to the value of that percentile
static void winsorize(const float limit, std::vector<T>& samples)
{
const auto low = percentile(limit, samples);
const auto high = percentile(100.0 - limit, samples);
for (auto& t : samples)
{
if (t < low)
{
t = low;
}
else if (t > high)
{
t = high;
}
}
}
static T percentile(const float p, const std::vector<T>& samples)
{
assert(!samples.empty());
assert(p <= 100.0);
assert(p >= 0.0);
if (samples.size() == 1)
{
return samples.front();
}
if (p == 100.0)
{
return samples.back();
}
const double rank = p / 100.0 * (static_cast<double>(samples.size()) - 1.0);
const double low_r = std::floor(rank);
const double dist = rank - low_r;
const size_t k = static_cast<size_t>(low_r);
const auto low = samples[k];
const auto high = samples[k + 1];
return T { static_cast<rep>(low.count() + (high - low).count() * dist) };
}
};
/* Benchmarking measurment using some desired unit of time measurement,
* e.g. T = std::chrono::milliseconds. T must be some std::chrono::duration
*/
template <typename T>
class Benchmarker
{
const size_t MAX_ITER;
const T MAX_RUNTIME;
template <typename Fn>
struct BenchWrapper
{
Fn fn;
BenchWrapper(Fn fn)
: fn(fn)
{
}
T operator()()
{
auto start = std::chrono::high_resolution_clock::now();
fn();
auto end = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<T>(end - start);
}
};
public:
using stats_type = Statistics<T>;
// Benchmark the functions either max_iter times or until max_runtime
// seconds have elapsed max_runtime should be > 0
Benchmarker(const size_t max_iter, const std::chrono::seconds max_runtime)
: MAX_ITER(max_iter)
, MAX_RUNTIME(std::chrono::duration_cast<T>(max_runtime))
{
}
// Create a benchmarker that will run the function for the desired number of
// iterations, regardless of how long it takes
Benchmarker(const size_t max_iter)
: MAX_ITER(max_iter)
, MAX_RUNTIME(0)
{
}
template <typename Fn>
typename std::enable_if<std::is_void<decltype(std::declval<Fn>()())>::value,
stats_type>::type
operator()(Fn fn) const
{
return (*this)(BenchWrapper<Fn> { fn });
}
template <typename Fn>
typename std::enable_if<std::is_same<decltype(std::declval<Fn>()()), T>::value,
stats_type>::type
operator()(Fn fn) const
{
// Do a single un-timed warm up run
fn();
T elapsed { 0 };
std::vector<T> samples;
for (size_t i = 0; i < MAX_ITER && (MAX_RUNTIME.count() == 0 || elapsed < MAX_RUNTIME);
++i, elapsed += samples.back())
{
samples.push_back(fn());
}
return stats_type { samples };
}
};
} // namespace pico_bench
template <typename T>
std::ostream&
operator<<(std::ostream& os, const pico_bench::Statistics<T>& stats)
{
os << "Statistics:\n"
<< "\tmax: " << stats.max().count() << stats.time_suffix << "\n"
<< "\tmin: " << stats.min().count() << stats.time_suffix << "\n"
<< "\tmedian: " << stats.median().count() << stats.time_suffix << "\n"
<< "\tmedian abs dev: " << stats.median_abs_dev().count() << stats.time_suffix << "\n"
<< "\tmean: " << stats.mean().count() << stats.time_suffix << "\n"
<< "\tstd dev: " << stats.std_dev().count() << stats.time_suffix << "\n"
<< "\t# of samples: " << stats.size();
return os;
}
#endif
@@ -0,0 +1,267 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_COMMON_ARITHMETIC_HPP
#define XSIMD_COMMON_ARITHMETIC_HPP
#include <complex>
#include <limits>
#include <type_traits>
#include "../../types/xsimd_batch_constant.hpp"
#include "./xsimd_common_details.hpp"
namespace xsimd
{
namespace kernel
{
using namespace types;
// bitwise_lshift
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value>::type*/>
XSIMD_INLINE batch<T, A> bitwise_lshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return detail::apply([](T x, T y) noexcept
{ return x << y; },
self, other);
}
template <size_t shift, class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value>::type*/>
XSIMD_INLINE batch<T, A> bitwise_lshift(batch<T, A> const& self, requires_arch<common>) noexcept
{
constexpr auto bits = std::numeric_limits<T>::digits + std::numeric_limits<T>::is_signed;
static_assert(shift < bits, "Shift must be less than the number of bits in T");
return bitwise_lshift(self, shift, A {});
}
// bitwise_rshift
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value>::type*/>
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return detail::apply([](T x, T y) noexcept
{ return x >> y; },
self, other);
}
template <size_t shift, class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value>::type*/>
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, requires_arch<common>) noexcept
{
constexpr auto bits = std::numeric_limits<T>::digits + std::numeric_limits<T>::is_signed;
static_assert(shift < bits, "Shift must be less than the number of bits in T");
return bitwise_rshift(self, shift, A {});
}
// decr
template <class A, class T>
XSIMD_INLINE batch<T, A> decr(batch<T, A> const& self, requires_arch<common>) noexcept
{
return self - T(1);
}
// decr_if
template <class A, class T, class Mask>
XSIMD_INLINE batch<T, A> decr_if(batch<T, A> const& self, Mask const& mask, requires_arch<common>) noexcept
{
return select(mask, decr(self), self);
}
// div
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> div(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return detail::apply([](T x, T y) noexcept -> T
{ return x / y; },
self, other);
}
// fma
template <class A, class T>
XSIMD_INLINE batch<T, A> fma(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<common>) noexcept
{
return x * y + z;
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> fma(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<common>) noexcept
{
auto res_r = fms(x.real(), y.real(), fms(x.imag(), y.imag(), z.real()));
auto res_i = fma(x.real(), y.imag(), fma(x.imag(), y.real(), z.imag()));
return { res_r, res_i };
}
// fms
template <class A, class T>
XSIMD_INLINE batch<T, A> fms(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<common>) noexcept
{
return x * y - z;
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> fms(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<common>) noexcept
{
auto res_r = fms(x.real(), y.real(), fma(x.imag(), y.imag(), z.real()));
auto res_i = fma(x.real(), y.imag(), fms(x.imag(), y.real(), z.imag()));
return { res_r, res_i };
}
// fnma
template <class A, class T>
XSIMD_INLINE batch<T, A> fnma(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<common>) noexcept
{
return -x * y + z;
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> fnma(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<common>) noexcept
{
auto res_r = -fms(x.real(), y.real(), fma(x.imag(), y.imag(), z.real()));
auto res_i = -fma(x.real(), y.imag(), fms(x.imag(), y.real(), z.imag()));
return { res_r, res_i };
}
// fnms
template <class A, class T>
XSIMD_INLINE batch<T, A> fnms(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<common>) noexcept
{
return -x * y - z;
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> fnms(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<common>) noexcept
{
auto res_r = -fms(x.real(), y.real(), fms(x.imag(), y.imag(), z.real()));
auto res_i = -fma(x.real(), y.imag(), fma(x.imag(), y.real(), z.imag()));
return { res_r, res_i };
}
// fmas
template <class A, class T>
XSIMD_INLINE batch<T, A> fmas(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<common>) noexcept
{
struct even_lane
{
static constexpr bool get(unsigned const i, unsigned) noexcept { return (i & 1u) == 0; }
};
const auto mask = make_batch_bool_constant<T, even_lane, A>();
return fma(x, y, select(mask, neg(z), z));
}
// incr
template <class A, class T>
XSIMD_INLINE batch<T, A> incr(batch<T, A> const& self, requires_arch<common>) noexcept
{
return self + T(1);
}
// incr_if
template <class A, class T, class Mask>
XSIMD_INLINE batch<T, A> incr_if(batch<T, A> const& self, Mask const& mask, requires_arch<common>) noexcept
{
return select(mask, incr(self), self);
}
// mul
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value>::type*/>
XSIMD_INLINE batch<T, A> mul(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return detail::apply([](T x, T y) noexcept -> T
{ return x * y; },
self, other);
}
// rotl
template <class A, class T, class STy>
XSIMD_INLINE batch<T, A> rotl(batch<T, A> const& self, STy other, requires_arch<common>) noexcept
{
constexpr auto bits = std::numeric_limits<T>::digits + std::numeric_limits<T>::is_signed;
return (self << other) | (self >> (bits - other));
}
template <size_t count, class A, class T>
XSIMD_INLINE batch<T, A> rotl(batch<T, A> const& self, requires_arch<common>) noexcept
{
constexpr auto bits = std::numeric_limits<T>::digits + std::numeric_limits<T>::is_signed;
static_assert(count < bits, "Count amount must be less than the number of bits in T");
return bitwise_lshift<count>(self) | bitwise_rshift<bits - count>(self);
}
// rotr
template <class A, class T, class STy>
XSIMD_INLINE batch<T, A> rotr(batch<T, A> const& self, STy other, requires_arch<common>) noexcept
{
constexpr auto bits = std::numeric_limits<T>::digits + std::numeric_limits<T>::is_signed;
return (self >> other) | (self << (bits - other));
}
template <size_t count, class A, class T>
XSIMD_INLINE batch<T, A> rotr(batch<T, A> const& self, requires_arch<common>) noexcept
{
constexpr auto bits = std::numeric_limits<T>::digits + std::numeric_limits<T>::is_signed;
static_assert(count < bits, "Count must be less than the number of bits in T");
return bitwise_rshift<count>(self) | bitwise_lshift<bits - count>(self);
}
// sadd
template <class A>
XSIMD_INLINE batch<float, A> sadd(batch<float, A> const& self, batch<float, A> const& other, requires_arch<common>) noexcept
{
return add(self, other); // no saturated arithmetic on floating point numbers
}
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value>::type*/>
XSIMD_INLINE batch<T, A> sadd(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
if (std::is_signed<T>::value)
{
auto self_pos_branch = min(std::numeric_limits<T>::max() - other, self);
auto self_neg_branch = max(std::numeric_limits<T>::min() - other, self);
return other + select(other >= 0, self_pos_branch, self_neg_branch);
}
else
{
const auto diffmax = std::numeric_limits<T>::max() - self;
const auto mindiff = min(diffmax, other);
return self + mindiff;
}
}
template <class A>
XSIMD_INLINE batch<double, A> sadd(batch<double, A> const& self, batch<double, A> const& other, requires_arch<common>) noexcept
{
return add(self, other); // no saturated arithmetic on floating point numbers
}
// ssub
template <class A>
XSIMD_INLINE batch<float, A> ssub(batch<float, A> const& self, batch<float, A> const& other, requires_arch<common>) noexcept
{
return sub(self, other); // no saturated arithmetic on floating point numbers
}
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value>::type*/>
XSIMD_INLINE batch<T, A> ssub(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
if (std::is_signed<T>::value)
{
return sadd(self, -other);
}
else
{
const auto diff = min(self, other);
return self - diff;
}
}
template <class A>
XSIMD_INLINE batch<double, A> ssub(batch<double, A> const& self, batch<double, A> const& other, requires_arch<common>) noexcept
{
return sub(self, other); // no saturated arithmetic on floating point numbers
}
}
}
#endif
@@ -0,0 +1,40 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_COMMON_CAST_HPP
#define XSIMD_COMMON_CAST_HPP
#include "../../types/xsimd_traits.hpp"
namespace xsimd
{
namespace kernel
{
template <class A, class T>
XSIMD_INLINE std::array<batch<widen_t<T>, A>, 2> widen(batch<T, A> const& x, requires_arch<common>) noexcept
{
alignas(A::alignment()) T buffer[batch<T, A>::size];
x.store_aligned(&buffer[0]);
using T_out = widen_t<T>;
alignas(A::alignment()) T_out out_buffer[batch<T, A>::size];
for (size_t i = 0; i < batch<T, A>::size; ++i)
out_buffer[i] = static_cast<T_out>(buffer[i]);
return { batch<T_out, A>::load_aligned(&out_buffer[0]),
batch<T_out, A>::load_aligned(&out_buffer[batch<T_out, A>::size]) };
}
}
}
#endif
@@ -0,0 +1,112 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_COMMON_COMPLEX_HPP
#define XSIMD_COMMON_COMPLEX_HPP
#include <complex>
#include "./xsimd_common_details.hpp"
namespace xsimd
{
namespace kernel
{
using namespace types;
// real
template <class A, class T>
XSIMD_INLINE batch<T, A> real(batch<T, A> const& self, requires_arch<common>) noexcept
{
return self;
}
template <class A, class T>
XSIMD_INLINE batch<T, A> real(batch<std::complex<T>, A> const& self, requires_arch<common>) noexcept
{
return self.real();
}
// imag
template <class A, class T>
XSIMD_INLINE batch<T, A> imag(batch<T, A> const& /*self*/, requires_arch<common>) noexcept
{
return batch<T, A>(T(0));
}
template <class A, class T>
XSIMD_INLINE batch<T, A> imag(batch<std::complex<T>, A> const& self, requires_arch<common>) noexcept
{
return self.imag();
}
// arg
template <class A, class T>
XSIMD_INLINE real_batch_type_t<batch<T, A>> arg(batch<T, A> const& self, requires_arch<common>) noexcept
{
return atan2(imag(self), real(self));
}
// conj
template <class A, class T>
XSIMD_INLINE complex_batch_type_t<batch<T, A>> conj(batch<T, A> const& self, requires_arch<common>) noexcept
{
return { real(self), -imag(self) };
}
// norm
template <class A, class T>
XSIMD_INLINE real_batch_type_t<batch<T, A>> norm(batch<T, A> const& self, requires_arch<common>) noexcept
{
return { fma(real(self), real(self), imag(self) * imag(self)) };
}
// proj
template <class A, class T>
XSIMD_INLINE complex_batch_type_t<batch<T, A>> proj(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = complex_batch_type_t<batch<T, A>>;
using real_batch = typename batch_type::real_batch;
using real_value_type = typename real_batch::value_type;
#ifdef __FAST_MATH__
return { self };
#else
auto cond = xsimd::isinf(real(self)) || xsimd::isinf(imag(self));
return select(cond,
batch_type(constants::infinity<real_batch>(),
copysign(real_batch(real_value_type(0)), imag(self))),
batch_type(self));
#endif
}
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> isnan(batch<std::complex<T>, A> const& self, requires_arch<common>) noexcept
{
return batch_bool<T, A>(isnan(self.real()) || isnan(self.imag()));
}
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> isinf(batch<std::complex<T>, A> const& self, requires_arch<common>) noexcept
{
return batch_bool<T, A>(isinf(self.real()) || isinf(self.imag()));
}
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> isfinite(batch<std::complex<T>, A> const& self, requires_arch<common>) noexcept
{
return batch_bool<T, A>(isfinite(self.real()) && isfinite(self.imag()));
}
}
}
#endif
@@ -0,0 +1,323 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_COMMON_DETAILS_HPP
#define XSIMD_COMMON_DETAILS_HPP
#include <complex>
#include "../../math/xsimd_rem_pio2.hpp"
#include "../../types/xsimd_common_arch.hpp"
#include "../../types/xsimd_utils.hpp"
#include "../xsimd_constants.hpp"
namespace xsimd
{
// Forward declaration. Should we put them in a separate file?
template <class T, class A>
XSIMD_INLINE batch<T, A> abs(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> abs(batch<std::complex<T>, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE bool any(batch_bool<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> atan2(batch<T, A> const& self, batch<T, A> const& other) noexcept;
template <class A, class T_out, class T_in>
XSIMD_INLINE batch<T_out, A> batch_cast(batch<T_in, A> const&, batch<T_out, A> const& out) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> bitofsign(batch<T, A> const& self) noexcept;
template <class T_out, class T_in, class A>
XSIMD_INLINE batch<T_out, A> bitwise_cast(batch<T_in, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> cos(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> cosh(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> exp(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> fma(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> fms(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> fmas(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> frexp(const batch<T, A>& x, const batch<as_integer_t<T>, A>& e) noexcept;
template <class T, class A, uint64_t... Coefs>
XSIMD_INLINE batch<T, A> horner(const batch<T, A>& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> hypot(const batch<T, A>& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch_bool<T, A> is_even(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch_bool<T, A> is_flint(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch_bool<T, A> is_odd(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE typename batch<T, A>::batch_bool_type isinf(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE typename batch<T, A>::batch_bool_type isfinite(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE typename batch<T, A>::batch_bool_type isnan(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> ldexp(const batch<T, A>& x, const batch<as_integer_t<T>, A>& e) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> log(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> nearbyint(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<as_integer_t<T>, A> nearbyint_as_int(const batch<T, A>& x) noexcept;
template <class T, class A>
XSIMD_INLINE T reduce_add(batch<T, A> const&) noexcept;
template <class T, class A>
XSIMD_INLINE T reduce_mul(batch<T, A> const&) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> select(batch_bool<T, A> const&, batch<T, A> const&, batch<T, A> const&) noexcept;
template <class T, class A>
XSIMD_INLINE batch<std::complex<T>, A> select(batch_bool<T, A> const&, batch<std::complex<T>, A> const&, batch<std::complex<T>, A> const&) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> sign(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> signnz(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> sin(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> sinh(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE std::pair<batch<T, A>, batch<T, A>> sincos(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> sqrt(batch<T, A> const& self) noexcept;
template <class T, class A, class Vt, Vt... Values>
XSIMD_INLINE typename std::enable_if<std::is_arithmetic<T>::value, batch<T, A>>::type
swizzle(batch<T, A> const& x, batch_constant<Vt, A, Values...> mask) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> tan(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<as_float_t<T>, A> to_float(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<as_integer_t<T>, A> to_int(batch<T, A> const& self) noexcept;
template <class T, class A>
XSIMD_INLINE batch<T, A> trunc(batch<T, A> const& self) noexcept;
namespace kernel
{
namespace detail
{
template <class F, class A, class T, class... Batches>
XSIMD_INLINE batch<T, A> apply(F&& func, batch<T, A> const& self, batch<T, A> const& other) noexcept
{
constexpr std::size_t size = batch<T, A>::size;
alignas(A::alignment()) T self_buffer[size];
alignas(A::alignment()) T other_buffer[size];
self.store_aligned(&self_buffer[0]);
other.store_aligned(&other_buffer[0]);
for (std::size_t i = 0; i < size; ++i)
{
self_buffer[i] = func(self_buffer[i], other_buffer[i]);
}
return batch<T, A>::load_aligned(self_buffer);
}
template <class U, class F, class A, class T>
XSIMD_INLINE batch<U, A> apply_transform(F&& func, batch<T, A> const& self) noexcept
{
static_assert(batch<T, A>::size == batch<U, A>::size,
"Source and destination sizes must match");
constexpr std::size_t src_size = batch<T, A>::size;
constexpr std::size_t dest_size = batch<U, A>::size;
alignas(A::alignment()) T self_buffer[src_size];
alignas(A::alignment()) U other_buffer[dest_size];
self.store_aligned(&self_buffer[0]);
for (std::size_t i = 0; i < src_size; ++i)
{
other_buffer[i] = func(self_buffer[i]);
}
return batch<U, A>::load_aligned(other_buffer);
}
}
// some common fast_cast conversion
namespace detail
{
template <class A>
XSIMD_INLINE batch<uint8_t, A> fast_cast(batch<int8_t, A> const& self, batch<uint8_t, A> const&, requires_arch<common>) noexcept
{
return bitwise_cast<uint8_t>(self);
}
template <class A>
XSIMD_INLINE batch<uint16_t, A> fast_cast(batch<int16_t, A> const& self, batch<uint16_t, A> const&, requires_arch<common>) noexcept
{
return bitwise_cast<uint16_t>(self);
}
template <class A>
XSIMD_INLINE batch<uint32_t, A> fast_cast(batch<int32_t, A> const& self, batch<uint32_t, A> const&, requires_arch<common>) noexcept
{
return bitwise_cast<uint32_t>(self);
}
template <class A>
XSIMD_INLINE batch<uint64_t, A> fast_cast(batch<int64_t, A> const& self, batch<uint64_t, A> const&, requires_arch<common>) noexcept
{
return bitwise_cast<uint64_t>(self);
}
template <class A>
XSIMD_INLINE batch<int8_t, A> fast_cast(batch<uint8_t, A> const& self, batch<int8_t, A> const&, requires_arch<common>) noexcept
{
return bitwise_cast<int8_t>(self);
}
template <class A>
XSIMD_INLINE batch<int16_t, A> fast_cast(batch<uint16_t, A> const& self, batch<int16_t, A> const&, requires_arch<common>) noexcept
{
return bitwise_cast<int16_t>(self);
}
template <class A>
XSIMD_INLINE batch<int32_t, A> fast_cast(batch<uint32_t, A> const& self, batch<int32_t, A> const&, requires_arch<common>) noexcept
{
return bitwise_cast<int32_t>(self);
}
template <class A>
XSIMD_INLINE batch<int64_t, A> fast_cast(batch<uint64_t, A> const& self, batch<int64_t, A> const&, requires_arch<common>) noexcept
{
return bitwise_cast<int64_t>(self);
}
// Provide a common uint32_t -> float cast only if we have a
// non-common int32_t -> float fast_cast
template <class A, class = decltype(fast_cast(std::declval<batch<int32_t, A> const&>(), std::declval<batch<float, A> const&>(), A {}))>
XSIMD_INLINE batch<float, A> fast_cast(batch<uint32_t, A> const& v, batch<float, A> const&, requires_arch<common>) noexcept
{
// see https://stackoverflow.com/questions/34066228/how-to-perform-uint32-float-conversion-with-sse
batch<uint32_t, A> msk_lo(0xFFFF);
batch<float, A> cnst65536f(65536.0f);
auto v_lo = batch_cast<int32_t>(v & msk_lo); /* extract the 16 lowest significant bits of self */
auto v_hi = batch_cast<int32_t>(v >> 16); /* 16 most significant bits of v */
auto v_lo_flt = batch_cast<float>(v_lo); /* No rounding */
auto v_hi_flt = batch_cast<float>(v_hi); /* No rounding */
v_hi_flt = cnst65536f * v_hi_flt; /* No rounding */
return v_hi_flt + v_lo_flt; /* Rounding may occur here, mul and add may fuse to fma for haswell and newer */
}
// Provide a common float -> uint32_t cast only if we have a
// non-common float -> int32_t fast_cast
template <class A, class = decltype(fast_cast(std::declval<batch<float, A> const&>(), std::declval<batch<int32_t, A> const&>(), A {}))>
XSIMD_INLINE batch<uint32_t, A> fast_cast(batch<float, A> const& v, batch<uint32_t, A> const&, requires_arch<common>) noexcept
{
auto is_large = v >= batch<float, A>(1u << 31);
auto small_v = bitwise_cast<float>(batch_cast<int32_t>(v));
auto large_v = bitwise_cast<float>(
batch_cast<int32_t>(v - batch<float, A>(1u << 31))
^ batch<int32_t, A>(1u << 31));
return bitwise_cast<uint32_t>(select(is_large, large_v, small_v));
}
}
namespace detail
{
// Generic conversion handling machinery. Each architecture must define
// conversion function when such conversions exits in the form of
// intrinsic. Then we use that information to automatically decide whether
// to use scalar or vector conversion when doing load / store / batch_cast
struct with_fast_conversion
{
};
struct with_slow_conversion
{
};
template <class A, class From, class To, class = void>
struct conversion_type_impl
{
using type = with_slow_conversion;
};
using xsimd::detail::void_t;
template <class A, class From, class To>
struct conversion_type_impl<A, From, To,
void_t<decltype(fast_cast(std::declval<const batch<From, A>&>(),
std::declval<const batch<To, A>&>(),
std::declval<const A&>()))>>
{
using type = with_fast_conversion;
};
template <class A, class From, class To>
using conversion_type = typename conversion_type_impl<A, From, To>::type;
}
namespace detail
{
/* origin: boost/simdfunction/horn.hpp*/
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class B, uint64_t c>
XSIMD_INLINE B coef() noexcept
{
using value_type = typename B::value_type;
return B(bit_cast<value_type>(as_unsigned_integer_t<value_type>(c)));
}
template <class B>
XSIMD_INLINE B horner(const B&) noexcept
{
return B(typename B::value_type(0.));
}
template <class B, uint64_t c0>
XSIMD_INLINE B horner(const B&) noexcept
{
return coef<B, c0>();
}
template <class B, uint64_t c0, uint64_t c1, uint64_t... args>
XSIMD_INLINE B horner(const B& self) noexcept
{
return fma(self, horner<B, c1, args...>(self), coef<B, c0>());
}
/* origin: boost/simdfunction/horn1.hpp*/
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class B>
XSIMD_INLINE B horner1(const B&) noexcept
{
return B(1.);
}
template <class B, uint64_t c0>
XSIMD_INLINE B horner1(const B& x) noexcept
{
return x + detail::coef<B, c0>();
}
template <class B, uint64_t c0, uint64_t c1, uint64_t... args>
XSIMD_INLINE B horner1(const B& x) noexcept
{
return fma(x, horner1<B, c1, args...>(x), detail::coef<B, c0>());
}
}
}
}
#endif
@@ -0,0 +1,247 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_COMMON_LOGICAL_HPP
#define XSIMD_COMMON_LOGICAL_HPP
#include "./xsimd_common_details.hpp"
#include <climits>
namespace xsimd
{
namespace kernel
{
using namespace types;
// count
template <class A, class T>
XSIMD_INLINE size_t count(batch_bool<T, A> const& self, requires_arch<common>) noexcept
{
uint64_t m = self.mask();
XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size < 14)
{
// https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSet64
return (m * 0x200040008001ULL & 0x111111111111111ULL) % 0xf;
}
else
{
#if defined __has_builtin
#if __has_builtin(__builtin_popcountg)
#define builtin_popcount(v) __builtin_popcountg(v)
#endif
#endif
#ifdef builtin_popcount
return builtin_popcount(m);
#else
// FIXME: we could do better by dispatching to the appropriate
// popcount instruction depending on the arch...
XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size <= 32)
{
uint32_t m32 = static_cast<uint32_t>(m);
// https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
m32 = m32 - ((m32 >> 1) & 0x55555555); // reuse input as temporary
m32 = (m32 & 0x33333333) + ((m32 >> 2) & 0x33333333); // temp
return (((m32 + (m32 >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; // count
}
else
{
// https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
m = m - ((m >> 1) & (uint64_t) ~(uint64_t)0 / 3); // temp
m = (m & (uint64_t) ~(uint64_t)0 / 15 * 3) + ((m >> 2) & (uint64_t) ~(uint64_t)0 / 15 * 3); // temp
m = (m + (m >> 4)) & (uint64_t) ~(uint64_t)0 / 255 * 15; // temp
return (m * ((uint64_t) ~(uint64_t)0 / 255)) >> (sizeof(uint64_t) - 1) * CHAR_BIT; // count
}
#endif
}
}
// from mask
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> from_mask(batch_bool<T, A> const&, uint64_t mask, requires_arch<common>) noexcept
{
alignas(A::alignment()) bool buffer[batch_bool<T, A>::size];
// This is inefficient but should never be called. It's just a
// temporary implementation until arm support is added.
for (size_t i = 0; i < batch_bool<T, A>::size; ++i)
buffer[i] = mask & (1ull << i);
return batch_bool<T, A>::load_aligned(buffer);
}
// ge
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> ge(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return other <= self;
}
// gt
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> gt(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return other < self;
}
// is_even
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> is_even(batch<T, A> const& self, requires_arch<common>) noexcept
{
return is_flint(self * T(0.5));
}
// is_flint
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> is_flint(batch<T, A> const& self, requires_arch<common>) noexcept
{
auto frac = select(isnan(self - self), constants::nan<batch<T, A>>(), self - trunc(self));
return frac == T(0.);
}
// is_odd
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> is_odd(batch<T, A> const& self, requires_arch<common>) noexcept
{
return is_even(self - T(1.));
}
// isinf
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> isinf(batch<T, A> const&, requires_arch<common>) noexcept
{
return batch_bool<T, A>(false);
}
template <class A>
XSIMD_INLINE batch_bool<float, A> isinf(batch<float, A> const& self, requires_arch<common>) noexcept
{
#ifdef __FAST_MATH__
(void)self;
return { false };
#else
return abs(self) == std::numeric_limits<float>::infinity();
#endif
}
template <class A>
XSIMD_INLINE batch_bool<double, A> isinf(batch<double, A> const& self, requires_arch<common>) noexcept
{
#ifdef __FAST_MATH__
(void)self;
return { false };
#else
return abs(self) == std::numeric_limits<double>::infinity();
#endif
}
// isfinite
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> isfinite(batch<T, A> const&, requires_arch<common>) noexcept
{
return batch_bool<T, A>(true);
}
template <class A>
XSIMD_INLINE batch_bool<float, A> isfinite(batch<float, A> const& self, requires_arch<common>) noexcept
{
return (self - self) == 0.f;
}
template <class A>
XSIMD_INLINE batch_bool<double, A> isfinite(batch<double, A> const& self, requires_arch<common>) noexcept
{
return (self - self) == 0.;
}
// isnan
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> isnan(batch<T, A> const&, requires_arch<common>) noexcept
{
return batch_bool<T, A>(false);
}
// le
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> le(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return (self < other) || (self == other);
}
// neq
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> neq(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return !(other == self);
}
// logical_and
template <class A, class T>
XSIMD_INLINE batch<T, A> logical_and(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return detail::apply([](T x, T y) noexcept
{ return x && y; },
self, other);
}
// logical_or
template <class A, class T>
XSIMD_INLINE batch<T, A> logical_or(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
return detail::apply([](T x, T y) noexcept
{ return x || y; },
self, other);
}
// mask
template <class A, class T>
XSIMD_INLINE uint64_t mask(batch_bool<T, A> const& self, requires_arch<common>) noexcept
{
alignas(A::alignment()) bool buffer[batch_bool<T, A>::size];
self.store_aligned(buffer);
// This is inefficient but should never be called. It's just a
// temporary implementation until arm support is added.
uint64_t res = 0;
for (size_t i = 0; i < batch_bool<T, A>::size; ++i)
if (buffer[i])
res |= 1ul << i;
return res;
}
// select
namespace detail
{
template <typename T, typename A>
using is_batch_bool_register_same = std::is_same<typename batch_bool<T, A>::register_type, typename batch<T, A>::register_type>;
}
template <class A, class T, typename std::enable_if<detail::is_batch_bool_register_same<T, A>::value, int>::type = 3>
XSIMD_INLINE batch_bool<T, A> select(batch_bool<T, A> const& cond, batch_bool<T, A> const& true_br, batch_bool<T, A> const& false_br, requires_arch<common>)
{
using register_type = typename batch_bool<T, A>::register_type;
// Do not cast, but rather reinterpret the masks as batches.
const auto true_v = batch<T, A> { static_cast<register_type>(true_br) };
const auto false_v = batch<T, A> { static_cast<register_type>(false_br) };
return batch_bool<T, A> { select(cond, true_v, false_v) };
}
template <class A, class T, typename std::enable_if<!detail::is_batch_bool_register_same<T, A>::value, int>::type = 3>
XSIMD_INLINE batch_bool<T, A> select(batch_bool<T, A> const& cond, batch_bool<T, A> const& true_br, batch_bool<T, A> const& false_br, requires_arch<common>)
{
return (true_br & cond) | (bitwise_andnot(false_br, cond));
}
template <class A, class T, bool... Values>
XSIMD_INLINE batch_bool<T, A> select(batch_bool_constant<T, A, Values...> const& cond, batch_bool<T, A> const& true_br, batch_bool<T, A> const& false_br, requires_arch<common>)
{
return (true_br & cond) | (false_br & ~cond);
}
}
}
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,970 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_COMMON_MEMORY_HPP
#define XSIMD_COMMON_MEMORY_HPP
#include <algorithm>
#include <array>
#include <complex>
#include <stdexcept>
#include "../../types/xsimd_batch_constant.hpp"
#include "./xsimd_common_details.hpp"
namespace xsimd
{
template <typename T, class A, T... Values>
struct batch_constant;
template <typename T, class A, bool... Values>
struct batch_bool_constant;
namespace kernel
{
using namespace types;
// broadcast
namespace detail
{
template <class T, class A>
struct broadcaster
{
using return_type = batch<T, A>;
static XSIMD_INLINE return_type run(T v) noexcept
{
return return_type::broadcast(v);
}
};
template <class A>
struct broadcaster<bool, A>
{
using return_type = batch_bool<xsimd::as_unsigned_integer_t<bool>, A>;
static XSIMD_INLINE return_type run(bool b) noexcept
{
return return_type(b);
}
};
}
// compress
namespace detail
{
template <class IT, class A, class I, size_t... Is>
XSIMD_INLINE batch<IT, A> create_compress_swizzle_mask(I bitmask, ::xsimd::detail::index_sequence<Is...>)
{
batch<IT, A> swizzle_mask(IT(0));
alignas(A::alignment()) IT mask_buffer[batch<IT, A>::size] = { Is... };
size_t inserted = 0;
for (size_t i = 0; i < sizeof...(Is); ++i)
if ((bitmask >> i) & 1u)
std::swap(mask_buffer[inserted++], mask_buffer[i]);
return batch<IT, A>::load_aligned(&mask_buffer[0]);
}
}
template <typename A, typename T>
XSIMD_INLINE batch<T, A>
compress(batch<T, A> const& x, batch_bool<T, A> const& mask,
kernel::requires_arch<common>) noexcept
{
using IT = as_unsigned_integer_t<T>;
constexpr std::size_t size = batch_bool<T, A>::size;
auto bitmask = mask.mask();
auto z = select(mask, x, batch<T, A>((T)0));
auto compress_mask = detail::create_compress_swizzle_mask<IT, A>(bitmask, ::xsimd::detail::make_index_sequence<size>());
return swizzle(z, compress_mask);
}
// expand
template <typename A, typename T>
XSIMD_INLINE batch<T, A>
expand(batch<T, A> const& x, batch_bool<T, A> const& mask,
kernel::requires_arch<common>) noexcept
{
constexpr auto size = batch<T, A>::size;
alignas(A::alignment()) T x_in[size], x_out[size] = { T() };
x.store_aligned(x_in);
int i = 0, j = 0;
for (auto bitmask = mask.mask(); bitmask; bitmask >>= 1, ++i)
{
if (bitmask & 1)
x_out[i] = x_in[j++];
}
return xsimd::batch<T, A>::load_aligned(x_out);
}
// extract_pair
template <class A, class T>
XSIMD_INLINE batch<T, A> extract_pair(batch<T, A> const& self, batch<T, A> const& other, std::size_t i, requires_arch<common>) noexcept
{
constexpr std::size_t size = batch<T, A>::size;
assert(i < size && "index in bounds");
alignas(A::alignment()) T self_buffer[size];
self.store_aligned(self_buffer);
alignas(A::alignment()) T other_buffer[size];
other.store_aligned(other_buffer);
alignas(A::alignment()) T concat_buffer[size];
for (std::size_t j = 0; j < (size - i); ++j)
{
concat_buffer[j] = other_buffer[i + j];
if (j < i)
{
concat_buffer[size - 1 - j] = self_buffer[i - 1 - j];
}
}
return batch<T, A>::load_aligned(concat_buffer);
}
// gather
namespace detail
{
// Not using XSIMD_INLINE here as it makes msvc hand got ever on avx512
template <size_t N, typename T, typename A, typename U, typename V, typename std::enable_if<N == 0, int>::type = 0>
inline batch<T, A> gather(U const* src, batch<V, A> const& index,
::xsimd::index<N> I) noexcept
{
return insert(batch<T, A> {}, static_cast<T>(src[index.get(I)]), I);
}
template <size_t N, typename T, typename A, typename U, typename V, typename std::enable_if<N != 0, int>::type = 0>
inline batch<T, A>
gather(U const* src, batch<V, A> const& index, ::xsimd::index<N> I) noexcept
{
static_assert(N <= batch<V, A>::size, "Incorrect value in recursion!");
const auto test = gather<N - 1, T, A>(src, index, {});
return insert(test, static_cast<T>(src[index.get(I)]), I);
}
} // namespace detail
template <typename T, typename A, typename V>
XSIMD_INLINE batch<T, A>
gather(batch<T, A> const&, T const* src, batch<V, A> const& index,
kernel::requires_arch<common>) noexcept
{
static_assert(batch<T, A>::size == batch<V, A>::size,
"Index and destination sizes must match");
return detail::gather<batch<V, A>::size - 1, T, A>(src, index, {});
}
// Gather with runtime indexes and mismatched strides.
template <typename T, typename A, typename U, typename V>
XSIMD_INLINE detail::sizes_mismatch_t<T, U, batch<T, A>>
gather(batch<T, A> const&, U const* src, batch<V, A> const& index,
kernel::requires_arch<common>) noexcept
{
static_assert(batch<T, A>::size == batch<V, A>::size,
"Index and destination sizes must match");
return detail::gather<batch<V, A>::size - 1, T, A>(src, index, {});
}
// Gather with runtime indexes and matching strides.
template <typename T, typename A, typename U, typename V>
XSIMD_INLINE detail::stride_match_t<T, U, batch<T, A>>
gather(batch<T, A> const&, U const* src, batch<V, A> const& index,
kernel::requires_arch<common>) noexcept
{
static_assert(batch<T, A>::size == batch<V, A>::size,
"Index and destination sizes must match");
return batch_cast<T>(kernel::gather(batch<U, A> {}, src, index, A {}));
}
// insert
template <class A, class T, size_t I>
XSIMD_INLINE batch<T, A> insert(batch<T, A> const& self, T val, index<I>, requires_arch<common>) noexcept
{
struct index_mask
{
static constexpr bool get(size_t index, size_t /* size*/)
{
return index != I;
}
};
batch<T, A> tmp(val);
return select(make_batch_bool_constant<T, index_mask, A>(), self, tmp);
}
// get
template <class A, size_t I, class T>
XSIMD_INLINE T get(batch<T, A> const& self, ::xsimd::index<I>, requires_arch<common>) noexcept
{
alignas(A::alignment()) T buffer[batch<T, A>::size];
self.store_aligned(&buffer[0]);
return buffer[I];
}
template <class A, size_t I, class T>
XSIMD_INLINE T get(batch_bool<T, A> const& self, ::xsimd::index<I>, requires_arch<common>) noexcept
{
alignas(A::alignment()) T buffer[batch_bool<T, A>::size];
self.store_aligned(&buffer[0]);
return buffer[I];
}
template <class A, size_t I, class T>
XSIMD_INLINE auto get(batch<std::complex<T>, A> const& self, ::xsimd::index<I>, requires_arch<common>) noexcept -> typename batch<std::complex<T>, A>::value_type
{
alignas(A::alignment()) T buffer[batch<std::complex<T>, A>::size];
self.store_aligned(&buffer[0]);
return buffer[I];
}
template <class A, class T>
XSIMD_INLINE T get(batch<T, A> const& self, std::size_t i, requires_arch<common>) noexcept
{
alignas(A::alignment()) T buffer[batch<T, A>::size];
self.store_aligned(&buffer[0]);
return buffer[i];
}
template <class A, class T>
XSIMD_INLINE T get(batch_bool<T, A> const& self, std::size_t i, requires_arch<common>) noexcept
{
alignas(A::alignment()) bool buffer[batch_bool<T, A>::size];
self.store_aligned(&buffer[0]);
return buffer[i];
}
template <class A, class T>
XSIMD_INLINE auto get(batch<std::complex<T>, A> const& self, std::size_t i, requires_arch<common>) noexcept -> typename batch<std::complex<T>, A>::value_type
{
using T2 = typename batch<std::complex<T>, A>::value_type;
alignas(A::alignment()) T2 buffer[batch<std::complex<T>, A>::size];
self.store_aligned(&buffer[0]);
return buffer[i];
}
// first
template <class A, class T>
XSIMD_INLINE T first(batch<T, A> const& self, requires_arch<common>) noexcept
{
return get(self, 0, common {});
}
template <class A, class T>
XSIMD_INLINE T first(batch_bool<T, A> const& self, requires_arch<common>) noexcept
{
return first(batch<T, A>(self), A {});
}
template <class A, class T>
XSIMD_INLINE auto first(batch<std::complex<T>, A> const& self, requires_arch<common>) noexcept -> typename batch<std::complex<T>, A>::value_type
{
return { first(self.real(), A {}), first(self.imag(), A {}) };
}
// load
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> load_unaligned(bool const* mem, batch_bool<T, A>, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
batch_type ref(0);
constexpr auto size = batch_bool<T, A>::size;
alignas(A::alignment()) T buffer[size];
for (std::size_t i = 0; i < size; ++i)
buffer[i] = mem[i] ? 1 : 0;
return ref != batch_type::load_aligned(&buffer[0]);
}
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> load_aligned(bool const* mem, batch_bool<T, A> b, requires_arch<common>) noexcept
{
return load_unaligned(mem, b, A {});
}
// load_aligned
namespace detail
{
template <class A, class T_in, class T_out>
XSIMD_INLINE batch<T_out, A> load_aligned(T_in const* mem, convert<T_out>, requires_arch<common>, with_fast_conversion) noexcept
{
using batch_type_in = batch<T_in, A>;
using batch_type_out = batch<T_out, A>;
return fast_cast(batch_type_in::load_aligned(mem), batch_type_out(), A {});
}
template <class A, class T_in, class T_out>
XSIMD_INLINE batch<T_out, A> load_aligned(T_in const* mem, convert<T_out>, requires_arch<common>, with_slow_conversion) noexcept
{
static_assert(!std::is_same<T_in, T_out>::value, "there should be a direct load for this type combination");
using batch_type_out = batch<T_out, A>;
alignas(A::alignment()) T_out buffer[batch_type_out::size];
std::copy(mem, mem + batch_type_out::size, std::begin(buffer));
return batch_type_out::load_aligned(buffer);
}
}
template <class A, class T_in, class T_out>
XSIMD_INLINE batch<T_out, A> load_aligned(T_in const* mem, convert<T_out> cvt, requires_arch<common>) noexcept
{
return detail::load_aligned<A>(mem, cvt, A {}, detail::conversion_type<A, T_in, T_out> {});
}
// load_unaligned
namespace detail
{
template <class A, class T_in, class T_out>
XSIMD_INLINE batch<T_out, A> load_unaligned(T_in const* mem, convert<T_out>, requires_arch<common>, with_fast_conversion) noexcept
{
using batch_type_in = batch<T_in, A>;
using batch_type_out = batch<T_out, A>;
return fast_cast(batch_type_in::load_unaligned(mem), batch_type_out(), A {});
}
template <class A, class T_in, class T_out>
XSIMD_INLINE batch<T_out, A> load_unaligned(T_in const* mem, convert<T_out> cvt, requires_arch<common>, with_slow_conversion) noexcept
{
static_assert(!std::is_same<T_in, T_out>::value, "there should be a direct load for this type combination");
return load_aligned<A>(mem, cvt, common {}, with_slow_conversion {});
}
}
template <class A, class T_in, class T_out>
XSIMD_INLINE batch<T_out, A> load_unaligned(T_in const* mem, convert<T_out> cvt, requires_arch<common>) noexcept
{
return detail::load_unaligned<A>(mem, cvt, common {}, detail::conversion_type<A, T_in, T_out> {});
}
template <class A, class T>
XSIMD_INLINE batch<T, A> load(T const* mem, aligned_mode, requires_arch<A>) noexcept
{
return load_aligned<A>(mem, convert<T> {}, A {});
}
template <class A, class T>
XSIMD_INLINE batch<T, A> load(T const* mem, unaligned_mode, requires_arch<A>) noexcept
{
return load_unaligned<A>(mem, convert<T> {}, A {});
}
template <class A, class T_in, class T_out, bool... Values, class alignment>
XSIMD_INLINE batch<T_out, A>
load_masked(T_in const* mem, batch_bool_constant<T_out, A, Values...>, convert<T_out>, alignment, requires_arch<common>) noexcept
{
constexpr std::size_t size = batch<T_out, A>::size;
alignas(A::alignment()) std::array<T_out, size> buffer {};
constexpr bool mask[size] = { Values... };
for (std::size_t i = 0; i < size; ++i)
buffer[i] = mask[i] ? static_cast<T_out>(mem[i]) : T_out(0);
return batch<T_out, A>::load(buffer.data(), aligned_mode {});
}
template <class A, class T_in, class T_out, bool... Values, class alignment>
XSIMD_INLINE void
store_masked(T_out* mem, batch<T_in, A> const& src, batch_bool_constant<T_in, A, Values...>, alignment, requires_arch<common>) noexcept
{
constexpr std::size_t size = batch<T_in, A>::size;
constexpr bool mask[size] = { Values... };
for (std::size_t i = 0; i < size; ++i)
if (mask[i])
{
mem[i] = static_cast<T_out>(src.get(i));
}
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE batch<int32_t, A> load_masked(int32_t const* mem, batch_bool_constant<int32_t, A, Values...>, convert<int32_t>, Mode, requires_arch<A>) noexcept
{
const auto f = load_masked<A>(reinterpret_cast<const float*>(mem), batch_bool_constant<float, A, Values...> {}, convert<float> {}, Mode {}, A {});
return bitwise_cast<int32_t>(f);
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE batch<uint32_t, A> load_masked(uint32_t const* mem, batch_bool_constant<uint32_t, A, Values...>, convert<uint32_t>, Mode, requires_arch<A>) noexcept
{
const auto f = load_masked<A>(reinterpret_cast<const float*>(mem), batch_bool_constant<float, A, Values...> {}, convert<float> {}, Mode {}, A {});
return bitwise_cast<uint32_t>(f);
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE typename std::enable_if<types::has_simd_register<double, A>::value, batch<int64_t, A>>::type
load_masked(int64_t const* mem, batch_bool_constant<int64_t, A, Values...>, convert<int64_t>, Mode, requires_arch<A>) noexcept
{
const auto d = load_masked<A>(reinterpret_cast<const double*>(mem), batch_bool_constant<double, A, Values...> {}, convert<double> {}, Mode {}, A {});
return bitwise_cast<int64_t>(d);
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE typename std::enable_if<types::has_simd_register<double, A>::value, batch<uint64_t, A>>::type
load_masked(uint64_t const* mem, batch_bool_constant<uint64_t, A, Values...>, convert<uint64_t>, Mode, requires_arch<A>) noexcept
{
const auto d = load_masked<A>(reinterpret_cast<const double*>(mem), batch_bool_constant<double, A, Values...> {}, convert<double> {}, Mode {}, A {});
return bitwise_cast<uint64_t>(d);
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE void store_masked(int32_t* mem, batch<int32_t, A> const& src, batch_bool_constant<int32_t, A, Values...>, Mode, requires_arch<A>) noexcept
{
store_masked<A>(reinterpret_cast<float*>(mem), bitwise_cast<float>(src), batch_bool_constant<float, A, Values...> {}, Mode {}, A {});
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE void store_masked(uint32_t* mem, batch<uint32_t, A> const& src, batch_bool_constant<uint32_t, A, Values...>, Mode, requires_arch<A>) noexcept
{
store_masked<A>(reinterpret_cast<float*>(mem), bitwise_cast<float>(src), batch_bool_constant<float, A, Values...> {}, Mode {}, A {});
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE typename std::enable_if<types::has_simd_register<double, A>::value, void>::type
store_masked(int64_t* mem, batch<int64_t, A> const& src, batch_bool_constant<int64_t, A, Values...>, Mode, requires_arch<A>) noexcept
{
store_masked<A>(reinterpret_cast<double*>(mem), bitwise_cast<double>(src), batch_bool_constant<double, A, Values...> {}, Mode {}, A {});
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE typename std::enable_if<types::has_simd_register<double, A>::value, void>::type
store_masked(uint64_t* mem, batch<uint64_t, A> const& src, batch_bool_constant<uint64_t, A, Values...>, Mode, requires_arch<A>) noexcept
{
store_masked<A>(reinterpret_cast<double*>(mem), bitwise_cast<double>(src), batch_bool_constant<double, A, Values...> {}, Mode {}, A {});
}
// rotate_right
template <size_t N, class A, class T>
XSIMD_INLINE batch<T, A> rotate_right(batch<T, A> const& self, requires_arch<common>) noexcept
{
struct rotate_generator
{
static constexpr size_t get(size_t index, size_t size)
{
return (index - N) % size;
}
};
return swizzle(self, make_batch_constant<as_unsigned_integer_t<T>, rotate_generator, A>());
}
template <size_t N, class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> rotate_right(batch<std::complex<T>, A> const& self, requires_arch<common>) noexcept
{
return { rotate_right<N>(self.real()), rotate_right<N>(self.imag()) };
}
// rotate_left
template <size_t N, class A, class T>
XSIMD_INLINE batch<T, A> rotate_left(batch<T, A> const& self, requires_arch<common>) noexcept
{
struct rotate_generator
{
static constexpr size_t get(size_t index, size_t size)
{
return (index + N) % size;
}
};
return swizzle(self, make_batch_constant<as_unsigned_integer_t<T>, rotate_generator, A>());
}
template <size_t N, class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> rotate_left(batch<std::complex<T>, A> const& self, requires_arch<common>) noexcept
{
return { rotate_left<N>(self.real()), rotate_left<N>(self.imag()) };
}
// Scatter with runtime indexes.
namespace detail
{
template <size_t N, typename T, typename A, typename U, typename V, typename std::enable_if<N == 0, int>::type = 0>
XSIMD_INLINE void scatter(batch<T, A> const& src, U* dst,
batch<V, A> const& index,
::xsimd::index<N> I) noexcept
{
dst[index.get(I)] = static_cast<U>(src.get(I));
}
template <size_t N, typename T, typename A, typename U, typename V, typename std::enable_if<N != 0, int>::type = 0>
XSIMD_INLINE void
scatter(batch<T, A> const& src, U* dst, batch<V, A> const& index,
::xsimd::index<N> I) noexcept
{
static_assert(N <= batch<V, A>::size, "Incorrect value in recursion!");
kernel::detail::scatter<N - 1, T, A, U, V>(
src, dst, index, {});
dst[index.get(I)] = static_cast<U>(src.get(I));
}
} // namespace detail
template <typename A, typename T, typename V>
XSIMD_INLINE void
scatter(batch<T, A> const& src, T* dst,
batch<V, A> const& index,
kernel::requires_arch<common>) noexcept
{
static_assert(batch<T, A>::size == batch<V, A>::size,
"Source and index sizes must match");
kernel::detail::scatter<batch<V, A>::size - 1, T, A, T, V>(
src, dst, index, {});
}
template <typename A, typename T, typename U, typename V>
XSIMD_INLINE detail::sizes_mismatch_t<T, U, void>
scatter(batch<T, A> const& src, U* dst,
batch<V, A> const& index,
kernel::requires_arch<common>) noexcept
{
static_assert(batch<T, A>::size == batch<V, A>::size,
"Source and index sizes must match");
kernel::detail::scatter<batch<V, A>::size - 1, T, A, U, V>(
src, dst, index, {});
}
template <typename A, typename T, typename U, typename V>
XSIMD_INLINE detail::stride_match_t<T, U, void>
scatter(batch<T, A> const& src, U* dst,
batch<V, A> const& index,
kernel::requires_arch<common>) noexcept
{
static_assert(batch<T, A>::size == batch<V, A>::size,
"Source and index sizes must match");
const auto tmp = batch_cast<U>(src);
kernel::scatter<A>(tmp, dst, index, A {});
}
// shuffle
namespace detail
{
constexpr bool is_swizzle_fst(size_t)
{
return true;
}
template <typename ITy, typename... ITys>
constexpr bool is_swizzle_fst(size_t bsize, ITy index, ITys... indices)
{
return index < bsize && is_swizzle_fst(bsize, indices...);
}
constexpr bool is_swizzle_snd(size_t)
{
return true;
}
template <typename ITy, typename... ITys>
constexpr bool is_swizzle_snd(size_t bsize, ITy index, ITys... indices)
{
return index >= bsize && is_swizzle_snd(bsize, indices...);
}
constexpr bool is_zip_lo(size_t)
{
return true;
}
template <typename ITy>
constexpr bool is_zip_lo(size_t, ITy)
{
return false;
}
template <typename ITy0, typename ITy1, typename... ITys>
constexpr bool is_zip_lo(size_t bsize, ITy0 index0, ITy1 index1, ITys... indices)
{
return index0 == (bsize - (sizeof...(indices) + 2)) && index1 == (2 * bsize - (sizeof...(indices) + 2)) && is_zip_lo(bsize, indices...);
}
constexpr bool is_zip_hi(size_t)
{
return true;
}
template <typename ITy>
constexpr bool is_zip_hi(size_t, ITy)
{
return false;
}
template <typename ITy0, typename ITy1, typename... ITys>
constexpr bool is_zip_hi(size_t bsize, ITy0 index0, ITy1 index1, ITys... indices)
{
return index0 == (bsize / 2 + bsize - (sizeof...(indices) + 2)) && index1 == (bsize / 2 + 2 * bsize - (sizeof...(indices) + 2)) && is_zip_hi(bsize, indices...);
}
constexpr bool is_select(size_t)
{
return true;
}
template <typename ITy, typename... ITys>
constexpr bool is_select(size_t bsize, ITy index, ITys... indices)
{
return (index < bsize ? index : index - bsize) == (bsize - sizeof...(ITys)) && is_select(bsize, indices...);
}
}
template <class A, typename T, typename ITy, ITy... Indices>
XSIMD_INLINE batch<T, A> shuffle(batch<T, A> const& x, batch<T, A> const& y, batch_constant<ITy, A, Indices...>, requires_arch<common>) noexcept
{
constexpr size_t bsize = sizeof...(Indices);
static_assert(bsize == batch<T, A>::size, "valid shuffle");
// Detect common patterns
XSIMD_IF_CONSTEXPR(detail::is_swizzle_fst(bsize, Indices...))
{
return swizzle(x, batch_constant<ITy, A, ((Indices >= bsize) ? 0 /* never happens */ : Indices)...>());
}
XSIMD_IF_CONSTEXPR(detail::is_swizzle_snd(bsize, Indices...))
{
return swizzle(y, batch_constant<ITy, A, ((Indices >= bsize) ? (Indices - bsize) : 0 /* never happens */)...>());
}
XSIMD_IF_CONSTEXPR(detail::is_zip_lo(bsize, Indices...))
{
return zip_lo(x, y);
}
XSIMD_IF_CONSTEXPR(detail::is_zip_hi(bsize, Indices...))
{
return zip_hi(x, y);
}
XSIMD_IF_CONSTEXPR(detail::is_select(bsize, Indices...))
{
return select(batch_bool_constant<T, A, (Indices < bsize)...>(), x, y);
}
#if defined(__has_builtin) && !defined(XSIMD_WITH_EMULATED)
#if __has_builtin(__builtin_shufflevector)
#define builtin_shuffle __builtin_shufflevector
#endif
#endif
#if defined(builtin_shuffle)
typedef T vty __attribute__((__vector_size__(sizeof(batch<T, A>))));
return (typename batch<T, A>::register_type)builtin_shuffle((vty)x.data, (vty)y.data, Indices...);
// FIXME: my experiments show that GCC only correctly optimizes this builtin
// starting at GCC 13, where it already has __builtin_shuffle_vector
//
// #elif __has_builtin(__builtin_shuffle) || GCC >= 6
// typedef ITy integer_vector_type __attribute__((vector_size(sizeof(batch<ITy, A>))));
// return __builtin_shuffle(x.data, y.data, integer_vector_type{Indices...});
#else
// Use a common_pattern. It is suboptimal but clang optimizes this
// pretty well.
batch<T, A> x_lane = swizzle(x, batch_constant<ITy, A, ((Indices >= bsize) ? (Indices - bsize) : Indices)...>());
batch<T, A> y_lane = swizzle(y, batch_constant<ITy, A, ((Indices >= bsize) ? (Indices - bsize) : Indices)...>());
batch_bool_constant<T, A, (Indices < bsize)...> select_x_lane;
return select(select_x_lane, x_lane, y_lane);
#endif
}
// store
template <class A, class T>
XSIMD_INLINE void store(batch_bool<T, A> const& self, bool* mem, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
constexpr auto size = batch_bool<T, A>::size;
alignas(A::alignment()) T buffer[size];
kernel::store_aligned<A>(&buffer[0], batch_type(self), A {});
for (std::size_t i = 0; i < size; ++i)
mem[i] = bool(buffer[i]);
}
// store_aligned
template <class A, class T_in, class T_out>
XSIMD_INLINE void store_aligned(T_out* mem, batch<T_in, A> const& self, requires_arch<common>) noexcept
{
static_assert(!std::is_same<T_in, T_out>::value, "there should be a direct store for this type combination");
alignas(A::alignment()) T_in buffer[batch<T_in, A>::size];
store_aligned(&buffer[0], self);
std::copy(std::begin(buffer), std::end(buffer), mem);
}
// store_unaligned
template <class A, class T_in, class T_out>
XSIMD_INLINE void store_unaligned(T_out* mem, batch<T_in, A> const& self, requires_arch<common>) noexcept
{
static_assert(!std::is_same<T_in, T_out>::value, "there should be a direct store for this type combination");
return store_aligned<A>(mem, self, common {});
}
// swizzle
template <class A, class T, class ITy, ITy... Vs>
XSIMD_INLINE batch<std::complex<T>, A> swizzle(batch<std::complex<T>, A> const& self, batch_constant<ITy, A, Vs...> mask, requires_arch<common>) noexcept
{
return { swizzle(self.real(), mask), swizzle(self.imag(), mask) };
}
template <class A, class T, class ITy>
XSIMD_INLINE batch<T, A> swizzle(batch<T, A> const& self, batch<ITy, A> mask, requires_arch<common>) noexcept
{
constexpr size_t size = batch<T, A>::size;
alignas(A::alignment()) T self_buffer[size];
store_aligned(&self_buffer[0], self);
alignas(A::alignment()) ITy mask_buffer[size];
store_aligned(&mask_buffer[0], mask);
alignas(A::alignment()) T out_buffer[size];
for (size_t i = 0; i < size; ++i)
out_buffer[i] = self_buffer[mask_buffer[i]];
return batch<T, A>::load_aligned(out_buffer);
}
template <class A, class T, class ITy, ITy... Is>
XSIMD_INLINE batch<T, A> swizzle(batch<T, A> const& self, batch_constant<ITy, A, Is...>, requires_arch<common>) noexcept
{
constexpr size_t size = batch<T, A>::size;
alignas(A::alignment()) T self_buffer[size];
store_aligned(&self_buffer[0], self);
return { self_buffer[Is]... };
}
template <class A, class T, class ITy>
XSIMD_INLINE batch<std::complex<T>, A> swizzle(batch<std::complex<T>, A> const& self, batch<ITy, A> mask, requires_arch<common>) noexcept
{
return { swizzle(self.real(), mask), swizzle(self.imag(), mask) };
}
// load_complex_aligned
namespace detail
{
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> load_complex(batch<T, A> const& /*hi*/, batch<T, A> const& /*lo*/, requires_arch<common>) noexcept
{
static_assert(std::is_same<T, void>::value, "load_complex not implemented for the required architecture");
}
template <class A, class T>
XSIMD_INLINE batch<T, A> complex_high(batch<std::complex<T>, A> const& /*src*/, requires_arch<common>) noexcept
{
static_assert(std::is_same<T, void>::value, "complex_high not implemented for the required architecture");
}
template <class A, class T>
XSIMD_INLINE batch<T, A> complex_low(batch<std::complex<T>, A> const& /*src*/, requires_arch<common>) noexcept
{
static_assert(std::is_same<T, void>::value, "complex_low not implemented for the required architecture");
}
}
template <class A, class T_out, class T_in>
XSIMD_INLINE batch<std::complex<T_out>, A> load_complex_aligned(std::complex<T_in> const* mem, convert<std::complex<T_out>>, requires_arch<common>) noexcept
{
using real_batch = batch<T_out, A>;
T_in const* buffer = reinterpret_cast<T_in const*>(mem);
real_batch hi = real_batch::load_aligned(buffer),
lo = real_batch::load_aligned(buffer + real_batch::size);
return detail::load_complex(hi, lo, A {});
}
// load_complex_unaligned
template <class A, class T_out, class T_in>
XSIMD_INLINE batch<std::complex<T_out>, A> load_complex_unaligned(std::complex<T_in> const* mem, convert<std::complex<T_out>>, requires_arch<common>) noexcept
{
using real_batch = batch<T_out, A>;
T_in const* buffer = reinterpret_cast<T_in const*>(mem);
real_batch hi = real_batch::load_unaligned(buffer),
lo = real_batch::load_unaligned(buffer + real_batch::size);
return detail::load_complex(hi, lo, A {});
}
// store_complex_aligned
template <class A, class T_out, class T_in>
XSIMD_INLINE void store_complex_aligned(std::complex<T_out>* dst, batch<std::complex<T_in>, A> const& src, requires_arch<common>) noexcept
{
using real_batch = batch<T_in, A>;
real_batch hi = detail::complex_high(src, A {});
real_batch lo = detail::complex_low(src, A {});
T_out* buffer = reinterpret_cast<T_out*>(dst);
lo.store_aligned(buffer);
hi.store_aligned(buffer + real_batch::size);
}
// store_complex_unaligned
template <class A, class T_out, class T_in>
XSIMD_INLINE void store_complex_unaligned(std::complex<T_out>* dst, batch<std::complex<T_in>, A> const& src, requires_arch<common>) noexcept
{
using real_batch = batch<T_in, A>;
real_batch hi = detail::complex_high(src, A {});
real_batch lo = detail::complex_low(src, A {});
T_out* buffer = reinterpret_cast<T_out*>(dst);
lo.store_unaligned(buffer);
hi.store_unaligned(buffer + real_batch::size);
}
// transpose
template <class A, class T>
XSIMD_INLINE void transpose(batch<T, A>* matrix_begin, batch<T, A>* matrix_end, requires_arch<common>) noexcept
{
assert((matrix_end - matrix_begin == batch<T, A>::size) && "correctly sized matrix");
(void)matrix_end;
alignas(A::alignment()) T scratch_buffer[batch<T, A>::size * batch<T, A>::size];
for (size_t i = 0; i < batch<T, A>::size; ++i)
{
matrix_begin[i].store_aligned(&scratch_buffer[i * batch<T, A>::size]);
}
// FIXME: this is super naive we can probably do better.
for (size_t i = 0; i < batch<T, A>::size; ++i)
{
for (size_t j = 0; j < i; ++j)
{
std::swap(scratch_buffer[i * batch<T, A>::size + j],
scratch_buffer[j * batch<T, A>::size + i]);
}
}
for (size_t i = 0; i < batch<T, A>::size; ++i)
{
matrix_begin[i] = batch<T, A>::load_aligned(&scratch_buffer[i * batch<T, A>::size]);
}
}
// transpose
template <class A, class = typename std::enable_if<batch<int16_t, A>::size == 8>::type>
XSIMD_INLINE void transpose(batch<int16_t, A>* matrix_begin, batch<int16_t, A>* matrix_end, requires_arch<common>) noexcept
{
assert((matrix_end - matrix_begin == batch<int16_t, A>::size) && "correctly sized matrix");
(void)matrix_end;
auto l0 = zip_lo(matrix_begin[0], matrix_begin[1]);
auto l1 = zip_lo(matrix_begin[2], matrix_begin[3]);
auto l2 = zip_lo(matrix_begin[4], matrix_begin[5]);
auto l3 = zip_lo(matrix_begin[6], matrix_begin[7]);
auto l4 = zip_lo(bit_cast<batch<int32_t, A>>(l0), bit_cast<batch<int32_t, A>>(l1));
auto l5 = zip_lo(bit_cast<batch<int32_t, A>>(l2), bit_cast<batch<int32_t, A>>(l3));
auto l6 = zip_hi(bit_cast<batch<int32_t, A>>(l0), bit_cast<batch<int32_t, A>>(l1));
auto l7 = zip_hi(bit_cast<batch<int32_t, A>>(l2), bit_cast<batch<int32_t, A>>(l3));
auto h0 = zip_hi(matrix_begin[0], matrix_begin[1]);
auto h1 = zip_hi(matrix_begin[2], matrix_begin[3]);
auto h2 = zip_hi(matrix_begin[4], matrix_begin[5]);
auto h3 = zip_hi(matrix_begin[6], matrix_begin[7]);
auto h4 = zip_lo(bit_cast<batch<int32_t, A>>(h0), bit_cast<batch<int32_t, A>>(h1));
auto h5 = zip_lo(bit_cast<batch<int32_t, A>>(h2), bit_cast<batch<int32_t, A>>(h3));
auto h6 = zip_hi(bit_cast<batch<int32_t, A>>(h0), bit_cast<batch<int32_t, A>>(h1));
auto h7 = zip_hi(bit_cast<batch<int32_t, A>>(h2), bit_cast<batch<int32_t, A>>(h3));
matrix_begin[0] = bit_cast<batch<int16_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(l4), bit_cast<batch<int64_t, A>>(l5)));
matrix_begin[1] = bit_cast<batch<int16_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(l4), bit_cast<batch<int64_t, A>>(l5)));
matrix_begin[2] = bit_cast<batch<int16_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(l6), bit_cast<batch<int64_t, A>>(l7)));
matrix_begin[3] = bit_cast<batch<int16_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(l6), bit_cast<batch<int64_t, A>>(l7)));
matrix_begin[4] = bit_cast<batch<int16_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(h4), bit_cast<batch<int64_t, A>>(h5)));
matrix_begin[5] = bit_cast<batch<int16_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(h4), bit_cast<batch<int64_t, A>>(h5)));
matrix_begin[6] = bit_cast<batch<int16_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(h6), bit_cast<batch<int64_t, A>>(h7)));
matrix_begin[7] = bit_cast<batch<int16_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(h6), bit_cast<batch<int64_t, A>>(h7)));
}
template <class A>
XSIMD_INLINE void transpose(batch<uint16_t, A>* matrix_begin, batch<uint16_t, A>* matrix_end, requires_arch<common>) noexcept
{
transpose(reinterpret_cast<batch<int16_t, A>*>(matrix_begin), reinterpret_cast<batch<int16_t, A>*>(matrix_end), A {});
}
template <class A, class = typename std::enable_if<batch<int8_t, A>::size == 16>::type>
XSIMD_INLINE void transpose(batch<int8_t, A>* matrix_begin, batch<int8_t, A>* matrix_end, requires_arch<common>) noexcept
{
assert((matrix_end - matrix_begin == batch<int8_t, A>::size) && "correctly sized matrix");
(void)matrix_end;
auto l0 = zip_lo(matrix_begin[0], matrix_begin[1]);
auto l1 = zip_lo(matrix_begin[2], matrix_begin[3]);
auto l2 = zip_lo(matrix_begin[4], matrix_begin[5]);
auto l3 = zip_lo(matrix_begin[6], matrix_begin[7]);
auto l4 = zip_lo(matrix_begin[8], matrix_begin[9]);
auto l5 = zip_lo(matrix_begin[10], matrix_begin[11]);
auto l6 = zip_lo(matrix_begin[12], matrix_begin[13]);
auto l7 = zip_lo(matrix_begin[14], matrix_begin[15]);
auto h0 = zip_hi(matrix_begin[0], matrix_begin[1]);
auto h1 = zip_hi(matrix_begin[2], matrix_begin[3]);
auto h2 = zip_hi(matrix_begin[4], matrix_begin[5]);
auto h3 = zip_hi(matrix_begin[6], matrix_begin[7]);
auto h4 = zip_hi(matrix_begin[8], matrix_begin[9]);
auto h5 = zip_hi(matrix_begin[10], matrix_begin[11]);
auto h6 = zip_hi(matrix_begin[12], matrix_begin[13]);
auto h7 = zip_hi(matrix_begin[14], matrix_begin[15]);
auto L0 = zip_lo(bit_cast<batch<int16_t, A>>(l0), bit_cast<batch<int16_t, A>>(l1));
auto L1 = zip_lo(bit_cast<batch<int16_t, A>>(l2), bit_cast<batch<int16_t, A>>(l3));
auto L2 = zip_lo(bit_cast<batch<int16_t, A>>(l4), bit_cast<batch<int16_t, A>>(l5));
auto L3 = zip_lo(bit_cast<batch<int16_t, A>>(l6), bit_cast<batch<int16_t, A>>(l7));
auto m0 = zip_lo(bit_cast<batch<int32_t, A>>(L0), bit_cast<batch<int32_t, A>>(L1));
auto m1 = zip_lo(bit_cast<batch<int32_t, A>>(L2), bit_cast<batch<int32_t, A>>(L3));
auto m2 = zip_hi(bit_cast<batch<int32_t, A>>(L0), bit_cast<batch<int32_t, A>>(L1));
auto m3 = zip_hi(bit_cast<batch<int32_t, A>>(L2), bit_cast<batch<int32_t, A>>(L3));
matrix_begin[0] = bit_cast<batch<int8_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(m0), bit_cast<batch<int64_t, A>>(m1)));
matrix_begin[1] = bit_cast<batch<int8_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(m0), bit_cast<batch<int64_t, A>>(m1)));
matrix_begin[2] = bit_cast<batch<int8_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(m2), bit_cast<batch<int64_t, A>>(m3)));
matrix_begin[3] = bit_cast<batch<int8_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(m2), bit_cast<batch<int64_t, A>>(m3)));
auto L4 = zip_hi(bit_cast<batch<int16_t, A>>(l0), bit_cast<batch<int16_t, A>>(l1));
auto L5 = zip_hi(bit_cast<batch<int16_t, A>>(l2), bit_cast<batch<int16_t, A>>(l3));
auto L6 = zip_hi(bit_cast<batch<int16_t, A>>(l4), bit_cast<batch<int16_t, A>>(l5));
auto L7 = zip_hi(bit_cast<batch<int16_t, A>>(l6), bit_cast<batch<int16_t, A>>(l7));
auto m4 = zip_lo(bit_cast<batch<int32_t, A>>(L4), bit_cast<batch<int32_t, A>>(L5));
auto m5 = zip_lo(bit_cast<batch<int32_t, A>>(L6), bit_cast<batch<int32_t, A>>(L7));
auto m6 = zip_hi(bit_cast<batch<int32_t, A>>(L4), bit_cast<batch<int32_t, A>>(L5));
auto m7 = zip_hi(bit_cast<batch<int32_t, A>>(L6), bit_cast<batch<int32_t, A>>(L7));
matrix_begin[4] = bit_cast<batch<int8_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(m4), bit_cast<batch<int64_t, A>>(m5)));
matrix_begin[5] = bit_cast<batch<int8_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(m4), bit_cast<batch<int64_t, A>>(m5)));
matrix_begin[6] = bit_cast<batch<int8_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(m6), bit_cast<batch<int64_t, A>>(m7)));
matrix_begin[7] = bit_cast<batch<int8_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(m6), bit_cast<batch<int64_t, A>>(m7)));
auto H0 = zip_lo(bit_cast<batch<int16_t, A>>(h0), bit_cast<batch<int16_t, A>>(h1));
auto H1 = zip_lo(bit_cast<batch<int16_t, A>>(h2), bit_cast<batch<int16_t, A>>(h3));
auto H2 = zip_lo(bit_cast<batch<int16_t, A>>(h4), bit_cast<batch<int16_t, A>>(h5));
auto H3 = zip_lo(bit_cast<batch<int16_t, A>>(h6), bit_cast<batch<int16_t, A>>(h7));
auto M0 = zip_lo(bit_cast<batch<int32_t, A>>(H0), bit_cast<batch<int32_t, A>>(H1));
auto M1 = zip_lo(bit_cast<batch<int32_t, A>>(H2), bit_cast<batch<int32_t, A>>(H3));
auto M2 = zip_hi(bit_cast<batch<int32_t, A>>(H0), bit_cast<batch<int32_t, A>>(H1));
auto M3 = zip_hi(bit_cast<batch<int32_t, A>>(H2), bit_cast<batch<int32_t, A>>(H3));
matrix_begin[8] = bit_cast<batch<int8_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(M0), bit_cast<batch<int64_t, A>>(M1)));
matrix_begin[9] = bit_cast<batch<int8_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(M0), bit_cast<batch<int64_t, A>>(M1)));
matrix_begin[10] = bit_cast<batch<int8_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(M2), bit_cast<batch<int64_t, A>>(M3)));
matrix_begin[11] = bit_cast<batch<int8_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(M2), bit_cast<batch<int64_t, A>>(M3)));
auto H4 = zip_hi(bit_cast<batch<int16_t, A>>(h0), bit_cast<batch<int16_t, A>>(h1));
auto H5 = zip_hi(bit_cast<batch<int16_t, A>>(h2), bit_cast<batch<int16_t, A>>(h3));
auto H6 = zip_hi(bit_cast<batch<int16_t, A>>(h4), bit_cast<batch<int16_t, A>>(h5));
auto H7 = zip_hi(bit_cast<batch<int16_t, A>>(h6), bit_cast<batch<int16_t, A>>(h7));
auto M4 = zip_lo(bit_cast<batch<int32_t, A>>(H4), bit_cast<batch<int32_t, A>>(H5));
auto M5 = zip_lo(bit_cast<batch<int32_t, A>>(H6), bit_cast<batch<int32_t, A>>(H7));
auto M6 = zip_hi(bit_cast<batch<int32_t, A>>(H4), bit_cast<batch<int32_t, A>>(H5));
auto M7 = zip_hi(bit_cast<batch<int32_t, A>>(H6), bit_cast<batch<int32_t, A>>(H7));
matrix_begin[12] = bit_cast<batch<int8_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(M4), bit_cast<batch<int64_t, A>>(M5)));
matrix_begin[13] = bit_cast<batch<int8_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(M4), bit_cast<batch<int64_t, A>>(M5)));
matrix_begin[14] = bit_cast<batch<int8_t, A>>(zip_lo(bit_cast<batch<int64_t, A>>(M6), bit_cast<batch<int64_t, A>>(M7)));
matrix_begin[15] = bit_cast<batch<int8_t, A>>(zip_hi(bit_cast<batch<int64_t, A>>(M6), bit_cast<batch<int64_t, A>>(M7)));
}
template <class A>
XSIMD_INLINE void transpose(batch<uint8_t, A>* matrix_begin, batch<uint8_t, A>* matrix_end, requires_arch<common>) noexcept
{
transpose(reinterpret_cast<batch<int8_t, A>*>(matrix_begin), reinterpret_cast<batch<int8_t, A>*>(matrix_end), A {});
}
}
}
#endif
@@ -0,0 +1,72 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_COMMON_ROUNDING_HPP
#define XSIMD_COMMON_ROUNDING_HPP
#include "./xsimd_common_details.hpp"
namespace xsimd
{
namespace kernel
{
using namespace types;
// ceil
template <class A, class T>
XSIMD_INLINE batch<T, A> ceil(batch<T, A> const& self, requires_arch<common>) noexcept
{
batch<T, A> truncated_self = trunc(self);
return select(truncated_self < self, truncated_self + 1, truncated_self);
}
// floor
template <class A, class T>
XSIMD_INLINE batch<T, A> floor(batch<T, A> const& self, requires_arch<common>) noexcept
{
batch<T, A> truncated_self = trunc(self);
return select(truncated_self > self, truncated_self - 1, truncated_self);
}
// round
template <class A, class T>
XSIMD_INLINE batch<T, A> round(batch<T, A> const& self, requires_arch<common>) noexcept
{
auto v = abs(self);
auto c = ceil(v);
auto cp = select(c - 0.5 > v, c - 1, c);
return select(v > constants::maxflint<batch<T, A>>(), self, copysign(cp, self));
}
// trunc
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> trunc(batch<T, A> const& self, requires_arch<common>) noexcept
{
return self;
}
template <class A>
XSIMD_INLINE batch<float, A> trunc(batch<float, A> const& self, requires_arch<common>) noexcept
{
return select(abs(self) < constants::maxflint<batch<float, A>>(), to_float(to_int(self)), self);
}
template <class A>
XSIMD_INLINE batch<double, A> trunc(batch<double, A> const& self, requires_arch<common>) noexcept
{
return select(abs(self) < constants::maxflint<batch<double, A>>(), to_float(to_int(self)), self);
}
}
}
#endif
@@ -0,0 +1,193 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* Copyright (c) Marco Barbone *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software.*
****************************************************************************/
#ifndef XSIMD_COMMON_SWIZZLE_HPP
#define XSIMD_COMMON_SWIZZLE_HPP
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include "../../config/xsimd_inline.hpp"
namespace xsimd
{
template <typename T, class A, T... Values>
struct batch_constant;
namespace kernel
{
namespace detail
{
// ────────────────────────────────────────────────────────────────────────
// get_at<I,Values...> → the I-th element of the pack
template <typename T, std::size_t I, T V0, T... Vs>
struct get_at
{
static constexpr T value = get_at<T, I - 1, Vs...>::value;
};
template <typename T, T V0, T... Vs>
struct get_at<T, 0, V0, Vs...>
{
static constexpr T value = V0;
};
// ────────────────────────────────────────────────────────────────────────
// identity_impl
template <std::size_t /*I*/, typename T>
XSIMD_INLINE constexpr bool identity_impl() noexcept { return true; }
template <std::size_t I, typename T, T V0, T... Vs>
XSIMD_INLINE constexpr bool identity_impl() noexcept
{
return V0 == static_cast<T>(I)
&& identity_impl<I + 1, T, Vs...>();
}
// ────────────────────────────────────────────────────────────────────────
// dup_lo_impl
template <std::size_t I, std::size_t N, typename T,
T... Vs, typename std::enable_if<I == N / 2, int>::type = 0>
XSIMD_INLINE constexpr bool dup_lo_impl() noexcept { return true; }
template <std::size_t I, std::size_t N, typename T,
T... Vs, typename std::enable_if<(I < N / 2), int>::type = 0>
XSIMD_INLINE constexpr bool dup_lo_impl() noexcept
{
return get_at<T, I, Vs...>::value < static_cast<T>(N / 2)
&& get_at<T, I + N / 2, Vs...>::value == get_at<T, I, Vs...>::value
&& dup_lo_impl<I + 1, N, T, Vs...>();
}
// ────────────────────────────────────────────────────────────────────────
// dup_hi_impl
template <std::size_t I, std::size_t N, typename T,
T... Vs, typename std::enable_if<I == N / 2, int>::type = 0>
XSIMD_INLINE constexpr bool dup_hi_impl() noexcept { return true; }
template <std::size_t I, std::size_t N, typename T,
T... Vs, typename std::enable_if<(I < N / 2), int>::type = 0>
XSIMD_INLINE constexpr bool dup_hi_impl() noexcept
{
return get_at<T, I, Vs...>::value >= static_cast<T>(N / 2)
&& get_at<T, I, Vs...>::value < static_cast<T>(N)
&& get_at<T, I + N / 2, Vs...>::value == get_at<T, I, Vs...>::value
&& dup_hi_impl<I + 1, N, T, Vs...>();
}
// ────────────────────────────────────────────────────────────────────────
// only_from_lo
template <typename T, T Size, T First, T... Vals>
struct only_from_lo_impl;
template <typename T, T Size, T Last>
struct only_from_lo_impl<T, Size, Last>
{
static constexpr bool value = (Last < (Size / 2));
};
template <typename T, T Size, T First, T... Vals>
struct only_from_lo_impl
{
static constexpr bool value = (First < (Size / 2)) && only_from_lo_impl<T, Size, Vals...>::value;
};
template <typename T, T... Vals>
constexpr bool is_only_from_lo()
{
return only_from_lo_impl<T, sizeof...(Vals), Vals...>::value;
};
// ────────────────────────────────────────────────────────────────────────
// only_from_hi
template <typename T, T Size, T First, T... Vals>
struct only_from_hi_impl;
template <typename T, T Size, T Last>
struct only_from_hi_impl<T, Size, Last>
{
static constexpr bool value = (Last >= (Size / 2));
};
template <typename T, T Size, T First, T... Vals>
struct only_from_hi_impl
{
static constexpr bool value = (First >= (Size / 2)) && only_from_hi_impl<T, Size, Vals...>::value;
};
template <typename T, T... Vals>
constexpr bool is_only_from_hi()
{
return only_from_hi_impl<T, sizeof...(Vals), Vals...>::value;
};
// ────────────────────────────────────────────────────────────────────────
// 1) helper to get the I-th value from the Vs pack
template <std::size_t I, uint32_t Head, uint32_t... Tail>
struct get_nth_value
{
static constexpr uint32_t value = get_nth_value<I - 1, Tail...>::value;
};
template <uint32_t Head, uint32_t... Tail>
struct get_nth_value<0, Head, Tail...>
{
static constexpr uint32_t value = Head;
};
// ────────────────────────────────────────────────────────────────────────
// 2) recursive cross‐lane test: true if any output‐lane i pulls from the opposite half
template <std::size_t I,
std::size_t N,
std::size_t H,
uint32_t... Vs>
struct cross_impl
{
// does element I cross? (i.e. i<H but V>=H) or (i>=H but V<H)
static constexpr uint32_t Vi = get_nth_value<I, Vs...>::value;
static constexpr bool curr = (I < H ? (Vi >= H) : (Vi < H));
static constexpr bool next = cross_impl<I + 1, N, H, Vs...>::value;
static constexpr bool value = curr || next;
};
template <std::size_t N, std::size_t H, uint32_t... Vs>
struct cross_impl<N, N, H, Vs...>
{
static constexpr bool value = false;
};
template <uint32_t... Vs>
XSIMD_INLINE constexpr bool is_cross_lane() noexcept
{
static_assert(sizeof...(Vs) >= 1, "Need at least one lane");
return cross_impl<0, sizeof...(Vs), sizeof...(Vs) / 2, Vs...>::value;
}
template <typename T, T... Vs>
XSIMD_INLINE constexpr bool is_identity() noexcept { return detail::identity_impl<0, T, Vs...>(); }
template <typename T, T... Vs>
XSIMD_INLINE constexpr bool is_dup_lo() noexcept { return detail::dup_lo_impl<0, sizeof...(Vs), T, Vs...>(); }
template <typename T, T... Vs>
XSIMD_INLINE constexpr bool is_dup_hi() noexcept { return detail::dup_hi_impl<0, sizeof...(Vs), T, Vs...>(); }
template <typename T, class A, T... Vs>
XSIMD_INLINE constexpr bool is_identity(batch_constant<T, A, Vs...>) noexcept { return is_identity<T, Vs...>(); }
template <typename T, class A, T... Vs>
XSIMD_INLINE constexpr bool is_dup_lo(batch_constant<T, A, Vs...>) noexcept { return is_dup_lo<T, Vs...>(); }
template <typename T, class A, T... Vs>
XSIMD_INLINE constexpr bool is_dup_hi(batch_constant<T, A, Vs...>) noexcept { return is_dup_hi<T, Vs...>(); }
template <typename T, class A, T... Vs>
XSIMD_INLINE constexpr bool is_only_from_lo(batch_constant<T, A, Vs...>) noexcept { return detail::is_only_from_lo<T, Vs...>(); }
template <typename T, class A, T... Vs>
XSIMD_INLINE constexpr bool is_only_from_hi(batch_constant<T, A, Vs...>) noexcept { return detail::is_only_from_hi<T, Vs...>(); }
template <typename T, class A, T... Vs>
XSIMD_INLINE constexpr bool is_cross_lane(batch_constant<T, A, Vs...>) noexcept { return detail::is_cross_lane<Vs...>(); }
} // namespace detail
} // namespace kernel
} // namespace xsimd
#endif // XSIMD_COMMON_SWIZZLE_HPP
@@ -0,0 +1,978 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_COMMON_TRIGO_HPP
#define XSIMD_COMMON_TRIGO_HPP
#include "./xsimd_common_details.hpp"
#include <array>
namespace xsimd
{
namespace kernel
{
/* origin: boost/simd/arch/common/detail/simd/trig_base.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
using namespace types;
// acos
template <class A, class T>
XSIMD_INLINE batch<T, A> acos(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
batch_type x = abs(self);
auto x_larger_05 = x > batch_type(0.5);
x = select(x_larger_05, sqrt(fma(batch_type(-0.5), x, batch_type(0.5))), self);
x = asin(x);
x = select(x_larger_05, x + x, x);
x = select(self < batch_type(-0.5), constants::pi<batch_type>() - x, x);
return select(x_larger_05, x, constants::pio2<batch_type>() - x);
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> acos(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
using batch_type = batch<std::complex<T>, A>;
using real_batch = typename batch_type::real_batch;
batch_type tmp = asin(z);
return { constants::pio2<real_batch>() - tmp.real(), -tmp.imag() };
}
// acosh
/* origin: boost/simd/arch/common/simd/function/acosh.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class A, class T>
XSIMD_INLINE batch<T, A> acosh(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
batch_type x = self - batch_type(1.);
auto test = x > constants::oneotwoeps<batch_type>();
batch_type z = select(test, self, x + sqrt(x + x + x * x));
batch_type l1pz = log1p(z);
return select(test, l1pz + constants::log_2<batch_type>(), l1pz);
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> acosh(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
using batch_type = batch<std::complex<T>, A>;
batch_type w = acos(z);
w = batch_type(-w.imag(), w.real());
return w;
}
// asin
template <class A>
XSIMD_INLINE batch<float, A> asin(batch<float, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<float, A>;
batch_type x = abs(self);
batch_type sign = bitofsign(self);
auto x_larger_05 = x > batch_type(0.5);
batch_type z = select(x_larger_05, batch_type(0.5) * (batch_type(1.) - x), x * x);
x = select(x_larger_05, sqrt(z), x);
batch_type z1 = detail::horner<batch_type,
0x3e2aaae4,
0x3d9980f6,
0x3d3a3ec7,
0x3cc617e3,
0x3d2cb352>(z);
z1 = fma(z1, z * x, x);
z = select(x_larger_05, constants::pio2<batch_type>() - (z1 + z1), z1);
return z ^ sign;
}
template <class A>
XSIMD_INLINE batch<double, A> asin(batch<double, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<double, A>;
batch_type x = abs(self);
auto small_cond = x < constants::sqrteps<batch_type>();
batch_type ct1 = batch_type(bit_cast<double>(int64_t(0x3fe4000000000000)));
batch_type zz1 = batch_type(1.) - x;
batch_type vp = zz1 * detail::horner<batch_type, 0x403c896240f3081dull, 0xc03991aaac01ab68ull, 0x401bdff5baf33e6aull, 0xbfe2079259f9290full, 0x3f684fc3988e9f08ull>(zz1) / detail::horner1<batch_type, 0x40756709b0b644beull, 0xc077fe08959063eeull, 0x40626219af6a7f42ull, 0xc035f2a2b6bf5d8cull>(zz1);
zz1 = sqrt(zz1 + zz1);
batch_type z = constants::pio4<batch_type>() - zz1;
zz1 = fms(zz1, vp, constants::pio_2lo<batch_type>());
z = z - zz1;
zz1 = z + constants::pio4<batch_type>();
batch_type zz2 = self * self;
z = zz2 * detail::horner<batch_type, 0xc020656c06ceafd5ull, 0x40339007da779259ull, 0xc0304331de27907bull, 0x4015c74b178a2dd9ull, 0xbfe34341333e5c16ull, 0x3f716b9b0bd48ad3ull>(zz2) / detail::horner1<batch_type, 0xc04898220a3607acull, 0x4061705684ffbf9dull, 0xc06265bb6d3576d7ull, 0x40519fc025fe9054ull, 0xc02d7b590b5e0eabull>(zz2);
zz2 = fma(x, z, x);
return select(x > batch_type(1.), constants::nan<batch_type>(),
select(small_cond, x,
select(x > ct1, zz1, zz2))
^ bitofsign(self));
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> asin(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
using batch_type = batch<std::complex<T>, A>;
using real_batch = typename batch_type::real_batch;
real_batch x = z.real();
real_batch y = z.imag();
batch_type ct(-y, x);
batch_type zz(real_batch(1.) - (x - y) * (x + y), -2 * x * y);
zz = log(ct + sqrt(zz));
batch_type resg(zz.imag(), -zz.real());
return select(y == real_batch(0.),
select(fabs(x) > real_batch(1.),
batch_type(constants::pio2<real_batch>(), real_batch(0.)),
batch_type(asin(x), real_batch(0.))),
resg);
}
// asinh
/* origin: boost/simd/arch/common/simd/function/asinh.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
namespace detail
{
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A>
average(const batch<T, A>& x1, const batch<T, A>& x2) noexcept
{
return (x1 & x2) + ((x1 ^ x2) >> 1);
}
template <class A, class T>
XSIMD_INLINE batch<T, A>
averagef(const batch<T, A>& x1, const batch<T, A>& x2) noexcept
{
using batch_type = batch<T, A>;
return fma(x1, batch_type(0.5), x2 * batch_type(0.5));
}
template <class A>
XSIMD_INLINE batch<float, A> average(batch<float, A> const& x1, batch<float, A> const& x2) noexcept
{
return averagef(x1, x2);
}
template <class A>
XSIMD_INLINE batch<double, A> average(batch<double, A> const& x1, batch<double, A> const& x2) noexcept
{
return averagef(x1, x2);
}
}
template <class A>
XSIMD_INLINE batch<float, A> asinh(batch<float, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<float, A>;
batch_type x = abs(self);
auto lthalf = x < batch_type(0.5);
batch_type x2 = x * x;
batch_type bts = bitofsign(self);
batch_type z(0.);
if (any(lthalf))
{
z = detail::horner<batch_type,
0x3f800000,
0xbe2aa9ad,
0x3d9949b1,
0xbd2ee581,
0x3ca4d6e6>(x2)
* x;
if (all(lthalf))
return z ^ bts;
}
batch_type tmp = select(x > constants::oneosqrteps<batch_type>(), x, detail::average(x, hypot(batch_type(1.), x)));
#ifndef XSIMD_NO_NANS
return select(isnan(self), constants::nan<batch_type>(), select(lthalf, z, log(tmp) + constants::log_2<batch_type>()) ^ bts);
#else
return select(lthalf, z, log(tmp) + constants::log_2<batch_type>()) ^ bts;
#endif
}
template <class A>
XSIMD_INLINE batch<double, A> asinh(batch<double, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<double, A>;
batch_type x = abs(self);
auto test = x > constants::oneosqrteps<batch_type>();
batch_type z = select(test, x - batch_type(1.), x + x * x / (batch_type(1.) + hypot(batch_type(1.), x)));
#ifndef XSIMD_NO_INFINITIES
z = select(x == constants::infinity<batch_type>(), x, z);
#endif
batch_type l1pz = log1p(z);
z = select(test, l1pz + constants::log_2<batch_type>(), l1pz);
return bitofsign(self) ^ z;
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> asinh(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
using batch_type = batch<std::complex<T>, A>;
batch_type w = asin(batch_type(-z.imag(), z.real()));
w = batch_type(w.imag(), -w.real());
return w;
}
// atan
namespace detail
{
template <class A>
static XSIMD_INLINE batch<float, A> kernel_atan(const batch<float, A>& x, const batch<float, A>& recx) noexcept
{
using batch_type = batch<float, A>;
const auto flag1 = x < constants::tan3pio8<batch_type>();
const auto flag2 = (x >= batch_type(bit_cast<float>((uint32_t)0x3ed413cd))) && flag1;
batch_type yy = select(flag1, batch_type(0.), constants::pio2<batch_type>());
yy = select(flag2, constants::pio4<batch_type>(), yy);
batch_type xx = select(flag1, x, -recx);
xx = select(flag2, (x - batch_type(1.)) / (x + batch_type(1.)), xx);
const batch_type z = xx * xx;
batch_type z1 = detail::horner<batch_type,
0xbeaaaa2aul,
0x3e4c925ful,
0xbe0e1b85ul,
0x3da4f0d1ul>(z);
z1 = fma(xx, z1 * z, xx);
z1 = select(flag2, z1 + constants::pio_4lo<batch_type>(), z1);
z1 = select(!flag1, z1 + constants::pio_2lo<batch_type>(), z1);
return yy + z1;
}
template <class A>
static XSIMD_INLINE batch<double, A> kernel_atan(const batch<double, A>& x, const batch<double, A>& recx) noexcept
{
using batch_type = batch<double, A>;
const auto flag1 = x < constants::tan3pio8<batch_type>();
const auto flag2 = (x >= constants::tanpio8<batch_type>()) && flag1;
batch_type yy = select(flag1, batch_type(0.), constants::pio2<batch_type>());
yy = select(flag2, constants::pio4<batch_type>(), yy);
batch_type xx = select(flag1, x, -recx);
xx = select(flag2, (x - batch_type(1.)) / (x + batch_type(1.)), xx);
batch_type z = xx * xx;
z *= detail::horner<batch_type,
0xc0503669fd28ec8eull,
0xc05eb8bf2d05ba25ull,
0xc052c08c36880273ull,
0xc03028545b6b807aull,
0xbfec007fa1f72594ull>(z)
/ detail::horner1<batch_type,
0x4068519efbbd62ecull,
0x407e563f13b049eaull,
0x407b0e18d2e2be3bull,
0x4064a0dd43b8fa25ull,
0x4038dbc45b14603cull>(z);
z = fma(xx, z, xx);
z = select(flag2, z + constants::pio_4lo<batch_type>(), z);
z = z + select(flag1, batch_type(0.), constants::pio_2lo<batch_type>());
return yy + z;
}
}
template <class A, class T>
XSIMD_INLINE batch<T, A> atan(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
const batch_type absa = abs(self);
const batch_type x = detail::kernel_atan(absa, batch_type(1.) / absa);
return x ^ bitofsign(self);
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> atan(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
using batch_type = batch<std::complex<T>, A>;
using real_batch = typename batch_type::real_batch;
real_batch x = z.real();
real_batch y = z.imag();
real_batch x2 = x * x;
real_batch one(1.);
real_batch a = one - x2 - (y * y);
real_batch w = 0.5 * atan2(2. * x, a);
real_batch num = y + one;
num = x2 + num * num;
real_batch den = y - one;
den = x2 + den * den;
#ifdef __FAST_MATH__
return batch_type(w, 0.25 * log(num / den));
#else
return select((x == real_batch(0.)) && (y == real_batch(1.)),
batch_type(real_batch(0.), constants::infinity<real_batch>()),
batch_type(w, 0.25 * log(num / den)));
#endif
}
// atanh
/* origin: boost/simd/arch/common/simd/function/acosh.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class A, class T>
XSIMD_INLINE batch<T, A> atanh(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
batch_type x = abs(self);
batch_type t = x + x;
batch_type z = batch_type(1.) - x;
auto test = x < batch_type(0.5);
batch_type tmp = select(test, x, t) / z;
return bitofsign(self) ^ (batch_type(0.5) * log1p(select(test, fma(t, tmp, t), tmp)));
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> atanh(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
using batch_type = batch<std::complex<T>, A>;
batch_type w = atan(batch_type(-z.imag(), z.real()));
w = batch_type(w.imag(), -w.real());
return w;
}
// atan2
template <class A, class T>
XSIMD_INLINE batch<T, A> atan2(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
const batch_type q = abs(self / other);
const batch_type z = detail::kernel_atan(q, batch_type(1.) / q);
return select(other > batch_type(0.), z, constants::pi<batch_type>() - z) * signnz(self);
}
// cos
namespace detail
{
template <class T, class A>
XSIMD_INLINE batch<T, A> quadrant(const batch<T, A>& x) noexcept
{
return x & batch<T, A>(3);
}
template <class A>
XSIMD_INLINE batch<float, A> quadrant(const batch<float, A>& x) noexcept
{
return to_float(quadrant(to_int(x)));
}
template <class A>
XSIMD_INLINE batch<double, A> quadrant(const batch<double, A>& x) noexcept
{
using batch_type = batch<double, A>;
batch_type a = x * batch_type(0.25);
return (a - floor(a)) * batch_type(4.);
}
/* origin: boost/simd/arch/common/detail/simd/f_trig_evaluation.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class A>
XSIMD_INLINE batch<float, A> cos_eval(const batch<float, A>& z) noexcept
{
using batch_type = batch<float, A>;
batch_type y = detail::horner<batch_type,
0x3d2aaaa5,
0xbab60619,
0x37ccf5ce>(z);
return batch_type(1.) + fma(z, batch_type(-0.5), y * z * z);
}
template <class A>
XSIMD_INLINE batch<float, A> sin_eval(const batch<float, A>& z, const batch<float, A>& x) noexcept
{
using batch_type = batch<float, A>;
batch_type y = detail::horner<batch_type,
0xbe2aaaa2,
0x3c08839d,
0xb94ca1f9>(z);
return fma(y * z, x, x);
}
template <class A>
static XSIMD_INLINE batch<float, A> base_tancot_eval(const batch<float, A>& z) noexcept
{
using batch_type = batch<float, A>;
batch_type zz = z * z;
batch_type y = detail::horner<batch_type,
0x3eaaaa6f,
0x3e0896dd,
0x3d5ac5c9,
0x3cc821b5,
0x3b4c779c,
0x3c19c53b>(zz);
return fma(y, zz * z, z);
}
template <class A, class BB>
static XSIMD_INLINE batch<float, A> tan_eval(const batch<float, A>& z, const BB& test) noexcept
{
using batch_type = batch<float, A>;
batch_type y = base_tancot_eval(z);
return select(test, y, -batch_type(1.) / y);
}
template <class A, class BB>
static XSIMD_INLINE batch<float, A> cot_eval(const batch<float, A>& z, const BB& test) noexcept
{
using batch_type = batch<float, A>;
batch_type y = base_tancot_eval(z);
return select(test, batch_type(1.) / y, -y);
}
/* origin: boost/simd/arch/common/detail/simd/d_trig_evaluation.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class A>
static XSIMD_INLINE batch<double, A> cos_eval(const batch<double, A>& z) noexcept
{
using batch_type = batch<double, A>;
batch_type y = detail::horner<batch_type,
0x3fe0000000000000ull,
0xbfa5555555555551ull,
0x3f56c16c16c15d47ull,
0xbefa01a019ddbcd9ull,
0x3e927e4f8e06d9a5ull,
0xbe21eea7c1e514d4ull,
0x3da8ff831ad9b219ull>(z);
return batch_type(1.) - y * z;
}
template <class A>
static XSIMD_INLINE batch<double, A> sin_eval(const batch<double, A>& z, const batch<double, A>& x) noexcept
{
using batch_type = batch<double, A>;
batch_type y = detail::horner<batch_type,
0xbfc5555555555548ull,
0x3f8111111110f7d0ull,
0xbf2a01a019bfdf03ull,
0x3ec71de3567d4896ull,
0xbe5ae5e5a9291691ull,
0x3de5d8fd1fcf0ec1ull>(z);
return fma(y * z, x, x);
}
template <class A>
static XSIMD_INLINE batch<double, A> base_tancot_eval(const batch<double, A>& z) noexcept
{
using batch_type = batch<double, A>;
batch_type zz = z * z;
batch_type num = detail::horner<batch_type,
0xc1711fead3299176ull,
0x413199eca5fc9dddull,
0xc0c992d8d24f3f38ull>(zz);
batch_type den = detail::horner1<batch_type,
0xc189afe03cbe5a31ull,
0x4177d98fc2ead8efull,
0xc13427bc582abc96ull,
0x40cab8a5eeb36572ull>(zz);
return fma(z, (zz * (num / den)), z);
}
template <class A, class BB>
static XSIMD_INLINE batch<double, A> tan_eval(const batch<double, A>& z, const BB& test) noexcept
{
using batch_type = batch<double, A>;
batch_type y = base_tancot_eval(z);
return select(test, y, -batch_type(1.) / y);
}
template <class A, class BB>
static XSIMD_INLINE batch<double, A> cot_eval(const batch<double, A>& z, const BB& test) noexcept
{
using batch_type = batch<double, A>;
batch_type y = base_tancot_eval(z);
return select(test, batch_type(1.) / y, -y);
}
/* origin: boost/simd/arch/common/detail/simd/trig_reduction.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
struct trigo_radian_tag
{
};
struct trigo_pi_tag
{
};
template <class B, class Tag = trigo_radian_tag>
struct trigo_reducer
{
static XSIMD_INLINE B reduce(const B& x, B& xr) noexcept
{
if (all(x <= constants::pio4<B>()))
{
xr = x;
return B(0.);
}
else if (all(x <= constants::pio2<B>()))
{
auto test = x > constants::pio4<B>();
xr = x - constants::pio2_1<B>();
xr -= constants::pio2_2<B>();
xr -= constants::pio2_3<B>();
xr = select(test, xr, x);
return select(test, B(1.), B(0.));
}
else if (all(x <= constants::twentypi<B>()))
{
B xi = nearbyint(x * constants::twoopi<B>());
xr = fnma(xi, constants::pio2_1<B>(), x);
xr -= xi * constants::pio2_2<B>();
xr -= xi * constants::pio2_3<B>();
return quadrant(xi);
}
else if (all(x <= constants::mediumpi<B>()))
{
B fn = nearbyint(x * constants::twoopi<B>());
B r = x - fn * constants::pio2_1<B>();
B w = fn * constants::pio2_1t<B>();
B t = r;
w = fn * constants::pio2_2<B>();
r = t - w;
w = fn * constants::pio2_2t<B>() - ((t - r) - w);
t = r;
w = fn * constants::pio2_3<B>();
r = t - w;
w = fn * constants::pio2_3t<B>() - ((t - r) - w);
xr = r - w;
return quadrant(fn);
}
else
{
static constexpr std::size_t size = B::size;
using value_type = typename B::value_type;
alignas(B) std::array<value_type, size> tmp;
alignas(B) std::array<value_type, size> txr;
alignas(B) std::array<value_type, size> args;
x.store_aligned(args.data());
for (std::size_t i = 0; i < size; ++i)
{
double arg = args[i];
#ifndef __FAST_MATH__
if (arg == std::numeric_limits<value_type>::infinity())
{
tmp[i] = 0.;
txr[i] = std::numeric_limits<value_type>::quiet_NaN();
}
else
#endif
{
double y[2];
std::int32_t n = ::xsimd::detail::__ieee754_rem_pio2(arg, y);
tmp[i] = value_type(n & 3);
txr[i] = value_type(y[0]);
}
}
xr = B::load_aligned(&txr[0]);
B res = B::load_aligned(&tmp[0]);
return res;
}
}
};
template <class B>
struct trigo_reducer<B, trigo_pi_tag>
{
static XSIMD_INLINE B reduce(const B& x, B& xr) noexcept
{
B xi = nearbyint(x * B(2.));
B x2 = x - xi * B(0.5);
xr = x2 * constants::pi<B>();
return quadrant(xi);
}
};
}
template <class A, class T>
XSIMD_INLINE batch<T, A> cos(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
const batch_type x = abs(self);
batch_type xr = constants::nan<batch_type>();
const batch_type n = detail::trigo_reducer<batch_type>::reduce(x, xr);
auto tmp = select(n >= batch_type(2.), batch_type(1.), batch_type(0.));
auto swap_bit = fma(batch_type(-2.), tmp, n);
auto sign_bit = select((swap_bit ^ tmp) != batch_type(0.), constants::signmask<batch_type>(), batch_type(0.));
const batch_type z = xr * xr;
const batch_type se = detail::sin_eval(z, xr);
const batch_type ce = detail::cos_eval(z);
const batch_type z1 = select(swap_bit != batch_type(0.), se, ce);
return z1 ^ sign_bit;
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> cos(batch<std::complex<T>, A> const& z, requires_arch<common>) noexcept
{
return { cos(z.real()) * cosh(z.imag()), -sin(z.real()) * sinh(z.imag()) };
}
// cosh
/* origin: boost/simd/arch/common/simd/function/cosh.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class A, class T>
XSIMD_INLINE batch<T, A> cosh(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
batch_type x = abs(self);
auto test1 = x > (constants::maxlog<batch_type>() - constants::log_2<batch_type>());
batch_type fac = select(test1, batch_type(0.5), batch_type(1.));
batch_type tmp = exp(x * fac);
batch_type tmp1 = batch_type(0.5) * tmp;
return select(test1, tmp1 * tmp, detail::average(tmp, batch_type(1.) / tmp));
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> cosh(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
auto x = z.real();
auto y = z.imag();
return { cosh(x) * cos(y), sinh(x) * sin(y) };
}
// sin
namespace detail
{
template <class A, class T, class Tag = trigo_radian_tag>
XSIMD_INLINE batch<T, A> sin(batch<T, A> const& self, Tag = Tag()) noexcept
{
using batch_type = batch<T, A>;
const batch_type x = abs(self);
batch_type xr = constants::nan<batch_type>();
const batch_type n = detail::trigo_reducer<batch_type, Tag>::reduce(x, xr);
auto tmp = select(n >= batch_type(2.), batch_type(1.), batch_type(0.));
auto swap_bit = fma(batch_type(-2.), tmp, n);
auto sign_bit = bitofsign(self) ^ select(tmp != batch_type(0.), constants::signmask<batch_type>(), batch_type(0.));
const batch_type z = xr * xr;
const batch_type se = detail::sin_eval(z, xr);
const batch_type ce = detail::cos_eval(z);
const batch_type z1 = select(swap_bit == batch_type(0.), se, ce);
return z1 ^ sign_bit;
}
}
template <class A, class T>
XSIMD_INLINE batch<T, A> sin(batch<T, A> const& self, requires_arch<common>) noexcept
{
return detail::sin(self);
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> sin(batch<std::complex<T>, A> const& z, requires_arch<common>) noexcept
{
return { sin(z.real()) * cosh(z.imag()), cos(z.real()) * sinh(z.imag()) };
}
// sincos
template <class A, class T>
XSIMD_INLINE std::pair<batch<T, A>, batch<T, A>> sincos(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
const batch_type x = abs(self);
batch_type xr = constants::nan<batch_type>();
const batch_type n = detail::trigo_reducer<batch_type>::reduce(x, xr);
auto tmp = select(n >= batch_type(2.), batch_type(1.), batch_type(0.));
auto swap_bit = fma(batch_type(-2.), tmp, n);
const batch_type z = xr * xr;
const batch_type se = detail::sin_eval(z, xr);
const batch_type ce = detail::cos_eval(z);
auto sin_sign_bit = bitofsign(self) ^ select(tmp != batch_type(0.), constants::signmask<batch_type>(), batch_type(0.));
const batch_type sin_z1 = select(swap_bit == batch_type(0.), se, ce);
auto cos_sign_bit = select((swap_bit ^ tmp) != batch_type(0.), constants::signmask<batch_type>(), batch_type(0.));
const batch_type cos_z1 = select(swap_bit != batch_type(0.), se, ce);
return std::make_pair(sin_z1 ^ sin_sign_bit, cos_z1 ^ cos_sign_bit);
}
template <class A, class T>
XSIMD_INLINE std::pair<batch<std::complex<T>, A>, batch<std::complex<T>, A>>
sincos(batch<std::complex<T>, A> const& z, requires_arch<common>) noexcept
{
using batch_type = batch<std::complex<T>, A>;
using real_batch = typename batch_type::real_batch;
real_batch rcos = cos(z.real());
real_batch rsin = sin(z.real());
real_batch icosh = cosh(z.imag());
real_batch isinh = sinh(z.imag());
return std::make_pair(batch_type(rsin * icosh, rcos * isinh), batch_type(rcos * icosh, -rsin * isinh));
}
// sinh
namespace detail
{
/* origin: boost/simd/arch/common/detail/common/sinh_kernel.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class A>
XSIMD_INLINE batch<float, A> sinh_kernel(batch<float, A> const& self) noexcept
{
using batch_type = batch<float, A>;
batch_type sqr_self = self * self;
return detail::horner<batch_type,
0x3f800000, // 1.0f
0x3e2aaacc, // 1.66667160211E-1f
0x3c087bbe, // 8.33028376239E-3f
0x39559e2f // 2.03721912945E-4f
>(sqr_self)
* self;
}
template <class A>
XSIMD_INLINE batch<double, A> sinh_kernel(batch<double, A> const& self) noexcept
{
using batch_type = batch<double, A>;
batch_type sqrself = self * self;
return fma(self, (detail::horner<batch_type,
0xc115782bdbf6ab05ull, // -3.51754964808151394800E5
0xc0c694b8c71d6182ull, // -1.15614435765005216044E4,
0xc064773a398ff4feull, // -1.63725857525983828727E2,
0xbfe9435fe8bb3cd6ull // -7.89474443963537015605E-1
>(sqrself)
/ detail::horner1<batch_type,
0xc1401a20e4f90044ull, // -2.11052978884890840399E6
0x40e1a7ba7ed72245ull, // 3.61578279834431989373E4,
0xc0715b6096e96484ull // -2.77711081420602794433E2,
>(sqrself))
* sqrself,
self);
}
}
/* origin: boost/simd/arch/common/simd/function/sinh.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class A, class T>
XSIMD_INLINE batch<T, A> sinh(batch<T, A> const& a, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
batch_type half(0.5);
batch_type x = abs(a);
auto lt1 = x < batch_type(1.);
batch_type bts = bitofsign(a);
batch_type z(0.);
if (any(lt1))
{
z = detail::sinh_kernel(x);
if (all(lt1))
return z ^ bts;
}
auto test1 = x > (constants::maxlog<batch_type>() - constants::log_2<batch_type>());
batch_type fac = select(test1, half, batch_type(1.));
batch_type tmp = exp(x * fac);
batch_type tmp1 = half * tmp;
batch_type r = select(test1, tmp1 * tmp, tmp1 - half / tmp);
return select(lt1, z, r) ^ bts;
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> sinh(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
auto x = z.real();
auto y = z.imag();
return { sinh(x) * cos(y), cosh(x) * sin(y) };
}
// tan
template <class A, class T>
XSIMD_INLINE batch<T, A> tan(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
const batch_type x = abs(self);
batch_type xr = constants::nan<batch_type>();
const batch_type n = detail::trigo_reducer<batch_type>::reduce(x, xr);
auto tmp = select(n >= batch_type(2.), batch_type(1.), batch_type(0.));
auto swap_bit = fma(batch_type(-2.), tmp, n);
auto test = (swap_bit == batch_type(0.));
const batch_type y = detail::tan_eval(xr, test);
return y ^ bitofsign(self);
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> tan(batch<std::complex<T>, A> const& z, requires_arch<common>) noexcept
{
using batch_type = batch<std::complex<T>, A>;
using real_batch = typename batch_type::real_batch;
real_batch d = cos(2 * z.real()) + cosh(2 * z.imag());
real_batch wreal = sin(2 * z.real()) / d;
real_batch wimag = sinh(2 * z.imag());
#ifdef __FAST_MATH__
return batch_type(wreal, real_batch(1.)), batch_type(wreal, wimag / d);
#else
batch_type winf(constants::infinity<real_batch>(), constants::infinity<real_batch>());
batch_type wres = select(isinf(wimag), batch_type(wreal, real_batch(1.)), batch_type(wreal, wimag / d));
return select(d == real_batch(0.), winf, wres);
#endif
}
// tanh
namespace detail
{
/* origin: boost/simd/arch/common/detail/common/tanh_kernel.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class B>
struct tanh_kernel;
template <class A>
struct tanh_kernel<batch<float, A>>
{
using batch_type = batch<float, A>;
static XSIMD_INLINE batch_type tanh(const batch_type& x) noexcept
{
batch_type sqrx = x * x;
return fma(detail::horner<batch_type,
0xbeaaaa99, // -3.33332819422E-1F
0x3e088393, // +1.33314422036E-1F
0xbd5c1e2d, // -5.37397155531E-2F
0x3ca9134e, // +2.06390887954E-2F
0xbbbaf0ea // -5.70498872745E-3F
>(sqrx)
* sqrx,
x, x);
}
static XSIMD_INLINE batch_type cotanh(const batch_type& x) noexcept
{
return batch_type(1.) / tanh(x);
}
};
template <class A>
struct tanh_kernel<batch<double, A>>
{
using batch_type = batch<double, A>;
static XSIMD_INLINE batch_type tanh(const batch_type& x) noexcept
{
batch_type sqrx = x * x;
return fma(sqrx * p(sqrx) / q(sqrx), x, x);
}
static XSIMD_INLINE batch_type cotanh(const batch_type& x) noexcept
{
batch_type sqrx = x * x;
batch_type qval = q(sqrx);
return qval / (x * fma(p(sqrx), sqrx, qval));
}
static XSIMD_INLINE batch_type p(const batch_type& x) noexcept
{
return detail::horner<batch_type,
0xc0993ac030580563, // -1.61468768441708447952E3
0xc058d26a0e26682d, // -9.92877231001918586564E1,
0xbfeedc5baafd6f4b // -9.64399179425052238628E-1
>(x);
}
static XSIMD_INLINE batch_type q(const batch_type& x) noexcept
{
return detail::horner1<batch_type,
0x40b2ec102442040c, // 4.84406305325125486048E3
0x40a176fa0e5535fa, // 2.23548839060100448583E3,
0x405c33f28a581B86 // 1.12811678491632931402E2,
>(x);
}
};
}
/* origin: boost/simd/arch/common/simd/function/tanh.hpp */
/*
* ====================================================
* copyright 2016 NumScale SAS
*
* Distributed under the Boost Software License, Version 1.0.
* (See copy at http://boost.org/LICENSE_1_0.txt)
* ====================================================
*/
template <class A, class T>
XSIMD_INLINE batch<T, A> tanh(batch<T, A> const& self, requires_arch<common>) noexcept
{
using batch_type = batch<T, A>;
batch_type one(1.);
batch_type x = abs(self);
auto test = x < (batch_type(5.) / batch_type(8.));
batch_type bts = bitofsign(self);
batch_type z = one;
if (any(test))
{
z = detail::tanh_kernel<batch_type>::tanh(x);
if (all(test))
return z ^ bts;
}
batch_type r = fma(batch_type(-2.), one / (one + exp(x + x)), one);
return select(test, z, r) ^ bts;
}
template <class A, class T>
XSIMD_INLINE batch<std::complex<T>, A> tanh(const batch<std::complex<T>, A>& z, requires_arch<common>) noexcept
{
using real_batch = typename batch<std::complex<T>, A>::real_batch;
auto x = z.real();
auto y = z.imag();
real_batch two(2);
auto d = cosh(two * x) + cos(two * y);
return { sinh(two * x) / d, sin(two * y) / d };
}
}
}
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+724
View File
@@ -0,0 +1,724 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_AVX512BW_HPP
#define XSIMD_AVX512BW_HPP
#include <array>
#include <type_traits>
#include "../types/xsimd_avx512bw_register.hpp"
namespace xsimd
{
namespace kernel
{
using namespace types;
namespace detail
{
template <class A, class T, int Cmp>
XSIMD_INLINE batch_bool<T, A> compare_int_avx512bw(batch<T, A> const& self, batch<T, A> const& other) noexcept
{
using register_type = typename batch_bool<T, A>::register_type;
if (std::is_signed<T>::value)
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return (register_type)_mm512_cmp_epi8_mask(self, other, Cmp);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return (register_type)_mm512_cmp_epi16_mask(self, other, Cmp);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 4)
{
return (register_type)_mm512_cmp_epi32_mask(self, other, Cmp);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 8)
{
return (register_type)_mm512_cmp_epi64_mask(self, other, Cmp);
}
}
else
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return (register_type)_mm512_cmp_epu8_mask(self, other, Cmp);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return (register_type)_mm512_cmp_epu16_mask(self, other, Cmp);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 4)
{
return (register_type)_mm512_cmp_epu32_mask(self, other, Cmp);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 8)
{
return (register_type)_mm512_cmp_epu64_mask(self, other, Cmp);
}
}
}
}
// abs
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> abs(batch<T, A> const& self, requires_arch<avx512bw>) noexcept
{
if (std::is_unsigned<T>::value)
{
return self;
}
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_abs_epi8(self);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_abs_epi16(self);
}
else
{
return abs(self, avx512dq {});
}
}
// add
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> add(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_add_epi8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_add_epi16(self, other);
}
else
{
return add(self, other, avx512dq {});
}
}
// avgr
template <class A, class T, class = typename std::enable_if<std::is_unsigned<T>::value>::type>
XSIMD_INLINE batch<T, A> avgr(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_avg_epu8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_avg_epu16(self, other);
}
else
{
return avgr(self, other, common {});
}
}
// avg
template <class A, class T, class = typename std::enable_if<std::is_unsigned<T>::value>::type>
XSIMD_INLINE batch<T, A> avg(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
auto adj = ((self ^ other) << 7) >> 7;
return avgr(self, other, A {}) - adj;
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
auto adj = ((self ^ other) << 15) >> 15;
return avgr(self, other, A {}) - adj;
}
else
{
return avg(self, other, common {});
}
}
// bitwise_lshift
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> bitwise_lshift(batch<T, A> const& self, int32_t other, requires_arch<avx512bw>) noexcept
{
#if defined(XSIMD_AVX512_SHIFT_INTRINSICS_IMM_ONLY)
XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_sllv_epi16(self, _mm512_set1_epi16(other));
#else
XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_slli_epi16(self, other);
#endif
}
else
{
return bitwise_lshift(self, other, avx512dq {});
}
}
// bitwise_rshift
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, int32_t other, requires_arch<avx512bw>) noexcept
{
if (std::is_signed<T>::value)
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
__m512i sign_mask = _mm512_set1_epi16((0xFF00 >> other) & 0x00FF);
__m512i zeros = _mm512_setzero_si512();
__mmask64 cmp_is_negative_mask = _mm512_cmpgt_epi8_mask(zeros, self);
__m512i cmp_sign_mask = _mm512_mask_blend_epi8(cmp_is_negative_mask, zeros, sign_mask);
#if defined(XSIMD_AVX512_SHIFT_INTRINSICS_IMM_ONLY)
__m512i res = _mm512_srav_epi16(self, _mm512_set1_epi16(other));
#else
__m512i res = _mm512_srai_epi16(self, other);
#endif
return _mm512_or_si512(cmp_sign_mask, _mm512_andnot_si512(sign_mask, res));
#if defined(XSIMD_AVX512_SHIFT_INTRINSICS_IMM_ONLY)
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_srav_epi16(self, _mm512_set1_epi16(other));
#else
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_srai_epi16(self, other);
#endif
}
else
{
return bitwise_rshift(self, other, avx512dq {});
}
}
else
{
#if defined(XSIMD_AVX512_SHIFT_INTRINSICS_IMM_ONLY)
XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_srlv_epi16(self, _mm512_set1_epi16(other));
#else
XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_srli_epi16(self, other);
#endif
}
else
{
return bitwise_rshift(self, other, avx512dq {});
}
}
}
// decr_if
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> decr_if(batch<T, A> const& self, batch_bool<T, A> const& mask, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_mask_sub_epi8(self, mask.data, self, _mm512_set1_epi8(1));
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_mask_sub_epi16(self, mask.data, self, _mm512_set1_epi16(1));
}
else
{
return decr_if(self, mask, avx512dq {});
}
}
// eq
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> eq(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
return detail::compare_int_avx512bw<A, T, _MM_CMPINT_EQ>(self, other);
}
// ge
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> ge(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
return detail::compare_int_avx512bw<A, T, _MM_CMPINT_GE>(self, other);
}
// gt
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> gt(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
return detail::compare_int_avx512bw<A, T, _MM_CMPINT_GT>(self, other);
}
// incr_if
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> incr_if(batch<T, A> const& self, batch_bool<T, A> const& mask, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_mask_add_epi8(self, mask.data, self, _mm512_set1_epi8(1));
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_mask_add_epi16(self, mask.data, self, _mm512_set1_epi16(1));
}
else
{
return incr_if(self, mask, avx512dq {});
}
}
// insert
template <class A, class T, size_t I, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> insert(batch<T, A> const& self, T val, index<I> pos, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_mask_set1_epi8(self, __mmask64(1ULL << (I & 63)), val);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_mask_set1_epi16(self, __mmask32(1 << (I & 31)), val);
}
else
{
return insert(self, val, pos, avx512dq {});
}
}
// le
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> le(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
return detail::compare_int_avx512bw<A, T, _MM_CMPINT_LE>(self, other);
}
// lt
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> lt(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
return detail::compare_int_avx512bw<A, T, _MM_CMPINT_LT>(self, other);
}
// load
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> load_unaligned(bool const* mem, batch_bool<T, A>, requires_arch<avx512bw>) noexcept
{
using mask_type = typename batch_bool<T, A>::register_type;
XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size == 64)
{
__m512i bool_val = _mm512_loadu_si512((__m512i const*)mem);
return (mask_type)_mm512_cmpgt_epu8_mask(bool_val, _mm512_setzero_si512());
}
else XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size == 32)
{
__m256i bpack = _mm256_loadu_si256((__m256i const*)mem);
return (mask_type)_mm512_cmpgt_epu16_mask(_mm512_cvtepu8_epi16(bpack), _mm512_setzero_si512());
}
else XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size == 16)
{
__m128i bpack = _mm_loadu_si128((__m128i const*)mem);
return (mask_type)_mm512_cmpgt_epu32_mask(_mm512_cvtepu8_epi32(bpack), _mm512_setzero_si512());
}
else XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size == 8)
{
__m128i bpack = _mm_loadl_epi64((__m128i const*)mem);
return (mask_type)_mm512_cmpgt_epu64_mask(_mm512_cvtepu8_epi64(bpack), _mm512_setzero_si512());
}
else
{
assert(false && "unexpected batch size");
return {};
}
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> load_aligned(bool const* mem, batch_bool<T, A>, requires_arch<avx512bw>) noexcept
{
using mask_type = typename batch_bool<T, A>::register_type;
XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size == 64)
{
__m512i bool_val = _mm512_load_si512((__m512i const*)mem);
return (mask_type)_mm512_cmpgt_epu8_mask(bool_val, _mm512_setzero_si512());
}
else XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size == 32)
{
__m256i bpack = _mm256_load_si256((__m256i const*)mem);
return (mask_type)_mm512_cmpgt_epu16_mask(_mm512_cvtepu8_epi16(bpack), _mm512_setzero_si512());
}
else XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size == 16)
{
__m128i bpack = _mm_load_si128((__m128i const*)mem);
return (mask_type)_mm512_cmpgt_epu32_mask(_mm512_cvtepu8_epi32(bpack), _mm512_setzero_si512());
}
else XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size == 8)
{
__m128i bpack = _mm_loadl_epi64((__m128i const*)mem);
return (mask_type)_mm512_cmpgt_epu64_mask(_mm512_cvtepu8_epi64(bpack), _mm512_setzero_si512());
}
else
{
assert(false && "unexpected batch size");
return {};
}
}
// max
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> max(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
if (std::is_signed<T>::value)
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_max_epi8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_max_epi16(self, other);
}
else
{
return max(self, other, avx512dq {});
}
}
else
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_max_epu8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_max_epu16(self, other);
}
else
{
return max(self, other, avx512dq {});
}
}
}
// min
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> min(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
if (std::is_signed<T>::value)
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_min_epi8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_min_epi16(self, other);
}
else
{
return min(self, other, avx512dq {});
}
}
else
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_min_epu8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_min_epu16(self, other);
}
else
{
return min(self, other, avx512dq {});
}
}
}
// mul
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> mul(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
__m512i upper = _mm512_and_si512(_mm512_mullo_epi16(self, other), _mm512_srli_epi16(_mm512_set1_epi16(-1), 8));
__m512i lower = _mm512_slli_epi16(_mm512_mullo_epi16(_mm512_srli_epi16(self, 8), _mm512_srli_epi16(other, 8)), 8);
return _mm512_or_si512(upper, lower);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_mullo_epi16(self, other);
}
else
{
return mul(self, other, avx512dq {});
}
}
// neq
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch_bool<T, A> neq(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
return detail::compare_int_avx512bw<A, T, _MM_CMPINT_NE>(self, other);
}
// sadd
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> sadd(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
if (std::is_signed<T>::value)
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_adds_epi8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_adds_epi16(self, other);
}
else
{
return sadd(self, other, avx512dq {});
}
}
else
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_adds_epu8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_adds_epu16(self, other);
}
else
{
return sadd(self, other, avx512dq {});
}
}
}
// select
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> select(batch_bool<T, A> const& cond, batch<T, A> const& true_br, batch<T, A> const& false_br, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_mask_blend_epi8(cond, false_br.data, true_br.data);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_mask_blend_epi16(cond, false_br.data, true_br.data);
}
else
{
return select(cond, true_br, false_br, avx512dq {});
}
}
// slide_left
template <size_t N, class A, class T, class = typename std::enable_if<(N & 3) == 2 && (N < 64)>::type>
XSIMD_INLINE batch<T, A> slide_left(batch<T, A> const& x, requires_arch<avx512bw>) noexcept
{
static_assert((N & 3) == 2 && N < 64, "The AVX512F implementation may have a lower latency.");
__mmask32 mask = 0xFFFFFFFFu << ((N / 2) & 31);
auto slide_pattern = make_batch_constant<uint16_t, detail::make_slide_left_pattern<N / 2>, A>();
return _mm512_maskz_permutexvar_epi16(mask, slide_pattern.as_batch(), x);
}
// slide_right
template <size_t N, class A, class T, class = typename std::enable_if<(N & 3) == 2 && (N < 64)>::type>
XSIMD_INLINE batch<T, A> slide_right(batch<T, A> const& x, requires_arch<avx512bw>) noexcept
{
static_assert((N & 3) == 2 && N < 64, "The AVX512F implementation may have a lower latency.");
__mmask32 mask = 0xFFFFFFFFu >> ((N / 2) & 31);
auto slide_pattern = make_batch_constant<uint16_t, detail::make_slide_right_pattern<N / 2>, A>();
return _mm512_maskz_permutexvar_epi16(mask, slide_pattern.as_batch(), x);
}
// ssub
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> ssub(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
if (std::is_signed<T>::value)
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_subs_epi8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_subs_epi16(self, other);
}
else
{
return ssub(self, other, avx512dq {});
}
}
else
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_subs_epu8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_subs_epu16(self, other);
}
else
{
return ssub(self, other, avx512dq {});
}
}
}
// store
template <class T, class A>
XSIMD_INLINE void store(batch_bool<T, A> const& self, bool* mem, requires_arch<avx512bw>) noexcept
{
constexpr auto size = batch_bool<T, A>::size;
__m512i bool_val = _mm512_maskz_set1_epi8(self.data, 0x01);
__mmask64 mask = size >= 64 ? ~(__mmask64)0 : (1ULL << size) - 1;
_mm512_mask_storeu_epi8((void*)mem, mask, bool_val);
}
// sub
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> sub(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
return _mm512_sub_epi8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
return _mm512_sub_epi16(self, other);
}
else
{
return sub(self, other, avx512dq {});
}
}
// swizzle (dynamic version)
template <class A>
XSIMD_INLINE batch<uint16_t, A> swizzle(batch<uint16_t, A> const& self, batch<uint16_t, A> mask, requires_arch<avx512bw>) noexcept
{
return _mm512_permutexvar_epi16(mask, self);
}
template <class A>
XSIMD_INLINE batch<int16_t, A> swizzle(batch<int16_t, A> const& self, batch<uint16_t, A> mask, requires_arch<avx512bw>) noexcept
{
return bitwise_cast<int16_t>(swizzle(bitwise_cast<uint16_t>(self), mask, avx512bw {}));
}
// swizzle (static version)
template <class A, uint16_t... Vs>
XSIMD_INLINE batch<uint16_t, A> swizzle(batch<uint16_t, A> const& self, batch_constant<uint16_t, A, Vs...> mask, requires_arch<avx512bw>) noexcept
{
return swizzle(self, mask.as_batch(), avx512bw {});
}
template <class A, uint16_t... Vs>
XSIMD_INLINE batch<int16_t, A> swizzle(batch<int16_t, A> const& self, batch_constant<uint16_t, A, Vs...> mask, requires_arch<avx512bw>) noexcept
{
return swizzle(self, mask.as_batch(), avx512bw {});
}
// widen
template <class A>
XSIMD_INLINE std::array<batch<widen_t<uint8_t>, A>, 2> widen(batch<uint8_t, A> const& x, requires_arch<avx512bw>) noexcept
{
__m256i x_lo = _mm512_extracti64x4_epi64(x, 0);
__m256i x_hi = _mm512_extracti64x4_epi64(x, 1);
__m512i lo = _mm512_cvtepu8_epi16(x_lo);
__m512i hi = _mm512_cvtepu8_epi16(x_hi);
return { lo, hi };
}
template <class A>
XSIMD_INLINE std::array<batch<widen_t<int8_t>, A>, 2> widen(batch<int8_t, A> const& x, requires_arch<avx512bw>) noexcept
{
__m256i x_lo = _mm512_extracti64x4_epi64(x, 0);
__m256i x_hi = _mm512_extracti64x4_epi64(x, 1);
__m512i lo = _mm512_cvtepi8_epi16(x_lo);
__m512i hi = _mm512_cvtepi8_epi16(x_hi);
return { lo, hi };
}
// zip_hi
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> zip_hi(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
__m512i lo, hi;
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
lo = _mm512_unpacklo_epi8(self, other);
hi = _mm512_unpackhi_epi8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
lo = _mm512_unpacklo_epi16(self, other);
hi = _mm512_unpackhi_epi16(self, other);
}
else
{
return zip_hi(self, other, avx512f {});
}
return _mm512_inserti32x4(
_mm512_inserti32x4(
_mm512_inserti32x4(hi, _mm512_extracti32x4_epi32(lo, 2), 0),
_mm512_extracti32x4_epi32(lo, 3),
2),
_mm512_extracti32x4_epi32(hi, 2),
1);
}
// zip_lo
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value>::type>
XSIMD_INLINE batch<T, A> zip_lo(batch<T, A> const& self, batch<T, A> const& other, requires_arch<avx512bw>) noexcept
{
__m512i lo, hi;
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
{
lo = _mm512_unpacklo_epi8(self, other);
hi = _mm512_unpackhi_epi8(self, other);
}
else XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
{
lo = _mm512_unpacklo_epi16(self, other);
hi = _mm512_unpackhi_epi16(self, other);
}
else
{
return zip_lo(self, other, avx512f {});
}
return _mm512_inserti32x4(
_mm512_inserti32x4(
_mm512_inserti32x4(lo, _mm512_extracti32x4_epi32(hi, 0), 1),
_mm512_extracti32x4_epi32(hi, 1),
3),
_mm512_extracti32x4_epi32(lo, 1),
2);
}
}
}
#endif
+28
View File
@@ -0,0 +1,28 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_AVX512CD_HPP
#define XSIMD_AVX512CD_HPP
#include "../types/xsimd_avx512cd_register.hpp"
namespace xsimd
{
namespace kernel
{
// Nothing there yet.
}
}
#endif
+269
View File
@@ -0,0 +1,269 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_AVX512DQ_HPP
#define XSIMD_AVX512DQ_HPP
#include "../types/xsimd_avx512dq_register.hpp"
namespace xsimd
{
namespace kernel
{
using namespace types;
// load_masked
template <class A, bool... Values, class Mode>
XSIMD_INLINE batch<int32_t, A> load_masked(int32_t const* mem, batch_bool_constant<int32_t, A, Values...> mask, convert<int32_t>, Mode, requires_arch<avx512dq>) noexcept
{
XSIMD_IF_CONSTEXPR(mask.countr_zero() >= 8)
{
constexpr auto mhi = ::xsimd::detail::upper_half<avx2>(mask);
const auto hi = load_masked<avx2>(mem + 8, mhi, convert<int32_t> {}, Mode {}, avx2 {});
return _mm512_inserti32x8(_mm512_setzero_si512(), hi, 1);
}
return load_masked<A>(mem, mask, convert<int32_t> {}, Mode {}, avx512f {});
}
template <class A, bool... Values, class Mode>
XSIMD_INLINE batch<float, A> load_masked(float const* mem, batch_bool_constant<float, A, Values...> mask, convert<float>, Mode, requires_arch<avx512dq>) noexcept
{
XSIMD_IF_CONSTEXPR(mask.countr_zero() >= 8)
{
constexpr auto mhi = ::xsimd::detail::upper_half<avx2>(mask);
const auto hi = load_masked<avx2>(mem + 8, mhi, convert<float> {}, Mode {}, avx2 {});
return _mm512_insertf32x8(_mm512_setzero_ps(), hi, 1);
}
return load_masked<A>(mem, mask, convert<float> {}, Mode {}, avx512f {});
}
// bitwise_and
template <class A>
XSIMD_INLINE batch<float, A> bitwise_and(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_and_ps(self, other);
}
template <class A>
XSIMD_INLINE batch<double, A> bitwise_and(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_and_pd(self, other);
}
// bitwise_andnot
template <class A>
XSIMD_INLINE batch<float, A> bitwise_andnot(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_andnot_ps(other, self);
}
template <class A>
XSIMD_INLINE batch<double, A> bitwise_andnot(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_andnot_pd(other, self);
}
// bitwise_not
template <class A>
XSIMD_INLINE batch<float, A> bitwise_not(batch<float, A> const& self, requires_arch<avx512dq>) noexcept
{
return _mm512_xor_ps(self, _mm512_castsi512_ps(_mm512_set1_epi32(-1)));
}
template <class A>
XSIMD_INLINE batch<double, A> bitwise_not(batch<double, A> const& self, requires_arch<avx512dq>) noexcept
{
return _mm512_xor_pd(self, _mm512_castsi512_pd(_mm512_set1_epi32(-1)));
}
// bitwise_or
template <class A>
XSIMD_INLINE batch<float, A> bitwise_or(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_or_ps(self, other);
}
template <class A>
XSIMD_INLINE batch<double, A> bitwise_or(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_or_pd(self, other);
}
template <class A, class T>
XSIMD_INLINE batch_bool<T, A> bitwise_or(batch_bool<T, A> const& self, batch_bool<T, A> const& other, requires_arch<avx512dq>) noexcept
{
using register_type = typename batch_bool<T, A>::register_type;
return register_type(self.data | other.data);
}
// bitwise_xor
template <class A>
XSIMD_INLINE batch<float, A> bitwise_xor(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_xor_ps(self, other);
}
template <class A>
XSIMD_INLINE batch<double, A> bitwise_xor(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_xor_pd(self, other);
}
// haddp
template <class A>
XSIMD_INLINE batch<float, A> haddp(batch<float, A> const* row, requires_arch<avx512dq>) noexcept
{
// The following folds over the vector once:
// tmp1 = [a0..8, b0..8]
// tmp2 = [a8..f, b8..f]
#define XSIMD_AVX512_HADDP_STEP1(I, a, b) \
batch<float, avx512dq> res##I; \
{ \
auto tmp1 = _mm512_shuffle_f32x4(a, b, _MM_SHUFFLE(1, 0, 1, 0)); \
auto tmp2 = _mm512_shuffle_f32x4(a, b, _MM_SHUFFLE(3, 2, 3, 2)); \
res##I = _mm512_add_ps(tmp1, tmp2); \
}
XSIMD_AVX512_HADDP_STEP1(0, row[0], row[2]);
XSIMD_AVX512_HADDP_STEP1(1, row[4], row[6]);
XSIMD_AVX512_HADDP_STEP1(2, row[1], row[3]);
XSIMD_AVX512_HADDP_STEP1(3, row[5], row[7]);
XSIMD_AVX512_HADDP_STEP1(4, row[8], row[10]);
XSIMD_AVX512_HADDP_STEP1(5, row[12], row[14]);
XSIMD_AVX512_HADDP_STEP1(6, row[9], row[11]);
XSIMD_AVX512_HADDP_STEP1(7, row[13], row[15]);
#undef XSIMD_AVX512_HADDP_STEP1
// The following flds the code and shuffles so that hadd_ps produces the correct result
// tmp1 = [a0..4, a8..12, b0..4, b8..12] (same for tmp3)
// tmp2 = [a5..8, a12..16, b5..8, b12..16] (same for tmp4)
// tmp5 = [r1[0], r1[2], r2[0], r2[2], r1[4], r1[6] ...
#define XSIMD_AVX512_HADDP_STEP2(I, a, b, c, d) \
batch<float, avx2> halfx##I; \
{ \
auto tmp1 = _mm512_shuffle_f32x4(a, b, _MM_SHUFFLE(2, 0, 2, 0)); \
auto tmp2 = _mm512_shuffle_f32x4(a, b, _MM_SHUFFLE(3, 1, 3, 1)); \
\
auto resx1 = _mm512_add_ps(tmp1, tmp2); \
\
auto tmp3 = _mm512_shuffle_f32x4(c, d, _MM_SHUFFLE(2, 0, 2, 0)); \
auto tmp4 = _mm512_shuffle_f32x4(c, d, _MM_SHUFFLE(3, 1, 3, 1)); \
\
auto resx2 = _mm512_add_ps(tmp3, tmp4); \
\
auto tmp5 = _mm512_shuffle_ps(resx1, resx2, _MM_SHUFFLE(2, 0, 2, 0)); \
auto tmp6 = _mm512_shuffle_ps(resx1, resx2, _MM_SHUFFLE(3, 1, 3, 1)); \
\
auto resx3 = _mm512_add_ps(tmp5, tmp6); \
\
halfx##I = _mm256_hadd_ps(_mm512_extractf32x8_ps(resx3, 0), \
_mm512_extractf32x8_ps(resx3, 1)); \
}
XSIMD_AVX512_HADDP_STEP2(0, res0, res1, res2, res3);
XSIMD_AVX512_HADDP_STEP2(1, res4, res5, res6, res7);
#undef XSIMD_AVX512_HADDP_STEP2
auto concat = _mm512_castps256_ps512(halfx0);
concat = _mm512_insertf32x8(concat, halfx1, 1);
return concat;
}
// ldexp
template <class A>
XSIMD_INLINE batch<double, A> ldexp(const batch<double, A>& self, const batch<as_integer_t<double>, A>& other, requires_arch<avx512dq>) noexcept
{
return _mm512_scalef_pd(self, _mm512_cvtepi64_pd(other));
}
// mul
template <class A>
XSIMD_INLINE batch<uint64_t, A> mul(batch<uint64_t, A> const& self, batch<uint64_t, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_mullo_epi64(self, other);
}
template <class A>
XSIMD_INLINE batch<int64_t, A> mul(batch<int64_t, A> const& self, batch<int64_t, A> const& other, requires_arch<avx512dq>) noexcept
{
return _mm512_mullo_epi64(self, other);
}
// nearbyint_as_int
template <class A>
XSIMD_INLINE batch<int64_t, A> nearbyint_as_int(batch<double, A> const& self,
requires_arch<avx512dq>) noexcept
{
return _mm512_cvtpd_epi64(self);
}
// reduce_add
template <class A>
XSIMD_INLINE float reduce_add(batch<float, A> const& rhs, requires_arch<avx512dq>) noexcept
{
__m256 tmp1 = _mm512_extractf32x8_ps(rhs, 1);
__m256 tmp2 = _mm512_extractf32x8_ps(rhs, 0);
__m256 res1 = _mm256_add_ps(tmp1, tmp2);
return reduce_add(batch<float, avx2>(res1), avx2 {});
}
// reduce_mul
template <class A>
XSIMD_INLINE float reduce_mul(batch<float, A> const& rhs, requires_arch<avx512dq>) noexcept
{
__m256 tmp1 = _mm512_extractf32x8_ps(rhs, 1);
__m256 tmp2 = _mm512_extractf32x8_ps(rhs, 0);
__m256 res1 = _mm256_mul_ps(tmp1, tmp2);
return reduce_mul(batch<float, avx2>(res1), avx2 {});
}
// swizzle constant mask
template <class A, uint32_t V0, uint32_t V1, uint32_t V2, uint32_t V3, uint32_t V4, uint32_t V5, uint32_t V6, uint32_t V7,
uint32_t V8, uint32_t V9, uint32_t V10, uint32_t V11, uint32_t V12, uint32_t V13, uint32_t V14, uint32_t V15>
XSIMD_INLINE batch<float, A> swizzle(batch<float, A> const& self,
batch_constant<uint32_t, A, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15> mask,
requires_arch<avx512dq>) noexcept
{
constexpr bool dup_lo = detail::is_dup_lo(mask);
constexpr bool dup_hi = detail::is_dup_hi(mask);
XSIMD_IF_CONSTEXPR(dup_lo || dup_hi)
{
const batch<float, avx2> half = _mm512_extractf32x8_ps(self, dup_lo ? 0 : 1);
constexpr typename std::conditional<dup_lo, batch_constant<uint32_t, avx2, V0 % 8, V1 % 8, V2 % 8, V3 % 8, V4 % 8, V5 % 8, V6 % 8, V7 % 8>,
batch_constant<uint32_t, avx2, V8 % 8, V9 % 8, V10 % 8, V11 % 8, V12 % 8, V13 % 8, V14 % 8, V15 % 8>>::type half_mask {};
auto permuted = swizzle(half, half_mask, avx2 {});
// merge the two slices into an AVX512F register:
return _mm512_broadcast_f32x8(permuted); // duplicates the 256-bit perm into both halves
}
return swizzle(self, mask, avx512f {});
}
// convert
namespace detail
{
template <class A>
XSIMD_INLINE batch<double, A> fast_cast(batch<int64_t, A> const& self, batch<double, A> const&, requires_arch<avx512dq>) noexcept
{
return _mm512_cvtepi64_pd(self);
}
template <class A>
XSIMD_INLINE batch<int64_t, A> fast_cast(batch<double, A> const& self, batch<int64_t, A> const&, requires_arch<avx512dq>) noexcept
{
return _mm512_cvttpd_epi64(self);
}
}
}
}
#endif
+20
View File
@@ -0,0 +1,20 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_AVX512ER_HPP
#define XSIMD_AVX512ER_HPP
#include <array>
#include <type_traits>
#include "../types/xsimd_avx512er_register.hpp"
#endif
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_AVX512IFMA_HPP
#define XSIMD_AVX512IFMA_HPP
#include <array>
#include <type_traits>
#include "../types/xsimd_avx512ifma_register.hpp"
#endif
+20
View File
@@ -0,0 +1,20 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XSIMD_AVX512PF_HPP
#define XSIMD_AVX512PF_HPP
#include <array>
#include <type_traits>
#include "../types/xsimd_avx512pf_register.hpp"
#endif

Some files were not shown because too many files have changed in this diff Show More