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