From cf977208a524a054026f503b7f9d249a36226562 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Thu, 26 Dec 2024 15:46:00 +0800 Subject: [PATCH] Fix vftint_w_d variant's code, reported by Yang Liu --- code/vftintrm_w_d.cpp | 19 +++++++++++++++++++ code/vftintrm_w_d.h | 8 ++++---- code/vftintrne_w_d.cpp | 19 +++++++++++++++++++ code/vftintrne_w_d.h | 8 ++++---- code/vftintrp_w_d.cpp | 19 +++++++++++++++++++ code/vftintrp_w_d.h | 8 ++++---- code/vftintrz_w_d.cpp | 19 +++++++++++++++++++ code/vftintrz_w_d.h | 8 ++++---- code/xvftintrm_w_d.cpp | 19 +++++++++++++++++++ code/xvftintrm_w_d.h | 11 ++++++++--- code/xvftintrne_w_d.cpp | 19 +++++++++++++++++++ code/xvftintrne_w_d.h | 11 ++++++++--- code/xvftintrp_w_d.cpp | 19 +++++++++++++++++++ code/xvftintrp_w_d.h | 11 ++++++++--- code/xvftintrz_w_d.cpp | 19 +++++++++++++++++++ code/xvftintrz_w_d.h | 11 ++++++++--- 16 files changed, 200 insertions(+), 28 deletions(-) create mode 100644 code/vftintrm_w_d.cpp create mode 100644 code/vftintrne_w_d.cpp create mode 100644 code/vftintrp_w_d.cpp create mode 100644 code/vftintrz_w_d.cpp create mode 100644 code/xvftintrm_w_d.cpp create mode 100644 code/xvftintrne_w_d.cpp create mode 100644 code/xvftintrp_w_d.cpp create mode 100644 code/xvftintrz_w_d.cpp diff --git a/code/vftintrm_w_d.cpp b/code/vftintrm_w_d.cpp new file mode 100644 index 00000000..4b34472f --- /dev/null +++ b/code/vftintrm_w_d.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +v128 vftintrm_w_d(v128 a, v128 b) { + v128 dst; +#include "vftintrm_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_vftintrm_w_d(a, b)); + PRINT(vftintrm_w_d(a, b)); + assert(vftintrm_w_d(a, b) == __lsx_vftintrm_w_d(a, b)); + } +} diff --git a/code/vftintrm_w_d.h b/code/vftintrm_w_d.h index 6874cf44..20bbde7a 100644 --- a/code/vftintrm_w_d.h +++ b/code/vftintrm_w_d.h @@ -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 } diff --git a/code/vftintrne_w_d.cpp b/code/vftintrne_w_d.cpp new file mode 100644 index 00000000..f1ba0008 --- /dev/null +++ b/code/vftintrne_w_d.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +v128 vftintrne_w_d(v128 a, v128 b) { + v128 dst; +#include "vftintrne_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_vftintrne_w_d(a, b)); + PRINT(vftintrne_w_d(a, b)); + assert(vftintrne_w_d(a, b) == __lsx_vftintrne_w_d(a, b)); + } +} diff --git a/code/vftintrne_w_d.h b/code/vftintrne_w_d.h index 6874cf44..20bbde7a 100644 --- a/code/vftintrne_w_d.h +++ b/code/vftintrne_w_d.h @@ -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 } diff --git a/code/vftintrp_w_d.cpp b/code/vftintrp_w_d.cpp new file mode 100644 index 00000000..688a36a6 --- /dev/null +++ b/code/vftintrp_w_d.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +v128 vftintrp_w_d(v128 a, v128 b) { + v128 dst; +#include "vftintrp_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_vftintrp_w_d(a, b)); + PRINT(vftintrp_w_d(a, b)); + assert(vftintrp_w_d(a, b) == __lsx_vftintrp_w_d(a, b)); + } +} diff --git a/code/vftintrp_w_d.h b/code/vftintrp_w_d.h index 6874cf44..20bbde7a 100644 --- a/code/vftintrp_w_d.h +++ b/code/vftintrp_w_d.h @@ -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 } diff --git a/code/vftintrz_w_d.cpp b/code/vftintrz_w_d.cpp new file mode 100644 index 00000000..a8a64f19 --- /dev/null +++ b/code/vftintrz_w_d.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +v128 vftintrz_w_d(v128 a, v128 b) { + v128 dst; +#include "vftintrz_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_vftintrz_w_d(a, b)); + PRINT(vftintrz_w_d(a, b)); + assert(vftintrz_w_d(a, b) == __lsx_vftintrz_w_d(a, b)); + } +} diff --git a/code/vftintrz_w_d.h b/code/vftintrz_w_d.h index 6874cf44..20bbde7a 100644 --- a/code/vftintrz_w_d.h +++ b/code/vftintrz_w_d.h @@ -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 } diff --git a/code/xvftintrm_w_d.cpp b/code/xvftintrm_w_d.cpp new file mode 100644 index 00000000..29a0ea1a --- /dev/null +++ b/code/xvftintrm_w_d.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +v256 xvftintrm_w_d(v256 a, v256 b) { + v256 dst; +#include "xvftintrm_w_d.h" + return dst; +} + +void test() { + { + __m256d a = {1.0, 2.0, 3.0, 4.0}; + __m256d b = {5.0, 6.0, 7.0, 8.0}; + PRINT(a); + PRINT(b); + PRINT(__lasx_xvftintrm_w_d(a, b)); + PRINT(xvftintrm_w_d(a, b)); + assert(xvftintrm_w_d(a, b) == __lasx_xvftintrm_w_d(a, b)); + } +} diff --git a/code/xvftintrm_w_d.h b/code/xvftintrm_w_d.h index 033e5491..1e2eab1a 100644 --- a/code/xvftintrm_w_d.h +++ b/code/xvftintrm_w_d.h @@ -1,5 +1,10 @@ for (int i = 0; i < 4; i++) { - dst.dword[i] = (i < 2) - ? (s64)a.fp64[i] - : (s64)b.fp64[i]; // rounding mode is not expressed in C + dst.word[i] = (i < 2) + ? (s64)b.fp64[i] + : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C +} +for (int i = 4; i < 8; i++) { + dst.word[i] = (i < 6) + ? (s64)b.fp64[i - 2] + : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C } diff --git a/code/xvftintrne_w_d.cpp b/code/xvftintrne_w_d.cpp new file mode 100644 index 00000000..2a4400e4 --- /dev/null +++ b/code/xvftintrne_w_d.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +v256 xvftintrne_w_d(v256 a, v256 b) { + v256 dst; +#include "xvftintrne_w_d.h" + return dst; +} + +void test() { + { + __m256d a = {1.0, 2.0, 3.0, 4.0}; + __m256d b = {5.0, 6.0, 7.0, 8.0}; + PRINT(a); + PRINT(b); + PRINT(__lasx_xvftintrne_w_d(a, b)); + PRINT(xvftintrne_w_d(a, b)); + assert(xvftintrne_w_d(a, b) == __lasx_xvftintrne_w_d(a, b)); + } +} diff --git a/code/xvftintrne_w_d.h b/code/xvftintrne_w_d.h index 033e5491..1e2eab1a 100644 --- a/code/xvftintrne_w_d.h +++ b/code/xvftintrne_w_d.h @@ -1,5 +1,10 @@ for (int i = 0; i < 4; i++) { - dst.dword[i] = (i < 2) - ? (s64)a.fp64[i] - : (s64)b.fp64[i]; // rounding mode is not expressed in C + dst.word[i] = (i < 2) + ? (s64)b.fp64[i] + : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C +} +for (int i = 4; i < 8; i++) { + dst.word[i] = (i < 6) + ? (s64)b.fp64[i - 2] + : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C } diff --git a/code/xvftintrp_w_d.cpp b/code/xvftintrp_w_d.cpp new file mode 100644 index 00000000..3a05f2d3 --- /dev/null +++ b/code/xvftintrp_w_d.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +v256 xvftintrp_w_d(v256 a, v256 b) { + v256 dst; +#include "xvftintrp_w_d.h" + return dst; +} + +void test() { + { + __m256d a = {1.0, 2.0, 3.0, 4.0}; + __m256d b = {5.0, 6.0, 7.0, 8.0}; + PRINT(a); + PRINT(b); + PRINT(__lasx_xvftintrp_w_d(a, b)); + PRINT(xvftintrp_w_d(a, b)); + assert(xvftintrp_w_d(a, b) == __lasx_xvftintrp_w_d(a, b)); + } +} diff --git a/code/xvftintrp_w_d.h b/code/xvftintrp_w_d.h index 033e5491..1e2eab1a 100644 --- a/code/xvftintrp_w_d.h +++ b/code/xvftintrp_w_d.h @@ -1,5 +1,10 @@ for (int i = 0; i < 4; i++) { - dst.dword[i] = (i < 2) - ? (s64)a.fp64[i] - : (s64)b.fp64[i]; // rounding mode is not expressed in C + dst.word[i] = (i < 2) + ? (s64)b.fp64[i] + : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C +} +for (int i = 4; i < 8; i++) { + dst.word[i] = (i < 6) + ? (s64)b.fp64[i - 2] + : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C } diff --git a/code/xvftintrz_w_d.cpp b/code/xvftintrz_w_d.cpp new file mode 100644 index 00000000..14ea771c --- /dev/null +++ b/code/xvftintrz_w_d.cpp @@ -0,0 +1,19 @@ +#include "common.h" + +v256 xvftintrz_w_d(v256 a, v256 b) { + v256 dst; +#include "xvftintrz_w_d.h" + return dst; +} + +void test() { + { + __m256d a = {1.0, 2.0, 3.0, 4.0}; + __m256d b = {5.0, 6.0, 7.0, 8.0}; + PRINT(a); + PRINT(b); + PRINT(__lasx_xvftintrz_w_d(a, b)); + PRINT(xvftintrz_w_d(a, b)); + assert(xvftintrz_w_d(a, b) == __lasx_xvftintrz_w_d(a, b)); + } +} diff --git a/code/xvftintrz_w_d.h b/code/xvftintrz_w_d.h index 033e5491..1e2eab1a 100644 --- a/code/xvftintrz_w_d.h +++ b/code/xvftintrz_w_d.h @@ -1,5 +1,10 @@ for (int i = 0; i < 4; i++) { - dst.dword[i] = (i < 2) - ? (s64)a.fp64[i] - : (s64)b.fp64[i]; // rounding mode is not expressed in C + dst.word[i] = (i < 2) + ? (s64)b.fp64[i] + : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C +} +for (int i = 4; i < 8; i++) { + dst.word[i] = (i < 6) + ? (s64)b.fp64[i - 2] + : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C }