summaryrefslogtreecommitdiff
path: root/core/salis.h
blob: e61752b9a3b9def6533c6252a8ed3b738d9a8967 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// file    : core/salis.h
// project : Salis-VM
// author  : Paul Oliver <contact@pauloliver.dev>

#pragma once

// index:
// [section] structs
// [section] extern globals
// [section] memory vector declarations
// [section] mutator declarations
// [section] process declarations
// [section] core declarations
// [section] salis declarations

// ----------------------------------------------------------------------------
// [section] macros
// ----------------------------------------------------------------------------
#define SALIS_UINT64_HALF 0x8000000000000000ul
#define SALIS_EVENT_ARRAY_SIZE_COL_MARKER "_evasize_"

// ----------------------------------------------------------------------------
// [section] structs
// ----------------------------------------------------------------------------
struct Proc {
#define ARCH_SPEC_PROC_FIELD(type, name) type name;
    ARCH_SPEC_PROC_FIELDS
#undef ARCH_SPEC_PROC_FIELD
};

struct EventArray {
    uint64_t blob_size;
    uint64_t data[MVEC_SIZE];
    uint64_t comp[MVEC_SIZE];
    struct DeflateParams params;
    thrd_t thrd;
};

struct Core {
    uint64_t step;
    uint64_t cycl;
    uint64_t mall;
    uint64_t muta[4];

    uint64_t pnum;
    uint64_t pcap;
    uint64_t pfst;
    uint64_t plst;
    uint64_t pcur;
    uint64_t psli;

    uint64_t ivpt;
    uint64_t *ivav;
    uint8_t *iviv;

    uint8_t mvec[MVEC_SIZE]; // The World
    struct Proc *pvec; // The organisms

    // Data aggregation fields
    thrd_t amb_thrd;
    double amb0;
    double amb1;

    uint64_t emb0;
    uint64_t emb1;
    uint64_t eliv;
    uint64_t edea;

    struct EventArray aeva;
    struct EventArray eeva;
    struct EventArray beva;

    // VM architecture specific fields
#define ARCH_SPEC_CORE_FIELD(type, name) type name;
    ARCH_SPEC_CORE_FIELDS
#undef ARCH_SPEC_CORE_FIELD

    thrd_t thrd;
};

// ----------------------------------------------------------------------------
// [section] extern globals
// ----------------------------------------------------------------------------
extern struct Core g_cores[CORES];
extern uint64_t g_step;

// ----------------------------------------------------------------------------
// [section] memory vector declarations
// ----------------------------------------------------------------------------
#if defined(ARCH_SPEC_MVEC_LOOP)
uint64_t mvec_loop(uint64_t addr);
#endif

bool mvec_is_alloc(const struct Core *core, uint64_t addr);
void mvec_alloc(struct Core *core, uint64_t addr);
void mvec_free(struct Core *core, uint64_t addr);

uint8_t mvec_get_byte(const struct Core *core, uint64_t addr);
uint8_t mvec_get_inst(const struct Core *core, uint64_t addr);
void mvec_set_inst(struct Core *core, uint64_t addr, uint8_t inst);

#if defined(ARCH_SPEC_MUTA_FLIP)
void mvec_flip_bit(struct Core *core, uint64_t addr, int bit);
#endif

bool mvec_proc_is_live(const struct Core *core, uint64_t pix);
bool mvec_is_in_mb0_of_proc(const struct Core *core, uint64_t addr, uint64_t pix);
bool mvec_is_in_mb1_of_proc(const struct Core *core, uint64_t addr, uint64_t pix);
bool mvec_is_proc_owner(const struct Core *core, uint64_t addr, uint64_t pix);
uint64_t mvec_get_owner(const struct Core *core, uint64_t addr);

// ----------------------------------------------------------------------------
// [section] mutator declarations
// ----------------------------------------------------------------------------
uint64_t muta_next(struct Core *core);
void muta_cosmic_ray(struct Core *core);

// ----------------------------------------------------------------------------
// [section] process declarations
// ----------------------------------------------------------------------------
void proc_new(struct Core *core, const struct Proc *proc);
void proc_kill(struct Core *core);
const struct Proc *proc_get(const struct Core *core, uint64_t pix);
struct Proc *proc_fetch(struct Core *core, uint64_t pix);

// ----------------------------------------------------------------------------
// [section] core declarations
// ----------------------------------------------------------------------------
void core_event_array_init(struct EventArray *eva);
void core_push_ipcm(struct Core *core, uint8_t inst, uint64_t addr);

// ----------------------------------------------------------------------------
// [section] salis declarations
// ----------------------------------------------------------------------------
#if defined(COMMAND_NEW)
void salis_init(void);
#endif

#if defined(COMMAND_LOAD)
void salis_load(void);
#endif

void salis_start(void);
void salis_join(void);
void salis_signal_stop(void);
void salis_step(uint64_t steps);
void salis_free(void);