Skip to content

Commit

Permalink
Add vssrani/vssrlni
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 13, 2023
1 parent a454590 commit f72a956
Show file tree
Hide file tree
Showing 37 changed files with 436 additions and 19 deletions.
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ Arranged from QEMU implementation and [GCC Intrinsics](https://gcc.gnu.org/onlin

TODO List:

### vssrln.b.h/h.w/w.d

### vssran.b.h/h.w/w.d

### vssrlrn.b.h/h.w/w.d

### vssrarn.b.h/h.w/w.d

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

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

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

### vssrarn.bu.h/hu.w/wu.d
Expand Down Expand Up @@ -118,12 +106,8 @@ TODO List:

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

### vssrlni.b.h/h.w/w.d/d.q/bu.h/hu.w/wu.d/du.q

### vssrlrni.b.h/h.w/w.d/d.q/bu.h/hu.w/wu.d/du.q

### vssrani.b.h/h.w/w.d/d.q/bu.h/hu.w/wu.d/du.q

### vssrarni.b.h/h.w/w.d/d.q

### vssrarni.bu.h/hu.w/wu.d/du.q
38 changes: 38 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,44 @@
print(f"}}", file=f)
print(f"}}", file=f)

for name, shift_sign in [("srl", "u"), ("sra", "s")]:
double_width_signed = double_width[:1]
with open(f"vs{name}ni_{width}_{double_width_signed}.h", "w") as f:
if shift_sign == "u":
min = 0
if sign == "u":
max = (2**w) - 1
else:
max = (2**(w - 1)) - 1
else:
if sign == "u":
min = 0
max = (2**w) - 1
else:
min = -(2 ** (w - 1))
max = (2 ** (w - 1)) - 1
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(f"if (i < {64 // w}) {{", file=f)
print(
f" {shift_sign}{double_w} temp = ({shift_sign}{double_w})b.{double_m}[i] >> imm;",
file=f,
)
print(
f" dst.{m}[i] = clamp<{shift_sign}{double_w}>(temp, {min}, {max});",
file=f,
)
print(f"}} else {{", file=f)
print(
f" {shift_sign}{double_w} temp = ({shift_sign}{double_w})a.{double_m}[i - {64 // w}] >> imm;",
file=f,
)
print(
f" dst.{m}[i] = clamp<{shift_sign}{double_w}>(temp, {min}, {max});",
file=f,
)
print(f"}}", file=f)
print(f"}}", file=f)

if width == "d" or width == "du":
with open(f"vextl_{double_width}_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // double_w};i++) {{", file=f)
Expand Down
5 changes: 4 additions & 1 deletion code/gen_tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
widths_vsrln = ["b_h", "h_w", "w_d"]
widths_vssrln = ["b_h", "bu_h", "h_w", "hu_w", "w_d", "wu_d"]
widths_vsrlni = ["b_h", "h_w", "w_d", "d_q"]
widths_vssrlni = ["b_h", "bu_h", "h_w", "hu_w", "w_d", "wu_d", "d_q", "du_q"]
widths_vaddw = [
"h_b",
"h_bu",
Expand Down Expand Up @@ -126,8 +127,10 @@
"vsrlri": (widths_signed, "v128 a, int imm", [0, 7]),
"vsrlrn": (widths_vsrln, "v128 a, v128 b"),
"vsrlrni": (widths_vsrlni, "v128 a, v128 b, int imm", [0, 7, 15]),
"vssrln": (widths_vssrln, "v128 a, v128 b"),
"vssran": (widths_vssrln, "v128 a, v128 b"),
"vssrani": (widths_vssrlni, "v128 a, v128 b, int imm", [0, 7, 15]),
"vssrln": (widths_vssrln, "v128 a, v128 b"),
"vssrlni": (widths_vssrlni, "v128 a, v128 b, int imm", [0, 7, 15]),
"vsub": (widths_signed, "v128 a, v128 b"),
"vsubwev": (widths_vsubw, "v128 a, v128 b"),
"vsubwod": (widths_vsubw, "v128 a, v128 b"),
Expand Down
13 changes: 13 additions & 0 deletions code/vssrani_b_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrani_b_h, 0);
FUZZ2(vssrani_b_h, 7);
FUZZ2(vssrani_b_h, 15);
}
9 changes: 9 additions & 0 deletions code/vssrani_b_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 16; i++) {
if (i < 8) {
s16 temp = (s16)b.half[i] >> imm;
dst.byte[i] = clamp<s16>(temp, -128, 127);
} else {
s16 temp = (s16)a.half[i - 8] >> imm;
dst.byte[i] = clamp<s16>(temp, -128, 127);
}
}
13 changes: 13 additions & 0 deletions code/vssrani_bu_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrani_bu_h, 0);
FUZZ2(vssrani_bu_h, 7);
FUZZ2(vssrani_bu_h, 15);
}
9 changes: 9 additions & 0 deletions code/vssrani_bu_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 16; i++) {
if (i < 8) {
s16 temp = (s16)b.half[i] >> imm;
dst.byte[i] = clamp<s16>(temp, 0, 255);
} else {
s16 temp = (s16)a.half[i - 8] >> imm;
dst.byte[i] = clamp<s16>(temp, 0, 255);
}
}
13 changes: 13 additions & 0 deletions code/vssrani_d_q.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrani_d_q, 0);
FUZZ2(vssrani_d_q, 7);
FUZZ2(vssrani_d_q, 15);
}
9 changes: 9 additions & 0 deletions code/vssrani_d_q.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 2; i++) {
if (i < 1) {
s128 temp = (s128)b.qword[i] >> imm;
dst.dword[i] = clamp<s128>(temp, -9223372036854775808, 9223372036854775807);
} else {
s128 temp = (s128)a.qword[i - 1] >> imm;
dst.dword[i] = clamp<s128>(temp, -9223372036854775808, 9223372036854775807);
}
}
13 changes: 13 additions & 0 deletions code/vssrani_du_q.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrani_du_q, 0);
FUZZ2(vssrani_du_q, 7);
FUZZ2(vssrani_du_q, 15);
}
9 changes: 9 additions & 0 deletions code/vssrani_du_q.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 2; i++) {
if (i < 1) {
s128 temp = (s128)b.qword[i] >> imm;
dst.dword[i] = clamp<s128>(temp, 0, 18446744073709551615);
} else {
s128 temp = (s128)a.qword[i - 1] >> imm;
dst.dword[i] = clamp<s128>(temp, 0, 18446744073709551615);
}
}
13 changes: 13 additions & 0 deletions code/vssrani_h_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrani_h_w, 0);
FUZZ2(vssrani_h_w, 7);
FUZZ2(vssrani_h_w, 15);
}
9 changes: 9 additions & 0 deletions code/vssrani_h_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 8; i++) {
if (i < 4) {
s32 temp = (s32)b.word[i] >> imm;
dst.half[i] = clamp<s32>(temp, -32768, 32767);
} else {
s32 temp = (s32)a.word[i - 4] >> imm;
dst.half[i] = clamp<s32>(temp, -32768, 32767);
}
}
13 changes: 13 additions & 0 deletions code/vssrani_hu_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrani_hu_w, 0);
FUZZ2(vssrani_hu_w, 7);
FUZZ2(vssrani_hu_w, 15);
}
9 changes: 9 additions & 0 deletions code/vssrani_hu_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 8; i++) {
if (i < 4) {
s32 temp = (s32)b.word[i] >> imm;
dst.half[i] = clamp<s32>(temp, 0, 65535);
} else {
s32 temp = (s32)a.word[i - 4] >> imm;
dst.half[i] = clamp<s32>(temp, 0, 65535);
}
}
13 changes: 13 additions & 0 deletions code/vssrani_w_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrani_w_d, 0);
FUZZ2(vssrani_w_d, 7);
FUZZ2(vssrani_w_d, 15);
}
9 changes: 9 additions & 0 deletions code/vssrani_w_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 4; i++) {
if (i < 2) {
s64 temp = (s64)b.dword[i] >> imm;
dst.word[i] = clamp<s64>(temp, -2147483648, 2147483647);
} else {
s64 temp = (s64)a.dword[i - 2] >> imm;
dst.word[i] = clamp<s64>(temp, -2147483648, 2147483647);
}
}
13 changes: 13 additions & 0 deletions code/vssrani_wu_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrani_wu_d, 0);
FUZZ2(vssrani_wu_d, 7);
FUZZ2(vssrani_wu_d, 15);
}
9 changes: 9 additions & 0 deletions code/vssrani_wu_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 4; i++) {
if (i < 2) {
s64 temp = (s64)b.dword[i] >> imm;
dst.word[i] = clamp<s64>(temp, 0, 4294967295);
} else {
s64 temp = (s64)a.dword[i - 2] >> imm;
dst.word[i] = clamp<s64>(temp, 0, 4294967295);
}
}
13 changes: 13 additions & 0 deletions code/vssrlni_b_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrlni_b_h, 0);
FUZZ2(vssrlni_b_h, 7);
FUZZ2(vssrlni_b_h, 15);
}
9 changes: 9 additions & 0 deletions code/vssrlni_b_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 16; i++) {
if (i < 8) {
u16 temp = (u16)b.half[i] >> imm;
dst.byte[i] = clamp<u16>(temp, 0, 127);
} else {
u16 temp = (u16)a.half[i - 8] >> imm;
dst.byte[i] = clamp<u16>(temp, 0, 127);
}
}
13 changes: 13 additions & 0 deletions code/vssrlni_bu_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrlni_bu_h, 0);
FUZZ2(vssrlni_bu_h, 7);
FUZZ2(vssrlni_bu_h, 15);
}
9 changes: 9 additions & 0 deletions code/vssrlni_bu_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 16; i++) {
if (i < 8) {
u16 temp = (u16)b.half[i] >> imm;
dst.byte[i] = clamp<u16>(temp, 0, 255);
} else {
u16 temp = (u16)a.half[i - 8] >> imm;
dst.byte[i] = clamp<u16>(temp, 0, 255);
}
}
13 changes: 13 additions & 0 deletions code/vssrlni_d_q.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrlni_d_q, 0);
FUZZ2(vssrlni_d_q, 7);
FUZZ2(vssrlni_d_q, 15);
}
9 changes: 9 additions & 0 deletions code/vssrlni_d_q.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 2; i++) {
if (i < 1) {
u128 temp = (u128)b.qword[i] >> imm;
dst.dword[i] = clamp<u128>(temp, 0, 9223372036854775807);
} else {
u128 temp = (u128)a.qword[i - 1] >> imm;
dst.dword[i] = clamp<u128>(temp, 0, 9223372036854775807);
}
}
13 changes: 13 additions & 0 deletions code/vssrlni_du_q.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrlni_du_q, 0);
FUZZ2(vssrlni_du_q, 7);
FUZZ2(vssrlni_du_q, 15);
}
9 changes: 9 additions & 0 deletions code/vssrlni_du_q.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (int i = 0; i < 2; i++) {
if (i < 1) {
u128 temp = (u128)b.qword[i] >> imm;
dst.dword[i] = clamp<u128>(temp, 0, 18446744073709551615);
} else {
u128 temp = (u128)a.qword[i - 1] >> imm;
dst.dword[i] = clamp<u128>(temp, 0, 18446744073709551615);
}
}
13 changes: 13 additions & 0 deletions code/vssrlni_h_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

void test() {
FUZZ2(vssrlni_h_w, 0);
FUZZ2(vssrlni_h_w, 7);
FUZZ2(vssrlni_h_w, 15);
}
Loading

0 comments on commit f72a956

Please sign in to comment.