diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..bee8a64b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/docs/lsx_integer/vaddsub.md b/docs/lsx_integer/vaddsub.md index 648b638a..c779e130 100644 --- a/docs/lsx_integer/vaddsub.md +++ b/docs/lsx_integer/vaddsub.md @@ -1,274 +1,16 @@ # Add/Subtract/Absolute Difference -## __m128i __lsx_vadd_b (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vadd_b (__m128i a, __m128i b) -#include -Instruction: vadd.b vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Add 8-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vadd_b.h' %} -``` - -## __m128i __lsx_vadd_h (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vadd_h (__m128i a, __m128i b) -#include -Instruction: vadd.h vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Add 16-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vadd_h.h' %} -``` - -## __m128i __lsx_vadd_w (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vadd_w (__m128i a, __m128i b) -#include -Instruction: vadd.w vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Add 32-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vadd_w.h' %} -``` - -## __m128i __lsx_vadd_d (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vadd_d (__m128i a, __m128i b) -#include -Instruction: vadd.d vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Add 64-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vadd_d.h' %} -``` - -## __m128i __lsx_vadd_q (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vadd_q (__m128i a, __m128i b) -#include -Instruction: vadd.q vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Add 128-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vadd_q.h' %} -``` - -## __m128i __lsx_vabsd_b (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vabsd_b (__m128i a, __m128i b) -#include -Instruction: vabsd.b vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute absolute difference of signed 8-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vabsd_b.h' %} -``` - -## __m128i __lsx_vabsd_bu (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vabsd_bu (__m128i a, __m128i b) -#include -Instruction: vabsd.bu vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute absolute difference of unsigned 8-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vabsd_bu.h' %} -``` - -## __m128i __lsx_vabsd_h (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vabsd_h (__m128i a, __m128i b) -#include -Instruction: vabsd.h vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute absolute difference of signed 16-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vabsd_h.h' %} -``` - -## __m128i __lsx_vabsd_hu (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vabsd_hu (__m128i a, __m128i b) -#include -Instruction: vabsd.hu vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute absolute difference of unsigned 16-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vabsd_hu.h' %} -``` - -## __m128i __lsx_vabsd_w (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vabsd_w (__m128i a, __m128i b) -#include -Instruction: vabsd.w vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute absolute difference of signed 32-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vabsd_w.h' %} -``` - -## __m128i __lsx_vabsd_wu (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vabsd_wu (__m128i a, __m128i b) -#include -Instruction: vabsd.wu vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute absolute difference of unsigned 32-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vabsd_wu.h' %} -``` - -## __m128i __lsx_vabsd_d (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vabsd_d (__m128i a, __m128i b) -#include -Instruction: vabsd.d vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute absolute difference of signed 64-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vabsd_d.h' %} -``` - -## __m128i __lsx_vabsd_du (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vabsd_du (__m128i a, __m128i b) -#include -Instruction: vabsd.du vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute absolute difference of unsigned 64-bit elements in `a` and `b`, save the result in `dst`. - -### Operation - -```c++ -{% include 'vabsd_du.h' %} -``` +{{ vadd('b') }} +{{ vadd('h') }} +{{ vadd('w') }} +{{ vadd('d') }} +{{ vadd('q') }} + +{{ vabsd('b') }} +{{ vabsd('bu') }} +{{ vabsd('h') }} +{{ vabsd('hu') }} +{{ vabsd('w') }} +{{ vabsd('wu') }} +{{ vabsd('d') }} +{{ vabsd('du') }} diff --git a/main.py b/main.py new file mode 100644 index 00000000..212fe041 --- /dev/null +++ b/main.py @@ -0,0 +1,71 @@ +def define_env(env): + widths = { + "b": 8, + "bu": 8, + "h": 16, + "hu": 16, + "w": 32, + "wu": 32, + "d": 64, + "du": 64, + "q": 128, + } + + signednesses = { + "b": "signed", + "bu": "unsigned", + "h": "signed", + "hu": "unsigned", + "w": "signed", + "wu": "unsigned", + "d": "signed", + "du": "unsigned", + "q": "signed", + } + + def include(file): + return open(f"code/{file}").read().strip() + + def instruction(intrinsic, instr, desc): + file_name = instr.split(" ")[0].replace(".", "_") + return f""" +## {intrinsic} + +### Synopsis + +```c++ +{intrinsic} +#include +Instruction: {instr} +CPU Flags: LSX +``` + +### Description + +{desc} + +### Operation + +```c++ +{include(f'{file_name}.h')} +``` +""" + + @env.macro + def vadd(name): + width = widths[name] + return instruction( + intrinsic=f"__m128i __lsx_vadd_{name} (__m128i a, __m128i b)", + instr=f"vadd.{name} vr, vr, vr", + desc=f"Add {width}-bit elements in `a` and `b`, save the result in `dst`.", + ) + + @env.macro + def vabsd(name): + width = widths[name] + signedness = signednesses[name] + return instruction( + intrinsic=f"__m128i __lsx_vabsd_{name} (__m128i a, __m128i b)", + instr=f"vabsd.{name} vr, vr, vr", + desc=f"Compute absolute difference of {signedness} {width}-bit elements in `a` and `b`, save the result in `dst`.", + )