Move test_v_helper library to top level. * Add test_v_helper lib as dependency to softrvv. * Move test_v_helper library to top-level for use by softrvv. * Move assert_vec_elem_eq and assert_vec_mask_eq into header for easier reuse. Change-Id: I5b82520be802309dddfd5e529cee1c6cc9568723
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fb669e..3dbdb92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -40,6 +40,7 @@ add_subdirectory(pw_unit_test_demo) enable_testing() +add_subdirectory(test_v_helpers) add_subdirectory(softrvv) add_subdirectory(tests)
diff --git a/softrvv/tests/templates/base.tpl.cpp b/softrvv/tests/templates/base.tpl.cpp index bf3e1db..586cfff 100644 --- a/softrvv/tests/templates/base.tpl.cpp +++ b/softrvv/tests/templates/base.tpl.cpp
@@ -19,4 +19,8 @@ #include "pw_unit_test/framework.h" #include "softrvv.h" +#include "test_v_helpers.h" + +using namespace test_v_helpers; + ${self.body()}
diff --git a/softrvv/tests/templates/opivv_opivx_test.tpl.cpp b/softrvv/tests/templates/opivv_opivx_test.tpl.cpp index 1586eb6..4625ebc 100644 --- a/softrvv/tests/templates/opivv_opivx_test.tpl.cpp +++ b/softrvv/tests/templates/opivv_opivx_test.tpl.cpp
@@ -11,28 +11,6 @@ namespace softrvv_${template_helper.op_code}_test { namespace { ${insert_variable_init(template_helper, src2, src1, rs1, ref_vv, ref_vx)} -template <typename T> -void assert_vec_elem_eq(int avl, void *test_vector_1, void *test_vector_2) { - T *ptr_vec_1 = reinterpret_cast<T *>(test_vector_1); - T *ptr_vec_2 = reinterpret_cast<T *>(test_vector_2); - for (int idx = 0; idx < avl; idx++) { - ASSERT_EQ(ptr_vec_1[idx], ptr_vec_2[idx]); - } -} - -template <typename T> -void assert_vec_mask_eq(int avl, void *test_vector_1, void *test_vector_2) { - uint32_t *ptr_vec_1 = reinterpret_cast<uint32_t *>(test_vector_1); - uint32_t *ptr_vec_2 = reinterpret_cast<uint32_t *>(test_vector_2); - for (int idx = 0; idx < avl; idx++) { - const int bits_in_element = sizeof(uint32_t) * 8; - int eidx = idx / bits_in_element; - int epos = idx % bits_in_element; - uint32_t *e1 = ptr_vec_1 + eidx; - uint32_t *e2 = ptr_vec_2 + eidx; - ASSERT_EQ(*e1 & (1 << epos), *e2 & (1 << epos)); - } -} class SoftRvv${template_helper.op_code.capitalize()}Test : public ::testing::Test { protected:
diff --git a/test_v_helpers/CMakeLists.txt b/test_v_helpers/CMakeLists.txt new file mode 100644 index 0000000..62f7e65 --- /dev/null +++ b/test_v_helpers/CMakeLists.txt
@@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.10) +enable_language(ASM) + +add_library(test_v_helpers + test_v_helpers.cpp) + +target_include_directories(test_v_helpers PUBLIC include) +target_link_libraries(test_v_helpers PUBLIC pw_unit_test) + +target_compile_options(test_v_helpers PUBLIC + ${VEC_DEFAULT_COPTS} +)
diff --git a/tests/include/test_v_helpers.h b/test_v_helpers/include/test_v_helpers.h similarity index 79% rename from tests/include/test_v_helpers.h rename to test_v_helpers/include/test_v_helpers.h index 7189b72..ba28e43 100644 --- a/tests/include/test_v_helpers.h +++ b/test_v_helpers/include/test_v_helpers.h
@@ -72,6 +72,21 @@ } template <typename T> +void assert_vec_mask_eq(int avl, void *test_vector_1, void *test_vector_2) { + const unsigned int bw_required = std::__bit_width(sizeof(T)* 8); + const unsigned int shift = bw_required - 1; + T *ptr_vec_1 = reinterpret_cast<T *>(test_vector_1); + T *ptr_vec_2 = reinterpret_cast<T *>(test_vector_2); + for (int idx = 0; idx < avl; idx++) { + unsigned int element_idx = idx >> shift; // Eqivalent to idx / (sizeof(T) * 8) + unsigned int element_pos = idx & ~(element_idx << shift); // Equivalent to idx % (sizeof(T) * 8) + T *e1 = ptr_vec_1 + element_idx; + T *e2 = ptr_vec_2 + element_idx; + ASSERT_EQ(*e1 & (1 << element_pos), *e2 & (1 << element_pos)); + } +} + +template <typename T> static std::tuple<int, int> vector_test_setup( VLMUL lmul, int32_t avl, const std::initializer_list<void *> &vec_list) { // Clear all vector registers
diff --git a/tests/test_v_helpers.cpp b/test_v_helpers/test_v_helpers.cpp similarity index 100% rename from tests/test_v_helpers.cpp rename to test_v_helpers/test_v_helpers.cpp
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fc3db8d..2230dd1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt
@@ -1,16 +1,3 @@ -cmake_minimum_required(VERSION 3.10) -enable_language(ASM) - -add_library(test_v_helpers - test_v_helpers.cpp) - -target_include_directories(test_v_helpers PUBLIC include) -target_link_libraries(test_v_helpers PUBLIC pw_unit_test) - -target_compile_options(test_v_helpers PUBLIC - ${VEC_DEFAULT_COPTS} -) - vec_cc_generated_test( NAME vsub