Skip to content

Commit

Permalink
Add vsigncov
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 83966f2 commit b10ccfb
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 3 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ TODO List:

### vfrstp.b/h

### vsignconv.b/h/w/d

### vfsub.s/d

### vfmul.s/d
Expand Down
7 changes: 7 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@
file=f,
)
print(f"}}", file=f)
with open(f"vsigncov_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = (a.{m}[i] == 0) ? 0 : ((s{w})a.{m}[i] > 0 ? b.{m}[i] : -b.{m}[i]);",
file=f,
)
print(f"}}", file=f)

for width in ["s", "d"]:
m = members_fp[width]
Expand Down
1 change: 1 addition & 0 deletions code/gen_tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"vreplve": (widths_signed, "v128 a, int idx", [0, 1]),
"vreplvei": (widths_signed, "v128 a, int idx", [0, 1]),
"vsadd": (widths_all, "v128 a, v128 b"),
"vsigncov": (widths_signed, "v128 a, v128 b"),
"vssub": (widths_all, "v128 a, v128 b"),
"vseq": (widths_signed, "v128 a, v128 b"),
"vsll": (widths_signed, "v128 a, v128 b"),
Expand Down
9 changes: 9 additions & 0 deletions code/vsigncov_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

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

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

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

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

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

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

void test() { FUZZ2(vsigncov_w); }
4 changes: 4 additions & 0 deletions code/vsigncov_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 4; i++) {
dst.word[i] =
(a.word[i] == 0) ? 0 : ((s32)a.word[i] > 0 ? b.word[i] : -b.word[i]);
}
7 changes: 6 additions & 1 deletion docs/lsx/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@
{{ vreplvei('b') }}
{{ vreplvei('h') }}
{{ vreplvei('w') }}
{{ vreplvei('d') }}
{{ vreplvei('d') }}

{{ vsigncov('b') }}
{{ vsigncov('h') }}
{{ vsigncov('w') }}
{{ vsigncov('d') }}
9 changes: 9 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,4 +752,13 @@ def vreplvei(name):
intrinsic=f"__m128i __lsx_vreplvei_{name} (__m128i a, imm0_{imm_upper} idx)",
instr=f"vreplvei.{name} vr, vr, imm",
desc=f"Repeat the element in lane `idx` of `a` to whole vector.",
)

@env.macro
def vsigncov(name):
width = widths[name]
return instruction(
intrinsic=f"__m128i __lsx_vsigncov_{name} (__m128i a, __m128i b)",
instr=f"vsigncov.{name} vr, vr, vr",
desc=f"If the {width}-bit element in `a` equals to zero, set the result to zero. If the signed {width}-bit element in `a` is posiive, copy element in `b` to result. Otherwise, copy negated element in `b` to result.",
)

0 comments on commit b10ccfb

Please sign in to comment.