From 0e1964bf74987f882260d4b9ed44007e4e484971 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 2 Jan 2022 16:02:57 +0900 Subject: [PATCH] [simd] Split out the ivec implementations And add any/all/none functions. --- include/QF/simd/vec2i.h | 90 +++++++++++++++++++++++++++++ include/QF/simd/vec4f.h | 27 --------- include/QF/simd/vec4i.h | 123 ++++++++++++++++++++++++++++++++++++++++ libs/util/simd.c | 4 ++ 4 files changed, 217 insertions(+), 27 deletions(-) create mode 100644 include/QF/simd/vec2i.h create mode 100644 include/QF/simd/vec4i.h diff --git a/include/QF/simd/vec2i.h b/include/QF/simd/vec2i.h new file mode 100644 index 000000000..694d5fa7b --- /dev/null +++ b/include/QF/simd/vec2i.h @@ -0,0 +1,90 @@ +/* + QF/simd/vec2i.h + + Vector functions for vec2i_t (ie, int) + + Copyright (C) 2022 Bill Currie + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ + +#ifndef __QF_simd_vec2i_h +#define __QF_simd_vec2i_h + +#include +#include + +#include "QF/simd/types.h" + +GNU89INLINE inline vec2i_t vabs2i (vec2i_t v) __attribute__((const)); +GNU89INLINE inline int any2i (vec2i_t v) __attribute__((const)); +GNU89INLINE inline int all2i (vec2i_t v) __attribute__((const)); +GNU89INLINE inline int none2i (vec2i_t v) __attribute__((const)); + +#ifndef IMPLEMENT_VEC2I_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +vec2i_t +vabs2i (vec2i_t v) +{ + const uint32_t nan = ~0u >> 1; + const vec2i_t abs = { nan, nan }; + return (vec2i_t) ((vec2i_t) v & abs); +} + +#ifndef IMPLEMENT_VEC2I_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +int +any2i (vec2i_t v) +{ + vec2i_t t = _m_pcmpeqd (v, (vec2i_t) {0, 0}); + return _mm_hadd_pi32 (t, t)[0] > -2; +} + +#ifndef IMPLEMENT_VEC2I_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +int +all2i (vec2i_t v) +{ + vec2i_t t = _m_pcmpeqd (v, (vec2i_t) {0, 0}); + return _mm_hadd_pi32 (t, t)[0] == 0; +} + +#ifndef IMPLEMENT_VEC2I_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +int +none2i (vec2i_t v) +{ + vec2i_t t = _m_pcmpeqd (v, (vec2i_t) {0, 0}); + return _mm_hadd_pi32 (t, t)[0] == -2; +} + +#endif//__QF_simd_vec2i_h diff --git a/include/QF/simd/vec4f.h b/include/QF/simd/vec4f.h index 9105e7952..7b7c8429d 100644 --- a/include/QF/simd/vec4f.h +++ b/include/QF/simd/vec4f.h @@ -99,8 +99,6 @@ GNU89INLINE inline void storevec3f (float *v3, vec4f_t v4); GNU89INLINE inline vec4f_t normalf (vec4f_t v) __attribute__((pure)); GNU89INLINE inline vec4f_t magnitudef (vec4f_t v) __attribute__((pure)); GNU89INLINE inline vec4f_t magnitude3f (vec4f_t v) __attribute__((pure)); -GNU89INLINE inline vec4i_t loadvec3i (const int *v3) __attribute__((pure)); -GNU89INLINE inline void storevec3i (int *v3, vec4i_t v4); #ifndef IMPLEMENT_VEC4F_Funcs GNU89INLINE inline @@ -424,29 +422,4 @@ CircumSphere_vf (const vec4f_t *points, int num_points); vspheref_t SmallestEnclosingBall_vf (const vec4f_t *points, int num_points); -#ifndef IMPLEMENT_VEC4F_Funcs -GNU89INLINE inline -#else -VISIBLE -#endif -vec4i_t -loadvec3i (const int *v3) -{ - vec4i_t v4 = { v3[0], v3[1], v3[2], 0 }; - return v4; -} - -#ifndef IMPLEMENT_VEC4F_Funcs -GNU89INLINE inline -#else -VISIBLE -#endif -void -storevec3i (int *v3, vec4i_t v4) -{ - v3[0] = v4[0]; - v3[1] = v4[1]; - v3[2] = v4[2]; -} - #endif//__QF_simd_vec4f_h diff --git a/include/QF/simd/vec4i.h b/include/QF/simd/vec4i.h new file mode 100644 index 000000000..6320cd83a --- /dev/null +++ b/include/QF/simd/vec4i.h @@ -0,0 +1,123 @@ +/* + QF/simd/vec4i.h + + Vector functions for vec4i_t (ie, int) + + Copyright (C) 2022 Bill Currie + + 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: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ + +#ifndef __QF_simd_vec4i_h +#define __QF_simd_vec4i_h + +#include +#include + +#include "QF/simd/types.h" + +GNU89INLINE inline vec4i_t vabs4i (vec4i_t v) __attribute__((const)); +GNU89INLINE inline int any4i (vec4i_t v) __attribute__((const)); +GNU89INLINE inline int all4i (vec4i_t v) __attribute__((const)); +GNU89INLINE inline int none4i (vec4i_t v) __attribute__((const)); +GNU89INLINE inline vec4i_t loadvec3i (const int *v3) __attribute__((pure)); +GNU89INLINE inline void storevec3i (int *v3, vec4i_t v4); + +#ifndef IMPLEMENT_VEC4F_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +vec4i_t +vabs4i (vec4i_t v) +{ + const uint32_t nan = ~0u >> 1; + const vec4i_t abs = { nan, nan, nan, nan }; + return (vec4i_t) ((vec4i_t) v & abs); +} + +#ifndef IMPLEMENT_VEC2I_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +int +any4i (vec4i_t v) +{ + return !__builtin_ia32_ptestz128 ((__v2di)v, (__v2di)v); + /*vec4i_t t = (v != (vec4i_t) {}); + t = __builtin_ia32_phaddd128 (t, t); + return __builtin_ia32_phaddd128 (t, t)[0] != 0;*/ +} + +#ifndef IMPLEMENT_VEC2I_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +int +all4i (vec4i_t v) +{ + vec4i_t t = (v == (vec4i_t) {}); + return __builtin_ia32_ptestz128 ((__v2di)t, (__v2di)t); + /*t = __builtin_ia32_phaddd128 (t, t); + return __builtin_ia32_phaddd128 (t, t)[0] == 0;*/ +} + +#ifndef IMPLEMENT_VEC2I_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +int +none4i (vec4i_t v) +{ + return __builtin_ia32_ptestz128 ((__v2di)v, (__v2di)v); + /*vec4i_t t = (v != (vec4i_t) {}); + t = __builtin_ia32_phaddd128 (t, t); + return __builtin_ia32_phaddd128 (t, t)[0] == 0;*/ +} + +#ifndef IMPLEMENT_VEC4F_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +vec4i_t +loadvec3i (const int *v3) +{ + vec4i_t v4 = { v3[0], v3[1], v3[2], 0 }; + return v4; +} + +#ifndef IMPLEMENT_VEC4F_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +void +storevec3i (int *v3, vec4i_t v4) +{ + v3[0] = v4[0]; + v3[1] = v4[1]; + v3[2] = v4[2]; +} + +#endif//__QF_simd_vec4i_h diff --git a/libs/util/simd.c b/libs/util/simd.c index c6cedf222..352a4169a 100644 --- a/libs/util/simd.c +++ b/libs/util/simd.c @@ -34,15 +34,19 @@ #define IMPLEMENT_VEC2F_Funcs #define IMPLEMENT_VEC2D_Funcs +#define IMPLEMENT_VEC2I_Funcs #define IMPLEMENT_VEC4F_Funcs #define IMPLEMENT_VEC4D_Funcs +#define IMPLEMENT_VEC4I_Funcs #define IMPLEMENT_MAT4F_Funcs #include "QF/mathlib.h" #include "QF/simd/vec2d.h" #include "QF/simd/vec2f.h" +#include "QF/simd/vec2i.h" #include "QF/simd/vec4d.h" #include "QF/simd/vec4f.h" +#include "QF/simd/vec4i.h" #include "QF/simd/mat4f.h" #include "QF/set.h" #include "QF/sys.h"