diff options
author | Brecht Van Lommel <brecht@blender.org> | 2021-02-14 16:20:51 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2021-02-17 18:26:24 +0300 |
commit | 859118d8f6ff022a16acbc6435488883424bad25 (patch) | |
tree | e0f708929a884070f7c3758f7fb58527cbdfd555 /source/blender/blenlib | |
parent | ac680c569e1b979f20c2e81dbd4f232085141aad (diff) |
BLI: add BLI_simd.h header to wrap SSE includes
In preparation of adding Neon support.
Ref D8237, T78710
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_simd.h | 28 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 11 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 2 |
5 files changed, 37 insertions, 12 deletions
diff --git a/source/blender/blenlib/BLI_simd.h b/source/blender/blenlib/BLI_simd.h new file mode 100644 index 00000000000..1518b6c1de2 --- /dev/null +++ b/source/blender/blenlib/BLI_simd.h @@ -0,0 +1,28 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +/** \file + * \ingroup bli + * + * SIMD instruction support. + */ + +#if defined(__SSE2__) +# include <emmintrin.h> +# define BLI_HAVE_SSE2 +#endif diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 28aa81e5858..39945960e68 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -31,11 +31,8 @@ #include <stdio.h> #include <stdlib.h> -#ifdef __SSE2__ -# include <emmintrin.h> -#endif - #include "BLI_math_base.h" +#include "BLI_simd.h" #ifdef __cplusplus extern "C" { @@ -685,10 +682,10 @@ MINLINE int integer_digits_i(const int i) /* Internal helpers for SSE2 implementation. * - * NOTE: Are to be called ONLY from inside `#ifdef __SSE2__` !!! + * NOTE: Are to be called ONLY from inside `#ifdef BLI_HAVE_SSE2` !!! */ -#ifdef __SSE2__ +#ifdef BLI_HAVE_SSE2 /* Calculate initial guess for arg^exp based on float representation * This method gives a constant bias, which can be easily compensated by @@ -769,7 +766,7 @@ MALWAYS_INLINE __m128 _bli_math_blend_sse(const __m128 mask, const __m128 a, con return _mm_or_ps(_mm_and_ps(mask, a), _mm_andnot_ps(mask, b)); } -#endif /* __SSE2__ */ +#endif /* BLI_HAVE_SSE2 */ /* Low level conversion functions */ MINLINE unsigned char unit_float_to_uchar_clamp(float val) diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index 26828cb8717..4c50c1c7af8 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -34,7 +34,7 @@ /******************************** Color Space ********************************/ -# ifdef __SSE2__ +# ifdef BLI_HAVE_SSE2 MALWAYS_INLINE __m128 srgb_to_linearrgb_v4_simd(const __m128 c) { @@ -75,7 +75,7 @@ MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3]) srgb[2] = r[2]; } -# else /* __SSE2__ */ +# else /* BLI_HAVE_SSE2 */ MINLINE void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3]) { @@ -90,7 +90,7 @@ MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3]) srgb[1] = linearrgb_to_srgb(linear[1]); srgb[2] = linearrgb_to_srgb(linear[2]); } -# endif /* __SSE2__ */ +# endif /* BLI_HAVE_SSE2 */ MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4]) { diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 5d78bb0b901..b7e94e6c512 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -5907,7 +5907,7 @@ static float ff_quad_form_factor(float *p, float *n, float *q0, float *q1, float #if 0 -# include <xmmintrin.h> +# include "BLI_simd.h" static __m128 sse_approx_acos(__m128 x) { diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 6b5efc3f8c4..b460d75d77f 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -277,7 +277,7 @@ void mul_m4_m4m4_uniq(float R[4][4], const float A[4][4], const float B[4][4]) BLI_assert(!ELEM(R, A, B)); /* matrix product: R[j][k] = A[j][i] . B[i][k] */ -#ifdef __SSE2__ +#ifdef BLI_HAVE_SSE2 __m128 A0 = _mm_loadu_ps(A[0]); __m128 A1 = _mm_loadu_ps(A[1]); __m128 A2 = _mm_loadu_ps(A[2]); |