diff --git a/code/gen_impl.py b/code/gen_impl.py new file mode 100644 index 00000000..afc2aea8 --- /dev/null +++ b/code/gen_impl.py @@ -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) \ No newline at end of file diff --git a/code/vavg_b.h b/code/vavg_b.h index 52e8d94f..543381ca 100644 --- a/code/vavg_b.h +++ b/code/vavg_b.h @@ -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); -} \ No newline at end of file +} diff --git a/code/vavg_bu.h b/code/vavg_bu.h index 4a9cb99c..85c9794e 100644 --- a/code/vavg_bu.h +++ b/code/vavg_bu.h @@ -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); -} \ No newline at end of file +} diff --git a/code/vavg_d.h b/code/vavg_d.h index 91fa226b..7701565d 100644 --- a/code/vavg_d.h +++ b/code/vavg_d.h @@ -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); -} \ No newline at end of file +} diff --git a/code/vavg_du.h b/code/vavg_du.h index 0cdb930b..e1897fe7 100644 --- a/code/vavg_du.h +++ b/code/vavg_du.h @@ -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); -} \ No newline at end of file +} diff --git a/code/vavg_h.h b/code/vavg_h.h index d9eaeb37..43133408 100644 --- a/code/vavg_h.h +++ b/code/vavg_h.h @@ -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); -} \ No newline at end of file +} diff --git a/code/vavg_hu.h b/code/vavg_hu.h index be428af1..f7b7d0f5 100644 --- a/code/vavg_hu.h +++ b/code/vavg_hu.h @@ -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); -} \ No newline at end of file +} diff --git a/code/vavg_w.h b/code/vavg_w.h index 32b0cf81..0f258e56 100644 --- a/code/vavg_w.h +++ b/code/vavg_w.h @@ -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); -} \ No newline at end of file +} diff --git a/code/vavg_wu.h b/code/vavg_wu.h index 7ab30ee6..22764aa9 100644 --- a/code/vavg_wu.h +++ b/code/vavg_wu.h @@ -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); -} \ No newline at end of file +}