Skip to content

Commit

Permalink
Fix vftint_w_d code, reported by Yang Liu
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 26, 2024
1 parent d7b542f commit 1df495b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
11 changes: 6 additions & 5 deletions code/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ union v256 {
void test();

void print(const char *s, v128 num) {
printf("v128 as __m128i %s: 0x%016lx 0x%016lx\n", s, num.dword[0], num.dword[1]);
printf("v128 as __m128i %s: 0x%016lx 0x%016lx\n", s, num.dword[0],
num.dword[1]);
printf("v128 as __m128 %s: %f %f %f %f\n", s, num.fp32[0], num.fp32[1],
num.fp32[2], num.fp32[3]);
printf("v128 as __m128d %s: %lf %lf\n", s, num.fp64[0], num.fp64[1]);
Expand All @@ -204,8 +205,8 @@ void print(const char *s, __m128d num) {
}

void print(const char *s, v256 num) {
printf("v256 as __m256i %s: 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n", s, num.dword[0],
num.dword[1], num.dword[2], num.dword[3]);
printf("v256 as __m256i %s: 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n", s,
num.dword[0], num.dword[1], num.dword[2], num.dword[3]);
printf("v256 as __m256 %s: %f %f %f %f %f %f %f %f\n", s, num.fp32[0],
num.fp32[1], num.fp32[2], num.fp32[3], num.fp32[4], num.fp32[5],
num.fp32[6], num.fp32[7]);
Expand All @@ -214,8 +215,8 @@ void print(const char *s, v256 num) {
}

void print(const char *s, __m256i num) {
printf("__m256i %s: 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n", s, num[0], num[1],
num[2], num[3]);
printf("__m256i %s: 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n", s, num[0],
num[1], num[2], num[3]);
}

void print(const char *s, __m256 num) {
Expand Down
19 changes: 19 additions & 0 deletions code/vftint_w_d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "common.h"

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

void test() {
{
__m128d a = {1.0, 2.0};
__m128d b = {3.0, 4.0};
PRINT(a);
PRINT(b);
PRINT(__lsx_vftint_w_d(a, b));
PRINT(vftint_w_d(a, b));
assert(vftint_w_d(a, b) == __lsx_vftint_w_d(a, b));
}
}
8 changes: 4 additions & 4 deletions code/vftint_w_d.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
for (int i = 0; i < 2; i++) {
dst.dword[i] = (i < 1)
? (s64)a.fp64[i]
: (s64)b.fp64[i]; // rounding mode is not expressed in C
for (int i = 0; i < 4; i++) {
dst.word[i] = (i < 2)
? (s64)b.fp64[i]
: (s64)a.fp64[i - 2]; // rounding mode is not expressed in C
}
6 changes: 4 additions & 2 deletions code/xvsetanyeqz_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ void test() {
assert(__lasx_xbz_b(a));
assert(__lasx_xbz_b(a) == xbz_b(a));

a = __m256i{0x1111111111111111, 0x1111111111111111, 0x1111111111111111, 0x1111111111111111};
a = __m256i{0x1111111111111111, 0x1111111111111111, 0x1111111111111111,
0x1111111111111111};
assert(!__lasx_xbz_b(a));
assert(__lasx_xbz_b(a) == xbz_b(a));

a = __m256i{0x1111111111111100, 0x1111111111111111, 0x1111111111111111, 0x1111111111111111};
a = __m256i{0x1111111111111100, 0x1111111111111111, 0x1111111111111111,
0x1111111111111111};
assert(__lasx_xbz_b(a));
assert(__lasx_xbz_b(a) == xbz_b(a));
}
6 changes: 4 additions & 2 deletions code/xvsetanyeqz_d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ void test() {
assert(__lasx_xbz_d(a));
assert(__lasx_xbz_d(a) == xbz_d(a));

a = __m256i{0x1111111111111111, 0x1111111111111111, 0x1111111111111111, 0x1111111111111111};
a = __m256i{0x1111111111111111, 0x1111111111111111, 0x1111111111111111,
0x1111111111111111};
assert(!__lasx_xbz_d(a));
assert(__lasx_xbz_d(a) == xbz_d(a));

a = __m256i{0x0000000000000000, 0x1111111111111111, 0x1111111111111111, 0x1111111111111111};
a = __m256i{0x0000000000000000, 0x1111111111111111, 0x1111111111111111,
0x1111111111111111};
assert(__lasx_xbz_d(a));
assert(__lasx_xbz_d(a) == xbz_d(a));
}
6 changes: 4 additions & 2 deletions code/xvsetanyeqz_h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ void test() {
assert(__lasx_xbz_h(a));
assert(__lasx_xbz_h(a) == xbz_h(a));

a = __m256i{0x1111111111111111, 0x1111111111111111, 0x1111111111111111, 0x1111111111111111};
a = __m256i{0x1111111111111111, 0x1111111111111111, 0x1111111111111111,
0x1111111111111111};
assert(!__lasx_xbz_h(a));
assert(__lasx_xbz_h(a) == xbz_h(a));

a = __m256i{0x1111111111110000, 0x1111111111111111, 0x1111111111111111, 0x1111111111111111};
a = __m256i{0x1111111111110000, 0x1111111111111111, 0x1111111111111111,
0x1111111111111111};
assert(__lasx_xbz_h(a));
assert(__lasx_xbz_h(a) == xbz_h(a));
}
6 changes: 4 additions & 2 deletions code/xvsetanyeqz_w.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ void test() {
assert(__lasx_xbz_w(a));
assert(__lasx_xbz_w(a) == xbz_w(a));

a = __m256i{0x1111111111111111, 0x1111111111111111, 0x1111111111111111, 0x1111111111111111};
a = __m256i{0x1111111111111111, 0x1111111111111111, 0x1111111111111111,
0x1111111111111111};
assert(!__lasx_xbz_w(a));
assert(__lasx_xbz_w(a) == xbz_w(a));

a = __m256i{0x1111111100000000, 0x1111111111111111, 0x1111111111111111, 0x1111111111111111};
a = __m256i{0x1111111100000000, 0x1111111111111111, 0x1111111111111111,
0x1111111111111111};
assert(__lasx_xbz_w(a));
assert(__lasx_xbz_w(a) == xbz_w(a));
}

0 comments on commit 1df495b

Please sign in to comment.