介绍

官网
https://xsimd.readthedocs.io/en/latest/
https://github.com/xtensor-stack/xsimd

安装

1
2
3
4
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/path/to/prefix ..
make install

支持的 指令集

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)

简单例子

将 根目录下的 include 文件内容,拷贝到 工程目录下即可

一个例子

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include "xsimd/xsimd.hpp"
#include <iostream>

namespace xs = xsimd;

int main(int argc, char* argv[]) {
    xs::batch<double, xs::avx> a = { 1.5, 2.5, 3.5, 4.5 };
    xs::batch<double, xs::avx> b = { 2.5, 3.5, 4.5, 5.5 };
    auto mean = (a + b) / 2;
    std::cout << mean << std::endl;
    return 0;
}

编译命令:

1
g++ -std=c++17 -mavx2 simple.cpp -g -o simple

结果:

1
(2.0, 3.0, 4.0, 5.0)

详细介绍

template<class T, class A>
class batch : public types::simd_register<T, A>, public xsimd::types::integral_only_operators<T, A>

batch of integer or floating point values.
Abstract representation of an SIMD register for floating point or integral value.
Template Parameters

  • T – the type of the underlying values.
  • A – the architecture this batch is tied too.

API

  • Data transfer,from memory、to memory
  • Arithmetic operators
  • Comparison
  • Bitwise
  • Mathematical
  • Reduction operators
  • Type conversion
  • Type Traits
  • Alignment manipulation
  • Architecture manipulation

参考