mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add a generic Eigen backend based on clang vector extensions
The goal of this MR is to implement a generic SIMD backend (packet ops) for Eigen that uses clang vector extensions instead of platform-dependent intrinsics. Ideally, this should make it possible to build Eigen and achieve reasonable speed on any platform that has a recent clang compiler, without having to write any inline assembly or intrinsics. Caveats: * The current implementation is a proof of concept and supports vectorization for float, double, int32_t, and int64_t using fixed-size 512-bit vectors (a somewhat arbitrary choice). I have not done much to tune this for speed yet. * For now, there is no way to enable this other than setting -DEIGEN_VECTORIZE_GENERIC on the command line. * This only compiles with newer versions of clang. I have tested that it compiles and all tests pass with clang 19.1.7. https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors Closes #2998 and #2997 See merge request libeigen/eigen!2051 Co-authored-by: Rasmus Munk Larsen <rmlarsen@google.com> Co-authored-by: Antonio Sánchez <cantonios@google.com>
This commit is contained in:
@@ -695,7 +695,6 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp_float(const Pack
|
||||
|
||||
template <typename Packet>
|
||||
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp_double(const Packet _x) {
|
||||
Packet x = _x;
|
||||
const Packet cst_zero = pset1<Packet>(0.0);
|
||||
const Packet cst_1 = pset1<Packet>(1.0);
|
||||
const Packet cst_2 = pset1<Packet>(2.0);
|
||||
@@ -719,7 +718,8 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp_double(const Pac
|
||||
|
||||
// clamp x
|
||||
Packet zero_mask = pcmp_lt(_x, cst_exp_lo);
|
||||
x = pmin(x, cst_exp_hi);
|
||||
Packet x = pmin(_x, cst_exp_hi);
|
||||
|
||||
// Express exp(x) as exp(g + n*log(2)).
|
||||
fx = pmadd(cst_cephes_LOG2EF, x, cst_half);
|
||||
|
||||
@@ -1352,7 +1352,6 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS T ptanh_double(const T& a_x)
|
||||
const T minus_clamp = pset1<T>(-17.714196154005176);
|
||||
#endif
|
||||
const T x = pmax(pmin(a_x, plus_clamp), minus_clamp);
|
||||
|
||||
// The following rational approximation was generated by rminimax
|
||||
// (https://gitlab.inria.fr/sfilip/rminimax) using the following
|
||||
// command:
|
||||
|
||||
Reference in New Issue
Block a user