Skip to content

Commit

Permalink
Add vrotri/vsrari/vsrlri
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 627d643 commit 8a54166
Show file tree
Hide file tree
Showing 29 changed files with 299 additions and 6 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ TODO List:

### vftintrneh.l.s

### vrotri.b/h/w/d

### vsrlri.b/h/w/d

### vsrari.b/h/w/d

### vpickve2gr.b/h/w/d/bu/hu/wu/du

### vsllwil.h.b/w.h/d.w
Expand Down
35 changes: 35 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@
file=f,
)
print(f"}}", file=f)
with open(f"vrotri_{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] >> imm) | (a.{m}[i] << ({w} - imm));",
file=f,
)
print(f"}}", file=f)
with open(f"vsrlr_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(f" if ((b.{m}[i] & 0x{w-1:x}) == 0) {{", file=f)
Expand All @@ -415,6 +422,20 @@
)
print(f" }}", file=f)
print(f"}}", file=f)
with open(f"vsrlri_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(f" if (imm == 0) {{", file=f)
print(
f" dst.{m}[i] = a.{m}[i];",
file=f,
)
print(f" }} else {{", file=f)
print(
f" dst.{m}[i] = (a.{m}[i] >> imm) + ((a.{m}[i] >> (imm - 1)) & 0x1);",
file=f,
)
print(f" }}", file=f)
print(f"}}", file=f)
with open(f"vsrar_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(f" if ((b.{m}[i] & 0x{w-1:x}) == 0) {{", file=f)
Expand All @@ -429,6 +450,20 @@
)
print(f" }}", file=f)
print(f"}}", file=f)
with open(f"vsrari_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(f" if (imm == 0) {{", file=f)
print(
f" dst.{m}[i] = a.{m}[i];",
file=f,
)
print(f" }} else {{", file=f)
print(
f" dst.{m}[i] = ((s{w})a.{m}[i] >> imm) + (((s{w})a.{m}[i] >> (imm - 1)) & 0x1);",
file=f,
)
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(
Expand Down
3 changes: 3 additions & 0 deletions code/gen_tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"vpickev": (widths_signed, "v128 a, v128 b"),
"vpickod": (widths_signed, "v128 a, v128 b"),
"vrotr": (widths_signed, "v128 a, v128 b"),
"vrotri": (widths_signed, "v128 a, int imm", [0, 7]),
"vreplve": (widths_signed, "v128 a, int idx", [0, 1]),
"vreplvei": (widths_signed, "v128 a, int idx", [0, 1]),
"vreplgr2vr": (widths_signed, "int val", [0, 1, 256]),
Expand All @@ -103,8 +104,10 @@
"vslei": (widths_all, "v128 a, int imm", [0, 15]),
"vsrl": (widths_signed, "v128 a, v128 b"),
"vsrlr": (widths_signed, "v128 a, v128 b"),
"vsrlri": (widths_signed, "v128 a, int imm", [0, 7]),
"vsra": (widths_signed, "v128 a, v128 b"),
"vsrar": (widths_signed, "v128 a, v128 b"),
"vsrari": (widths_signed, "v128 a, int imm", [0, 7]),
"vsub": (widths_signed, "v128 a, v128 b"),
"vsubwev": (widths_vsubw, "v128 a, v128 b"),
"vsubwod": (widths_vsubw, "v128 a, v128 b"),
Expand Down
12 changes: 12 additions & 0 deletions code/vrotri_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vrotri_b(v128 a, int imm) {
v128 dst;
#include "vrotri_b.h"
return dst;
}

void test() {
FUZZ1(vrotri_b, 0);
FUZZ1(vrotri_b, 7);
}
3 changes: 3 additions & 0 deletions code/vrotri_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] = (a.byte[i] >> imm) | (a.byte[i] << (8 - imm));
}
12 changes: 12 additions & 0 deletions code/vrotri_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vrotri_d(v128 a, int imm) {
v128 dst;
#include "vrotri_d.h"
return dst;
}

void test() {
FUZZ1(vrotri_d, 0);
FUZZ1(vrotri_d, 7);
}
3 changes: 3 additions & 0 deletions code/vrotri_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] = (a.dword[i] >> imm) | (a.dword[i] << (64 - imm));
}
12 changes: 12 additions & 0 deletions code/vrotri_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vrotri_h(v128 a, int imm) {
v128 dst;
#include "vrotri_h.h"
return dst;
}

void test() {
FUZZ1(vrotri_h, 0);
FUZZ1(vrotri_h, 7);
}
3 changes: 3 additions & 0 deletions code/vrotri_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] = (a.half[i] >> imm) | (a.half[i] << (16 - imm));
}
12 changes: 12 additions & 0 deletions code/vrotri_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vrotri_w(v128 a, int imm) {
v128 dst;
#include "vrotri_w.h"
return dst;
}

void test() {
FUZZ1(vrotri_w, 0);
FUZZ1(vrotri_w, 7);
}
3 changes: 3 additions & 0 deletions code/vrotri_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] = (a.word[i] >> imm) | (a.word[i] << (32 - imm));
}
12 changes: 12 additions & 0 deletions code/vsrari_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vsrari_b(v128 a, int imm) {
v128 dst;
#include "vsrari_b.h"
return dst;
}

void test() {
FUZZ1(vsrari_b, 0);
FUZZ1(vsrari_b, 7);
}
7 changes: 7 additions & 0 deletions code/vsrari_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for (int i = 0; i < 16; i++) {
if (imm == 0) {
dst.byte[i] = a.byte[i];
} else {
dst.byte[i] = ((s8)a.byte[i] >> imm) + (((s8)a.byte[i] >> (imm - 1)) & 0x1);
}
}
12 changes: 12 additions & 0 deletions code/vsrari_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vsrari_d(v128 a, int imm) {
v128 dst;
#include "vsrari_d.h"
return dst;
}

void test() {
FUZZ1(vsrari_d, 0);
FUZZ1(vsrari_d, 7);
}
8 changes: 8 additions & 0 deletions code/vsrari_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
for (int i = 0; i < 2; i++) {
if (imm == 0) {
dst.dword[i] = a.dword[i];
} else {
dst.dword[i] =
((s64)a.dword[i] >> imm) + (((s64)a.dword[i] >> (imm - 1)) & 0x1);
}
}
12 changes: 12 additions & 0 deletions code/vsrari_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vsrari_h(v128 a, int imm) {
v128 dst;
#include "vsrari_h.h"
return dst;
}

void test() {
FUZZ1(vsrari_h, 0);
FUZZ1(vsrari_h, 7);
}
8 changes: 8 additions & 0 deletions code/vsrari_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
for (int i = 0; i < 8; i++) {
if (imm == 0) {
dst.half[i] = a.half[i];
} else {
dst.half[i] =
((s16)a.half[i] >> imm) + (((s16)a.half[i] >> (imm - 1)) & 0x1);
}
}
12 changes: 12 additions & 0 deletions code/vsrari_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vsrari_w(v128 a, int imm) {
v128 dst;
#include "vsrari_w.h"
return dst;
}

void test() {
FUZZ1(vsrari_w, 0);
FUZZ1(vsrari_w, 7);
}
8 changes: 8 additions & 0 deletions code/vsrari_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
for (int i = 0; i < 4; i++) {
if (imm == 0) {
dst.word[i] = a.word[i];
} else {
dst.word[i] =
((s32)a.word[i] >> imm) + (((s32)a.word[i] >> (imm - 1)) & 0x1);
}
}
12 changes: 12 additions & 0 deletions code/vsrlri_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vsrlri_b(v128 a, int imm) {
v128 dst;
#include "vsrlri_b.h"
return dst;
}

void test() {
FUZZ1(vsrlri_b, 0);
FUZZ1(vsrlri_b, 7);
}
7 changes: 7 additions & 0 deletions code/vsrlri_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for (int i = 0; i < 16; i++) {
if (imm == 0) {
dst.byte[i] = a.byte[i];
} else {
dst.byte[i] = (a.byte[i] >> imm) + ((a.byte[i] >> (imm - 1)) & 0x1);
}
}
12 changes: 12 additions & 0 deletions code/vsrlri_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vsrlri_d(v128 a, int imm) {
v128 dst;
#include "vsrlri_d.h"
return dst;
}

void test() {
FUZZ1(vsrlri_d, 0);
FUZZ1(vsrlri_d, 7);
}
7 changes: 7 additions & 0 deletions code/vsrlri_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for (int i = 0; i < 2; i++) {
if (imm == 0) {
dst.dword[i] = a.dword[i];
} else {
dst.dword[i] = (a.dword[i] >> imm) + ((a.dword[i] >> (imm - 1)) & 0x1);
}
}
12 changes: 12 additions & 0 deletions code/vsrlri_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vsrlri_h(v128 a, int imm) {
v128 dst;
#include "vsrlri_h.h"
return dst;
}

void test() {
FUZZ1(vsrlri_h, 0);
FUZZ1(vsrlri_h, 7);
}
7 changes: 7 additions & 0 deletions code/vsrlri_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for (int i = 0; i < 8; i++) {
if (imm == 0) {
dst.half[i] = a.half[i];
} else {
dst.half[i] = (a.half[i] >> imm) + ((a.half[i] >> (imm - 1)) & 0x1);
}
}
12 changes: 12 additions & 0 deletions code/vsrlri_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

v128 vsrlri_w(v128 a, int imm) {
v128 dst;
#include "vsrlri_w.h"
return dst;
}

void test() {
FUZZ1(vsrlri_w, 0);
FUZZ1(vsrlri_w, 7);
}
7 changes: 7 additions & 0 deletions code/vsrlri_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for (int i = 0; i < 4; i++) {
if (imm == 0) {
dst.word[i] = a.word[i];
} else {
dst.word[i] = (a.word[i] >> imm) + ((a.word[i] >> (imm - 1)) & 0x1);
}
}
15 changes: 15 additions & 0 deletions docs/lsx/shift.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ Compute 128-bit `a` shifted right by `imm * 8` bits.
{{ vsrlr('w') }}
{{ vsrlr('d') }}

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

{{ vsra('b') }}
{{ vsra('h') }}
{{ vsra('w') }}
Expand All @@ -67,7 +72,17 @@ Compute 128-bit `a` shifted right by `imm * 8` bits.
{{ vsrar('w') }}
{{ vsrar('d') }}

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

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

{{ vrotri('b') }}
{{ vrotri('h') }}
{{ vrotri('w') }}
{{ vrotri('d') }}
Loading

0 comments on commit 8a54166

Please sign in to comment.