From a05c52f62bc8276842aae33a1b47e1c1bd7243b2 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Tue, 12 Dec 2023 20:05:16 +0800 Subject: [PATCH] Add vnor/vnori/vor/vori/vorn/vxor/vxori --- README.md | 16 ---------- code/vnor_v.cpp | 9 ++++++ code/vnor_v.h | 3 ++ code/vnori_b.cpp | 15 ++++++++++ code/vnori_b.h | 3 ++ code/vor_v.cpp | 9 ++++++ code/vor_v.h | 3 ++ code/vori_b.cpp | 15 ++++++++++ code/vori_b.h | 3 ++ code/vorn_v.cpp | 9 ++++++ code/vorn_v.h | 3 ++ code/vxor_v.cpp | 9 ++++++ code/vxor_v.h | 3 ++ code/vxori_b.cpp | 15 ++++++++++ code/vxori_b.h | 3 ++ docs/lsx/logical.md | 72 +++++++-------------------------------------- main.py | 16 ++++++++++ 17 files changed, 128 insertions(+), 78 deletions(-) create mode 100644 code/vnor_v.cpp create mode 100644 code/vnor_v.h create mode 100644 code/vnori_b.cpp create mode 100644 code/vnori_b.h create mode 100644 code/vor_v.cpp create mode 100644 code/vor_v.h create mode 100644 code/vori_b.cpp create mode 100644 code/vori_b.h create mode 100644 code/vorn_v.cpp create mode 100644 code/vorn_v.h create mode 100644 code/vxor_v.cpp create mode 100644 code/vxor_v.h create mode 100644 code/vxori_b.cpp create mode 100644 code/vxori_b.h diff --git a/README.md b/README.md index c8654c3a..8afaf8f5 100644 --- a/README.md +++ b/README.md @@ -108,16 +108,6 @@ Vector Multiplication High ### vreplve.b/h/w/d -### vand.v - -### vor.v - -### vxor.v - -### vnor.v - -### vorn.v - ### vfrstp.b/h ### vsignconv.b/h/w/d @@ -288,10 +278,4 @@ Vector Multiplication High ### vshuf4i.b/h/w/d -### vori.b - -### vxori.b - -### vnori.b - ### vldi diff --git a/code/vnor_v.cpp b/code/vnor_v.cpp new file mode 100644 index 00000000..d875b575 --- /dev/null +++ b/code/vnor_v.cpp @@ -0,0 +1,9 @@ +#include "common.h" + +v128 vnor_v(v128 a, v128 b) { + v128 dst; +#include "vnor_v.h" + return dst; +} + +void test() { FUZZ2(vnor_v); } diff --git a/code/vnor_v.h b/code/vnor_v.h new file mode 100644 index 00000000..b3f94489 --- /dev/null +++ b/code/vnor_v.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = ~(a.dword[i] | b.dword[i]); +} \ No newline at end of file diff --git a/code/vnori_b.cpp b/code/vnori_b.cpp new file mode 100644 index 00000000..2abb2ad8 --- /dev/null +++ b/code/vnori_b.cpp @@ -0,0 +1,15 @@ +#include "common.h" + +v128 vnori_b(v128 a, int imm) { + v128 dst; +#include "vnori_b.h" + return dst; +} + +void test() { + FUZZ1(vnori_b, 0x00); + FUZZ1(vnori_b, 0x04); + FUZZ1(vnori_b, 0x08); + FUZZ1(vnori_b, 0x10); + FUZZ1(vnori_b, 0xFF); +} diff --git a/code/vnori_b.h b/code/vnori_b.h new file mode 100644 index 00000000..d67e7e0f --- /dev/null +++ b/code/vnori_b.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 16; i++) { + dst.byte[i] = ~(a.byte[i] | imm); +} \ No newline at end of file diff --git a/code/vor_v.cpp b/code/vor_v.cpp new file mode 100644 index 00000000..0721c844 --- /dev/null +++ b/code/vor_v.cpp @@ -0,0 +1,9 @@ +#include "common.h" + +v128 vor_v(v128 a, v128 b) { + v128 dst; +#include "vor_v.h" + return dst; +} + +void test() { FUZZ2(vor_v); } diff --git a/code/vor_v.h b/code/vor_v.h new file mode 100644 index 00000000..2e6d28b1 --- /dev/null +++ b/code/vor_v.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = a.dword[i] | b.dword[i]; +} \ No newline at end of file diff --git a/code/vori_b.cpp b/code/vori_b.cpp new file mode 100644 index 00000000..d6970f62 --- /dev/null +++ b/code/vori_b.cpp @@ -0,0 +1,15 @@ +#include "common.h" + +v128 vori_b(v128 a, int imm) { + v128 dst; +#include "vori_b.h" + return dst; +} + +void test() { + FUZZ1(vori_b, 0x00); + FUZZ1(vori_b, 0x04); + FUZZ1(vori_b, 0x08); + FUZZ1(vori_b, 0x10); + FUZZ1(vori_b, 0xFF); +} diff --git a/code/vori_b.h b/code/vori_b.h new file mode 100644 index 00000000..d6e63938 --- /dev/null +++ b/code/vori_b.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 16; i++) { + dst.byte[i] = a.byte[i] | imm; +} \ No newline at end of file diff --git a/code/vorn_v.cpp b/code/vorn_v.cpp new file mode 100644 index 00000000..d875b575 --- /dev/null +++ b/code/vorn_v.cpp @@ -0,0 +1,9 @@ +#include "common.h" + +v128 vnor_v(v128 a, v128 b) { + v128 dst; +#include "vnor_v.h" + return dst; +} + +void test() { FUZZ2(vnor_v); } diff --git a/code/vorn_v.h b/code/vorn_v.h new file mode 100644 index 00000000..da524de5 --- /dev/null +++ b/code/vorn_v.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = a.dword[i] | (~b.dword[i]); +} \ No newline at end of file diff --git a/code/vxor_v.cpp b/code/vxor_v.cpp new file mode 100644 index 00000000..6e33c2b8 --- /dev/null +++ b/code/vxor_v.cpp @@ -0,0 +1,9 @@ +#include "common.h" + +v128 vxor_v(v128 a, v128 b) { + v128 dst; +#include "vxor_v.h" + return dst; +} + +void test() { FUZZ2(vxor_v); } diff --git a/code/vxor_v.h b/code/vxor_v.h new file mode 100644 index 00000000..f8ad844d --- /dev/null +++ b/code/vxor_v.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = a.dword[i] ^ b.dword[i]; +} \ No newline at end of file diff --git a/code/vxori_b.cpp b/code/vxori_b.cpp new file mode 100644 index 00000000..f8732438 --- /dev/null +++ b/code/vxori_b.cpp @@ -0,0 +1,15 @@ +#include "common.h" + +v128 vxori_b(v128 a, int imm) { + v128 dst; +#include "vxori_b.h" + return dst; +} + +void test() { + FUZZ1(vxori_b, 0x00); + FUZZ1(vxori_b, 0x04); + FUZZ1(vxori_b, 0x08); + FUZZ1(vxori_b, 0x10); + FUZZ1(vxori_b, 0xFF); +} diff --git a/code/vxori_b.h b/code/vxori_b.h new file mode 100644 index 00000000..98cb3458 --- /dev/null +++ b/code/vxori_b.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 16; i++) { + dst.byte[i] = a.byte[i] ^ imm; +} \ No newline at end of file diff --git a/docs/lsx/logical.md b/docs/lsx/logical.md index 362a8405..6b114477 100644 --- a/docs/lsx/logical.md +++ b/docs/lsx/logical.md @@ -1,64 +1,12 @@ # Logical -## __m128i __lsx_vandi_b (__m128i a, imm0_255 imm) - -### Synopsis - -```c++ -__m128i __lsx_vandi_b (__m128i a, imm0_255 imm) -#include -Instruction: vandi.b vr, vr, imm -CPU Flags: LSX -``` - -### Description - -Compute bitwise AND between 8-bit elements in `a` and `imm`. - -### Operation - -```c++ -{% include 'vandi_b.h' %} -``` - -## __m128i __lsx_vandn_v (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vandn_v (__m128i a, __m128i b) -#include -Instruction: vandn.v vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute bitwise ANDN between elements in `a` and `b`. - -### Operation - -```c++ -{% include 'vandn_v.h' %} -``` - -## __m128i __lsx_vand_v (__m128i a, __m128i b) - -### Synopsis - -```c++ -__m128i __lsx_vand_v (__m128i a, __m128i b) -#include -Instruction: vand.v vr, vr, vr -CPU Flags: LSX -``` - -### Description - -Compute bitwise AND between elements in `a` and `b`. - -### Operation - -```c++ -{% include 'vand_v.h' %} -``` +{{ vlogical('and') }} +{{ vlogicali('and') }} +{{ vlogical('andn') }} +{{ vlogical('nor') }} +{{ vlogicali('nor') }} +{{ vlogical('or') }} +{{ vlogicali('or') }} +{{ vlogical('orn') }} +{{ vlogical('xor') }} +{{ vlogicali('xor') }} \ No newline at end of file diff --git a/main.py b/main.py index 07726325..bde40a0c 100644 --- a/main.py +++ b/main.py @@ -455,3 +455,19 @@ def vsub(name): instr=f"vsub.{name} vr, vr, vr", desc=f"Subtract {width}-bit elements in `a` and `b`, save the result in `dst`.", ) + + @env.macro + def vlogical(op): + return instruction( + intrinsic=f"__m128i __lsx_v{op}_v (__m128i a, __m128i b)", + instr=f"v{op}.v vr, vr, vr", + desc=f"Compute bitwise {op.upper()} between elements in `a` and `b`.", + ) + + @env.macro + def vlogicali(op): + return instruction ( + intrinsic=f"__m128i __lsx_v{op}i_b (__m128i a, imm0_255 imm)", + instr=f"v{op}i.b vr, vr, imm", + desc=f"Compute bitwise {op.upper()} between elements in `a` and `imm`.", + )