| #include <limits.h> |
| #include <riscv_vector.h> |
| #include <softrvv.h> |
| #include <springbok.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| |
| #include <stdint.h> |
| #include <bit> |
| #include <tuple> |
| |
| #include "pw_unit_test/framework.h" |
| #include "test_v_helpers.h" |
| |
| #ifdef __cplusplus |
| |
| using float32_t = float; |
| using float64_t = double; |
| using float128_t = long double; |
| |
| #else |
| |
| typedef float float32_t; |
| typedef double float64_t; |
| typedef long double float128_t; |
| |
| #endif // __cplusplus |
| |
| namespace vfadd_vv_test |
| { |
| namespace |
| { |
| using namespace test_v_helpers; |
| |
| float src_vector_1[MAXVL_BYTES]; |
| float src_vector_2[MAXVL_BYTES]; |
| float dest_vector[MAXVL_BYTES]; |
| float ref_dest_vector[MAXVL_BYTES]; |
| |
| class VfaddTest : public ::testing::Test { |
| protected: |
| void SetUp() override { zero_vector_registers(); } |
| void TearDown() override { zero_vector_registers(); } |
| }; |
| |
| TEST_F(VfaddTest, vfadd_vv32m1) { |
| for (int i = 0; i < AVL_COUNT; i++) { |
| int32_t avl = AVLS[i]; |
| int vlmax; |
| int vl; |
| |
| /* For non narrowing instructions all vectors have same type*/ |
| std::tie(vlmax, vl) = vector_test_setup<int32_t>( |
| VLMUL::LMUL_M1, avl, |
| {dest_vector, ref_dest_vector, src_vector_1}); |
| |
| if (avl > vlmax) { |
| continue; |
| } |
| |
| float *ptr_vec_1 = reinterpret_cast<float *>(src_vector_1); |
| float *ptr_vec_2 = reinterpret_cast<float *>(src_vector_2); |
| float *ptr_dest_vec = reinterpret_cast<float *>(dest_vector); |
| float *ptr_ref_dest_vec = reinterpret_cast<float *>(ref_dest_vector); |
| |
| // set up values to test up to index of the AVL |
| fill_random_vector<float>(ptr_vec_1, avl); |
| fill_random_vector<float>(ptr_vec_2, avl); |
| memset(dest_vector, 0, MAXVL_BYTES); |
| memset(ref_dest_vector, 0, MAXVL_BYTES); |
| |
| // Generate reference vector |
| softrvv::vfadd_vv<float>(ptr_ref_dest_vec, ptr_vec_2, ptr_vec_1, avl); |
| // Load vector registers |
| __asm__ volatile("vle32.v v8, (%0)" : : "r"(ptr_vec_1)); |
| __asm__ volatile("vle32.v v16, (%0)" : : "r"(ptr_vec_2)); |
| |
| // Run target instruction |
| __asm__ volatile("vfadd.vv v24, v16, v8"); |
| |
| // Store result vector register |
| __asm__ volatile("vse32.v v24, (%0)" : : "r"(ptr_dest_vec)); |
| // Check vector elements |
| assert_vec_elem_eq<float>(vlmax, dest_vector, ref_dest_vector); |
| } |
| } |
| } |
| } |