Skip to content

Commit

Permalink
Add vfdiv
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 614b0b1 commit b6d8145
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 2 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ Vector Multiplication High

### vfmul.s/d

### vfdiv.s/d

### vfmax.s/d

### vfmin.s/d
Expand Down
15 changes: 15 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
"qu": "qword",
}

members_fp = {
"s": "fp32",
"d": "fp64",
}

for width in ["b", "bu", "h", "hu", "w", "wu", "d", "du"]:
w = widths[width]
m = members[width]
Expand Down Expand Up @@ -200,4 +205,14 @@
)
print(f"}}", file=f)

for width in ["s", "d"]:
m = members_fp[width]
with open(f"vfdiv_{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];",
file=f,
)
print(f"}}", file=f)

os.system("clang-format -i *.cpp *.h")
1 change: 1 addition & 0 deletions code/gen_tb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

widths_signed = ["b", "h", "w", "d"]
widths_fp = ["s", "d"]
widths_all = ["b", "bu", "h", "hu", "w", "wu", "d", "du"]
widths_vexth = ["h_b", "hu_bu", "w_h", "wu_hu", "d_w", "du_wu", "q_d", "qu_du"]
widths_vaddw = [
Expand Down
3 changes: 3 additions & 0 deletions code/vfdiv_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.fp64[i] = a.fp64[i] / b.fp64[i];
}
3 changes: 3 additions & 0 deletions code/vfdiv_s.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.fp32[i] = a.fp32[i] / b.fp32[i];
}
3 changes: 3 additions & 0 deletions docs/lsx/float_computation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ for (int i = 0;i < 4;i++) {
dst.fp32[i] = a.fp32[i] + b.fp32[i];
}
```

{{ vfdiv('s') }}
{{ vfdiv('d') }}
20 changes: 20 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def define_env(env):
"qu": "unsigned",
}

precisions = {
"s": "single",
"d": "double"
}

fp_types = {
"s": "__m128",
"d": "__m128d"
}

def include(file):
return open(f"code/{file}").read().strip()

Expand Down Expand Up @@ -323,6 +333,16 @@ def vfcmp(cond):
"""
)

@env.macro
def vfdiv(name):
precision = precisions[name]
fp_type = fp_types[name]
return instruction(
intrinsic=f"{fp_type} __lsx_vfdiv_{name} ({fp_type} a, {fp_type} b)",
instr=f"vfdiv.{name} vr, vr, vr",
desc=f"Divide {fp_type} precision floating point elements in `a` by elements in `b`.",
)

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

0 comments on commit b6d8145

Please sign in to comment.