Added the vmadd and vnmsub tests.

Change-Id: I59733523d4a5eb52548e750f7dbc59d0ad5f3198
diff --git a/softrvv/include/softrvv.h b/softrvv/include/softrvv.h
index 887769d..4fc2e20 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_vmadd_vnmsub.h"
 #include "softrvv_vmacc.h"
 #include "softrvv_vmax.h"
 #include "softrvv_vmfeq.h"
diff --git a/softrvv/include/softrvv_vmadd_vnmsub.h b/softrvv/include/softrvv_vmadd_vnmsub.h
new file mode 100644
index 0000000..22a2486
--- /dev/null
+++ b/softrvv/include/softrvv_vmadd_vnmsub.h
@@ -0,0 +1,39 @@
+#ifndef SOFTRVV_VMADD_VNMSUB_H
+#define SOFTRVV_VMADD_VNMSUB_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace softrvv {
+
+template <typename T1, typename T2>
+void vmadd_vv(T1 *vd, T2 *vs1, const T2 *vs2, int32_t avl) {
+  for (int32_t idx = 0; idx < avl; idx++) {
+     vd[idx] = (vs1[idx] * vd[idx]) + vs2[idx];
+  }
+}
+
+template <typename T1, typename T2>
+void vmadd_vx(T1 *vd, const T2 *rs1, const T2 *vs2, int32_t avl) {
+  for (int32_t idx = 0; idx < avl; idx++) {
+     vd[idx] = (*rs1 * vd[idx]) + vs2[idx];
+  }
+}
+
+template <typename T1, typename T2>
+void vnmsub_vv(T1 *vd, T2 *vs1, const T2 *vs2, int32_t avl) {
+  for (int32_t idx = 0; idx < avl; idx++) {
+     vd[idx] = -(vs1[idx] * vd[idx]) + vs2[idx];
+  }
+}
+
+template <typename T1, typename T2>
+void vnmsub_vx(T1 *vd, const T2 *rs1, const T2 *vs2, int32_t avl) {
+  for (int32_t idx = 0; idx < avl; idx++) {
+     vd[idx] = -(*rs1 * vd[idx]) + vs2[idx];
+  }
+}
+
+}  // namespace softrvv
+
+#endif  // SOFTRVV_VMADD_VNMSUB_H
diff --git a/softrvv/tests/CMakeLists.txt b/softrvv/tests/CMakeLists.txt
index 9441381..aec740a 100644
--- a/softrvv/tests/CMakeLists.txt
+++ b/softrvv/tests/CMakeLists.txt
@@ -342,3 +342,14 @@
    -Xlinker --defsym=__itcm_length__=128K
 )
 
+vec_cc_test(
+  NAME
+    softrvv_vmadd_vnmsub
+  SRCS
+    softrvv_vmadd_vnmsub_test.cpp
+  DEPS
+    softrvv
+  LINKOPTS
+   -Xlinker --defsym=__itcm_length__=128K
+)
+
diff --git a/softrvv/tests/softrvv_vmadd_vnmsub_test.cpp b/softrvv/tests/softrvv_vmadd_vnmsub_test.cpp
new file mode 100644
index 0000000..8c1284f
--- /dev/null
+++ b/softrvv/tests/softrvv_vmadd_vnmsub_test.cpp
@@ -0,0 +1,72 @@
+#include <riscv_vector.h>
+#include <springbok.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pw_unit_test/framework.h"
+#include "softrvv.h"
+
+namespace softrvv_vmadd_vnmsub_test {
+namespace {
+
+class SoftRvvVmaddTest : public ::testing::Test {
+ protected:
+  void SetUp() override { }
+};
+
+class SoftRvvVnmsubTest : public ::testing::Test {
+ protected:
+  void SetUp() override { }
+};
+
+
+// Integer multiply-add, overwrite multiplicand
+// vmadd.vv vd, vs1, vs2, vm    # vd[i] = (vs1[i] * vd[i]) + vs2[i]
+uint32_t vmaddvv_vs1[] = {1, 1, 128,   64,   0};
+uint32_t vmaddvv_vs2[] = {0, 1,   1,   2,  32};
+const uint32_t vmaddvv_kAVL = sizeof(vmaddvv_vs2) / sizeof(vmaddvv_vs2[0]);
+uint32_t vmaddvv_vd[] =  {0, 1,  2,   4,   8};
+int32_t vmaddvv_ref[] =  {0, 2,  257, 258,  32};
+TEST_F(SoftRvvVmaddTest, VV) {
+  softrvv::vmadd_vv<uint32_t>(vmaddvv_vd, vmaddvv_vs1, vmaddvv_vs2, vmaddvv_kAVL);
+  ASSERT_EQ(memcmp(vmaddvv_vd, vmaddvv_ref, sizeof(vmaddvv_vd)), 0);
+}
+
+// Integer multiply-add, overwrite multiplicand
+// vmadd.vx vd, rs1, vs2, vm    # vd[i] = (x[rs1] * vd[i]) + vs2[i]
+uint32_t vmaddvx_rs1[] = {170};
+uint32_t vmaddvx_vs2[] = {0, 1,   1,   2, 32};
+const uint32_t vmaddvx_kAVL = sizeof(vmaddvx_vs2) / sizeof(vmaddvx_vs2[0]);
+uint32_t vmaddvx_vd[] =  {0, 1,   2,   4,  8};
+int32_t vmaddvx_ref[] =  {0, 171,   341,   682,  1392};
+TEST_F(SoftRvvVmaddTest, VX) {
+    softrvv::vmadd_vx<uint32_t>(vmaddvx_vd, vmaddvx_rs1, vmaddvx_vs2, vmaddvx_kAVL);
+    ASSERT_EQ(memcmp(vmaddvx_vd, vmaddvx_ref, sizeof(vmaddvx_vd)), 0);
+}
+
+// Integer multiply-sub, overwrite multiplicand
+// vnmsub.vv vd, vs1, vs2, vm    # vd[i] = -(vs1[i] * vd[i]) + vs2[i]
+uint32_t vnmsubvv_vs1[] = {220,  24,  1234,   150,     1386};
+uint32_t vnmsubvv_vs2[] = {  1,   2,     2,    10,     1000};
+const uint32_t vnmsubvv_kAVL = sizeof(vnmsubvv_vs2) / sizeof(vnmsubvv_vs2[0]);
+uint32_t vnmsubvv_vd[] =  {  0,  10,    10,  1000,        1};
+int32_t vnmsubvv_ref[] = {1, -238, -12338,  -149990, -386};
+TEST_F(SoftRvvVnmsubTest, VV) {
+  softrvv::vnmsub_vv<uint32_t>(vnmsubvv_vd, vnmsubvv_vs1, vnmsubvv_vs2, vnmsubvv_kAVL);
+  ASSERT_EQ(memcmp(vnmsubvv_vd, vnmsubvv_ref, sizeof(vnmsubvv_ref)), 0);
+}
+
+// Integer multiply-sub, overwrite minuend
+// vnmsub.vx vd, rs1, vs2, vm    # vd[i] = -(x[rs1] * vd[i]) + vs2[i]
+uint32_t vnmsubvx_rs1[] = {170};
+uint32_t vnmsubvx_vs2[] = {  1, 2, 2, 10, 1000};
+const uint32_t vnmsubvx_kAVL = sizeof(vnmsubvx_vs2) / sizeof(vnmsubvx_vs2[0]);
+uint32_t vnmsubvx_vd[] = {170, 350, 10, 0, 0};
+int32_t vnmsubvx_ref[] = {-28899, -59498, -1698, 10, 1000};
+TEST_F(SoftRvvVnmsubTest, VX) {
+    softrvv::vnmsub_vx<uint32_t>(vnmsubvx_vd, vnmsubvx_rs1, vnmsubvx_vs2, vnmsubvx_kAVL);
+    ASSERT_EQ(memcmp(vnmsubvx_vd, vnmsubvx_ref, sizeof(vnmsubvx_ref)), 0);
+}
+
+}  // namespace
+}  // namespace softrvv_vmacc_vnmsub_test