Skip to content

Commit

Permalink
Add vpickev/vpickod
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 389bb4d commit dd3659e
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 4 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ TODO List:

### vssrarn.bu.h/hu.w/wu.d

### vpickev.b/h/w/d

### vpickod.b/h/w/d

### vreplve.b/h/w/d

### vfrstp.b/h
Expand Down
14 changes: 14 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@
file=f,
)
print(f"}}", file=f)
with open(f"vpickev_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = (i < {64 // w}) ? b.{m}[i * 2] : a.{m}[(i - {64 // w}) * 2];",
file=f,
)
print(f"}}", file=f)
with open(f"vpickod_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = (i < {64 // w}) ? b.{m}[i * 2 + 1] : a.{m}[(i - {64 // w}) * 2 + 1];",
file=f,
)
print(f"}}", file=f)

for width in ["s", "d"]:
m = members_fp[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 @@ -77,6 +77,8 @@
"vpackev": (widths_signed, "v128 a, v128 b"),
"vpackod": (widths_signed, "v128 a, v128 b"),
"vpcnt": (widths_signed, "v128 a"),
"vpickev": (widths_signed, "v128 a, v128 b"),
"vpickod": (widths_signed, "v128 a, v128 b"),
"vrotr": (widths_signed, "v128 a, v128 b"),
"vsadd": (widths_all, "v128 a, v128 b"),
"vssub": (widths_all, "v128 a, v128 b"),
Expand Down
9 changes: 9 additions & 0 deletions code/vpickev_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vpickev_b); }
3 changes: 3 additions & 0 deletions code/vpickev_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] = (i < 8) ? b.byte[i * 2] : a.byte[(i - 8) * 2];
}
9 changes: 9 additions & 0 deletions code/vpickev_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vpickev_d); }
3 changes: 3 additions & 0 deletions code/vpickev_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] = (i < 1) ? b.dword[i * 2] : a.dword[(i - 1) * 2];
}
9 changes: 9 additions & 0 deletions code/vpickev_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vpickev_h); }
3 changes: 3 additions & 0 deletions code/vpickev_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] = (i < 4) ? b.half[i * 2] : a.half[(i - 4) * 2];
}
9 changes: 9 additions & 0 deletions code/vpickev_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vpickev_w); }
3 changes: 3 additions & 0 deletions code/vpickev_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] = (i < 2) ? b.word[i * 2] : a.word[(i - 2) * 2];
}
9 changes: 9 additions & 0 deletions code/vpickod_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vpickod_b); }
3 changes: 3 additions & 0 deletions code/vpickod_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] = (i < 8) ? b.byte[i * 2 + 1] : a.byte[(i - 8) * 2 + 1];
}
9 changes: 9 additions & 0 deletions code/vpickod_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vpickod_d); }
3 changes: 3 additions & 0 deletions code/vpickod_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] = (i < 1) ? b.dword[i * 2 + 1] : a.dword[(i - 1) * 2 + 1];
}
9 changes: 9 additions & 0 deletions code/vpickod_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vpickod_h); }
3 changes: 3 additions & 0 deletions code/vpickod_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] = (i < 4) ? b.half[i * 2 + 1] : a.half[(i - 4) * 2 + 1];
}
9 changes: 9 additions & 0 deletions code/vpickod_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vpickod_w); }
3 changes: 3 additions & 0 deletions code/vpickod_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] = (i < 2) ? b.word[i * 2 + 1] : a.word[(i - 2) * 2 + 1];
}
10 changes: 10 additions & 0 deletions docs/lsx/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@
{{ vpackod('h') }}
{{ vpackod('w') }}
{{ vpackod('d') }}

{{ vpickev('b') }}
{{ vpickev('h') }}
{{ vpickev('w') }}
{{ vpickev('d') }}

{{ vpickod('b') }}
{{ vpickod('h') }}
{{ vpickod('w') }}
{{ vpickod('d') }}
18 changes: 18 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,22 @@ def vpackod(name):
intrinsic=f"__m128i __lsx_vpackod_{name} (__m128i a, __m128i b)",
instr=f"vpackod.{name} vr, vr, vr",
desc=f"Collect and pack odd-positioned {width}-bit elements in `a` and `b` and store `dst`.",
)

@env.macro
def vpickev(name):
width = widths[name]
return instruction(
intrinsic=f"__m128i __lsx_vpickev_{name} (__m128i a, __m128i b)",
instr=f"vpickev.{name} vr, vr, vr",
desc=f"Pick even-positioned {width}-bit elements in `b` first, then pick even-positioned {width}-bit elements in `a`.",
)

@env.macro
def vpickod(name):
width = widths[name]
return instruction(
intrinsic=f"__m128i __lsx_vpickod_{name} (__m128i a, __m128i b)",
instr=f"vpickod.{name} vr, vr, vr",
desc=f"Pick odd-positioned {width}-bit elements in `b` first, then pick odd-positioned {width}-bit elements in `a`.",
)

0 comments on commit dd3659e

Please sign in to comment.