Add MACC tests.
- Removed leftover debug code in templates.
- Added vnmsac test
- Remove refuse in test/CMakeLists.txt
Change-Id: Id6d35703b3020b685fcd5061c71d19b5d8bdbca9
diff --git a/softrvv/include/softrvv.h b/softrvv/include/softrvv.h
index f9b2ea5..887769d 100644
--- a/softrvv/include/softrvv.h
+++ b/softrvv/include/softrvv.h
@@ -15,6 +15,7 @@
#include "softrvv_vfmin.h"
#include "softrvv_vfmul.h"
#include "softrvv_vfsub.h"
+#include "softrvv_vmacc.h"
#include "softrvv_vmax.h"
#include "softrvv_vmfeq.h"
#include "softrvv_vmfge.h"
diff --git a/softrvv/include/softrvv_vmacc.h b/softrvv/include/softrvv_vmacc.h
new file mode 100644
index 0000000..f87aec6
--- /dev/null
+++ b/softrvv/include/softrvv_vmacc.h
@@ -0,0 +1,40 @@
+#ifndef SOFTRVV_VMACC_H
+#define SOFTRVV_VMACC_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace softrvv {
+
+template <typename T1, typename T2>
+void vmacc_vx(T1 *vd, const T2 *rs1, const T2 *vs2, int32_t avl) {
+ for (int32_t idx = 0; idx < avl; idx++) {
+ vd[idx] = (*rs1 * vs2[idx]) + vd[idx];
+ }
+}
+
+template <typename T1, typename T2>
+void vmacc_vv(T1 *vd, T2 *vs1, const T2 *vs2, int32_t avl) {
+ for (int32_t idx = 0; idx < avl; idx++) {
+ vd[idx] = (vs1[idx] * vs2[idx]) + vd[idx];
+ }
+}
+
+template <typename T1, typename T2>
+void vnmsac_vv(T1 *vd, T2 *vs1, const T2 *vs2, int32_t avl) {
+ for (int32_t idx = 0; idx < avl; idx++) {
+ vd[idx] = -(vs1[idx] * vs2[idx]) + vd[idx];
+ }
+}
+
+template <typename T1, typename T2>
+void vnmsac_vx(T1 *vd, const T2 *rs1, const T2 *vs2, int32_t avl) {
+ for (int32_t idx = 0; idx < avl; idx++) {
+ vd[idx] = -(*rs1 * vs2[idx]) + vd[idx];
+ }
+}
+
+
+} // namespace softrvv
+
+#endif // SOFTRVV_VMACC_H
diff --git a/softrvv/tests/CMakeLists.txt b/softrvv/tests/CMakeLists.txt
index 6d3d482..9441381 100644
--- a/softrvv/tests/CMakeLists.txt
+++ b/softrvv/tests/CMakeLists.txt
@@ -331,3 +331,14 @@
-Xlinker --defsym=__itcm_length__=128K
)
+vec_cc_test(
+ NAME
+ softrvv_vmacc
+ SRCS
+ softrvv_vmacc_test.cpp
+ DEPS
+ softrvv
+ LINKOPTS
+ -Xlinker --defsym=__itcm_length__=128K
+)
+
diff --git a/softrvv/tests/softrvv_vmacc_test.cpp b/softrvv/tests/softrvv_vmacc_test.cpp
new file mode 100644
index 0000000..ed784d5
--- /dev/null
+++ b/softrvv/tests/softrvv_vmacc_test.cpp
@@ -0,0 +1,71 @@
+#include <riscv_vector.h>
+#include <springbok.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pw_unit_test/framework.h"
+#include "softrvv.h"
+
+namespace softrvv_vmacc_test {
+namespace {
+
+class SoftRvvVmaccTest : public ::testing::Test {
+ protected:
+ void SetUp() override { }
+};
+
+class SoftRvvVnmsacTest : public ::testing::Test {
+ protected:
+ void SetUp() override { }
+};
+
+// Integer multiply-add, overwrite addend
+// vmacc.vv vd, vs1, vs2, vm # vd[i] = +(vs1[i] * vs2[i]) + vd[i]
+uint32_t vmacvv_vs1[] = {1, 1, 128, 64, 0};
+uint32_t vmacvv_vs2[] = {0, 1, 1, 2, 32};
+const uint32_t vmacvv_kAVL = sizeof(vmacvv_vs2) / sizeof(vmacvv_vs2[0]);
+uint32_t vmacvv_vd[] = {0, 1, 2, 4, 8};
+int32_t vmacvv_ref[] = {0, 2, 130, 132, 8};
+TEST_F(SoftRvvVmaccTest, VV) {
+ softrvv::vmacc_vv<uint32_t>(vmacvv_vd, vmacvv_vs1, vmacvv_vs2, vmacvv_kAVL);
+ ASSERT_EQ(memcmp(vmacvv_vd, vmacvv_ref, sizeof(vmacvv_vd)), 0);
+}
+
+// Integer multiply-add, overwrite addend
+// vmacc.vx vd, rs1, vs2, vm # vd[i] = +(x[rs1] * src2[i]) + vd[i]
+uint32_t vmaccvx_rs1[] = {170};
+uint32_t vmaccvx_vs2[] = {0, 1, 1, 2, 32};
+const uint32_t vmaccvx_kAVL = sizeof(vmaccvx_vs2) / sizeof(vmaccvx_vs2[0]);
+uint32_t vmaccvx_vd[] = {0, 1, 2, 4, 8};
+int32_t vmaccvx_ref[] = {0, 171, 172, 344, 5448};
+TEST_F(SoftRvvVmaccTest, VX) {
+ softrvv::vmacc_vx<uint32_t>(vmaccvx_vd, vmaccvx_rs1, vmaccvx_vs2, vmaccvx_kAVL);
+ ASSERT_EQ(memcmp(vmaccvx_vd, vmaccvx_ref, sizeof(vmaccvx_vd)), 0);
+}
+
+// Integer multiply-sub, overwrite minuend
+// vnmsac.vv vd, vs1, vs2, vm # vd[i] = -(vs1[i] * vs2[i]) + vd[i]
+uint32_t vnmsacvv_vs1[] = {220, 24, 1234, 150, 1386};
+uint32_t vnmsacvv_vs2[] = { 1, 2, 2, 10, 1000};
+const uint32_t vnmsacvv_kAVL = sizeof(vnmsacvv_vs2) / sizeof(vnmsacvv_vs2[0]);
+uint32_t vnmsacvv_vd[] = { 0, 10, 10, 1000, 1};
+int32_t vnmsacvv_ref[] = {-220, -38, -2458, -500, -1385999};
+TEST_F(SoftRvvVnmsacTest, VV) {
+ softrvv::vnmsac_vv<uint32_t>(vnmsacvv_vd, vnmsacvv_vs1, vnmsacvv_vs2, vnmsacvv_kAVL);
+ ASSERT_EQ(memcmp(vnmsacvv_vd, vnmsacvv_ref, sizeof(vnmsacvv_ref)), 0);
+}
+
+// Integer multiply-sub, overwrite minuend
+// vnmsac.vx vd, rs1, vs2, vm # vd[i] = -(x[rs1] * vs2[i]) + vd[i]
+uint32_t vnmsacvx_rs1[] = {170};
+uint32_t vnmsacvx_vs2[] = { 1, 2, 2, 10, 1000};
+const uint32_t vnmsacvx_kAVL = sizeof(vnmsacvx_vs2) / sizeof(vnmsacvx_vs2[0]);
+uint32_t vnmsacvx_vd[] = {170, 350, 10, 0, 0};
+int32_t vnmsacvx_ref[] = {0, 10, -330, -1700, -170000};
+TEST_F(SoftRvvVnmsacTest, VX) {
+ softrvv::vnmsac_vx<uint32_t>(vnmsacvx_vd, vnmsacvx_rs1, vnmsacvx_vs2, vnmsacvx_kAVL);
+ ASSERT_EQ(memcmp(vnmsacvx_vd, vnmsacvx_ref, sizeof(vnmsacvx_ref)), 0);
+}
+
+} // namespace
+} // namespace softrvv_vmacc_test
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4214281..e51930f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,4 +1,3 @@
-
vec_cc_generated_test(
NAME
vfadd