Skip to content

Commit

Permalink
Add vadda
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent ba28e91 commit 98b3d76
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ Vector Half Add Unsigned

Vector Half Sub Unsigned

### vadda.b/h/w/d

Vector Add Absolute

### vavg.b/h/w/d

Vector Average
Expand Down
3 changes: 3 additions & 0 deletions code/vadda_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] = abs(a.byte[i]) + abs(b.byte[i]);
}
4 changes: 4 additions & 0 deletions code/vadda_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 2; i++) {
dst.dword[i] = abs(a.dword[i]) + abs(b.dword[i]);
}

4 changes: 4 additions & 0 deletions code/vadda_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 8; i++) {
dst.half[i] = abs(a.half[i]) + abs(b.half[i]);
}

3 changes: 3 additions & 0 deletions code/vadda_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] = abs(a.word[i]) + abs(b.word[i]);
}
7 changes: 6 additions & 1 deletion docs/lsx_integer/vaddsub.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add/Subtract/Absolute Difference
# Add/Subtract/Absolute

{{ vadd('b') }}
{{ vadd('h') }}
Expand All @@ -14,3 +14,8 @@
{{ vabsd('wu') }}
{{ vabsd('d') }}
{{ vabsd('du') }}

{{ vadda('b') }}
{{ vadda('h') }}
{{ vadda('w') }}
{{ vadda('d') }}
9 changes: 9 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,12 @@ def vldrepl(name):
instr=f"vldrepl.{name} vr, r, imm",
desc=f"Read {width}-bit data from memory address `addr + (offset << {shift})`, replicate the data to all vector lanes and save into `dst`.",
)

@env.macro
def vadda(name):
width = widths[name]
return instruction(
intrinsic=f"__m128i __lsx_vadda_{name} (__m128i a, __m128i b)",
instr=f"vadda.{name} vr, vr, vr",
desc=f"Add absolute of {width}-bit elements in `a` and `b`, save the result in `dst`.",
)

0 comments on commit 98b3d76

Please sign in to comment.