| #include <limits.h> |
| #include <riscv_vector.h> |
| #include <softrvv.h> |
| #include <springbok.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| |
| #include <bit> |
| #include <tuple> |
| |
| #include "pw_unit_test/framework.h" |
| #include "test_v_helpers.h" |
| |
| namespace vadd_vx_test { |
| namespace { |
| |
| using namespace test_v_helpers; |
| |
| uint8_t test_vector_1[MAXVL_BYTES]; |
| uint8_t reference_vector_1[MAXVL_BYTES]; |
| |
| class VaddVxTest : public ::testing::Test { |
| protected: |
| void SetUp() override { zero_vector_registers(); } |
| void TearDown() override { zero_vector_registers(); } |
| }; |
| |
| // Below is a non-macro version of the test for more convenient debugging. |
| // Remove the "DISABLED_" prefix to enable this test for debugging. |
| TEST_F(VaddVxTest, DISABLED_vadd_vx_demo) { |
| for (int i = 0; i < AVL_COUNT; i++) { |
| int32_t avl = AVLS[i]; |
| int vlmax; |
| int vl; |
| std::tie(vlmax, vl) = vector_test_setup<int8_t>( |
| VLMUL::LMUL_M1, avl, test_vector_1, reference_vector_1); |
| if (avl > vlmax) { |
| continue; |
| } |
| int8_t *ptr_vec_1 = reinterpret_cast<int8_t *>(test_vector_1); |
| int8_t *ptr_ref_vec_1 = reinterpret_cast<int8_t *>(reference_vector_1); |
| int8_t test_val = 8; |
| __asm__ volatile("vadd.vx v8, v8, %[RS1]" ::[RS1] "r"(test_val)); |
| softrvv::vadd_vx<int8_t>(ptr_ref_vec_1, ptr_ref_vec_1, &test_val, avl); |
| __asm__ volatile("vse8.v v8, (%0)" : : "r"(ptr_vec_1)); |
| assert_vec_elem_eq<int8_t>(vlmax, test_vector_1, reference_vector_1); |
| } |
| } |
| |
| #define DEFINE_TEST_VADD_VX(_SEW_, _LMUL_, TEST_VAL) \ |
| TEST_F(VaddVxTest, vadd_vx##_SEW_##m##_LMUL_) { \ |
| for (int i = 0; i < AVL_COUNT; i++) { \ |
| int32_t avl = AVLS[i]; \ |
| int vlmax; \ |
| int vl; \ |
| std::tie(vlmax, vl) = vector_test_setup<int##_SEW_##_t>( \ |
| VLMUL::LMUL_M##_LMUL_, avl, test_vector_1, reference_vector_1); \ |
| if (avl > vlmax) { \ |
| continue; \ |
| } \ |
| int##_SEW_##_t *ptr_vec_1 = \ |
| reinterpret_cast<int##_SEW_##_t *>(test_vector_1); \ |
| int##_SEW_##_t *ptr_ref_vec_1 = \ |
| reinterpret_cast<int##_SEW_##_t *>(reference_vector_1); \ |
| const int##_SEW_##_t test_val = TEST_VAL; \ |
| __asm__ volatile("vadd.vx v8, v8, %[RS1]" ::[RS1] "r"(test_val)); \ |
| softrvv::vadd_vx<int##_SEW_##_t>(ptr_ref_vec_1, ptr_ref_vec_1, \ |
| &test_val, avl); \ |
| __asm__ volatile("vse" #_SEW_ ".v v8, (%0)" : : "r"(ptr_vec_1)); \ |
| assert_vec_elem_eq<int##_SEW_##_t>(vlmax, test_vector_1, \ |
| reference_vector_1); \ |
| } \ |
| } |
| |
| // TODO(gkielian): modify macro to permit more than one test per sew/lmul pair |
| DEFINE_TEST_VADD_VX(8, 1, INT8_MIN) |
| DEFINE_TEST_VADD_VX(8, 2, INT8_MAX) |
| DEFINE_TEST_VADD_VX(8, 4, -1) |
| DEFINE_TEST_VADD_VX(8, 8, 2) |
| |
| DEFINE_TEST_VADD_VX(16, 1, INT16_MIN) |
| DEFINE_TEST_VADD_VX(16, 2, INT16_MAX) |
| DEFINE_TEST_VADD_VX(16, 4, -1) |
| DEFINE_TEST_VADD_VX(16, 8, 2) |
| |
| DEFINE_TEST_VADD_VX(32, 1, INT32_MIN) |
| DEFINE_TEST_VADD_VX(32, 2, INT32_MAX) |
| DEFINE_TEST_VADD_VX(32, 4, -1) |
| DEFINE_TEST_VADD_VX(32, 8, 2) |
| |
| } // namespace |
| } // namespace vadd_vx_test |