From 91682878c82065d4163c9105c3fafec9c0919eef Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Thu, 14 Dec 2023 15:27:55 +0800 Subject: [PATCH] Add tests for vset --- check_instr.py | 2 ++ code/untested.py | 6 ++++-- code/vsetallnez_b.cpp | 18 ++++++++++++++++++ code/vsetallnez_d.cpp | 18 ++++++++++++++++++ code/vsetallnez_h.cpp | 18 ++++++++++++++++++ code/vsetallnez_w.cpp | 18 ++++++++++++++++++ code/vsetanyeqz_b.cpp | 18 ++++++++++++++++++ code/vsetanyeqz_d.cpp | 18 ++++++++++++++++++ code/vsetanyeqz_h.cpp | 18 ++++++++++++++++++ code/vsetanyeqz_w.cpp | 18 ++++++++++++++++++ code/vseteqz_v.cpp | 12 ++++++++++++ code/vsetnez_v.cpp | 12 ++++++++++++ main.py | 8 ++++---- 13 files changed, 178 insertions(+), 6 deletions(-) create mode 100644 code/vsetallnez_b.cpp create mode 100644 code/vsetallnez_d.cpp create mode 100644 code/vsetallnez_h.cpp create mode 100644 code/vsetallnez_w.cpp create mode 100644 code/vsetanyeqz_b.cpp create mode 100644 code/vsetanyeqz_d.cpp create mode 100644 code/vsetanyeqz_h.cpp create mode 100644 code/vsetanyeqz_w.cpp create mode 100644 code/vseteqz_v.cpp create mode 100644 code/vsetnez_v.cpp diff --git a/check_instr.py b/check_instr.py index 3df258ba..9fc7bade 100644 --- a/check_instr.py +++ b/check_instr.py @@ -25,6 +25,8 @@ encoded.append("vr") elif part[0] == "r": encoded.append("r") + elif part[0] == "c": + encoded.append("fcc") elif part[0] == "u" or part[0] == "s": encoded.append("imm") encoding[name] = ", ".join(encoded) diff --git a/code/untested.py b/code/untested.py index cb3b3cd3..a1e6c6b1 100644 --- a/code/untested.py +++ b/code/untested.py @@ -6,17 +6,19 @@ if os.path.exists(src): # make sure we are testing the expected instruction if src.split(".")[0] not in open(src, 'r').read(): + # intrinsic's name is different from instruction's name + if src.startswith("vset") or src.startswith("vset"): + continue print("Bad test:", src) if not os.path.exists(src): if ( src.startswith("xvf") or src.startswith("vf") - or src.startswith("xvset") - or src.startswith("vset") or src.startswith("xvld") or src.startswith("vld") or src.startswith("xvst") or src.startswith("vst") + or src == "common.cpp" ): # skipped continue diff --git a/code/vsetallnez_b.cpp b/code/vsetallnez_b.cpp new file mode 100644 index 00000000..3a4b5807 --- /dev/null +++ b/code/vsetallnez_b.cpp @@ -0,0 +1,18 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(!__lsx_bnz_b(a)); + + a = __m128i {1, 0}; + assert(!__lsx_bnz_b(a)); + + a = __m128i {0, 1}; + assert(!__lsx_bnz_b(a)); + + a = __m128i {0x1111111111111111, 0x1111111111111111}; + assert(__lsx_bnz_b(a)); + + a = __m128i {0x1111111111111100, 0x1111111111111111}; + assert(!__lsx_bnz_b(a)); +} \ No newline at end of file diff --git a/code/vsetallnez_d.cpp b/code/vsetallnez_d.cpp new file mode 100644 index 00000000..17af4b4b --- /dev/null +++ b/code/vsetallnez_d.cpp @@ -0,0 +1,18 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(!__lsx_bnz_d(a)); + + a = __m128i {1, 0}; + assert(!__lsx_bnz_d(a)); + + a = __m128i {0, 1}; + assert(!__lsx_bnz_d(a)); + + a = __m128i {0x1111111111111111, 0x1111111111111111}; + assert(__lsx_bnz_d(a)); + + a = __m128i {0x0, 0x1111111111111111}; + assert(!__lsx_bnz_d(a)); +} \ No newline at end of file diff --git a/code/vsetallnez_h.cpp b/code/vsetallnez_h.cpp new file mode 100644 index 00000000..d1524475 --- /dev/null +++ b/code/vsetallnez_h.cpp @@ -0,0 +1,18 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(!__lsx_bnz_h(a)); + + a = __m128i {1, 0}; + assert(!__lsx_bnz_h(a)); + + a = __m128i {0, 1}; + assert(!__lsx_bnz_h(a)); + + a = __m128i {0x1111111111111111, 0x1111111111111111}; + assert(__lsx_bnz_h(a)); + + a = __m128i {0x1111111111110000, 0x1111111111111111}; + assert(!__lsx_bnz_h(a)); +} \ No newline at end of file diff --git a/code/vsetallnez_w.cpp b/code/vsetallnez_w.cpp new file mode 100644 index 00000000..80e38c62 --- /dev/null +++ b/code/vsetallnez_w.cpp @@ -0,0 +1,18 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(!__lsx_bnz_w(a)); + + a = __m128i {1, 0}; + assert(!__lsx_bnz_w(a)); + + a = __m128i {0, 1}; + assert(!__lsx_bnz_w(a)); + + a = __m128i {0x1111111111111111, 0x1111111111111111}; + assert(__lsx_bnz_w(a)); + + a = __m128i {0x1111111100000000, 0x1111111111111111}; + assert(!__lsx_bnz_w(a)); +} \ No newline at end of file diff --git a/code/vsetanyeqz_b.cpp b/code/vsetanyeqz_b.cpp new file mode 100644 index 00000000..df2dd2c1 --- /dev/null +++ b/code/vsetanyeqz_b.cpp @@ -0,0 +1,18 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(__lsx_bz_b(a)); + + a = __m128i {1, 0}; + assert(__lsx_bz_b(a)); + + a = __m128i {0, 1}; + assert(__lsx_bz_b(a)); + + a = __m128i {0x1111111111111111, 0x1111111111111111}; + assert(!__lsx_bz_b(a)); + + a = __m128i {0x1111111111111100, 0x1111111111111111}; + assert(__lsx_bz_b(a)); +} \ No newline at end of file diff --git a/code/vsetanyeqz_d.cpp b/code/vsetanyeqz_d.cpp new file mode 100644 index 00000000..efdf3c37 --- /dev/null +++ b/code/vsetanyeqz_d.cpp @@ -0,0 +1,18 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(__lsx_bz_d(a)); + + a = __m128i {1, 0}; + assert(__lsx_bz_d(a)); + + a = __m128i {0, 1}; + assert(__lsx_bz_d(a)); + + a = __m128i {0x1111111111111111, 0x1111111111111111}; + assert(!__lsx_bz_d(a)); + + a = __m128i {0x0, 0x1111111111111111}; + assert(__lsx_bz_d(a)); +} \ No newline at end of file diff --git a/code/vsetanyeqz_h.cpp b/code/vsetanyeqz_h.cpp new file mode 100644 index 00000000..883e00d7 --- /dev/null +++ b/code/vsetanyeqz_h.cpp @@ -0,0 +1,18 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(__lsx_bz_h(a)); + + a = __m128i {1, 0}; + assert(__lsx_bz_h(a)); + + a = __m128i {0, 1}; + assert(__lsx_bz_h(a)); + + a = __m128i {0x1111111111111111, 0x1111111111111111}; + assert(!__lsx_bz_h(a)); + + a = __m128i {0x1111111111110000, 0x1111111111111111}; + assert(__lsx_bz_h(a)); +} \ No newline at end of file diff --git a/code/vsetanyeqz_w.cpp b/code/vsetanyeqz_w.cpp new file mode 100644 index 00000000..444f1e8e --- /dev/null +++ b/code/vsetanyeqz_w.cpp @@ -0,0 +1,18 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(__lsx_bz_w(a)); + + a = __m128i {1, 0}; + assert(__lsx_bz_w(a)); + + a = __m128i {0, 1}; + assert(__lsx_bz_b(a)); + + a = __m128i {0x1111111111111111, 0x1111111111111111}; + assert(!__lsx_bz_w(a)); + + a = __m128i {0x1111111100000000, 0x1111111111111111}; + assert(__lsx_bz_w(a)); +} \ No newline at end of file diff --git a/code/vseteqz_v.cpp b/code/vseteqz_v.cpp new file mode 100644 index 00000000..43d25367 --- /dev/null +++ b/code/vseteqz_v.cpp @@ -0,0 +1,12 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(__lsx_bz_v(a)); + + a = __m128i {1, 0}; + assert(!__lsx_bz_v(a)); + + a = __m128i {0, 1}; + assert(!__lsx_bz_v(a)); +} \ No newline at end of file diff --git a/code/vsetnez_v.cpp b/code/vsetnez_v.cpp new file mode 100644 index 00000000..6aa0bdc0 --- /dev/null +++ b/code/vsetnez_v.cpp @@ -0,0 +1,12 @@ +#include "common.h" + +void test() { + __m128i a = {0, 0}; + assert(!__lsx_bnz_v(a)); + + a = __m128i {1, 0}; + assert(__lsx_bnz_v(a)); + + a = __m128i {0, 1}; + assert(__lsx_bnz_v(a)); +} \ No newline at end of file diff --git a/main.py b/main.py index d124c978..cdf2a14e 100644 --- a/main.py +++ b/main.py @@ -1096,7 +1096,7 @@ def vshuf4i(name): def bz_v(): return instruction( intrinsic=f"int __lsx_bz_v (__m128i a)", - instr=f"vseteqz.v vr; bcnez", + instr=f"vseteqz.v fcc, vr; bcnez", desc=f"Expected to be used in branches: branch if the whole vector `a` equals to zero.", ) @@ -1104,7 +1104,7 @@ def bz_v(): def bnz_v(): return instruction( intrinsic=f"int __lsx_bnz_v (__m128i a)", - instr=f"vsetnez.v vr; bcnez", + instr=f"vsetnez.v fcc, vr; bcnez", desc=f"Expected to be used in branches: branch if the whole vector `a` is non-zero.", ) @@ -1113,7 +1113,7 @@ def bz(name): width = widths[name] return instruction( intrinsic=f"int __lsx_bz_{name} (__m128i a)", - instr=f"vsetanyeqz.{name} vr; bcnez", + instr=f"vsetanyeqz.{name} fcc, vr; bcnez", desc=f"Expected to be used in branches: branch if any {width}-bit element in `a` equals to zero.", ) @@ -1122,7 +1122,7 @@ def bnz(name): width = widths[name] return instruction( intrinsic=f"int __lsx_bnz_{name} (__m128i a)", - instr=f"vsetallnez.{name} vr; bcnez", + instr=f"vsetallnez.{name} fcc, vr; bcnez", desc=f"Expected to be used in branches: branch if all {width}-bit elements in `a` are non-zero.", )