aboutsummaryrefslogtreecommitdiff
path: root/test/ui/v1/stack/ui.c
blob: 1ad047e6430fe359414b0da98b87b6a97520ebca (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
#if !defined(COMMAND_NEW)
#error
#endif

int main(void) {
    salis_init();

    while (mvec_is_proc_owner(g_cores, g_cores->pvec->ip, g_cores->pcur)) {
        uint8_t inst = mvec_get_inst(g_cores, g_cores->pvec->ip);

        if (inst != pshn && inst != popn) {
            salis_step(1);
            continue;
        }

        uint64_t *reg = &g_cores->pvec->r0x;

        switch (mvec_get_inst(g_cores, g_cores->pvec->ip + 1)) {
        case nop0:
            reg = &g_cores->pvec->r0x;
            break;
        case nop1:
            reg = &g_cores->pvec->r1x;
            break;
        case nop2:
            reg = &g_cores->pvec->r2x;
            break;
        case nop3:
            reg = &g_cores->pvec->r3x;
            break;
        }

        uint64_t reg_val = *reg;
        uint64_t stack_val[8] = {
            g_cores->pvec->s0,
            g_cores->pvec->s1,
            g_cores->pvec->s2,
            g_cores->pvec->s3,
            g_cores->pvec->s4,
            g_cores->pvec->s5,
            g_cores->pvec->s6,
            g_cores->pvec->s7,
        };

        salis_step(1);

        switch (inst) {
        case pshn:
            assert(*reg == reg_val);
            assert(g_cores->pvec->s0 == *reg);
            assert(g_cores->pvec->s1 == stack_val[0]);
            assert(g_cores->pvec->s2 == stack_val[1]);
            assert(g_cores->pvec->s3 == stack_val[2]);
            assert(g_cores->pvec->s4 == stack_val[3]);
            assert(g_cores->pvec->s5 == stack_val[4]);
            assert(g_cores->pvec->s6 == stack_val[5]);
            assert(g_cores->pvec->s7 == stack_val[6]);
            break;
        case popn:
            assert(*reg == stack_val[0]);
            assert(g_cores->pvec->s0 == stack_val[1]);
            assert(g_cores->pvec->s1 == stack_val[2]);
            assert(g_cores->pvec->s2 == stack_val[3]);
            assert(g_cores->pvec->s3 == stack_val[4]);
            assert(g_cores->pvec->s4 == stack_val[5]);
            assert(g_cores->pvec->s5 == stack_val[6]);
            assert(g_cores->pvec->s6 == stack_val[7]);
            assert(g_cores->pvec->s7 == 0);
            break;
        }
    }

    salis_free();
    return 0;
}