summaryrefslogtreecommitdiff
path: root/test/ui/v1/2rops/ui.c
blob: e74172bd08d5ec5ab4ee63ba2ba1cc36e29b0c22 (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
// file    : test/ui/v1/2rops/ui.c
// project : Salis-VM
// author  : Paul Oliver <contact@pauloliver.dev>

#include <assert.h>
#include <stdint.h>
#include <threads.h>
#include <zlib.h>

#include "arch_spec.h"
#include "arch_inst.h"
#include "compress.h"
#include "salis.h"

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 != rdup && inst != rswp) {
            salis_step(1);
            continue;
        }

        uint64_t *regs[2] = {
            &g_cores->pvec->r0x,
            &g_cores->pvec->r0x,
        };

        for (uint64_t i = 0; i < 2; i++) {
            uint8_t rmod = mvec_get_inst(g_cores, g_cores->pvec->ip + 1 + i);
            if (rmod == nop0) regs[i] = &g_cores->pvec->r0x;
            else if (rmod == nop1) regs[i] = &g_cores->pvec->r1x;
            else if (rmod == nop2) regs[i] = &g_cores->pvec->r2x;
            else if (rmod == nop3) regs[i] = &g_cores->pvec->r3x;
            else break;
        }

        uint64_t reg_vals[2] = {*regs[0], *regs[1]};
        salis_step(1);

        switch (inst) {
        case rdup:
            assert(*regs[1] == reg_vals[0]);
            break;
        case rswp:
            assert(*regs[0] == reg_vals[1]);
            assert(*regs[1] == reg_vals[0]);
            break;
        }
    }

    salis_save_and_free();
    return 0;
}