Skip to content

Commit

Permalink
Add vandi.b vandn.v vand.v
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 12, 2023
1 parent fe52550 commit b576aeb
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 128 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ Vector Multiplication High

### vnor.v

### vandn.v

### vorn.v

### vfrstp.b/h
Expand Down Expand Up @@ -421,8 +419,6 @@ Vector Multiplication High

### vbitseli.b

### vandi.b

### vori.b

### vxori.b
Expand Down
2 changes: 2 additions & 0 deletions code/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ union v128 {
v4i32 __v4i32;
v8i16 __v8i16;
v16i8 __v16i8;
v16u8 __v16u8;

u8 byte[16];
u16 half[8];
Expand All @@ -45,6 +46,7 @@ union v128 {
operator v4i32() { return __v4i32; }
operator v8i16() { return __v8i16; }
operator v16i8() { return __v16i8; }
operator v16u8() { return __v16u8; }
bool operator==(const v128 &other) const {
return memcmp(byte, other.byte, 16) == 0;
}
Expand Down
11 changes: 11 additions & 0 deletions code/vand_v.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "common.h"

v128 vand_v(v128 a, v128 b) {
v128 dst;
#include "vand_v.h"
return dst;
}

void test() {
FUZZ2(vand_v);
}
3 changes: 3 additions & 0 deletions code/vand_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.dword[i] = a.dword[i] & b.dword[i];
}
15 changes: 15 additions & 0 deletions code/vandi_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "common.h"

v128 vandi_b(v128 a, int imm) {
v128 dst;
#include "vandi_b.h"
return dst;
}

void test() {
FUZZ1(vandi_b, 0x00);
FUZZ1(vandi_b, 0x04);
FUZZ1(vandi_b, 0x08);
FUZZ1(vandi_b, 0x10);
FUZZ1(vandi_b, 0xFF);
}
3 changes: 3 additions & 0 deletions code/vandi_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] = a.byte[i] & imm;
}
11 changes: 11 additions & 0 deletions code/vandn_v.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "common.h"

v128 vandn_v(v128 a, v128 b) {
v128 dst;
#include "vandn_v.h"
return dst;
}

void test() {
FUZZ2(vandn_v);
}
3 changes: 3 additions & 0 deletions code/vandn_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.dword[i] = b.dword[i] & (~a.dword[i]);
}
8 changes: 0 additions & 8 deletions code/vbitsel_v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,5 @@ v128 vbitsel_v(v128 a, v128 b, v128 c) {
}

void test() {
__m128i a = {0x123456789ABCDEF0, 0x0FEDCBA987654321};
__m128i b = {0x1122334455667788, 0x1212343456567878};
__m128i c = {0x0FF0FFFF00000000, 0x0102040810204080};
PRINT(a);
PRINT(b);
PRINT(c);
PRINT(__lsx_vbitsel_v(a, b, c));

FUZZ3(vbitsel_v);
}
42 changes: 0 additions & 42 deletions code/vshuf_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,5 @@ v128 vshuf_b(v128 a, v128 b, v128 c) {
}

void test() {
__m128i a = {0x123456789ABCDEF0, 0x0FEDCBA987654321};
__m128i b = {0x1122334455667788, 0x1212343456567878};
__m128i c = {0x0001020304050607, 0x0001020304050607};
PRINT(a);
PRINT(b);
PRINT(c);
PRINT(__lsx_vshuf_b(a, b, c));

c = __m128i{0x08090A0B0C0D0E0F, 0x08090A0B0C0D0E0F};
PRINT(c);
PRINT(__lsx_vshuf_b(a, b, c));

c = __m128i{0x1011121314151617, 0x1011121314151617};
PRINT(c);
PRINT(__lsx_vshuf_b(a, b, c));

c = __m128i{0x18191A1B1C1D1E1F, 0x18191A1B1C1D1E1F};
PRINT(c);
PRINT(__lsx_vshuf_b(a, b, c));

c = __m128i{0x2021FFFFFFFFFFFF, 0x2223FFFFFFFFFFFF};
PRINT(c);
PRINT(__lsx_vshuf_b(a, b, c));

c = __m128i{0x0706050403020100, 0x1F1E1D1C1B1A1918};
PRINT(c);
PRINT(__lsx_vshuf_b(a, b, c));

c = __m128i{0x20406080A0C0E0FF, 0x1030507090B0D0F0};
PRINT(c);
PRINT(__lsx_vshuf_b(a, b, c));

a = __m128i{0x1716151413121110, 0x1F1E1D1C1B1A1918};
b = __m128i{0x0706050403020100, 0x0F0E0D0C0B0A0908};

for (int i = 0; i < 64; i++) {
c = __m128i{i, 0};
PRINT(c);
PRINT(__lsx_vshuf_b(a, b, c));
PRINT(vshuf_b(a, b, c));
}

FUZZ3(vshuf_b);
}
37 changes: 0 additions & 37 deletions code/vshuf_h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,5 @@ v128 vshuf_h(v128 a, v128 b, v128 c) {
}

void test() {
__m128i b = {0x123456789ABCDEF0, 0x0FEDCBA987654321};
__m128i c = {0x1122334455667788, 0x1212343456567878};
__m128i a = {0x0001020304050607, 0x0001020304050607};
PRINT(a);
PRINT(b);
PRINT(c);
PRINT(__lsx_vshuf_h(a, b, c));

a = __m128i{0x08090A0B0C0D0E0F, 0x08090A0B0C0D0E0F};
PRINT(a);
PRINT(__lsx_vshuf_h(a, b, c));

a = __m128i{0x1011121314151617, 0x1011121314151617};
PRINT(a);
PRINT(__lsx_vshuf_h(a, b, c));

a = __m128i{0x18191A1B1C1D1E1F, 0x18191A1B1C1D1E1F};
PRINT(a);
PRINT(__lsx_vshuf_h(a, b, c));

a = __m128i{0x2021FFFFFFFFFFFF, 0x2223FFFFFFFFFFFF};
PRINT(a);
PRINT(__lsx_vshuf_h(a, b, c));

a = __m128i{0x0706050403020100, 0x1F1E1D1C1B1A1918};
PRINT(a);
PRINT(__lsx_vshuf_h(a, b, c));

b = __m128i{0x000B000A00090008, 0x000F000E000D000C};
c = __m128i{0x0003000200010000, 0x0007000600050004};

for (int i = 0; i < 64; i++) {
a = __m128i{i, 0};
PRINT(a);
PRINT(__lsx_vshuf_h(a, b, c));
}

FUZZ3(vshuf_h);
}
37 changes: 0 additions & 37 deletions code/vshuf_w.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,5 @@ v128 vshuf_w(v128 a, v128 b, v128 c) {
}

void test() {
__m128i b = {0x123456789ABCDEF0, 0x0FEDCBA987654321};
__m128i c = {0x1122334455667788, 0x1212343456567878};
__m128i a = {0x0001020304050607, 0x0001020304050607};
PRINT(a);
PRINT(b);
PRINT(c);
PRINT(__lsx_vshuf_w(a, b, c));

a = __m128i{0x08090A0B0C0D0E0F, 0x08090A0B0C0D0E0F};
PRINT(a);
PRINT(__lsx_vshuf_w(a, b, c));

a = __m128i{0x1011121314151617, 0x1011121314151617};
PRINT(a);
PRINT(__lsx_vshuf_w(a, b, c));

a = __m128i{0x18191A1B1C1D1E1F, 0x18191A1B1C1D1E1F};
PRINT(a);
PRINT(__lsx_vshuf_w(a, b, c));

a = __m128i{0x2021FFFFFFFFFFFF, 0x2223FFFFFFFFFFFF};
PRINT(a);
PRINT(__lsx_vshuf_w(a, b, c));

a = __m128i{0x0706050403020100, 0x1F1E1D1C1B1A1918};
PRINT(a);
PRINT(__lsx_vshuf_w(a, b, c));

b = __m128i{0x0000000500000004, 0x0000000700000006};
c = __m128i{0x0000000100000000, 0x0000000300000002};

for (int i = 0; i < 64; i++) {
a = __m128i{i, 0};
PRINT(a);
PRINT(__lsx_vshuf_w(a, b, c));
}

FUZZ3(vshuf_w);
}
64 changes: 64 additions & 0 deletions docs/lsx_bitops/vlogic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Bitwise Logical

## __m128i __lsx_vandi_b (__m128i a, imm0_255 imm)

### Synopsis

```c++
__m128i __lsx_vandi_b (__m128i a, imm0_255 imm)
#include <lsxintrin.h>
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 <lsxintrin.h>
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 <lsxintrin.h>
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' %}
```

0 comments on commit b576aeb

Please sign in to comment.