Message ID | 20240131230938.325919-5-iii@linux.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | target/s390x: Emulate CVDG and CVB* | expand |
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>
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
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; +}
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