xref: /qemu/tests/tcg/s390x/rxsbg.c (revision 4c6f44644d08f6f712474288d61deba601421988)
1*04fce706SIlya Leoshkevich /*
2*04fce706SIlya Leoshkevich  * Test the RXSBG instruction.
3*04fce706SIlya Leoshkevich  *
4*04fce706SIlya Leoshkevich  * SPDX-License-Identifier: GPL-2.0-or-later
5*04fce706SIlya Leoshkevich  */
6*04fce706SIlya Leoshkevich #include <assert.h>
7*04fce706SIlya Leoshkevich #include <stdlib.h>
8*04fce706SIlya Leoshkevich 
9*04fce706SIlya Leoshkevich static inline __attribute__((__always_inline__)) void
rxsbg(unsigned long * r1,unsigned long r2,int i3,int i4,int i5,int * cc)10*04fce706SIlya Leoshkevich rxsbg(unsigned long *r1, unsigned long r2, int i3, int i4, int i5, int *cc)
11*04fce706SIlya Leoshkevich {
12*04fce706SIlya Leoshkevich     asm("rxsbg %[r1],%[r2],%[i3],%[i4],%[i5]\n"
13*04fce706SIlya Leoshkevich         "ipm %[cc]"
14*04fce706SIlya Leoshkevich         : [r1] "+r" (*r1), [cc] "=r" (*cc)
15*04fce706SIlya Leoshkevich         : [r2] "r" (r2) , [i3] "i" (i3) , [i4] "i" (i4) , [i5] "i" (i5)
16*04fce706SIlya Leoshkevich         : "cc");
17*04fce706SIlya Leoshkevich     *cc = (*cc >> 28) & 3;
18*04fce706SIlya Leoshkevich }
19*04fce706SIlya Leoshkevich 
test_cc0(void)20*04fce706SIlya Leoshkevich void test_cc0(void)
21*04fce706SIlya Leoshkevich {
22*04fce706SIlya Leoshkevich     unsigned long r1 = 6;
23*04fce706SIlya Leoshkevich     int cc;
24*04fce706SIlya Leoshkevich 
25*04fce706SIlya Leoshkevich     rxsbg(&r1, 3, 61 | 0x80, 62, 1, &cc);
26*04fce706SIlya Leoshkevich     assert(r1 == 6);
27*04fce706SIlya Leoshkevich     assert(cc == 0);
28*04fce706SIlya Leoshkevich }
29*04fce706SIlya Leoshkevich 
test_cc1(void)30*04fce706SIlya Leoshkevich void test_cc1(void)
31*04fce706SIlya Leoshkevich {
32*04fce706SIlya Leoshkevich     unsigned long r1 = 2;
33*04fce706SIlya Leoshkevich     int cc;
34*04fce706SIlya Leoshkevich 
35*04fce706SIlya Leoshkevich     rxsbg(&r1, 3, 61 | 0x80, 62, 1, &cc);
36*04fce706SIlya Leoshkevich     assert(r1 == 2);
37*04fce706SIlya Leoshkevich     assert(cc == 1);
38*04fce706SIlya Leoshkevich }
39*04fce706SIlya Leoshkevich 
main(void)40*04fce706SIlya Leoshkevich int main(void)
41*04fce706SIlya Leoshkevich {
42*04fce706SIlya Leoshkevich     test_cc0();
43*04fce706SIlya Leoshkevich     test_cc1();
44*04fce706SIlya Leoshkevich 
45*04fce706SIlya Leoshkevich     return EXIT_SUCCESS;
46*04fce706SIlya Leoshkevich }
47