[simd] Add vabsf and some more tests

This commit is contained in:
Bill Currie 2021-03-28 19:49:43 +09:00
parent eb325376b1
commit b6ab832ed4
2 changed files with 56 additions and 0 deletions

View file

@ -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

View file

@ -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])))