| // Copyright 2023 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include <riscv_vector.h> |
| #include <springbok.h> |
| #include <stddef.h> |
| |
| #include "pw_unit_test/framework.h" |
| #include "test_v_helpers.h" |
| |
| namespace vle_vse_test { |
| namespace { |
| |
| using namespace test_v_helpers; |
| |
| uint8_t test_vector_1[MAXVL_BYTES]; |
| uint8_t test_vector_2[MAXVL_BYTES]; |
| |
| static void vlevse_test(VSEW sew, VLMUL lmul, bool use_intrinsic = false) { |
| for (int i = 0; i <= AVL_COUNT; ++i) { |
| zero_vector_registers(); |
| int32_t avl = AVLS[i]; |
| int vlmax; |
| int vl; |
| switch (sew) { |
| case SEW_E8: |
| std::tie(vlmax, vl) = vector_test_setup<uint8_t>( |
| lmul, avl, {test_vector_1, test_vector_2}); |
| break; |
| case SEW_E16: |
| std::tie(vlmax, vl) = vector_test_setup<uint16_t>( |
| lmul, avl, {test_vector_1, test_vector_2}); |
| break; |
| case SEW_E32: |
| std::tie(vlmax, vl) = vector_test_setup<uint32_t>( |
| lmul, avl, {test_vector_1, test_vector_2}); |
| break; |
| default: { |
| LOG_ERROR("Not supported SEW"); |
| ASSERT_TRUE(false); |
| break; |
| } |
| } |
| |
| if (avl > vlmax) { |
| continue; |
| } |
| LOG_DEBUG("vl: %d", vl); |
| |
| // load c-array values into vector |
| // TODO(gkielian): utilize intrinsics for vle |
| if (use_intrinsic) { |
| } else { |
| switch (sew) { |
| case SEW_E8: { |
| fill_random_vector<uint8_t>(test_vector_1, vl); |
| __asm__ volatile("vle8.v v0, (%0)" : : "r"(test_vector_1)); |
| __asm__ volatile("vse8.v v0, (%0)" : : "r"(test_vector_2)); |
| assert_vec_elem_eq<uint8_t>(vl, test_vector_1, test_vector_2); |
| break; |
| } |
| case SEW_E16: { |
| fill_random_vector<uint16_t>( |
| reinterpret_cast<uint16_t *>(test_vector_1), vl); |
| __asm__ volatile("vle16.v v0, (%0)" : : "r"(test_vector_1)); |
| __asm__ volatile("vse16.v v0, (%0)" : : "r"(test_vector_2)); |
| assert_vec_elem_eq<uint16_t>(vl, test_vector_1, test_vector_2); |
| break; |
| } |
| case SEW_E32: { |
| fill_random_vector<uint32_t>( |
| reinterpret_cast<uint32_t *>(test_vector_1), vl); |
| __asm__ volatile("vle32.v v0, (%0)" : : "r"(test_vector_1)); |
| __asm__ volatile("vse32.v v0, (%0)" : : "r"(test_vector_2)); |
| assert_vec_elem_eq<uint32_t>(vl, test_vector_1, test_vector_2); |
| break; |
| } |
| default: |
| break; |
| } |
| } |
| } |
| } |
| |
| TEST(VleVseTest, vle8vse8_e8m1) { |
| vlevse_test(VSEW::SEW_E8, VLMUL::LMUL_M1, false); |
| } |
| |
| TEST(VleVseTest, vle8vse8_e8m2) { |
| vlevse_test(VSEW::SEW_E8, VLMUL::LMUL_M2, false); |
| } |
| |
| TEST(VleVseTest, vle8vse8_e8m4) { |
| vlevse_test(VSEW::SEW_E8, VLMUL::LMUL_M4, false); |
| } |
| |
| TEST(VleVseTest, vle8vse8_e8m8) { |
| vlevse_test(VSEW::SEW_E8, VLMUL::LMUL_M8, false); |
| } |
| |
| TEST(VleVseTest, vle16vse16_e16m1) { |
| vlevse_test(VSEW::SEW_E16, VLMUL::LMUL_M1, false); |
| } |
| |
| TEST(VleVseTest, vle16vse16_e16m2) { |
| vlevse_test(VSEW::SEW_E16, VLMUL::LMUL_M2, false); |
| } |
| |
| TEST(VleVseTest, vle16vse16_e16m4) { |
| vlevse_test(VSEW::SEW_E16, VLMUL::LMUL_M4, false); |
| } |
| |
| TEST(VleVseTest, vle16vse16_e16m8) { |
| vlevse_test(VSEW::SEW_E16, VLMUL::LMUL_M8, false); |
| } |
| |
| TEST(VleVseTest, vle32vse32_e32m1) { |
| vlevse_test(VSEW::SEW_E32, VLMUL::LMUL_M1, false); |
| } |
| |
| TEST(VleVseTest, vle32vse32_e32m2) { |
| vlevse_test(VSEW::SEW_E32, VLMUL::LMUL_M2, false); |
| } |
| |
| TEST(VleVseTest, vle32vse32_e32m4) { |
| vlevse_test(VSEW::SEW_E32, VLMUL::LMUL_M4, false); |
| } |
| |
| TEST(VleVseTest, vle32vse32_e32m8) { |
| vlevse_test(VSEW::SEW_E32, VLMUL::LMUL_M8, false); |
| } |
| |
| TEST(VleVseTest, vle8vse8_e8mf2) { vlevse_test(VSEW::SEW_E8, VLMUL::LMUL_MF2); } |
| |
| TEST(VleVseTest, vle8vse8_e8mf4) { vlevse_test(VSEW::SEW_E8, VLMUL::LMUL_MF4); } |
| |
| TEST(VleVseTest, vle16vse16_e16mf2) { |
| vlevse_test(VSEW::SEW_E16, VLMUL::LMUL_MF2); |
| } |
| |
| } // namespace |
| } // namespace vle_vse_test |