Skip to content

Commit

Permalink
Add vpackev/vpackod
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 3c1e68b commit 389bb4d
Show file tree
Hide file tree
Showing 22 changed files with 151 additions and 16 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

### vpackev.b/h/w/d

### vpackod.b/h/w/d

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

### vpickod.b/h/w/d
Expand Down
14 changes: 14 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,20 @@
)
print(f" }}", file=f)
print(f"}}", file=f)
with open(f"vpackev_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = (i % 2 == 1) ? a.{m}[i-1] : b.{m}[i];",
file=f,
)
print(f"}}", file=f)
with open(f"vpackod_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = (i % 2 == 1) ? a.{m}[i] : b.{m}[i+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 @@ -74,6 +74,8 @@
"vmul": (widths_signed, "v128 a, v128 b"),
"vmulwev": (widths_vaddw, "v128 a, v128 b"),
"vmulwod": (widths_vaddw, "v128 a, v128 b"),
"vpackev": (widths_signed, "v128 a, v128 b"),
"vpackod": (widths_signed, "v128 a, v128 b"),
"vpcnt": (widths_signed, "v128 a"),
"vrotr": (widths_signed, "v128 a, v128 b"),
"vsadd": (widths_all, "v128 a, v128 b"),
Expand Down
9 changes: 9 additions & 0 deletions code/vpackev_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

void test() { FUZZ2(vpackod_w); }
3 changes: 3 additions & 0 deletions code/vpackod_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 == 1) ? a.word[i] : b.word[i + 1];
}
11 changes: 0 additions & 11 deletions docs/lsx/interleaving.md

This file was deleted.

22 changes: 21 additions & 1 deletion docs/lsx/misc.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# Misc

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

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

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

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

{{ vpackod('b') }}
{{ vpackod('h') }}
{{ vpackod('w') }}
{{ vpackod('d') }}
18 changes: 18 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,4 +697,22 @@ def vsrar(name):
intrinsic=f"__m128i __lsx_vsrar_{name} (__m128i a, __m128i b)",
instr=f"vsrar.{name} vr, vr, vr",
desc=f"Arithmetic right shift (with rounding) the signed {width}-bit elements in `a` by elements in `b`, store the result to `dst`.",
)

@env.macro
def vpackev(name):
width = widths[name]
return instruction(
intrinsic=f"__m128i __lsx_vpackev_{name} (__m128i a, __m128i b)",
instr=f"vpackev.{name} vr, vr, vr",
desc=f"Collect and pack even-positioned {width}-bit elements in `a` and `b` and store `dst`.",
)

@env.macro
def vpackod(name):
width = widths[name]
return instruction(
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`.",
)

0 comments on commit 389bb4d

Please sign in to comment.