Skip to content

Commit

Permalink
Add vslt/vsle
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 059e3df commit f3a7a6d
Show file tree
Hide file tree
Showing 37 changed files with 241 additions and 5 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ Arranged from QEMU implementation and [GCC Intrinsics](https://gcc.gnu.org/onlin

TODO List:

### vle/lt.b/h/w/d

Vector Set Equal/Less than or Equal/Less Than

### vsadd.b/h/w/d

Vector Saturated Add
Expand Down
8 changes: 8 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@
file=f,
)
print(f"}}", file=f)
for name, op in [("lt", "<"), ("le", "<=")]:
with open(f"vs{name}_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = (({sign}{w})a.{m}[i] {op} ({sign}{w})b.{m}[i]) ? 0x{((1 << w) - 1):X} : 0;",
file=f,
)
print(f"}}", file=f)

for width in ["b", "bu", "h", "hu", "w", "wu", "d", "du"]:
double_width = double_widths[width]
Expand Down
2 changes: 2 additions & 0 deletions code/gen_tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
"vmulwod": (widths_vaddw, "v128 a, v128 b"),
"vpcnt": (widths_signed, "v128 a"),
"vseq": (widths_signed, "v128 a, v128 b"),
"vslt": (widths_all, "v128 a, v128 b"),
"vsle": (widths_all, "v128 a, v128 b"),
"vsub": (widths_signed, "v128 a, v128 b"),
"vsubwev": (widths_vsubw, "v128 a, v128 b"),
"vsubwod": (widths_vsubw, "v128 a, v128 b"),
Expand Down
9 changes: 9 additions & 0 deletions code/vsle_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vsle_b(v128 a, v128 b) {
v128 dst;
#include "vsle_b.h"
return dst;
}

void test() { FUZZ2(vsle_b); }
3 changes: 3 additions & 0 deletions code/vsle_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 16; i++) {
dst.byte[i] = ((s8)a.byte[i] <= (s8)b.byte[i]) ? 0xFF : 0;
}
9 changes: 9 additions & 0 deletions code/vsle_bu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vsle_bu(v128 a, v128 b) {
v128 dst;
#include "vsle_bu.h"
return dst;
}

void test() { FUZZ2(vsle_bu); }
3 changes: 3 additions & 0 deletions code/vsle_bu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 16; i++) {
dst.byte[i] = ((u8)a.byte[i] <= (u8)b.byte[i]) ? 0xFF : 0;
}
9 changes: 9 additions & 0 deletions code/vsle_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vsle_d(v128 a, v128 b) {
v128 dst;
#include "vsle_d.h"
return dst;
}

void test() { FUZZ2(vsle_d); }
3 changes: 3 additions & 0 deletions code/vsle_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.dword[i] = ((s64)a.dword[i] <= (s64)b.dword[i]) ? 0xFFFFFFFFFFFFFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vsle_du.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vsle_du(v128 a, v128 b) {
v128 dst;
#include "vsle_du.h"
return dst;
}

void test() { FUZZ2(vsle_du); }
3 changes: 3 additions & 0 deletions code/vsle_du.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.dword[i] = ((u64)a.dword[i] <= (u64)b.dword[i]) ? 0xFFFFFFFFFFFFFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vsle_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vsle_h(v128 a, v128 b) {
v128 dst;
#include "vsle_h.h"
return dst;
}

void test() { FUZZ2(vsle_h); }
3 changes: 3 additions & 0 deletions code/vsle_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.half[i] = ((s16)a.half[i] <= (s16)b.half[i]) ? 0xFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vsle_hu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vsle_hu(v128 a, v128 b) {
v128 dst;
#include "vsle_hu.h"
return dst;
}

void test() { FUZZ2(vsle_hu); }
3 changes: 3 additions & 0 deletions code/vsle_hu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.half[i] = ((u16)a.half[i] <= (u16)b.half[i]) ? 0xFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vsle_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vsle_w(v128 a, v128 b) {
v128 dst;
#include "vsle_w.h"
return dst;
}

void test() { FUZZ2(vsle_w); }
3 changes: 3 additions & 0 deletions code/vsle_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.word[i] = ((s32)a.word[i] <= (s32)b.word[i]) ? 0xFFFFFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vsle_wu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vsle_wu(v128 a, v128 b) {
v128 dst;
#include "vsle_wu.h"
return dst;
}

void test() { FUZZ2(vsle_wu); }
3 changes: 3 additions & 0 deletions code/vsle_wu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.word[i] = ((u32)a.word[i] <= (u32)b.word[i]) ? 0xFFFFFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vslt_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vslt_b(v128 a, v128 b) {
v128 dst;
#include "vslt_b.h"
return dst;
}

void test() { FUZZ2(vslt_b); }
3 changes: 3 additions & 0 deletions code/vslt_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 16; i++) {
dst.byte[i] = ((s8)a.byte[i] < (s8)b.byte[i]) ? 0xFF : 0;
}
9 changes: 9 additions & 0 deletions code/vslt_bu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vslt_bu(v128 a, v128 b) {
v128 dst;
#include "vslt_bu.h"
return dst;
}

void test() { FUZZ2(vslt_bu); }
3 changes: 3 additions & 0 deletions code/vslt_bu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 16; i++) {
dst.byte[i] = ((u8)a.byte[i] < (u8)b.byte[i]) ? 0xFF : 0;
}
9 changes: 9 additions & 0 deletions code/vslt_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vslt_d(v128 a, v128 b) {
v128 dst;
#include "vslt_d.h"
return dst;
}

void test() { FUZZ2(vslt_d); }
3 changes: 3 additions & 0 deletions code/vslt_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.dword[i] = ((s64)a.dword[i] < (s64)b.dword[i]) ? 0xFFFFFFFFFFFFFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vslt_du.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vslt_du(v128 a, v128 b) {
v128 dst;
#include "vslt_du.h"
return dst;
}

void test() { FUZZ2(vslt_du); }
3 changes: 3 additions & 0 deletions code/vslt_du.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.dword[i] = ((u64)a.dword[i] < (u64)b.dword[i]) ? 0xFFFFFFFFFFFFFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vslt_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vslt_h(v128 a, v128 b) {
v128 dst;
#include "vslt_h.h"
return dst;
}

void test() { FUZZ2(vslt_h); }
3 changes: 3 additions & 0 deletions code/vslt_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.half[i] = ((s16)a.half[i] < (s16)b.half[i]) ? 0xFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vslt_hu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vslt_hu(v128 a, v128 b) {
v128 dst;
#include "vslt_hu.h"
return dst;
}

void test() { FUZZ2(vslt_hu); }
3 changes: 3 additions & 0 deletions code/vslt_hu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.half[i] = ((u16)a.half[i] < (u16)b.half[i]) ? 0xFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vslt_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vslt_w(v128 a, v128 b) {
v128 dst;
#include "vslt_w.h"
return dst;
}

void test() { FUZZ2(vslt_w); }
3 changes: 3 additions & 0 deletions code/vslt_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.word[i] = ((s32)a.word[i] < (s32)b.word[i]) ? 0xFFFFFFFF : 0;
}
9 changes: 9 additions & 0 deletions code/vslt_wu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vslt_wu(v128 a, v128 b) {
v128 dst;
#include "vslt_wu.h"
return dst;
}

void test() { FUZZ2(vslt_wu); }
3 changes: 3 additions & 0 deletions code/vslt_wu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.word[i] = ((u32)a.word[i] < (u32)b.word[i]) ? 0xFFFFFFFF : 0;
}
20 changes: 19 additions & 1 deletion docs/lsx/integer_comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@
{{ vseq('b') }}
{{ vseq('h') }}
{{ vseq('w') }}
{{ vseq('d') }}
{{ vseq('d') }}

{{ vslt('b') }}
{{ vslt('bu') }}
{{ vslt('h') }}
{{ vslt('hu') }}
{{ vslt('w') }}
{{ vslt('wu') }}
{{ vslt('d') }}
{{ vslt('du') }}

{{ vsle('b') }}
{{ vsle('bu') }}
{{ vsle('h') }}
{{ vsle('hu') }}
{{ vsle('w') }}
{{ vsle('wu') }}
{{ vsle('d') }}
{{ vsle('du') }}
20 changes: 20 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,24 @@ def vseq(name):
intrinsic=f"__m128i __lsx_vseq_{name} (__m128i a, __m128i b)",
instr=f"vseq.{name} vr, vr",
desc=f"Compare the {width}-bit elements in `a` and `b`, store all-ones to `dst` if equal, zero otherwise.",
)

@env.macro
def vslt(name):
width = widths[name]
signedness = signednesses[name]
return instruction(
intrinsic=f"__m128i __lsx_vslt_{name} (__m128i a, __m128i b)",
instr=f"vslt.{name} vr, vr",
desc=f"Compare the {signedness} {width}-bit elements in `a` and `b`, store all-ones to `dst` if corresponding element in `a` is less than `b`, zero otherwise.",
)

@env.macro
def vsle(name):
width = widths[name]
signedness = signednesses[name]
return instruction(
intrinsic=f"__m128i __lsx_vslt_{name} (__m128i a, __m128i b)",
instr=f"vslt.{name} vr, vr",
desc=f"Compare the {signedness} {width}-bit elements in `a` and `b`, store all-ones to `dst` if corresponding element in `a` is less than or equal `b`, zero otherwise.",
)

0 comments on commit f3a7a6d

Please sign in to comment.