Skip to content

Commit

Permalink
Add vsrlrni/vsrarni
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 13, 2023
1 parent 476b709 commit 2a5308e
Show file tree
Hide file tree
Showing 29 changed files with 339 additions and 6 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,10 @@ TODO List:

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

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

### 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

### vsrarni.b.h/h.w/w.d/d.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
Expand Down
57 changes: 57 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,63 @@
file=f,
)
print(f"}}", file=f)
with open(f"vsrlrni_{width}_{double_width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(f"if (i < {64 // w}) {{", file=f)
print(f"if (imm == 0) {{", file=f)
print(
f" dst.{m}[i] = (u{w})(u{double_w})b.{double_m}[i];",
file=f,
)
print(f"}} else {{", file=f)
print(
f" dst.{m}[i] = (u{w})(((u{double_w})b.{double_m}[i] >> imm) + (((u{double_w})b.{double_m}[i] >> (imm - 1)) & 0x1));",
file=f,
)
print(f"}}", file=f)
print(f"}} else {{", file=f)
print(f"if (imm == 0) {{", file=f)
print(
f" dst.{m}[i] = (u{w})(u{double_w})a.{double_m}[i - {64 // w}];",
file=f,
)
print(f"}} else {{", file=f)
print(
f" dst.{m}[i] = (u{w})(((u{double_w})a.{double_m}[i - {64 // w}] >> imm) + (((u{double_w})a.{double_m}[i - {64 // w}] >> (imm - 1)) & 0x1));",
file=f,
)
print(f"}}", file=f)
print(f"}}", file=f)
print(f"}}", file=f)
with open(f"vsrarni_{width}_{double_width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(f"if (i < {64 // w}) {{", file=f)
print(f"if (imm == 0) {{", file=f)
print(
f" dst.{m}[i] = (s{w})(s{double_w})b.{double_m}[i];",
file=f,
)
print(f"}} else {{", file=f)
print(
f" dst.{m}[i] = (s{w})(((s{double_w})b.{double_m}[i] >> imm) + (((s{double_w})b.{double_m}[i] >> (imm - 1)) & 0x1));",
file=f,
)
print(f"}}", file=f)
print(f"}} else {{", file=f)
print(f"if (imm == 0) {{", file=f)
print(
f" dst.{m}[i] = (s{w})(s{double_w})a.{double_m}[i - {64 // w}];",
file=f,
)
print(f"}} else {{", file=f)
print(
f" dst.{m}[i] = (u{w})(((s{double_w})a.{double_m}[i - {64 // w}] >> imm) + (((s{double_w})a.{double_m}[i - {64 // w}] >> (imm - 1)) & 0x1));",
file=f,
)
print(f"}}", 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:
Expand Down
6 changes: 4 additions & 2 deletions code/gen_tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@
"vsra": (widths_signed, "v128 a, v128 b"),
"vsrai": (widths_signed, "v128 a, int imm", [0, 7]),
"vsran": (widths_vsrln, "v128 a, v128 b"),
"vsrani": (widths_vsrlni, "v128 a, v128 b, int imm", [0, 7]),
"vsrani": (widths_vsrlni, "v128 a, v128 b, int imm", [0, 7, 15]),
"vsrar": (widths_signed, "v128 a, v128 b"),
"vsrari": (widths_signed, "v128 a, int imm", [0, 7]),
"vsrarn": (widths_vsrln, "v128 a, v128 b"),
"vsrarni": (widths_vsrlni, "v128 a, v128 b, int imm", [0, 7, 15]),
"vsrl": (widths_signed, "v128 a, v128 b"),
"vsrli": (widths_signed, "v128 a, int imm", [0, 7]),
"vsrln": (widths_vsrln, "v128 a, v128 b"),
"vsrlni": (widths_vsrlni, "v128 a, v128 b, int imm", [0, 7]),
"vsrlni": (widths_vsrlni, "v128 a, v128 b, int imm", [0, 7, 15]),
"vsrlr": (widths_signed, "v128 a, v128 b"),
"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]),
"vsub": (widths_signed, "v128 a, v128 b"),
"vsubwev": (widths_vsubw, "v128 a, v128 b"),
"vsubwod": (widths_vsubw, "v128 a, v128 b"),
Expand Down
1 change: 1 addition & 0 deletions code/vsrani_b_h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ v128 vsrani_b_h(v128 a, v128 b, int imm) {
void test() {
FUZZ2(vsrani_b_h, 0);
FUZZ2(vsrani_b_h, 7);
FUZZ2(vsrani_b_h, 15);
}
1 change: 1 addition & 0 deletions code/vsrani_d_q.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ v128 vsrani_d_q(v128 a, v128 b, int imm) {
void test() {
FUZZ2(vsrani_d_q, 0);
FUZZ2(vsrani_d_q, 7);
FUZZ2(vsrani_d_q, 15);
}
1 change: 1 addition & 0 deletions code/vsrani_h_w.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ v128 vsrani_h_w(v128 a, v128 b, int imm) {
void test() {
FUZZ2(vsrani_h_w, 0);
FUZZ2(vsrani_h_w, 7);
FUZZ2(vsrani_h_w, 15);
}
1 change: 1 addition & 0 deletions code/vsrani_w_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ v128 vsrani_w_d(v128 a, v128 b, int imm) {
void test() {
FUZZ2(vsrani_w_d, 0);
FUZZ2(vsrani_w_d, 7);
FUZZ2(vsrani_w_d, 15);
}
13 changes: 13 additions & 0 deletions code/vsrarni_b_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

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

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

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

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

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

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

void test() {
FUZZ2(vsrarni_w_d, 0);
FUZZ2(vsrarni_w_d, 7);
FUZZ2(vsrarni_w_d, 15);
}
17 changes: 17 additions & 0 deletions code/vsrarni_w_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
for (int i = 0; i < 4; i++) {
if (i < 2) {
if (imm == 0) {
dst.word[i] = (s32)(s64)b.dword[i];
} else {
dst.word[i] = (s32)(((s64)b.dword[i] >> imm) +
(((s64)b.dword[i] >> (imm - 1)) & 0x1));
}
} else {
if (imm == 0) {
dst.word[i] = (s32)(s64)a.dword[i - 2];
} else {
dst.word[i] = (u32)(((s64)a.dword[i - 2] >> imm) +
(((s64)a.dword[i - 2] >> (imm - 1)) & 0x1));
}
}
}
1 change: 1 addition & 0 deletions code/vsrlni_b_h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ v128 vsrlni_b_h(v128 a, v128 b, int imm) {
void test() {
FUZZ2(vsrlni_b_h, 0);
FUZZ2(vsrlni_b_h, 7);
FUZZ2(vsrlni_b_h, 15);
}
1 change: 1 addition & 0 deletions code/vsrlni_d_q.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ v128 vsrlni_d_q(v128 a, v128 b, int imm) {
void test() {
FUZZ2(vsrlni_d_q, 0);
FUZZ2(vsrlni_d_q, 7);
FUZZ2(vsrlni_d_q, 15);
}
1 change: 1 addition & 0 deletions code/vsrlni_h_w.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ v128 vsrlni_h_w(v128 a, v128 b, int imm) {
void test() {
FUZZ2(vsrlni_h_w, 0);
FUZZ2(vsrlni_h_w, 7);
FUZZ2(vsrlni_h_w, 15);
}
1 change: 1 addition & 0 deletions code/vsrlni_w_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ v128 vsrlni_w_d(v128 a, v128 b, int imm) {
void test() {
FUZZ2(vsrlni_w_d, 0);
FUZZ2(vsrlni_w_d, 7);
FUZZ2(vsrlni_w_d, 15);
}
13 changes: 13 additions & 0 deletions code/vsrlrni_b_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

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

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

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

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

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

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

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

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

0 comments on commit 2a5308e

Please sign in to comment.