Add test for vmv.v.x.

Change-Id: I8521fc74315e75aa627472330c431b9db278d2f0
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4642da1..be3aa24 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -50,4 +50,6 @@
   LINKOPTS
    -T${LINKER_SCRIPT}
    -Xlinker --defsym=__itcm_length__=256K
+  TIMEOUT
+    40
 )
diff --git a/tests/vmv_test.cpp b/tests/vmv_test.cpp
index 804baff..22b93b8 100644
--- a/tests/vmv_test.cpp
+++ b/tests/vmv_test.cpp
@@ -31,7 +31,7 @@
 }
 
 template <typename T>
-static std::tuple<int, int> vmv_v_v_i_test_setup(VLMUL lmul, uint32_t avl) {
+static std::tuple<int, int> vmv_test_setup(VLMUL lmul, uint32_t avl) {
   // Clear all vector registers
   zero_vector_registers();
 
@@ -67,7 +67,7 @@
     uint32_t avl = AVLS[i];
     int vlmax;
     int vl;
-    std::tie(vlmax, vl) = vmv_v_v_i_test_setup<uint8_t>(VLMUL::LMUL_M1, avl);
+    std::tie(vlmax, vl) = vmv_test_setup<uint8_t>(VLMUL::LMUL_M1, avl);
     if (avl > vlmax) {
       continue;
     }
@@ -85,7 +85,7 @@
     uint32_t avl = AVLS[i];
     int vlmax;
     int vl;
-    std::tie(vlmax, vl) = vmv_v_v_i_test_setup<uint8_t>(VLMUL::LMUL_M1, avl);
+    std::tie(vlmax, vl) = vmv_test_setup<uint8_t>(VLMUL::LMUL_M1, avl);
     if (avl > vlmax) {
       continue;
     }
@@ -104,7 +104,7 @@
       int vlmax;                                                               \
       int vl;                                                                  \
       std::tie(vlmax, vl) =                                                    \
-          vmv_v_v_i_test_setup<uint##_SEW_##_t>(VLMUL::LMUL_M##_LMUL_, avl);   \
+          vmv_test_setup<uint##_SEW_##_t>(VLMUL::LMUL_M##_LMUL_, avl);         \
       if (avl > vlmax) {                                                       \
         continue;                                                              \
       }                                                                        \
@@ -133,26 +133,26 @@
 DEFINE_TEST_VMV_V_V_I_INTRINSIC(32, 4)
 DEFINE_TEST_VMV_V_V_I_INTRINSIC(32, 8)
 
-#define DEFINE_TEST_VMV_V_V_I(_SEW_, _LMUL_)                                 \
-  TEST(VmvTest, vmv_v_v_i##_SEW_##m##_LMUL_) {                               \
-    for (int i = 0; i < AVL_COUNT; i++) {                                    \
-      uint32_t avl = AVLS[i];                                                \
-      int vlmax;                                                             \
-      int vl;                                                                \
-      std::tie(vlmax, vl) =                                                  \
-          vmv_v_v_i_test_setup<uint##_SEW_##_t>(VLMUL::LMUL_M##_LMUL_, avl); \
-      if (avl > vlmax) {                                                     \
-        continue;                                                            \
-      }                                                                      \
-      uint##_SEW_##_t *ptr_vec_1 =                                           \
-          reinterpret_cast<uint##_SEW_##_t *>(test_vector_1);                \
-      uint##_SEW_##_t *ptr_vec_2 =                                           \
-          reinterpret_cast<uint##_SEW_##_t *>(test_vector_2);                \
-      __asm__ volatile("vle" #_SEW_ ".v v0, (%0)" : : "r"(ptr_vec_1));       \
-      __asm__ volatile("vmv.v.v v8, v0");                                    \
-      __asm__ volatile("vse" #_SEW_ ".v v8, (%0)" : : "r"(ptr_vec_2));       \
-      vmv_check<uint##_SEW_##_t>(vlmax);                                     \
-    }                                                                        \
+#define DEFINE_TEST_VMV_V_V_I(_SEW_, _LMUL_)                           \
+  TEST(VmvTest, vmv_v_v_i##_SEW_##m##_LMUL_) {                         \
+    for (int i = 0; i < AVL_COUNT; i++) {                              \
+      uint32_t avl = AVLS[i];                                          \
+      int vlmax;                                                       \
+      int vl;                                                          \
+      std::tie(vlmax, vl) =                                            \
+          vmv_test_setup<uint##_SEW_##_t>(VLMUL::LMUL_M##_LMUL_, avl); \
+      if (avl > vlmax) {                                               \
+        continue;                                                      \
+      }                                                                \
+      uint##_SEW_##_t *ptr_vec_1 =                                     \
+          reinterpret_cast<uint##_SEW_##_t *>(test_vector_1);          \
+      uint##_SEW_##_t *ptr_vec_2 =                                     \
+          reinterpret_cast<uint##_SEW_##_t *>(test_vector_2);          \
+      __asm__ volatile("vle" #_SEW_ ".v v0, (%0)" : : "r"(ptr_vec_1)); \
+      __asm__ volatile("vmv.v.v v8, v0");                              \
+      __asm__ volatile("vse" #_SEW_ ".v v8, (%0)" : : "r"(ptr_vec_2)); \
+      vmv_check<uint##_SEW_##_t>(vlmax);                               \
+    }                                                                  \
   }
 
 DEFINE_TEST_VMV_V_V_I(8, 1)
@@ -169,5 +169,67 @@
 DEFINE_TEST_VMV_V_V_I(32, 2)
 DEFINE_TEST_VMV_V_V_I(32, 4)
 DEFINE_TEST_VMV_V_V_I(32, 8)
+
+TEST(VmvTest, vmv_v_x_demo) {
+  for (int i = 0; i < AVL_COUNT; i++) {
+    uint32_t avl = AVLS[i];
+    int vlmax;
+    int vl;
+    std::tie(vlmax, vl) = vmv_test_setup<uint8_t>(VLMUL::LMUL_M1, avl);
+    if (avl > vlmax) {
+      continue;
+    }
+    uint8_t *ptr_vec_1 = reinterpret_cast<uint8_t *>(test_vector_1);
+    uint8_t *ptr_vec_2 = reinterpret_cast<uint8_t *>(test_vector_2);
+    uint8_t test_val = 0xAB;
+    __asm__ volatile("vmv.v.x v8, %[RS1]" ::[RS1] "r"(test_val));
+    for (int i = 0; i < vl; i++) {
+      ptr_vec_1[i] = test_val;
+    }
+    __asm__ volatile("vse8.v v8, (%0)" : : "r"(ptr_vec_2));
+    vmv_check<uint8_t>(vlmax);
+  }
+}
+
+#define DEFINE_TEST_VMV_V_X_I(_SEW_, _LMUL_, TEST_VAL)                 \
+  TEST(VmvTest, vmv_v_x_e##_SEW_##m##_LMUL_) {                         \
+    for (int i = 0; i < AVL_COUNT; i++) {                              \
+      uint32_t avl = AVLS[i];                                          \
+      int vlmax;                                                       \
+      int vl;                                                          \
+      std::tie(vlmax, vl) =                                            \
+          vmv_test_setup<uint##_SEW_##_t>(VLMUL::LMUL_M##_LMUL_, avl); \
+      if (avl > vlmax) {                                               \
+        continue;                                                      \
+      }                                                                \
+      uint##_SEW_##_t *ptr_vec_1 =                                     \
+          reinterpret_cast<uint##_SEW_##_t *>(test_vector_1);          \
+      uint##_SEW_##_t *ptr_vec_2 =                                     \
+          reinterpret_cast<uint##_SEW_##_t *>(test_vector_2);          \
+      const uint##_SEW_##_t test_val = TEST_VAL;                       \
+      __asm__ volatile("vmv.v.x v8, %[RS1]" ::[RS1] "r"(test_val));    \
+      for (int i = 0; i < vl; i++) {                                   \
+        ptr_vec_1[i] = test_val;                                       \
+      }                                                                \
+      __asm__ volatile("vse" #_SEW_ ".v v8, (%0)" : : "r"(ptr_vec_2)); \
+      vmv_check<uint##_SEW_##_t>(vlmax);                               \
+    }                                                                  \
+  }
+
+DEFINE_TEST_VMV_V_X_I(8, 1, 0xab)
+DEFINE_TEST_VMV_V_X_I(8, 2, 0xac)
+DEFINE_TEST_VMV_V_X_I(8, 4, 0xad)
+DEFINE_TEST_VMV_V_X_I(8, 8, 0xae)
+
+DEFINE_TEST_VMV_V_X_I(16, 1, 0xabc1)
+DEFINE_TEST_VMV_V_X_I(16, 2, 0xabc2)
+DEFINE_TEST_VMV_V_X_I(16, 4, 0xabc3)
+DEFINE_TEST_VMV_V_X_I(16, 8, 0xabc4)
+
+DEFINE_TEST_VMV_V_X_I(32, 1, 0xabcdef12)
+DEFINE_TEST_VMV_V_X_I(32, 2, 0xabcdef13)
+DEFINE_TEST_VMV_V_X_I(32, 4, 0xabcdef14)
+DEFINE_TEST_VMV_V_X_I(32, 8, 0xabcdef15)
+
 }  // namespace
 }  // namespace vmv_test