xref: /qemu/tests/tcg/s390x/lcbb.c (revision f8ed3648)
1 /*
2  * Test the LCBB instruction.
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  */
6 #include <assert.h>
7 #include <stdlib.h>
8 
9 static inline __attribute__((__always_inline__)) void
10 lcbb(long *r1, void *dxb2, int m3, int *cc)
11 {
12     asm("lcbb %[r1],%[dxb2],%[m3]\n"
13         "ipm %[cc]"
14         : [r1] "+r" (*r1), [cc] "=r" (*cc)
15         : [dxb2] "R" (*(char *)dxb2), [m3] "i" (m3)
16         : "cc");
17     *cc = (*cc >> 28) & 3;
18 }
19 
20 static char buf[0x1000] __attribute__((aligned(0x1000)));
21 
22 static inline __attribute__((__always_inline__)) void
23 test_lcbb(void *p, int m3, int exp_r1, int exp_cc)
24 {
25     long r1 = 0xfedcba9876543210;
26     int cc;
27 
28     lcbb(&r1, p, m3, &cc);
29     assert(r1 == (0xfedcba9800000000 | exp_r1));
30     assert(cc == exp_cc);
31 }
32 
33 int main(void)
34 {
35     test_lcbb(&buf[0],    0, 16, 0);
36     test_lcbb(&buf[63],   0,  1, 3);
37     test_lcbb(&buf[0],    1, 16, 0);
38     test_lcbb(&buf[127],  1,  1, 3);
39     test_lcbb(&buf[0],    2, 16, 0);
40     test_lcbb(&buf[255],  2,  1, 3);
41     test_lcbb(&buf[0],    3, 16, 0);
42     test_lcbb(&buf[511],  3,  1, 3);
43     test_lcbb(&buf[0],    4, 16, 0);
44     test_lcbb(&buf[1023], 4,  1, 3);
45     test_lcbb(&buf[0],    5, 16, 0);
46     test_lcbb(&buf[2047], 5,  1, 3);
47     test_lcbb(&buf[0],    6, 16, 0);
48     test_lcbb(&buf[4095], 6,  1, 3);
49 
50     return EXIT_SUCCESS;
51 }
52