rsimd

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

commit 896a516c378be27ae73708bfad24732272cdee40
parent 7dd8954d4229525bfbebefa1720ff04513517c73
Author: vaplv <vaplv@free.fr>
Date:   Sun, 10 Mar 2019 10:58:09 +0100

Test the soa8f2 functions

Diffstat:
Mcmake/CMakeLists.txt | 1+
Msrc/soa8f2.h | 22++++++++++++++++++++++
Asrc/test_soa8f2.c | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 154 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -119,6 +119,7 @@ if(NOT NO_TEST) new_test(test_soa4f2) new_test(test_soa4f3) new_test(test_soa4f4) + new_test(test_soa8f2 "-mavx") if(SSE4_1 AND CMAKE_COMPILER_IS_GNUCC) new_test_named(test_v4f_sse4_1 test_v4f "-msse4.1") diff --git a/src/soa8f2.h b/src/soa8f2.h @@ -0,0 +1,22 @@ +/* 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 SOA8F2_H +#define SOA8F2_H + +#define RSIMD_WIDTH__ 8 +#include "soaXf2.h" + +#endif /* SOA8F2_H */ diff --git a/src/test_soa8f2.c b/src/test_soa8f2.c @@ -0,0 +1,131 @@ +/* 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 "soa8f2.h" +#include "test_soaXf_utils.h" + +int +main(int argc, char** argv) +{ + v8f_T a[2], b[2], c[2]; + v8f_T v0, v1, v2, v3; + (void)argc, (void)argv; + + CHK(soa8f2_set(a, soa8f2_splat(c, v8f_set1(-1))) == a); + CHECK_V8MASK(v8f_eq(a[0], v8f_set1(-1.f)), V8TRUE); + CHECK_V8MASK(v8f_eq(a[1], v8f_set1(-1.f)), V8TRUE); + + v0 = v8f_set(.5f, 1.f, 2.f, 3.f, 4.f, 5.f , 6.f , 7.f); + v1 = v8f_set(8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f); + CHK(soa8f2(c, v0, v1) == c); + CHK(soa8f2_set(a, c) == a); + CHECK_V8MASK(v8f_eq(c[0], v0), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v1), V8TRUE); + CHECK_V8MASK(v8f_eq(a[0], v0), V8TRUE); + CHECK_V8MASK(v8f_eq(a[1], v1), V8TRUE); + + v0 = v8f_set(.5f, -1.f, -2.f, 3.f, -4.f, 5.f , 6.f , -7.f); + v1 = v8f_set(-8.f, 9.f, -10.f, 11.f, 12.f, -13.f, -14.f, -15.f); + CHK(soa8f2(a, v0, v1) == a); + CHK(soa8f2_minus(b, a) == b); + CHECK_V8MASK(v8f_eq(b[0], v8f_minus(v0)), V8TRUE); + CHECK_V8MASK(v8f_eq(b[1], v8f_minus(v1)), V8TRUE); + + v2 = v8f_set(1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f); + CHK(soa8f2_addf(c, a, v2) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_add(v0, v2)), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_add(v1, v2)), V8TRUE); + CHK(soa8f2_add(c, a, b) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_zero()), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_zero()), V8TRUE); + CHK(soa8f2_subf(c, a, v2) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_sub(v0, v2)), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_sub(v1, v2)), V8TRUE); + CHK(soa8f2_sub(c, a, b) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_sub(a[0], b[0])), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_sub(a[1], b[1])), V8TRUE); + CHK(soa8f2_mulf(c, a, v2) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_mul(v0, v2)), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_mul(v1, v2)), V8TRUE); + CHK(soa8f2_mul(c, a, b) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_mul(a[0], b[0])), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_mul(a[1], b[1])), V8TRUE); + CHK(soa8f2_divf(c, a, v2) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_div(v0, v2)), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_div(v1, v2)), V8TRUE); + CHK(soa8f2_div(c, a, b) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_set1(-1.f)), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_set1(-1.f)), V8TRUE); + + v3 = v8f_set(1.f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f, 2.f, 4.f); + CHK(soa8f2_lerp(c, a, b, v3)); + CHECK_V8MASK(v8f_eq(c[0], v8f_lerp(a[0], b[0], v3)), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_lerp(a[1], b[1], v3)), V8TRUE); + + v3 = soa8f2_sum(b); + CHECK_V8MASK(v8f_eq(v3, v8f_add(b[0], b[1])), V8TRUE); + v0 = v8f_mul(a[0], b[0]); + v1 = v8f_mul(a[1], b[1]); + v2 = v8f_add(v0, v1); + v3 = soa8f2_dot(a, b); + CHECK_V8MASK(v8f_eq(v3, v2), V8TRUE); + v2 = v8f_sqrt(soa8f2_dot(a, a)); + v3 = soa8f2_len(a); + CHECK_V8MASK(v8f_eq(v3, v2), V8TRUE); + + CHECK_V8MASK(soa8f2_is_normalized(a), V8FALSE); + v2 = soa8f2_normalize(b, a); + CHECK_V8MASK(v8f_eq_eps(v3, v2, v8f_set1(1.e-4f)), V8TRUE); + CHECK_V8MASK(soa8f2_is_normalized(b), V8TRUE); + v2 = soa8f2_len(b); + CHECK_V8MASK(v8f_eq_eps(v2, v8f_set1(1), v8f_set1(1.e-4f)), V8TRUE); + soa8f2_divf(c, a, v3); + CHECK_V8MASK(v8f_eq_eps(b[0], c[0], v8f_set1(1.e-4f)), V8TRUE); + CHECK_V8MASK(v8f_eq_eps(b[1], c[1], v8f_set1(1.e-4f)), V8TRUE); + + CHECK_V8MASK(soa8f2_eq(a, a), V8TRUE); + CHECK_V8MASK(soa8f2_eq(a, b), V8FALSE); + soa8f2_addf(b, a, v8f_set1(1.e-4f)); + CHECK_V8MASK(soa8f2_eq(a, b), V8FALSE); + CHECK_V8MASK(soa8f2_eq_eps(a, b, v8f_set1(1.e-3f)), V8TRUE); + v2 = v8f_set(0, 0, 1.e-3f, 0, 0, 0, 1.e-3f, 1.e-3f); + CHECK_V8MASK__(soa8f2_eq_eps(a, b, v2), 0, 0, ~0, 0, 0, 0, ~0, ~0); + + CHK(soa8f2_min(c, a, b) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_min(a[0], b[0])), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_min(a[1], b[1])), V8TRUE); + CHK(soa8f2_max(c, a, b) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_max(a[0], b[0])), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_max(a[1], b[1])), V8TRUE); + + v0 = v8f_mask(0,0,~0,~0,0,~0,~0,0); + v1 = v8f_mask(0,~0,~0,0,0,0,0,~0); + CHK(soa8f2_sel(c, b, a, v0) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_sel(b[0], a[0], v0)), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_sel(b[1], a[1], v0)), V8TRUE); + soa8f2(c, v0, v1); + CHK(soa8f2_selv(c, b, a, c) == c); + CHECK_V8MASK(v8f_eq(c[0], v8f_sel(b[0], a[0], v0)), V8TRUE); + CHECK_V8MASK(v8f_eq(c[1], v8f_sel(b[1], a[1], v1)), V8TRUE); + + v0 = v8f_mul(a[0], b[1]); + v1 = v8f_mul(a[1], b[0]); + v2 = v8f_sub(v0, v1); + v3 = soa8f2_cross(a, b); + CHECK_V8MASK(v8f_eq_eps(v3, v2, v8f_set1(1.e-6f)), V8TRUE); + + return 0; +} +