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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
// file : arch/null/arch.c
// project : Salis-VM
// author : Paul Oliver <contact@pauloliver.dev>
//
// Example of a minimal viable VM architecture. Useful for testing.
// Also works as a placeholder when creating new VM architectures.
// index:
// [section] includes
// [section] getters
// [section] callbacks
// [section] validation
// [section] data
// [section] main
// ----------------------------------------------------------------------------
// [section] includes
// ----------------------------------------------------------------------------
#include <assert.h>
#include <sqlite3.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <threads.h>
#include <zlib.h>
#include "arch.h"
#include "arch_spec.h"
#include "arch_inst.h"
#include "compress.h"
#include "logger.h"
#include "salis.h"
#include "sql.h"
// ----------------------------------------------------------------------------
// [section] getters
// ----------------------------------------------------------------------------
uint64_t arch_proc_get_ip_addr(const struct Core *core, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
return proc_get(core, pix)->ip;
}
uint64_t arch_proc_get_sp_addr(const struct Core *core, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
return proc_get(core, pix)->sp;
}
uint64_t arch_proc_get_mb0_addr(const struct Core *core, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
return proc_get(core, pix)->mb0a;
}
uint64_t arch_proc_get_mb0_size(const struct Core *core, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
return proc_get(core, pix)->mb0s;
}
uint64_t arch_proc_get_mb1_addr(const struct Core *core, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
return proc_get(core, pix)->mb1a;
}
uint64_t arch_proc_get_mb1_size(const struct Core *core, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
return proc_get(core, pix)->mb1s;
}
uint64_t arch_proc_get_slice(const struct Core *core, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
(void)core;
(void)pix;
return 1;
}
// ----------------------------------------------------------------------------
// [section] callbacks
// ----------------------------------------------------------------------------
void arch_on_proc_step(struct Core *core, uint64_t pix) {
assert(core);
assert(mvec_proc_is_live(core, pix));
(void)core;
(void)pix;
return;
}
void arch_on_proc_kill(struct Core *core) {
assert(core);
assert(core->pnum > 1);
(void)core;
}
// ----------------------------------------------------------------------------
// [section] validation
// ----------------------------------------------------------------------------
#if !defined(NDEBUG)
void arch_validate_core(struct Core *core) {
assert(core);
(void)core;
}
#endif
// ----------------------------------------------------------------------------
// [section] data
// ----------------------------------------------------------------------------
void arch_push_data_header(void) {
log_info("Creating arch table in SQLite database");
sql_exec(
NULL, NULL,
"create table arch ("
#define FOR_CORE(i) \
"null_0_pop_" #i " int not null, " \
"null_1_pop_" #i " int not null, " \
"null_2_pop_" #i " int not null, " \
"null_3_pop_" #i " int not null, "
FOR_CORES
#undef FOR_CORE
"step int not null"
");"
);
}
static int arch_count_inst_pop(struct Core *core) {
assert(core);
for (uint64_t i = 0; i < MVEC_SIZE; i++) {
core->ipop[mvec_get_inst(core, i)]++;
}
#if !defined(NDEBUG)
uint64_t pop_total = 0;
for (uint64_t i = 0; i < ARCH_INST_COUNT; i++) {
pop_total += core->ipop[i];
}
assert(pop_total == MVEC_SIZE);
#endif
return 0;
}
void arch_prepare_data_line(void) {
assert(g_sim_db);
// Measure instruction population in parallel
for (int i = 0; i < CORES; i++) {
struct Core *core = &g_cores[i];
thrd_create(&core->ipop_thrd, (thrd_start_t)arch_count_inst_pop, core);
}
for (int i = 0; i < CORES; i++) {
struct Core *core = &g_cores[i];
thrd_join(core->ipop_thrd, NULL);
}
}
void arch_push_data_line(FILE *eva_file) {
assert(eva_file);
(void)eva_file;
log_info("Pushing row to arch table in SQLite database");
sql_exec(
NULL, NULL,
"insert into arch ("
#define FOR_CORE(i) \
"null_0_pop_" #i ", " \
"null_1_pop_" #i ", " \
"null_2_pop_" #i ", " \
"null_3_pop_" #i ", "
FOR_CORES
#undef FOR_CORE
"step"
") values ("
#define FOR_CORE(i) \
"%ld, %ld, %ld, %ld, "
FOR_CORES
#undef FOR_CORE
"%ld"
");",
#define FOR_CORE(i) \
g_cores[i].ipop[0], \
g_cores[i].ipop[1], \
g_cores[i].ipop[2], \
g_cores[i].ipop[3],
FOR_CORES
#undef FOR_CORE
g_step
);
// Reset data aggregation fields
for (int i = 0; i < CORES; i++) {
struct Core *core = &g_cores[i];
memset(core->ipop, 0, sizeof(uint64_t) * ARCH_INST_COUNT);
}
}
// ----------------------------------------------------------------------------
// [section] main
// ----------------------------------------------------------------------------
#if defined(COMMAND_NEW)
void arch_core_init(struct Core *core) {
assert(core);
for (uint64_t i = 0; i < CLONES; i++) {
uint64_t addr_clone = (MVEC_SIZE / CLONES) * i;
struct Proc *panc = proc_fetch(core, i);
panc->mb0a = addr_clone;
panc->mb0s = ANC_SIZE;
panc->ip = addr_clone;
panc->sp = addr_clone;
}
}
#endif
#if defined(COMMAND_LOAD)
void arch_core_load(struct Core *core, FILE *f) {
assert(core);
assert(f);
(void)core;
(void)f;
}
#endif
void arch_core_save(const struct Core *core, FILE *f) {
assert(core);
assert(f);
(void)core;
(void)f;
}
void arch_core_free(struct Core *core) {
assert(core);
(void)core;
}
|