summaryrefslogtreecommitdiff
path: root/core/salis.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/salis.c')
-rw-r--r--core/salis.c85
1 files changed, 40 insertions, 45 deletions
diff --git a/core/salis.c b/core/salis.c
index 6cc0725..99d26a2 100644
--- a/core/salis.c
+++ b/core/salis.c
@@ -37,10 +37,6 @@
// ----------------------------------------------------------------------------
// [section] macros
// ----------------------------------------------------------------------------
-#define INST_MASK 0x7f
-#define IPCM_FLAG 0x80
-#define MALL_FLAG 0x80
-
#define STEP_GROUP_TIME_MIN_MS 0x400
#define STEP_GROUP_TIME_MAX_MS 0x800
@@ -50,13 +46,13 @@
struct Core g_cores[CORES];
uint64_t g_step;
uint64_t g_sync;
-const struct Proc g_null_proc;
+static const struct Proc g_null_proc;
-char g_asav_pbuf[AUTOSAVE_NAME_LEN];
-char g_evas_pbuf[EVA_SAVE_NAME_LEN];
+static char g_asav_pbuf[AUTOSAVE_NAME_LEN];
+static char g_evas_pbuf[EVA_SAVE_NAME_LEN];
-atomic_bool g_running;
-thrd_t g_thrd;
+static atomic_bool g_running;
+static thrd_t g_thrd;
// ----------------------------------------------------------------------------
// [section] memory vector functions
@@ -71,10 +67,10 @@ bool mvec_is_alloc(const struct Core *core, uint64_t addr) {
assert(core);
#if defined(ARCH_SPEC_MVEC_LOOP)
- return core->mvec[mvec_loop(addr)] & MALL_FLAG ? true : false;
+ return core->mvec[mvec_loop(addr)] & SALIS_MALL_FLAG ? true : false;
#else
if (addr < MVEC_SIZE) {
- return core->mvec[addr] & MALL_FLAG ? true : false;
+ return core->mvec[addr] & SALIS_MALL_FLAG ? true : false;
} else {
return true;
}
@@ -92,7 +88,7 @@ void mvec_alloc(struct Core *core, uint64_t addr) {
uint64_t loop_addr = addr;
#endif
- core->mvec[loop_addr] |= MALL_FLAG;
+ core->mvec[loop_addr] |= SALIS_MALL_FLAG;
core->aeva.data[loop_addr]++;
core->mall++;
}
@@ -109,33 +105,19 @@ void mvec_free(struct Core *core, uint64_t addr) {
uint64_t loop_addr = addr;
#endif
- core->mvec[loop_addr] ^= MALL_FLAG;
+ core->mvec[loop_addr] ^= SALIS_MALL_FLAG;
core->aeva.data[loop_addr]++;
core->mall--;
}
-uint8_t mvec_get_byte(const struct Core *core, uint64_t addr) {
- assert(core);
-
-#if defined(ARCH_SPEC_MVEC_LOOP)
- return core->mvec[mvec_loop(addr)];
-#else
- if (addr < MVEC_SIZE) {
- return core->mvec[addr];
- } else {
- return 0;
- }
-#endif
-}
-
uint8_t mvec_get_inst(const struct Core *core, uint64_t addr) {
assert(core);
#if defined(ARCH_SPEC_MVEC_LOOP)
- return core->mvec[mvec_loop(addr)] & INST_MASK;
+ return core->mvec[mvec_loop(addr)] & ARCH_INST_MASK;
#else
if (addr < MVEC_SIZE) {
- return core->mvec[addr] & INST_MASK;
+ return core->mvec[addr] & ARCH_INST_MASK;
} else {
return 0;
}
@@ -144,14 +126,14 @@ 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) {
assert(core);
- assert(inst < ARCH_INST_CAP);
+ assert(inst < ARCH_INST_COUNT);
#if defined(ARCH_SPEC_MVEC_LOOP)
- core->mvec[mvec_loop(addr)] &= MALL_FLAG;
+ core->mvec[mvec_loop(addr)] &= SALIS_MALL_FLAG;
core->mvec[mvec_loop(addr)] |= inst;
#else
assert(addr < MVEC_SIZE);
- core->mvec[addr] &= MALL_FLAG;
+ core->mvec[addr] &= SALIS_MALL_FLAG;
core->mvec[addr] |= inst;
#endif
}
@@ -160,7 +142,7 @@ void mvec_set_inst(struct Core *core, uint64_t addr, uint8_t inst) {
void mvec_flip_bit(struct Core *core, uint64_t addr, int bit) {
assert(core);
assert(bit < 8);
- core->mvec[addr] ^= (1 << bit) & INST_MASK;
+ core->mvec[addr] ^= (1 << bit) & ARCH_INST_MASK;
}
#endif
@@ -250,7 +232,7 @@ void muta_cosmic_ray(struct Core *core) {
#if defined(ARCH_SPEC_MUTA_FLIP)
mvec_flip_bit(core, a, (int)(b % 8));
#else
- mvec_set_inst(core, a, b & INST_MASK);
+ mvec_set_inst(core, a, b & ARCH_INST_MASK);
#endif
}
}
@@ -474,8 +456,8 @@ static void core_pull_ipcm(struct Core *core) {
uint8_t *iinst = &core->iviv[core->ivpt];
uint64_t *iaddr = &core->ivav[core->ivpt];
- if ((*iinst & IPCM_FLAG) != 0) {
- mvec_set_inst(core, *iaddr, *iinst & INST_MASK);
+ if ((*iinst & SALIS_IPCM_FLAG) != 0) {
+ mvec_set_inst(core, *iaddr, *iinst & ARCH_INST_MASK);
*iinst = 0;
*iaddr = 0;
}
@@ -487,12 +469,12 @@ static void core_pull_ipcm(struct Core *core) {
void core_push_ipcm(struct Core *core, uint8_t inst, uint64_t addr) {
assert(core);
assert(core->ivpt < SYNC_INTERVAL);
- assert((inst & IPCM_FLAG) == 0);
+ assert((inst & SALIS_IPCM_FLAG) == 0);
uint8_t *iinst = &core->iviv[core->ivpt];
uint64_t *iaddr = &core->ivav[core->ivpt];
assert(*iinst == 0);
assert(*iaddr == 0);
- *iinst = inst | IPCM_FLAG;
+ *iinst = inst | SALIS_IPCM_FLAG;
*iaddr = addr;
}
@@ -622,7 +604,7 @@ static void core_validate(struct Core *core) {
for (uint64_t i = 0; i < SYNC_INTERVAL; i++) {
uint8_t iinst = core->iviv[i];
- if ((iinst & IPCM_FLAG) == 0) {
+ if ((iinst & SALIS_IPCM_FLAG) == 0) {
uint64_t iaddr = core->ivav[i];
assert(iinst == 0);
assert(iaddr == 0);
@@ -997,9 +979,11 @@ static int salis_thread(void *data) {
assert(atomic_load_explicit(&g_running, memory_order_relaxed));
(void)data;
+#if defined(SALIS_LOG_TIME)
+ uint64_t step_start = g_step;
struct timespec time_start;
clock_gettime(CLOCK_MONOTONIC_COARSE, &time_start);
- uint64_t step_start = g_step;
+#endif
while (atomic_load_explicit(&g_running, memory_order_relaxed)) {
log_trace("Launching core threads");
@@ -1037,18 +1021,24 @@ static int salis_thread(void *data) {
salis_validate();
#endif
+#if defined(SALIS_LOG_TIME)
// Log simulation steps/s
+ // This will only trigger in situations where `salis_thread()`
+ // is let to run for more than 1 second.
struct timespec time_end;
clock_gettime(CLOCK_MONOTONIC_COARSE, &time_end);
- int time_delta = time_end.tv_sec - time_start.tv_sec;
+ float time_delta = (float)(time_end.tv_sec - time_start.tv_sec);
+ time_delta += (float)(time_end.tv_nsec - time_start.tv_nsec) / 1000000000.f;
- if (time_delta > 0) {
+ if (time_delta > 1.f) {
uint64_t step_end = g_step;
- uint64_t step_delta = step_end - step_start;
+ float step_delta = (float)(step_end - step_start);
+ float steps_per_sec = step_delta / time_delta;
time_start = time_end;
step_start = step_end;
- log_info("Running simulation @%#018lx steps/s", step_delta);
+ log_info("Running simulation @%#018lx steps/s", (uint64_t)steps_per_sec);
}
+#endif
}
return 0;
@@ -1067,6 +1057,12 @@ void salis_join(void) {
thrd_join(g_thrd, NULL);
}
+void salis_wait(void) {
+ assert(!atomic_load_explicit(&g_running, memory_order_relaxed));
+ log_trace("Waiting for main thread");
+ thrd_join(g_thrd, NULL);
+}
+
void salis_signal_stop(void) {
assert(atomic_load_explicit(&g_running, memory_order_relaxed));
log_trace("Signaling main thread to stop");
@@ -1083,7 +1079,6 @@ void salis_step(uint64_t steps) {
}
g_step++;
-
salis_check_intervals();
}