Add softrvv vor vv, vi, vx Refactored to remove `[static 1]` (seems this is a c99 feature and not included in c++). Change-Id: I2c84f7de0e4d0ac6587034d37fbecd45f12f5af7
diff --git a/softrvv/include/softrvv.h b/softrvv/include/softrvv.h index e46af99..e056e13 100644 --- a/softrvv/include/softrvv.h +++ b/softrvv/include/softrvv.h
@@ -8,6 +8,7 @@ #include "softrvv_vdiv.h" #include "softrvv_vmin.h" #include "softrvv_vmul_vmulh.h" +#include "softrvv_vor.h" #include "softrvv_vrem.h" #include "softrvv_vsext_vzext.h" #include "softrvv_vsub.h"
diff --git a/softrvv/include/softrvv_vor.h b/softrvv/include/softrvv_vor.h new file mode 100644 index 0000000..102c796 --- /dev/null +++ b/softrvv/include/softrvv_vor.h
@@ -0,0 +1,24 @@ +#ifndef SOFTRVV_VOR_H +#define SOFTRVV_VOR_H + +#include <stddef.h> + +namespace softrvv { + +template <typename T> +void vor_vx(T *dest, T *src1, const T *src2, size_t avl) { + for (size_t idx = 0; idx < avl; idx++) { + dest[idx] = src1[idx] | *src2; + } +} + +template <typename T> +void vor_vv(T *dest, T *src1, T *src2, size_t avl) { + for (size_t idx = 0; idx < avl; idx++) { + dest[idx] = src1[idx] | src2[idx]; + } +} + +} // namespace softrvv + +#endif // SOFTRVV_VOR_H
diff --git a/softrvv/tests/CMakeLists.txt b/softrvv/tests/CMakeLists.txt index d6e962c..4152bb1 100644 --- a/softrvv/tests/CMakeLists.txt +++ b/softrvv/tests/CMakeLists.txt
@@ -56,6 +56,17 @@ vec_cc_test( NAME + softrvv_vor + SRCS + softrvv_vor_test.cpp + DEPS + softrvv + LINKOPTS + -Xlinker --defsym=__itcm_length__=128K +) + +vec_cc_test( + NAME softrvv_vsext SRCS softrvv_vsext_test.cpp
diff --git a/softrvv/tests/softrvv_vor_test.cpp b/softrvv/tests/softrvv_vor_test.cpp new file mode 100644 index 0000000..9d01e5d --- /dev/null +++ b/softrvv/tests/softrvv_vor_test.cpp
@@ -0,0 +1,68 @@ +#include <riscv_vector.h> +#include <springbok.h> +#include <stdio.h> +#include <stdlib.h> + +#include "pw_unit_test/framework.h" +#include "softrvv.h" + +namespace softrvv_vor_test { +namespace { + +uint32_t src1[] = {0xAA, 0xA5, 0x5A, 0x55, 0xFF}; // 0x55 = 0b0101 + +// vector test +uint32_t src2[] = {0xAA, 0xAA, 0x00, 0xAA, 0xAA}; // 0xAA = 0b1010 + +// register tests +uint32_t rs1[] = {0xAA, 0x0A, 0xA0}; + +// imm tests +// Note: simm5 is sign extended before op +uint32_t imm[] = { + 0xF0, + 0x05, + 0x0E, +}; // simm5 ∈ [-16, 15]; 0xF0 = -16; 0x0E = 15 + +const uint32_t kAVL = sizeof(src1) / sizeof(src1[0]); +uint32_t dest[kAVL]; + +uint32_t ref_vv[] = {0xAA, 0xAF, 0x5A, 0xFF, 0xFF}; + +uint32_t ref_vx[3][kAVL] = {{0xAA, 0xAF, 0xFA, 0xFF, 0xFF}, + {0xAA, 0xAF, 0x5A, 0x5F, 0xFF}, + {0xAA, 0xA5, 0xFA, 0xF5, 0xFF}}; + +uint32_t ref_vi[3][kAVL] = {{0xFA, 0xF5, 0xFA, 0xF5, 0xFF}, + {0xAF, 0xA5, 0x5F, 0x55, 0xFF}, + {0xAE, 0xAF, 0x5E, 0x5F, 0xFF}}; + +class SoftRvvVorTest : public ::testing::Test { + protected: + void SetUp() override { memset(dest, 0, sizeof(dest)); } +}; + +TEST_F(SoftRvvVorTest, VV) { + softrvv::vor_vv<uint32_t>(dest, src1, src2, kAVL); + ASSERT_EQ(memcmp(dest, ref_vv, sizeof(dest)), 0); +} + +TEST_F(SoftRvvVorTest, VX) { + const int32_t num_vx_tests = sizeof(rs1) / sizeof(rs1[0]); + for (int32_t i = 0; i < num_vx_tests; i++) { + softrvv::vor_vx<uint32_t>(dest, src1, &rs1[i], kAVL); + ASSERT_EQ(memcmp(dest, &ref_vx[i], sizeof(dest)), 0); + } +} + +TEST_F(SoftRvvVorTest, VI) { + const int32_t num_vi_tests = sizeof(imm) / sizeof(imm[0]); + for (int32_t i = 0; i < num_vi_tests; i++) { + softrvv::vor_vx<uint32_t>(dest, src1, &imm[i], kAVL); + ASSERT_EQ(memcmp(dest, &ref_vi[i], sizeof(dest)), 0); + } +} + +} // namespace +} // namespace softrvv_vor_test
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 308fb22..d3546e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt
@@ -44,6 +44,17 @@ vec_cc_generated_test( NAME + vor + OPFMT + OPIVV + OPIVX + OPIVI + LINKOPTS + -Xlinker --defsym=__itcm_length__=256K +) + +vec_cc_generated_test( + NAME vmin OPFMT OPIVV