summaryrefslogtreecommitdiff
path: root/test/ui/v1/ifnzs/ui.c
blob: 0c3921e488f025ba8ca07a35227bef441df407fa (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/ifnzs/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) {
    uint64_t next_addr = 0;

    salis_init();

    while (mvec_is_proc_owner(g_cores, g_cores->pvec->ip, g_cores->pcur)) {
        assert(g_cores->pvec->ip == next_addr);

        if (mvec_get_inst(g_cores, g_cores->pvec->ip) == ifnz) {
            switch (mvec_get_inst(g_cores, g_cores->pvec->ip + 1)) {
            case nop0:
                next_addr += g_cores->pvec->r0x ? 1 : 2;
                break;
            case nop1:
                next_addr += g_cores->pvec->r1x ? 1 : 2;
                break;
            case nop2:
                next_addr += g_cores->pvec->r2x ? 1 : 2;
                break;
            case nop3:
                next_addr += g_cores->pvec->r3x ? 1 : 2;
                break;
            default:
                next_addr += g_cores->pvec->r0x ? 0 : 1;
            }
        }

        salis_step(1);
        next_addr++;

        assert(g_cores->pvec->ip == next_addr);
    }

    assert(g_cores->pvec->ip == ANC_SIZE);
    assert(g_cores->pvec->r0x == 2);
    assert(g_cores->pvec->r1x == 2);
    assert(g_cores->pvec->r2x == 2);
    assert(g_cores->pvec->r3x == 2);

    salis_save_and_free();
    return 0;
}