Skip to content

Commit

Permalink
Add vextl
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 5e53971 commit 856dbf1
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 4 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,8 @@ Vector Multiplication High

### vsllwil.h.b/w.h/d.w

### vextl.q.d

### vsllwil.hu.bu/wu.hu/du.wu

### vextl.qu.du

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

### vslli.b/h/w/d
Expand Down
9 changes: 9 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
)
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)
print(
f" dst.{double_m}[i] = ({sign}{double_w})({sign}{w})a.{m}[i];",
file=f,
)
print(f"}}", file=f)

for width in ["b", "bu", "h", "hu", "w", "wu", "d", "du"]:
double_width = double_widths[width]
w = widths[width]
Expand Down
1 change: 1 addition & 0 deletions code/gen_tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"vclz": (widths_signed, "v128 a"),
"vdiv": (widths_all, "v128 a, v128 b"),
"vexth": (widths_vexth, "v128 a"),
"vextl": (["q_d", "qu_du"], "v128 a"),
}

for name in tb:
Expand Down
9 changes: 9 additions & 0 deletions code/vextl_q_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vextl_q_d(v128 a) {
v128 dst;
#include "vextl_q_d.h"
return dst;
}

void test() { FUZZ1(vextl_q_d); }
3 changes: 3 additions & 0 deletions code/vextl_q_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 1; i++) {
dst.qword[i] = (s128)(s64)a.dword[i];
}
9 changes: 9 additions & 0 deletions code/vextl_qu_du.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

v128 vextl_qu_du(v128 a) {
v128 dst;
#include "vextl_qu_du.h"
return dst;
}

void test() { FUZZ1(vextl_qu_du); }
3 changes: 3 additions & 0 deletions code/vextl_qu_du.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 1; i++) {
dst.qword[i] = (u128)(u64)a.dword[i];
}
3 changes: 3 additions & 0 deletions docs/lsx/bitwise.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,6 @@ Compute bitwise selection: for each bit position, if the bit in `a` equals to on
{{ vexth('du', 'wu') }}
{{ vexth('q', 'd') }}
{{ vexth('qu', 'du') }}

{{ vextl('q', 'd') }}
{{ vextl('qu', 'du') }}
11 changes: 11 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ def vexth(name, name2):
desc=f"Extend {signedness} {width2}-bit elements in the higher half of `a` to {width}-bit.",
)

@env.macro
def vextl(name, name2):
width = widths[name[0]]
width2 = widths[name2[0]]
signedness = signednesses[name]
return instruction(
intrinsic=f"__m128i __lsx_vextl_{name}_{name2} (__m128i a)",
instr=f"vextl.{name}.{name2} vr, vr",
desc=f"Extend {signedness} {width2}-bit elements in the lower half of `a` to {width}-bit.",
)

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

0 comments on commit 856dbf1

Please sign in to comment.