Skip to content

Commit

Permalink
Add vslli/vsrli/vsrai
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 8a54166 commit 353adcd
Show file tree
Hide file tree
Showing 29 changed files with 250 additions and 7 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ TODO List:

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

### vslli.b/h/w/d

### vsrli.b/h/w/d

### vsrai.b/h/w/d

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

### vsrlrni.b.h/h.w/w.d/d.q
Expand Down
21 changes: 21 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,20 +380,41 @@
file=f,
)
print(f"}}", file=f)
with open(f"vslli_{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;",
file=f,
)
print(f"}}", file=f)
with open(f"vsrl_{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] >> (b.{m}[i] & 0x{w-1:x});",
file=f,
)
print(f"}}", file=f)
with open(f"vsrli_{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;",
file=f,
)
print(f"}}", file=f)
with open(f"vsra_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = ((s{w})a.{m}[i]) >> (b.{m}[i] & 0x{w-1:x});",
file=f,
)
print(f"}}", file=f)
with open(f"vsrai_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = ((s{w})a.{m}[i]) >> imm;",
file=f,
)
print(f"}}", file=f)
with open(f"vrotr_{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 @@ -98,14 +98,17 @@
"vsub": (widths_signed, "v128 a, v128 b"),
"vsubi": (widths_unsigned, "v128 a, int imm", [0, 31]),
"vsll": (widths_signed, "v128 a, v128 b"),
"vslli": (widths_signed, "v128 a, int imm", [0, 7]),
"vslt": (widths_all, "v128 a, v128 b"),
"vslti": (widths_all, "v128 a, int imm", [0, 15]),
"vsle": (widths_all, "v128 a, v128 b"),
"vslei": (widths_all, "v128 a, int imm", [0, 15]),
"vsrl": (widths_signed, "v128 a, v128 b"),
"vsrli": (widths_signed, "v128 a, int imm", [0, 7]),
"vsrlr": (widths_signed, "v128 a, v128 b"),
"vsrlri": (widths_signed, "v128 a, int imm", [0, 7]),
"vsra": (widths_signed, "v128 a, v128 b"),
"vsrai": (widths_signed, "v128 a, int imm", [0, 7]),
"vsrar": (widths_signed, "v128 a, v128 b"),
"vsrari": (widths_signed, "v128 a, int imm", [0, 7]),
"vsub": (widths_signed, "v128 a, v128 b"),
Expand Down
12 changes: 12 additions & 0 deletions code/vslli_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

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

void test() {
FUZZ1(vslli_b, 0);
FUZZ1(vslli_b, 7);
}
3 changes: 3 additions & 0 deletions code/vslli_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;
}
12 changes: 12 additions & 0 deletions code/vslli_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

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

void test() {
FUZZ1(vslli_d, 0);
FUZZ1(vslli_d, 7);
}
3 changes: 3 additions & 0 deletions code/vslli_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;
}
12 changes: 12 additions & 0 deletions code/vslli_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

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

void test() {
FUZZ1(vslli_h, 0);
FUZZ1(vslli_h, 7);
}
3 changes: 3 additions & 0 deletions code/vslli_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;
}
12 changes: 12 additions & 0 deletions code/vslli_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

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

void test() {
FUZZ1(vslli_w, 0);
FUZZ1(vslli_w, 7);
}
3 changes: 3 additions & 0 deletions code/vslli_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;
}
12 changes: 12 additions & 0 deletions code/vsrai_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

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

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

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

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

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

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

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

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

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

void test() {
FUZZ1(vsrli_b, 0);
FUZZ1(vsrli_b, 7);
}
3 changes: 3 additions & 0 deletions code/vsrli_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;
}
12 changes: 12 additions & 0 deletions code/vsrli_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

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

void test() {
FUZZ1(vsrli_d, 0);
FUZZ1(vsrli_d, 7);
}
3 changes: 3 additions & 0 deletions code/vsrli_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;
}
12 changes: 12 additions & 0 deletions code/vsrli_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

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

void test() {
FUZZ1(vsrli_h, 0);
FUZZ1(vsrli_h, 7);
}
3 changes: 3 additions & 0 deletions code/vsrli_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;
}
12 changes: 12 additions & 0 deletions code/vsrli_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

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

void test() {
FUZZ1(vsrli_w, 0);
FUZZ1(vsrli_w, 7);
}
3 changes: 3 additions & 0 deletions code/vsrli_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;
}
17 changes: 16 additions & 1 deletion docs/lsx/shift.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ Compute 128-bit `a` shifted right by `imm * 8` bits.
{{ vsll('w') }}
{{ vsll('d') }}

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

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

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

{{ vsrlr('b') }}
{{ vsrlr('h') }}
{{ vsrlr('w') }}
Expand All @@ -67,6 +77,11 @@ Compute 128-bit `a` shifted right by `imm * 8` bits.
{{ vsra('w') }}
{{ vsra('d') }}

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

{{ vsrar('b') }}
{{ vsrar('h') }}
{{ vsrar('w') }}
Expand All @@ -85,4 +100,4 @@ Compute 128-bit `a` shifted right by `imm * 8` bits.
{{ vrotri('b') }}
{{ vrotri('h') }}
{{ vrotri('w') }}
{{ vrotri('d') }}
{{ vrotri('d') }}
30 changes: 30 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,16 @@ def vsll(name):
desc=f"Logical left shift the unsigned {width}-bit elements in `a` by elements in `b`, store the result to `dst`.",
)

@env.macro
def vslli(name):
width = widths[name]
signedness = signednesses[name]
return instruction(
intrinsic=f"__m128i __lsx_vslli_{name} (__m128i a, imm0_{width-1} imm)",
instr=f"vslli.{name} vr, vr, imm",
desc=f"Logical left shift the unsigned {width}-bit elements in `a` by `imm`, store the result to `dst`.",
)

@env.macro
def vsrl(name):
width = widths[name]
Expand All @@ -705,6 +715,16 @@ def vsrl(name):
desc=f"Logical right shift the unsigned {width}-bit elements in `a` by elements in `b`, store the result to `dst`.",
)

@env.macro
def vsrli(name):
width = widths[name]
signedness = signednesses[name]
return instruction(
intrinsic=f"__m128i __lsx_vsrli_{name} (__m128i a, imm0_{width-1} imm)",
instr=f"vsrli.{name} vr, vr, imm",
desc=f"Logical right shift the unsigned {width}-bit elements in `a` by `imm`, store the result to `dst`.",
)

@env.macro
def vsra(name):
width = widths[name]
Expand All @@ -715,6 +735,16 @@ def vsra(name):
desc=f"Arithmetic right shift the signed {width}-bit elements in `a` by elements in `b`, store the result to `dst`.",
)

@env.macro
def vsrai(name):
width = widths[name]
signedness = signednesses[name]
return instruction(
intrinsic=f"__m128i __lsx_vsrai_{name} (__m128i a, imm0_{width-1} imm)",
instr=f"vsrai.{name} vr, vr, imm",
desc=f"Arithmetic right shift the signed {width}-bit elements in `a` by `imm`, store the result to `dst`.",
)

@env.macro
def vrotr(name):
width = widths[name]
Expand Down

0 comments on commit 353adcd

Please sign in to comment.