aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/hppa/stby.c
blob: 36bd5f723c3d560a7010b9e292d02a46a74e2e68 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Test STBY */

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct S {
    unsigned a;
    unsigned b;
    unsigned c;
};

static void check(const struct S *s, unsigned e,
                  const char *which, const char *insn, int ofs)
{
    int err = 0;

    if (s->a != 0) {
        fprintf(stderr, "%s %s %d: garbage before word 0x%08x\n",
                which, insn, ofs, s->a);
        err = 1;
    }
    if (s->c != 0) {
        fprintf(stderr, "%s %s %d: garbage after word 0x%08x\n",
                which, insn, ofs, s->c);
        err = 1;
    }
    if (s->b != e) {
        fprintf(stderr, "%s %s %d: 0x%08x != 0x%08x\n",
                which, insn, ofs, s->b, e);
        err = 1;
    }

    if (err) {
        exit(1);
    }
}

#define TEST(INSN, OFS, E)                                         \
    do {                                                           \
        s.b = 0;                                                   \
        asm volatile(INSN " %1, " #OFS "(%0)"                      \
                     : : "r"(&s.b), "r" (0x11223344) : "memory");  \
        check(&s, E, which, INSN, OFS);                            \
    } while (0)

static void test(const char *which)
{
    struct S s = { };

    TEST("stby,b", 0, 0x11223344);
    TEST("stby,b", 1, 0x00223344);
    TEST("stby,b", 2, 0x00003344);
    TEST("stby,b", 3, 0x00000044);

    TEST("stby,e", 0, 0x00000000);
    TEST("stby,e", 1, 0x11000000);
    TEST("stby,e", 2, 0x11220000);
    TEST("stby,e", 3, 0x11223300);
}

static void *child(void *x)
{
    return NULL;
}

int main()
{
    int err;
    pthread_t thr;

    /* Run test in serial mode */
    test("serial");

    /* Create a dummy thread to start parallel mode. */
    err = pthread_create(&thr, NULL, child, NULL);
    if (err != 0) {
        fprintf(stderr, "pthread_create: %s\n", strerror(err));
        return 2;
    }

    /* Run test in parallel mode */
    test("parallel");
    return 0;
}