File: lcbb.c

package info (click to toggle)
qemu 1%3A7.2%2Bdfsg-7%2Bdeb12u13
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 288,192 kB
  • sloc: ansic: 2,701,923; pascal: 112,708; python: 62,697; sh: 50,281; asm: 48,732; makefile: 17,260; cpp: 9,441; perl: 8,084; xml: 2,911; objc: 1,870; php: 1,299; tcl: 1,188; yacc: 604; lex: 363; sql: 71; awk: 35; sed: 11; javascript: 7
file content (51 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Test the LCBB instruction.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */
#include <assert.h>
#include <stdlib.h>

static inline __attribute__((__always_inline__)) void
lcbb(long *r1, void *dxb2, int m3, int *cc)
{
    asm("lcbb %[r1],%[dxb2],%[m3]\n"
        "ipm %[cc]"
        : [r1] "+r" (*r1), [cc] "=r" (*cc)
        : [dxb2] "R" (*(char *)dxb2), [m3] "i" (m3)
        : "cc");
    *cc = (*cc >> 28) & 3;
}

static char buf[0x1000] __attribute__((aligned(0x1000)));

static inline __attribute__((__always_inline__)) void
test_lcbb(void *p, int m3, int exp_r1, int exp_cc)
{
    long r1 = 0xfedcba9876543210;
    int cc;

    lcbb(&r1, p, m3, &cc);
    assert(r1 == (0xfedcba9800000000 | exp_r1));
    assert(cc == exp_cc);
}

int main(void)
{
    test_lcbb(&buf[0],    0, 16, 0);
    test_lcbb(&buf[63],   0,  1, 3);
    test_lcbb(&buf[0],    1, 16, 0);
    test_lcbb(&buf[127],  1,  1, 3);
    test_lcbb(&buf[0],    2, 16, 0);
    test_lcbb(&buf[255],  2,  1, 3);
    test_lcbb(&buf[0],    3, 16, 0);
    test_lcbb(&buf[511],  3,  1, 3);
    test_lcbb(&buf[0],    4, 16, 0);
    test_lcbb(&buf[1023], 4,  1, 3);
    test_lcbb(&buf[0],    5, 16, 0);
    test_lcbb(&buf[2047], 5,  1, 3);
    test_lcbb(&buf[0],    6, 16, 0);
    test_lcbb(&buf[4095], 6,  1, 3);

    return EXIT_SUCCESS;
}