xref: /qemu/tests/tcg/s390x/cvd.c (revision 7653b1ea)
1 /*
2  * Test the CONVERT TO DECIMAL instruction.
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  */
6 #include <assert.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 
10 static uint64_t cvd(int32_t x)
11 {
12     uint64_t ret;
13 
14     asm("cvd %[x],%[ret]" : [ret] "=R" (ret) : [x] "r" (x));
15 
16     return ret;
17 }
18 
19 static uint64_t cvdy(int32_t x)
20 {
21     uint64_t ret;
22 
23     asm("cvdy %[x],%[ret]" : [ret] "=T" (ret) : [x] "r" (x));
24 
25     return ret;
26 }
27 
28 static __uint128_t cvdg(int64_t x)
29 {
30     __uint128_t ret;
31 
32     asm("cvdg %[x],%[ret]" : [ret] "=T" (ret) : [x] "r" (x));
33 
34     return ret;
35 }
36 
37 int main(void)
38 {
39     __uint128_t m = (((__uint128_t)0x9223372036854775) << 16) | 0x8070;
40 
41     assert(cvd(0) == 0xc);
42     assert(cvd(1) == 0x1c);
43     assert(cvd(25594) == 0x25594c);
44     assert(cvd(-1) == 0x1d);
45     assert(cvd(0x7fffffff) == 0x2147483647c);
46     assert(cvd(-0x80000000) == 0x2147483648d);
47 
48     assert(cvdy(0) == 0xc);
49     assert(cvdy(1) == 0x1c);
50     assert(cvdy(25594) == 0x25594c);
51     assert(cvdy(-1) == 0x1d);
52     assert(cvdy(0x7fffffff) == 0x2147483647c);
53     assert(cvdy(-0x80000000) == 0x2147483648d);
54 
55     assert(cvdg(0) == 0xc);
56     assert(cvdg(1) == 0x1c);
57     assert(cvdg(25594) == 0x25594c);
58     assert(cvdg(-1) == 0x1d);
59     assert(cvdg(0x7fffffffffffffff) == (m + 0xc));
60     assert(cvdg(-0x8000000000000000) == (m + 0x1d));
61 
62     return EXIT_SUCCESS;
63 }
64