Add vand tests covering vv, vx, and vi
Note, while tests are created for each vv, vx, and vi cases,
we are able to reuse the softrvv vand.vx for both the vx and vi
reference values.
Change-Id: Idaff09de253bcc74168155606b4080f433e95549
diff --git a/softrvv/include/softrvv.h b/softrvv/include/softrvv.h
index 0ab210f..e532f94 100644
--- a/softrvv/include/softrvv.h
+++ b/softrvv/include/softrvv.h
@@ -5,6 +5,7 @@
#include "encoding.h"
#include "softrvv_vadd.h"
+#include "softrvv_vand.h"
#include "softrvv_vdiv.h"
#include "softrvv_vmax.h"
#include "softrvv_vmin.h"
diff --git a/softrvv/include/softrvv_vand.h b/softrvv/include/softrvv_vand.h
new file mode 100644
index 0000000..e9aae00
--- /dev/null
+++ b/softrvv/include/softrvv_vand.h
@@ -0,0 +1,25 @@
+#ifndef SOFTRVV_VAND_H
+#define SOFTRVV_VAND_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace softrvv {
+
+template <typename T>
+void vand_vx(T *dest, T *src1, const T *src2, int32_t avl) {
+ for (int32_t idx = 0; idx < avl; idx++) {
+ dest[idx] = src1[idx] & *src2;
+ }
+}
+
+template <typename T>
+void vand_vv(T *dest, T *src1, T *src2, int32_t avl) {
+ for (int32_t idx = 0; idx < avl; idx++) {
+ dest[idx] = src1[idx] & src2[idx];
+ }
+}
+
+} // namespace softrvv
+
+#endif // SOFTRVV_VAND_H
diff --git a/softrvv/tests/CMakeLists.txt b/softrvv/tests/CMakeLists.txt
index 221e353..3807827 100644
--- a/softrvv/tests/CMakeLists.txt
+++ b/softrvv/tests/CMakeLists.txt
@@ -182,3 +182,14 @@
LINKOPTS
-Xlinker --defsym=__itcm_length__=128K
)
+
+vec_cc_test(
+ NAME
+ softrvv_vand
+ SRCS
+ softrvv_vand_test.cpp
+ DEPS
+ softrvv
+ LINKOPTS
+ -Xlinker --defsym=__itcm_length__=128K
+)
diff --git a/softrvv/tests/softrvv_vand_test.cpp b/softrvv/tests/softrvv_vand_test.cpp
new file mode 100644
index 0000000..2eb5f5f
--- /dev/null
+++ b/softrvv/tests/softrvv_vand_test.cpp
@@ -0,0 +1,48 @@
+#include <riscv_vector.h>
+#include <springbok.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pw_unit_test/framework.h"
+#include "softrvv.h"
+
+namespace softrvv_vand_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};
+
+const uint32_t kAVL = sizeof(src1) / sizeof(src1[0]);
+uint32_t dest[kAVL];
+
+uint32_t ref_vv[] = {0xAA, 0xA0, 0x00, 0x00, 0xAA};
+
+uint32_t ref_vx[3][kAVL] = {{0xAA, 0xA0, 0x0A, 0x00, 0xAA},
+ {0x0A, 0x00, 0x0A, 0x00, 0x0A},
+ {0xA0, 0xA0, 0x00, 0x00, 0xA0}};
+
+class SoftRvvVandTest : public ::testing::Test {
+ protected:
+ void SetUp() override { memset(dest, 0, sizeof(dest)); }
+};
+
+TEST_F(SoftRvvVandTest, VV) {
+ softrvv::vand_vv<uint32_t>(dest, src1, src2, kAVL);
+ ASSERT_EQ(memcmp(dest, ref_vv, sizeof(dest)), 0);
+}
+
+TEST_F(SoftRvvVandTest, VX) {
+ const int32_t num_vx_tests = sizeof(rs1) / sizeof(rs1[0]);
+ for (int32_t i = 0; i < num_vx_tests; i++) {
+ softrvv::vand_vx<uint32_t>(dest, src1, &rs1[i], kAVL);
+ ASSERT_EQ(memcmp(dest, &ref_vx[i], sizeof(dest)), 0);
+ }
+}
+
+} // namespace
+} // namespace softrvv_vand_test
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 687aeb7..710743b 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -204,6 +204,18 @@
-Xlinker --defsym=__itcm_length__=128K
)
+
+vec_cc_generated_test(
+ NAME
+ vand
+ OPFMT
+ OPIVV
+ OPIVX
+ OPIVI
+ LINKOPTS
+ -Xlinker --defsym=__itcm_length__=200K
+)
+
vec_cc_generated_test(
NAME
vmaxu