Skip to content

Commit

Permalink
Add vdiv
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 4bf308a commit 150730a
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 3 deletions.
7 changes: 7 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
file=f,
)
print(f"}}", file=f)
with open(f"vdiv_{width}.h", "w") as f:
print(f"for (int i = 0;i < {128 // w};i++) {{", file=f)
print(
f" dst.{m}[i] = (b.{m}[i] == 0) ? 0 : ({sign}{w})a.{m}[i] / (({sign}{w})b.{m}[i]);",
file=f,
)
print(f"}}", file=f)

for width in ["b", "bu", "h", "hu", "w", "wu", "d", "du"]:
double_width = double_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 @@ -31,6 +31,7 @@
"vbitrevi": (widths_signed, "v128 a, int imm", [0, 3, 7]),
"vclo": (widths_signed, "v128 a"),
"vclz": (widths_signed, "v128 a"),
"vdiv": (widths_all, "v128 a, v128 b"),
}

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

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

void test() { FUZZ2(vdiv_b); }
3 changes: 3 additions & 0 deletions code/vdiv_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] = (b.byte[i] == 0) ? 0 : (s8)a.byte[i] / ((s8)b.byte[i]);
}
9 changes: 9 additions & 0 deletions code/vdiv_bu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vdiv_bu); }
3 changes: 3 additions & 0 deletions code/vdiv_bu.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] = (b.byte[i] == 0) ? 0 : (u8)a.byte[i] / ((u8)b.byte[i]);
}
9 changes: 9 additions & 0 deletions code/vdiv_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vdiv_d); }
3 changes: 3 additions & 0 deletions code/vdiv_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] = (b.dword[i] == 0) ? 0 : (s64)a.dword[i] / ((s64)b.dword[i]);
}
9 changes: 9 additions & 0 deletions code/vdiv_du.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vdiv_du); }
3 changes: 3 additions & 0 deletions code/vdiv_du.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] = (b.dword[i] == 0) ? 0 : (u64)a.dword[i] / ((u64)b.dword[i]);
}
9 changes: 9 additions & 0 deletions code/vdiv_h.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vdiv_h); }
3 changes: 3 additions & 0 deletions code/vdiv_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] = (b.half[i] == 0) ? 0 : (s16)a.half[i] / ((s16)b.half[i]);
}
9 changes: 9 additions & 0 deletions code/vdiv_hu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vdiv_hu); }
3 changes: 3 additions & 0 deletions code/vdiv_hu.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] = (b.half[i] == 0) ? 0 : (u16)a.half[i] / ((u16)b.half[i]);
}
9 changes: 9 additions & 0 deletions code/vdiv_w.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vdiv_w); }
3 changes: 3 additions & 0 deletions code/vdiv_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] = (b.word[i] == 0) ? 0 : (s32)a.word[i] / ((s32)b.word[i]);
}
9 changes: 9 additions & 0 deletions code/vdiv_wu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common.h"

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

void test() { FUZZ2(vdiv_wu); }
3 changes: 3 additions & 0 deletions code/vdiv_wu.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] = (b.word[i] == 0) ? 0 : (u32)a.word[i] / ((u32)b.word[i]);
}
13 changes: 11 additions & 2 deletions docs/lsx_integer/vaddsub.md → docs/lsx_integer/computation.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add, Subtract, Absolute and Average
# Integer Computation

{{ vadd('b') }}
{{ vadd('h') }}
Expand Down Expand Up @@ -67,4 +67,13 @@
{{ vavgr('w') }}
{{ vavgr('wu') }}
{{ vavgr('d') }}
{{ vavgr('du') }}
{{ vavgr('du') }}

{{ vdiv('b') }}
{{ vdiv('bu') }}
{{ vdiv('h') }}
{{ vdiv('hu') }}
{{ vdiv('w') }}
{{ vdiv('wu') }}
{{ vdiv('d') }}
{{ vdiv('du') }}
2 changes: 1 addition & 1 deletion docs/lsx_integer/vshift.md → docs/lsx_integer/shift.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Shift
# Integer Shift

## __m128i __lsx_vbsll_v (__m128i a, imm0_31 imm)

Expand Down
9 changes: 9 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ def vclz(name):
desc=f"Count leading zeros of {width}-bit elements in `a`.",
)

@env.macro
def vdiv(name):
width = widths[name]
return instruction(
intrinsic=f"__m128i __lsx_div_{name} (__m128i a, __m128i b)",
instr=f"vdiv.{name} vr, vr, vr",
desc=f"Divide {width}-bit elements in `a` by elements in `b`.",
)

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

0 comments on commit 150730a

Please sign in to comment.