From b6ab832ed4aee2c55f5b66a0227159c763a0f353 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 28 Mar 2021 19:49:43 +0900 Subject: [PATCH] [simd] Add vabsf and some more tests --- include/QF/simd/vec4f.h | 14 +++++++++++++ libs/util/test/test-simd.c | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/QF/simd/vec4f.h b/include/QF/simd/vec4f.h index 04ee24c94..8ae4cbd5e 100644 --- a/include/QF/simd/vec4f.h +++ b/include/QF/simd/vec4f.h @@ -32,6 +32,7 @@ #include "QF/simd/types.h" +GNU89INLINE inline vec4f_t vabsf (vec4f_t v) __attribute__((const)); GNU89INLINE inline vec4f_t vsqrtf (vec4f_t v) __attribute__((const)); GNU89INLINE inline vec4f_t vceilf (vec4f_t v) __attribute__((const)); GNU89INLINE inline vec4f_t vfloorf (vec4f_t v) __attribute__((const)); @@ -97,6 +98,19 @@ 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)); +#ifndef IMPLEMENT_VEC4F_Funcs +GNU89INLINE inline +#else +VISIBLE +#endif +vec4f_t +vabsf (vec4f_t v) +{ + const uint32_t nan = ~0u >> 1; + const vec4i_t abs = { nan, nan, nan, nan }; + return _mm_and_ps (v, (__m128) abs); +} + #ifndef IMPLEMENT_VEC4F_Funcs GNU89INLINE inline #else diff --git a/libs/util/test/test-simd.c b/libs/util/test/test-simd.c index b14a1be9c..ebaab413f 100644 --- a/libs/util/test/test-simd.c +++ b/libs/util/test/test-simd.c @@ -27,6 +27,9 @@ #define none { -1, -1, -1, -1 } #define nqident { 0, 0, 0, -1 } +#define pi { M_PI, M_PI, M_PI, M_PI } // lots of bits +#define pmpi { -M_PI, M_PI, -M_PI, M_PI } // lots of bits + #define identity \ { { 1, 0, 0, 0 }, \ { 0, 1, 0, 0 }, \ @@ -124,6 +127,26 @@ static vec4f_t tqconjf (vec4f_t v, vec4f_t ignore) return qconjf (v); } +static vec4f_t tvabsf (vec4f_t v, vec4f_t ignore) +{ + return vabsf (v); +} + +static vec4f_t tvsqrtf (vec4f_t v, vec4f_t ignore) +{ + return vsqrtf (v); +} + +static vec4f_t tmagnitudef (vec4f_t v, vec4f_t ignore) +{ + return magnitudef (v); +} + +static vec4f_t tmagnitude3f (vec4f_t v, vec4f_t ignore) +{ + return magnitude3f (v); +} + static vec4d_test_t vec4d_tests[] = { // 3D dot products { dotd, right, right, one }, @@ -348,10 +371,29 @@ static vec4f_test_t vec4f_tests[] = { { qrotf, up, forward, { -s05, 0, 0, s05 } }, { qrotf, up, up, qident }, + { tvabsf, pmpi, {}, pi }, + { tvsqrtf, { 1, 4, 9, 16}, {}, {1, 2, 3, 4} }, { tvtruncf, { 1.1, 2.9, -1.1, -2.9 }, {}, { 1, 2, -1, -2 } }, { tvceilf, { 1.1, 2.9, -1.1, -2.9 }, {}, { 2, 3, -1, -2 } }, { tvfloorf, { 1.1, 2.9, -1.1, -2.9 }, {}, { 1, 2, -2, -3 } }, { tqconjf, one, {}, { -1, -1, -1, 1 } }, + { tmagnitudef, { 3, 4, 12, 84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { 3, 4, 12, -84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { 3, 4, -12, 84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { 3, 4, -12, -84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { 3, -4, 12, 84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { 3, -4, 12, -84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { 3, -4, -12, 84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { 3, -4, -12, -84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { -3, 4, 12, 84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { -3, 4, 12, -84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { -3, 4, -12, 84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { -3, 4, -12, -84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { -3, -4, 12, 84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { -3, -4, 12, -84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { -3, -4, -12, 84}, {}, {85, 85, 85, 85} }, + { tmagnitudef, { -3, -4, -12, -84}, {}, {85, 85, 85, 85} }, + { tmagnitude3f, { -3, -4, -12, -84}, {}, {13, 13, 13, 13} }, }; #define num_vec4f_tests (sizeof (vec4f_tests) / (sizeof (vec4f_tests[0])))