Enable checks for illegal vtypes.
* Enable tests for illegal lmul/sew combinations.
* Mark them as illegal and modify test to check for illegal condition.
Change-Id: I5a08460a2a07c1ee643c3f21defde5f9e19886e4
diff --git a/tests/vsetvl_test.cpp b/tests/vsetvl_test.cpp
index 0aedb0a..90351c0 100644
--- a/tests/vsetvl_test.cpp
+++ b/tests/vsetvl_test.cpp
@@ -12,34 +12,71 @@
using namespace test_v_helpers;
const uint64_t VLEN = 512u;
+const uint32_t VILL = 0x80000000;
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
+static inline uint32_t read_vtype() {
+ uint32_t vtype;
+ __asm__ volatile("csrr %[VTYPE], vtype" : [VTYPE] "=r"(vtype) :);
+ return vtype;
+}
+
+static inline bool is_illegal_vtype() {
+ uint32_t vtype = read_vtype();
+ if (vtype & VILL) {
+ return true;
+ }
+ return false;
+}
+
static uint32_t calculate_vl(uint32_t sew, uint32_t avl, float lmul) {
uint32_t vlmax = (uint32_t)(VLEN * lmul / sew);
return MIN(avl, vlmax);
}
-static void test_vsetvl(VSEW sew, VLMUL vlmul, uint32_t width, float lmul) {
+static void test_vsetvl(VSEW sew, VLMUL vlmul, uint32_t width, float lmul,
+ bool expect_illegal = false) {
size_t vl = 0;
for (int i = 0; i < AVL_COUNT; i++) {
vl = set_vsetvl_intrinsic(sew, vlmul, AVLS[i]);
- EXPECT_EQ(vl, calculate_vl(width, AVLS[i], lmul));
+ if (!expect_illegal) {
+ EXPECT_EQ(vl, calculate_vl(width, AVLS[i], lmul));
+ } else {
+ EXPECT_TRUE(is_illegal_vtype());
+ }
}
for (int i = 0; i < AVL_COUNT; i++) {
vl = set_vsetvl(sew, vlmul, AVLS[i], false, false);
- EXPECT_EQ(vl, calculate_vl(width, AVLS[i], lmul));
+ if (!expect_illegal) {
+ EXPECT_EQ(vl, calculate_vl(width, AVLS[i], lmul));
+ } else {
+ EXPECT_TRUE(is_illegal_vtype());
+ }
}
for (int i = 0; i < AVL_COUNT; i++) {
vl = set_vsetvli(sew, vlmul, AVLS[i]);
- EXPECT_EQ(vl, calculate_vl(width, AVLS[i], lmul));
+ if (!expect_illegal) {
+ EXPECT_EQ(vl, calculate_vl(width, AVLS[i], lmul));
+ } else {
+ EXPECT_TRUE(is_illegal_vtype());
+ }
}
vl = set_vsetivli(sew, vlmul);
- EXPECT_EQ(vl, calculate_vl(width, AVL_CONST, lmul));
+ if (!expect_illegal) {
+ EXPECT_EQ(vl, calculate_vl(width, AVL_CONST, lmul));
+ } else {
+ EXPECT_TRUE(is_illegal_vtype());
+ }
}
-static void test_vsetvlmax(VSEW sew, VLMUL vlmul, uint32_t width, float lmul) {
- EXPECT_EQ(get_vsetvlmax_intrinsic(sew, vlmul), (int)VLEN / width * lmul);
+static void test_vsetvlmax(VSEW sew, VLMUL vlmul, uint32_t width, float lmul,
+ bool expect_illegal = false) {
+ if (!expect_illegal) {
+ EXPECT_EQ(get_vsetvlmax_intrinsic(sew, vlmul), (int)VLEN / width * lmul);
+ } else {
+ EXPECT_EQ(get_vsetvlmax_intrinsic(sew, vlmul), 0);
+ }
}
TEST(VsetvlTest, vsetvl_e8m1) {
@@ -102,17 +139,16 @@
test_vsetvl(VSEW::SEW_E16, VLMUL::LMUL_MF2, 16, 0.5);
}
-// The tests pass on Renode but fail on Qemu.
-TEST(VsetvlTest, DISABLED_vsetvl_e8mf8) {
- test_vsetvl(VSEW::SEW_E8, VLMUL::LMUL_MF8, 8, 0.125);
+TEST(VsetvlTest, vsetvl_e8mf8_vill) {
+ test_vsetvl(VSEW::SEW_E8, VLMUL::LMUL_MF8, 8, 0.125, true);
}
-TEST(VsetvlTest, DISABLED_vsetvl_e16m4) {
- test_vsetvl(VSEW::SEW_E16, VLMUL::LMUL_MF4, 16, 0.25);
+TEST(VsetvlTest, vsetvl_e16mf4_vill) {
+ test_vsetvl(VSEW::SEW_E16, VLMUL::LMUL_MF4, 16, 0.25, true);
}
-TEST(VsetvlTest, DISABLED_vsetvl_e32mf2) {
- test_vsetvl(VSEW::SEW_E32, VLMUL::LMUL_MF2, 32, 0.5);
+TEST(VsetvlTest, vsetvl_e32mf2_vill) {
+ test_vsetvl(VSEW::SEW_E32, VLMUL::LMUL_MF2, 32, 0.5, true);
}
TEST(VsetvlTest, vsetvlmax_e8m1) {
@@ -175,17 +211,16 @@
test_vsetvlmax(VSEW::SEW_E16, VLMUL::LMUL_MF2, 16, 0.5);
}
-// The tests pass on Renode but fail on Qemu.
-TEST(VsetvlTest, DISABLED_vsetvlmax_e8mf8) {
- test_vsetvlmax(VSEW::SEW_E8, VLMUL::LMUL_MF8, 8, 0.125);
+TEST(VsetvlTest, vsetvlmax_e8mf8_vill) {
+ test_vsetvlmax(VSEW::SEW_E8, VLMUL::LMUL_MF8, 8, 0.125, true);
}
-TEST(VsetvlTest, DISABLED_vsetvlmax_e16m4) {
- test_vsetvlmax(VSEW::SEW_E16, VLMUL::LMUL_MF4, 16, 0.25);
+TEST(VsetvlTest, vsetvlmax_e16mf4_vill) {
+ test_vsetvlmax(VSEW::SEW_E16, VLMUL::LMUL_MF4, 16, 0.25, true);
}
-TEST(VsetvlTest, DISABLED_vsetvlmax_e32mf2) {
- test_vsetvlmax(VSEW::SEW_E32, VLMUL::LMUL_MF2, 32, 0.5);
+TEST(VsetvlTest, vsetvlmax_e32mf2_vill) {
+ test_vsetvlmax(VSEW::SEW_E32, VLMUL::LMUL_MF2, 32, 0.5, true);
}
} // namespace