[PATCH v3 4/4] tests/tcg/s390x: Test CONVERT TO BINARY

Ilya Leoshkevich posted 4 patches 9 months, 4 weeks ago
Maintainers: Thomas Huth <thuth@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>
There is a newer version of this series
[PATCH v3 4/4] tests/tcg/s390x: Test CONVERT TO BINARY
Posted by Ilya Leoshkevich 9 months, 4 weeks ago
Check the CVB's and CVBG's corner cases.

Co-developed-by: Pavel Zbitskiy <pavel.zbitskiy@gmail.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/cvb.c           | 47 +++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 tests/tcg/s390x/cvb.c

diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 04e4bddd83d..e2aba2ec274 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -46,6 +46,7 @@ TESTS+=laalg
 TESTS+=add-logical-with-carry
 TESTS+=lae
 TESTS+=cvd
+TESTS+=cvb
 
 cdsg: CFLAGS+=-pthread
 cdsg: LDFLAGS+=-pthread
diff --git a/tests/tcg/s390x/cvb.c b/tests/tcg/s390x/cvb.c
new file mode 100644
index 00000000000..47b7a7965f4
--- /dev/null
+++ b/tests/tcg/s390x/cvb.c
@@ -0,0 +1,47 @@
+/*
+ * Test the CONVERT TO DECIMAL instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+static int32_t cvb(uint64_t x)
+{
+    uint32_t ret;
+
+    asm("cvb %[ret],%[x]" : [ret] "=r" (ret) : [x] "R" (x));
+
+    return ret;
+}
+
+static int64_t cvbg(__uint128_t x)
+{
+    int64_t ret;
+
+    asm("cvbg %[ret],%[x]" : [ret] "=r" (ret) : [x] "T" (x));
+
+    return ret;
+}
+
+int main(void)
+{
+    __uint128_t m = (((__uint128_t)0x9223372036854775) << 16) | 0x8070;
+
+    assert(cvb(0xc) == 0);
+    assert(cvb(0x1c) == 1);
+    assert(cvb(0x25594c) == 25594);
+    assert(cvb(0x1d) == -1);
+    assert(cvb(0x2147483647c) == 0x7fffffff);
+    assert(cvb(0x2147483647d) == -0x7fffffff);
+
+    assert(cvbg(0xc) == 0);
+    assert(cvbg(0x1c) == 1);
+    assert(cvbg(0x25594c) == 25594);
+    assert(cvbg(0x1d) == -1);
+    assert(cvbg(m | 0xc) == 0x7fffffffffffffff);
+    assert(cvbg(m | 0xd) == -0x7fffffffffffffff);
+
+    return EXIT_SUCCESS;
+}
-- 
2.43.0
Re: [PATCH v3 4/4] tests/tcg/s390x: Test CONVERT TO BINARY
Posted by Thomas Huth 9 months, 4 weeks ago
On 01/02/2024 00.07, Ilya Leoshkevich wrote:
> Check the CVB's and CVBG's corner cases.
> 
> Co-developed-by: Pavel Zbitskiy <pavel.zbitskiy@gmail.com>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>   tests/tcg/s390x/Makefile.target |  1 +
>   tests/tcg/s390x/cvb.c           | 47 +++++++++++++++++++++++++++++++++
>   2 files changed, 48 insertions(+)
>   create mode 100644 tests/tcg/s390x/cvb.c
> 
> diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
> index 04e4bddd83d..e2aba2ec274 100644
> --- a/tests/tcg/s390x/Makefile.target
> +++ b/tests/tcg/s390x/Makefile.target
> @@ -46,6 +46,7 @@ TESTS+=laalg
>   TESTS+=add-logical-with-carry
>   TESTS+=lae
>   TESTS+=cvd
> +TESTS+=cvb
>   
>   cdsg: CFLAGS+=-pthread
>   cdsg: LDFLAGS+=-pthread
> diff --git a/tests/tcg/s390x/cvb.c b/tests/tcg/s390x/cvb.c
> new file mode 100644
> index 00000000000..47b7a7965f4
> --- /dev/null
> +++ b/tests/tcg/s390x/cvb.c
> @@ -0,0 +1,47 @@
> +/*
> + * Test the CONVERT TO DECIMAL instruction.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +#include <assert.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +
> +static int32_t cvb(uint64_t x)
> +{
> +    uint32_t ret;
> +
> +    asm("cvb %[ret],%[x]" : [ret] "=r" (ret) : [x] "R" (x));
> +
> +    return ret;
> +}
> +
> +static int64_t cvbg(__uint128_t x)
> +{
> +    int64_t ret;
> +
> +    asm("cvbg %[ret],%[x]" : [ret] "=r" (ret) : [x] "T" (x));
> +
> +    return ret;
> +}

Just to be on the safe side, could you please add a check for CVBY, too?

  Thanks,
   Thomas
Re: [PATCH v3 4/4] tests/tcg/s390x: Test CONVERT TO BINARY
Posted by Thomas Huth 9 months, 4 weeks ago
On 01/02/2024 00.07, Ilya Leoshkevich wrote:
> Check the CVB's and CVBG's corner cases.
> 
> Co-developed-by: Pavel Zbitskiy <pavel.zbitskiy@gmail.com>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>   tests/tcg/s390x/Makefile.target |  1 +
>   tests/tcg/s390x/cvb.c           | 47 +++++++++++++++++++++++++++++++++
>   2 files changed, 48 insertions(+)
>   create mode 100644 tests/tcg/s390x/cvb.c
> 
> diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
> index 04e4bddd83d..e2aba2ec274 100644
> --- a/tests/tcg/s390x/Makefile.target
> +++ b/tests/tcg/s390x/Makefile.target
> @@ -46,6 +46,7 @@ TESTS+=laalg
>   TESTS+=add-logical-with-carry
>   TESTS+=lae
>   TESTS+=cvd
> +TESTS+=cvb
>   
>   cdsg: CFLAGS+=-pthread
>   cdsg: LDFLAGS+=-pthread
> diff --git a/tests/tcg/s390x/cvb.c b/tests/tcg/s390x/cvb.c
> new file mode 100644
> index 00000000000..47b7a7965f4
> --- /dev/null
> +++ b/tests/tcg/s390x/cvb.c
> @@ -0,0 +1,47 @@
> +/*
> + * Test the CONVERT TO DECIMAL instruction.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +#include <assert.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +
> +static int32_t cvb(uint64_t x)
> +{
> +    uint32_t ret;
> +
> +    asm("cvb %[ret],%[x]" : [ret] "=r" (ret) : [x] "R" (x));
> +
> +    return ret;
> +}
> +
> +static int64_t cvbg(__uint128_t x)
> +{
> +    int64_t ret;
> +
> +    asm("cvbg %[ret],%[x]" : [ret] "=r" (ret) : [x] "T" (x));
> +
> +    return ret;
> +}
> +
> +int main(void)
> +{
> +    __uint128_t m = (((__uint128_t)0x9223372036854775) << 16) | 0x8070;
> +
> +    assert(cvb(0xc) == 0);
> +    assert(cvb(0x1c) == 1);
> +    assert(cvb(0x25594c) == 25594);
> +    assert(cvb(0x1d) == -1);
> +    assert(cvb(0x2147483647c) == 0x7fffffff);
> +    assert(cvb(0x2147483647d) == -0x7fffffff);
> +
> +    assert(cvbg(0xc) == 0);
> +    assert(cvbg(0x1c) == 1);
> +    assert(cvbg(0x25594c) == 25594);
> +    assert(cvbg(0x1d) == -1);
> +    assert(cvbg(m | 0xc) == 0x7fffffffffffffff);
> +    assert(cvbg(m | 0xd) == -0x7fffffffffffffff);
> +
> +    return EXIT_SUCCESS;
> +}

Reviewed-by: Thomas Huth <thuth@redhat.com>