Skip to content

Commit

Permalink
Add tests for vset
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 14, 2023
1 parent 0776dcd commit 9168287
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 6 deletions.
2 changes: 2 additions & 0 deletions check_instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions code/untested.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions code/vsetallnez_b.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
18 changes: 18 additions & 0 deletions code/vsetallnez_d.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
18 changes: 18 additions & 0 deletions code/vsetallnez_h.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
18 changes: 18 additions & 0 deletions code/vsetallnez_w.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
18 changes: 18 additions & 0 deletions code/vsetanyeqz_b.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
18 changes: 18 additions & 0 deletions code/vsetanyeqz_d.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
18 changes: 18 additions & 0 deletions code/vsetanyeqz_h.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
18 changes: 18 additions & 0 deletions code/vsetanyeqz_w.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
12 changes: 12 additions & 0 deletions code/vseteqz_v.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
12 changes: 12 additions & 0 deletions code/vsetnez_v.cpp
Original file line number Diff line number Diff line change
@@ -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));
}
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,15 +1096,15 @@ 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.",
)

@my_macro(env)
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.",
)

Expand All @@ -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.",
)

Expand All @@ -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.",
)

Expand Down

0 comments on commit 9168287

Please sign in to comment.