rsimd

Make SIMD instruction sets easier to use
git clone git://git.meso-star.fr/rsimd.git
Log | Files | Refs | README | LICENSE

commit d9088d1c00342b493c341935550144d0746c4d8c
parent 217c510f0e10b5dfdff25ca8335171408b739feb
Author: vaplv <vaplv@free.fr>
Date:   Sun, 24 Feb 2019 21:16:14 +0100

Refactor the soaXf<2|3|4> files

Diffstat:
Mcmake/CMakeLists.txt | 6+++++-
Msrc/soa4f2.h | 11+----------
Msrc/soa4f3.h | 15+--------------
Msrc/soa4f4.h | 2++
Asrc/soa8f2.h | 0
Asrc/soaXf2.h | 33+++++++++++++++++++++++++++++++++
Asrc/soaXf3.h | 38++++++++++++++++++++++++++++++++++++++
Msrc/soaXfY.h | 36+++---------------------------------
Asrc/soaXfY_begin.h | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/soaXfY_end.h | 31+++++++++++++++++++++++++++++++
10 files changed, 171 insertions(+), 58 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -54,6 +54,10 @@ set(RSIMD_FILES_INC_LEGACY aosq.h rsimd.h soaXfY.h + soaXfY_begin.h + soaXfY_end.h + soaXf2.h + soaXf3.h soa4f2.h soa4f3.h soa4f4.h) @@ -76,7 +80,7 @@ rcmake_prepend_path(RSIMD_FILES_INC_SSE ${RSIMD_SOURCE_DIR}) rcmake_prepend_path(RSIMD_FILES_INC_AVX ${RSIMD_SOURCE_DIR}) rcmake_prepend_path(RSIMD_FILES_SRC ${RSIMD_SOURCE_DIR}) rcmake_prepend_path(RSIMD_FILES_DOC ${PROJECT_SOURCE_DIR}/../) -set(RSIMD_FILES_INC +set(RSIMD_FILES_INC ${RSIMD_FILES_INC_LEGACY} ${RSIMD_FILES_INC_SSE} ${RSIMD_FILES_INC_AVX}) diff --git a/src/soa4f2.h b/src/soa4f2.h @@ -16,16 +16,7 @@ #ifndef SOA4F2_H #define SOA4F2_H -/* Generate the common soa4f2 funcs */ #define RSIMD_WIDTH__ 4 -#define RSIMD_SOA_DIMENSION__ 2 -#include "soaXfY.h" - -static FINLINE v4f_T -soa4f2_cross(const v4f_T a[2], const v4f_T b[2]) -{ - ASSERT(a && b); - return v4f_sub(v4f_mul(a[0], b[1]), v4f_mul(a[1], b[0])); -} +#include "soaXf2.h" #endif /* SOA4F2_H */ diff --git a/src/soa4f3.h b/src/soa4f3.h @@ -16,20 +16,7 @@ #ifndef SOA4F3_H #define SOA4F3_H -/* Generate the common soa4f3 functions */ #define RSIMD_WIDTH__ 4 -#define RSIMD_SOA_DIMENSION__ 3 -#include "soaXfY.h" - -static FINLINE v4f_T* -soa4f3_cross(v4f_T dst[3], const v4f_T a[3], const v4f_T b[3]) -{ - v4f_T tmp[3]; - ASSERT(dst && a && b); - tmp[0] = v4f_sub(v4f_mul(a[1], b[2]), v4f_mul(a[2], b[1])); - tmp[1] = v4f_sub(v4f_mul(a[2], b[0]), v4f_mul(a[0], b[2])); - tmp[2] = v4f_sub(v4f_mul(a[0], b[1]), v4f_mul(a[1], b[0])); - return soa4f3_set__(dst, tmp); -} +#include "soaXf3.h" #endif /* SOA4F3_H */ diff --git a/src/soa4f4.h b/src/soa4f4.h @@ -19,7 +19,9 @@ /* Generate the common soa4f4 functions */ #define RSIMD_WIDTH__ 4 #define RSIMD_SOA_DIMENSION__ 4 +#include "soaXfY_begin.h" #include "soaXfY.h" +#include "soaXfY_end.h" #endif /* SOA4F4_H */ diff --git a/src/soa8f2.h b/src/soa8f2.h diff --git a/src/soaXf2.h b/src/soaXf2.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2014-2019 Vincent Forest (vaplv@free.fr) + * + * The RSIMD library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSIMD library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef RSIMD_WIDTH__ + #error "Undefined RSIMD_WIDTH__ macro" +#endif + +#define RSIMD_SOA_DIMENSION__ 2 +#include "soaXfY_begin.h" +#include "soaXfY.h" + +static FINLINE RSIMD_vXf_T__ +RSIMD_soaXfY__(cross)(const RSIMD_vXf_T__ a[2], const RSIMD_vXf_T__ b[2]) +{ + ASSERT(a && b); + return RSIMD_vXf__(sub) + (RSIMD_vXf__(mul)(a[0], b[1]), + RSIMD_vXf__(mul)(a[1], b[0])); +} + +#include "soaXfY_end.h" diff --git a/src/soaXf3.h b/src/soaXf3.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2014-2019 Vincent Forest (vaplv@free.fr) + * + * The RSIMD library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSIMD library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef RSIMD_WIDTH__ + #error "Undefined RSIMD_WIDTH__ macro" +#endif + +#define RSIMD_SOA_DIMENSION__ 3 +#include "soaXfY_begin.h" +#include "soaXfY.h" + +static FINLINE RSIMD_vXf_T__* +RSIMD_soaXfY__(cross) + (RSIMD_vXf_T__ dst[3], + const RSIMD_vXf_T__ a[3], + const RSIMD_vXf_T__ b[3]) +{ + RSIMD_vXf_T__ tmp[3]; + ASSERT(dst && a && b); + tmp[0] = RSIMD_vXf__(sub)(RSIMD_vXf__(mul)(a[1], b[2]), RSIMD_vXf__(mul)(a[2], b[1])); + tmp[1] = RSIMD_vXf__(sub)(RSIMD_vXf__(mul)(a[2], b[0]), RSIMD_vXf__(mul)(a[0], b[2])); + tmp[2] = RSIMD_vXf__(sub)(RSIMD_vXf__(mul)(a[0], b[1]), RSIMD_vXf__(mul)(a[1], b[0])); + return RSIMD_soaXfY__(set__)(dst, tmp); +} + +#include "soaXfY_end.h" diff --git a/src/soaXfY.h b/src/soaXfY.h @@ -14,32 +14,13 @@ * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */ /* - * Header used to generate funcs on SoA SIMD float vectors of X dimensions + * Header used to generate funcs on SoA SIMD float vectors of Y dimensions */ -#include "rsimd.h" -#if !defined(RSIMD_SOA_DIMENSION__) - #error "Undefined RSIMD_SOA_DIMENSION__ macro" -#endif -#if !defined(RSIMD_WIDTH__) - #error "Undefined RSIMD_WIDTH__ macro" -#endif -#if RSIMD_SOA_DIMENSION__ < 1 || RSIMD_SOA_DIMENSION__ > 4 - #error "Unexpected RSIMD_SOA_DIMENSION__ value" -#endif -#if RSIMD_WIDTH__ != 4 && RSIMD_WIDTH__ != 8 - #error "Unexpected RSIMD_WIDTH__ value" +#ifndef SOAXFY_BEGIN_H + #error "The soaXfY_begin.h header must be included first" #endif -/* Macros generic to RSIMD_WIDTH__ */ -#define RSIMD_vXf__(Func) \ - CONCAT(CONCAT(CONCAT(CONCAT(v, RSIMD_WIDTH__), f), _), Func) -#define RSIMD_vXf_T__ CONCAT(CONCAT(v, RSIMD_WIDTH__), f_T) -#define RSIMD_soaXfY_PREFIX__ \ - CONCAT(CONCAT(CONCAT(soa, RSIMD_WIDTH__), f), RSIMD_SOA_DIMENSION__) -#define RSIMD_soaXfY__(Func) CONCAT(CONCAT(RSIMD_soaXfY_PREFIX__, _), Func) -#define SIZEOF_RSIMD_soaXfY__ sizeof(RSIMD_vXf_T__[RSIMD_SOA_DIMENSION__]) - /* Force GCC to unroll the loops */ #ifdef COMPILER_GCC #pragma GCC push_options @@ -376,14 +357,3 @@ RSIMD_soaXfY__(selv) #pragma GCC pop_options #endif -/* Undef helper macros */ -#undef RSIMD_vXf__ -#undef RSIMD_vXf_T__ -#undef RSIMD_soaXfY_PREFIX__ -#undef RSIMD_soaXfY__ -#undef SIZEOF_RSIMD_soaXfY__ - -/* Undef parameters */ -#undef RSIMD_SOA_DIMENSION__ -#undef RSIMD_WIDTH__ - diff --git a/src/soaXfY_begin.h b/src/soaXfY_begin.h @@ -0,0 +1,57 @@ +/* Copyright (C) 2014-2019 Vincent Forest (vaplv@free.fr) + * + * The RSIMD library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSIMD library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */ + +#include "rsimd.h" + +/* This file can be included once */ +#ifdef SOAXFY_BEGIN_H + #error "The soaXfY_begin.h header is already included" +#endif +#define SOAXFY_BEGIN_H + +/* Check parameters */ +#if !defined(RSIMD_SOA_DIMENSION__) + #error "Undefined RSIMD_SOA_DIMENSION__ macro" +#endif +#if !defined(RSIMD_WIDTH__) + #error "Undefined RSIMD_WIDTH__ macro" +#endif +#if RSIMD_SOA_DIMENSION__ < 1 || RSIMD_SOA_DIMENSION__ > 4 + #error "Unexpected RSIMD_SOA_DIMENSION__ value" +#endif +#if RSIMD_WIDTH__ != 4 && RSIMD_WIDTH__ != 8 + #error "Unexpected RSIMD_WIDTH__ value" +#endif + +/* Check that internal macros are not already defined */ +#if defined(RSIMD_vXf__) \ + || defined(RSIMD_vXf_T__) \ + || defined(RSIMD_soaXfY_PREFIX__) \ + || defined(RSIMD_soaXfY__) \ + || defined(SIZEOF_RSIMD_soaXfY__) + #error "Unexpected macro definition" +#endif + +/* Macros generic to RSIMD_WIDTH__ */ +#define RSIMD_vXf__(Func) \ + CONCAT(CONCAT(CONCAT(CONCAT(v, RSIMD_WIDTH__), f), _), Func) +#define RSIMD_vXf_T__ CONCAT(CONCAT(v, RSIMD_WIDTH__), f_T) + +/* Macros genric to RSIMD_WIDTH__ and RSIMD_SOA_DIMENSION__ */ +#define RSIMD_soaXfY_PREFIX__ \ + CONCAT(CONCAT(CONCAT(soa, RSIMD_WIDTH__), f), RSIMD_SOA_DIMENSION__) +#define RSIMD_soaXfY__(Func) CONCAT(CONCAT(RSIMD_soaXfY_PREFIX__, _), Func) +#define SIZEOF_RSIMD_soaXfY__ sizeof(RSIMD_vXf_T__[RSIMD_SOA_DIMENSION__]) + diff --git a/src/soaXfY_end.h b/src/soaXfY_end.h @@ -0,0 +1,31 @@ +/* Copyright (C) 2014-2019 Vincent Forest (vaplv@free.fr) + * + * The RSIMD library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The RSIMD library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the RSIMD library. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SOAXFY_BEGIN_H + #error "The soaXfY_begin.h file must be included" +#endif + +/* Undef helper macros */ +#undef RSIMD_vXf__ +#undef RSIMD_vXf_T__ +#undef RSIMD_soaXfY_PREFIX__ +#undef RSIMD_soaXfY__ +#undef SIZEOF_RSIMD_soaXfY__ + +/* Undef parameters */ +#undef RSIMD_SOA_DIMENSION__ +#undef RSIMD_WIDTH__ + +#undef SOAXFY_BEGIN_H