Skip to content

Commit

Permalink
Add automation
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent 0661534 commit 9f4f9da
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 16 deletions.
36 changes: 36 additions & 0 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
widths_all = ["b", "bu", "h", "hu", "w", "wu", "d", "du"]

widths = {
"b": 8,
"bu": 8,
"h": 16,
"hu": 16,
"w": 32,
"wu": 32,
"d": 64,
"du": 64,
"q": 128,
}

members = {
"b": "byte",
"bu": "byte",
"h": "half",
"hu": "half",
"w": "word",
"wu": "word",
"d": "dword",
"du": "dword",
}

for width in widths_all:
w = widths[width]
m = members[width]
if "u" in width:
sign = "u"
else:
sign = "s"
with open(f"vavg_{width}.h", 'w') as f:
print(f'for (int i = 0;i < {128 // w};i++) {{', file=f)
print(f' dst.{m}[i] = (({sign}{w})a.{m}[i] >> 1) + (({sign}{w})b.{m}[i] >> 1) + (a.{m}[i] & b.{m}[i] & 1);', file=f)
print(f'}}', file=f)
4 changes: 2 additions & 2 deletions code/vavg_b.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for (int i = 0; i < 16; i++) {
for (int i = 0;i < 16;i++) {
dst.byte[i] = ((s8)a.byte[i] >> 1) + ((s8)b.byte[i] >> 1) + (a.byte[i] & b.byte[i] & 1);
}
}
4 changes: 2 additions & 2 deletions code/vavg_bu.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for (int i = 0; i < 16; i++) {
for (int i = 0;i < 16;i++) {
dst.byte[i] = ((u8)a.byte[i] >> 1) + ((u8)b.byte[i] >> 1) + (a.byte[i] & b.byte[i] & 1);
}
}
4 changes: 2 additions & 2 deletions code/vavg_d.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for (int i = 0; i < 2; i++) {
for (int i = 0;i < 2;i++) {
dst.dword[i] = ((s64)a.dword[i] >> 1) + ((s64)b.dword[i] >> 1) + (a.dword[i] & b.dword[i] & 1);
}
}
4 changes: 2 additions & 2 deletions code/vavg_du.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for (int i = 0; i < 2; i++) {
for (int i = 0;i < 2;i++) {
dst.dword[i] = ((u64)a.dword[i] >> 1) + ((u64)b.dword[i] >> 1) + (a.dword[i] & b.dword[i] & 1);
}
}
4 changes: 2 additions & 2 deletions code/vavg_h.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for (int i = 0; i < 8; i++) {
for (int i = 0;i < 8;i++) {
dst.half[i] = ((s16)a.half[i] >> 1) + ((s16)b.half[i] >> 1) + (a.half[i] & b.half[i] & 1);
}
}
4 changes: 2 additions & 2 deletions code/vavg_hu.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for (int i = 0; i < 8; i++) {
for (int i = 0;i < 8;i++) {
dst.half[i] = ((u16)a.half[i] >> 1) + ((u16)b.half[i] >> 1) + (a.half[i] & b.half[i] & 1);
}
}
4 changes: 2 additions & 2 deletions code/vavg_w.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for (int i = 0; i < 4; i++) {
for (int i = 0;i < 4;i++) {
dst.word[i] = ((s32)a.word[i] >> 1) + ((s32)b.word[i] >> 1) + (a.word[i] & b.word[i] & 1);
}
}
4 changes: 2 additions & 2 deletions code/vavg_wu.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
for (int i = 0; i < 4; i++) {
for (int i = 0;i < 4;i++) {
dst.word[i] = ((u32)a.word[i] >> 1) + ((u32)b.word[i] >> 1) + (a.word[i] & b.word[i] & 1);
}
}

0 comments on commit 9f4f9da

Please sign in to comment.