aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2024-02-29 02:29:14 +0100
committerPaul Oliver <contact@pauloliver.dev>2024-02-29 02:29:14 +0100
commit2b62fa482a7553c07e7664b736a646af35c1f72d (patch)
tree1f3ab646228c302e8a85289a66bdd81b15871737
parent59546320f16259b1bc8a1d397dd9c0203a0349f8 (diff)
Removed Memory module's IP flag.
[#28] IP flag served no purpose except to facilitate rendering. However, performance has a higher priority so I've eliminated this feature. IP rendering can still be implemented via other methods.
-rw-r--r--bin/printer.py1
-rw-r--r--include/memory.h14
-rw-r--r--src/memory.c16
-rw-r--r--src/process.c79
4 files changed, 8 insertions, 102 deletions
diff --git a/bin/printer.py b/bin/printer.py
index c7735f2..e29f4f8 100644
--- a/bin/printer.py
+++ b/bin/printer.py
@@ -514,7 +514,6 @@ class Printer:
("e", "size", self.__sim.lib.sal_mem_get_size),
("e", "blocks", self.__sim.lib.sal_mem_get_block_start_count),
("e", "allocated", self.__sim.lib.sal_mem_get_allocated_count),
- ("e", "ips", self.__sim.lib.sal_mem_get_ip_count),
("s", ""),
("h", "INSTRUCTIONS"),
] + inst_widget),
diff --git a/include/memory.h b/include/memory.h
index e7b97ee..9797cd7 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -10,7 +10,6 @@
#ifndef SALIS_MEMORY_H
#define SALIS_MEMORY_H
-#define IP_FLAG 0x80
#define BLOCK_START_FLAG 0x40
#define ALLOCATED_FLAG 0x20
#define INSTRUCTION_MASK 0x1f
@@ -30,11 +29,6 @@ SALIS_API uint32 sal_mem_get_order(void);
*/
SALIS_API uint32 sal_mem_get_size(void);
-/** Get amount of addresses with the IP flag set on them.
-* @return Amount of addresses with the IP flag set
-*/
-SALIS_API uint32 sal_mem_get_ip_count(void);
-
/** Get amount of addresses with the memory-block-start flag set on them.
* @return Amount of addresses with the memory-block-start flag set
*/
@@ -67,12 +61,6 @@ SALIS_API boolean sal_mem_is_over_capacity(void);
*/
SALIS_API boolean sal_mem_is_address_valid(uint32 address);
-/** Check if given address has the IP flag set.
-* @param address Address being queried
-* @return IP flag is set on this address
-*/
-SALIS_API boolean sal_mem_is_ip(uint32 address);
-
/** Check if given address has the memory-block-start flag set.
* @param address Address being queried
* @return Memory-block-start flag is set on this address
@@ -85,10 +73,8 @@ SALIS_API boolean sal_mem_is_block_start(uint32 address);
*/
SALIS_API boolean sal_mem_is_allocated(uint32 address);
-void _sal_mem_set_ip(uint32 address);
void _sal_mem_set_block_start(uint32 address);
void _sal_mem_set_allocated(uint32 address);
-void _sal_mem_unset_ip(uint32 address);
void _sal_mem_unset_block_start(uint32 address);
void _sal_mem_unset_allocated(uint32 address);
diff --git a/src/memory.c b/src/memory.c
index c586eb0..87fc7ee 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -12,7 +12,6 @@
static boolean g_is_init;
static uint32 g_order;
static uint32 g_size;
-static uint32 g_ip_count;
static uint32 g_block_start_count;
static uint32 g_allocated_count;
static uint32 g_capacity;
@@ -46,7 +45,6 @@ void _sal_mem_quit(void)
g_is_init = FALSE;
g_order = 0;
g_size = 0;
- g_ip_count = 0;
g_block_start_count = 0;
g_allocated_count = 0;
g_capacity = 0;
@@ -63,7 +61,6 @@ void _sal_mem_load_from(FILE *file)
fread(&g_is_init, sizeof(boolean), 1, file);
fread(&g_order, sizeof(uint32), 1, file);
fread(&g_size, sizeof(uint32), 1, file);
- fread(&g_ip_count, sizeof(uint32), 1, file);
fread(&g_block_start_count, sizeof(uint32), 1, file);
fread(&g_allocated_count, sizeof(uint32), 1, file);
fread(&g_capacity, sizeof(uint32), 1, file);
@@ -82,7 +79,6 @@ void _sal_mem_save_into(FILE *file)
fwrite(&g_is_init, sizeof(boolean), 1, file);
fwrite(&g_order, sizeof(uint32), 1, file);
fwrite(&g_size, sizeof(uint32), 1, file);
- fwrite(&g_ip_count, sizeof(uint32), 1, file);
fwrite(&g_block_start_count, sizeof(uint32), 1, file);
fwrite(&g_allocated_count, sizeof(uint32), 1, file);
fwrite(&g_capacity, sizeof(uint32), 1, file);
@@ -94,7 +90,6 @@ void _sal_mem_save_into(FILE *file)
*/
UINT32_GETTER(mem, order)
UINT32_GETTER(mem, size)
-UINT32_GETTER(mem, ip_count)
UINT32_GETTER(mem, block_start_count)
UINT32_GETTER(mem, allocated_count)
UINT32_GETTER(mem, capacity)
@@ -128,9 +123,8 @@ boolean sal_mem_is_address_valid(uint32 address)
/* We declare a standard macro to test whether a specific FLAG is set on a given
byte. Remember, a Salis byte contains a 5 bit instruction (of 32 possible) plus
-3 flags: IP, BLOCK_START and ALLOCATED. These flags help organisms identify
-where there is free memory space to reproduce on, and tell the python printer
-module how to color each byte.
+2 flags: BLOCK_START and ALLOCATED. These flags help organisms identify where
+there is free memory space to reproduce on.
*/
#define FLAG_TEST(name, flag) \
boolean sal_mem_is_##name(uint32 address) \
@@ -140,7 +134,6 @@ boolean sal_mem_is_##name(uint32 address) \
return !!(g_memory[address] & flag); \
}
-FLAG_TEST(ip, IP_FLAG)
FLAG_TEST(block_start, BLOCK_START_FLAG)
FLAG_TEST(allocated, ALLOCATED_FLAG)
@@ -159,7 +152,6 @@ void _sal_mem_set_##name(uint32 address) \
} \
}
-FLAG_SETTER(ip, IP_FLAG)
FLAG_SETTER(block_start, BLOCK_START_FLAG)
FLAG_SETTER(allocated, ALLOCATED_FLAG)
@@ -178,7 +170,6 @@ void _sal_mem_unset_##name(uint32 address) \
} \
}
-FLAG_UNSETTER(ip, IP_FLAG)
FLAG_UNSETTER(block_start, BLOCK_START_FLAG)
FLAG_UNSETTER(allocated, ALLOCATED_FLAG)
@@ -293,7 +284,6 @@ static boolean module_is_valid(void)
to when running optimized, but it is also **very** useful for debugging!
*/
uint32 bidx;
- uint32 ip_count = 0;
uint32 block_start_count = 0;
uint32 allocated_count = 0;
assert(g_is_init);
@@ -304,12 +294,10 @@ static boolean module_is_valid(void)
then compare the sum to the flag counters to assert module validity.
*/
for (bidx = 0; bidx < g_size; bidx++) {
- if (sal_mem_is_ip(bidx)) ip_count++;
if (sal_mem_is_block_start(bidx)) block_start_count++;
if (sal_mem_is_allocated(bidx)) allocated_count++;
}
- assert(ip_count == g_ip_count);
assert(block_start_count == g_block_start_count);
assert(allocated_count == g_allocated_count);
return TRUE;
diff --git a/src/process.c b/src/process.c
index d997c9b..50ca3eb 100644
--- a/src/process.c
+++ b/src/process.c
@@ -245,8 +245,7 @@ static uint32 get_new_proc_from_queue(uint32 queue_lock)
}
static void proc_create(
- uint32 address, uint32 size, uint32 queue_lock,
- boolean set_ip, boolean allocate
+ uint32 address, uint32 size, uint32 queue_lock, boolean allocate
) {
/* Give birth to a new process! We must specify the address and size of the
new organism.
@@ -256,15 +255,6 @@ static void proc_create(
assert(sal_mem_is_address_valid(address));
assert(sal_mem_is_address_valid(address + size - 1));
- /* When organisms are generated manually (by an user), we must set the IP
- flag on the first byte of its owned memory. When organisms replicate by
- themselves, we don't set the flag, as it gets set at the end of the module
- cycle. Take a look at the '_sal_proc_cycle()' function for more info.
- */
- if (set_ip) {
- _sal_mem_set_ip(address);
- }
-
/* When organisms are generated manually (by an user), we must explicitly
allocate its entire memory block. When organisms replicate by themselves,
we assume they have already allocated the child's memory, so we don't need
@@ -298,7 +288,7 @@ void sal_proc_create(uint32 address, uint32 mb1s)
*/
assert(g_is_init);
assert(block_is_free_and_valid(address, mb1s));
- proc_create(address, mb1s, 0, TRUE, TRUE);
+ proc_create(address, mb1s, 0, TRUE);
}
static void free_memory_block(uint32 address, uint32 size)
@@ -339,7 +329,7 @@ static void free_memory_owned_by(uint32 pidx)
}
}
-static void proc_kill(boolean reset_ips)
+static void proc_kill(void)
{
/* Kill process on bottom of reaper queue (the oldest process).
*/
@@ -349,13 +339,6 @@ static void proc_kill(boolean reset_ips)
assert(g_last != UINT32_MAX);
assert(!sal_proc_is_free(g_first));
- /* When called manually by an user, we must clear and reset the IP flags of
- all processes in order to preserve module validity.
- */
- if (reset_ips) {
- _sal_mem_unset_ip(g_procs[g_first].ip);
- }
-
/* Free up owned memory and reset process data structure back to zero.
*/
free_memory_owned_by(g_first);
@@ -369,19 +352,6 @@ static void proc_kill(boolean reset_ips)
g_first++;
g_first %= g_capacity;
}
-
- /* Reset IP flags of all living processes. We use openmp to do this faster.
- */
- if (reset_ips) {
- uint32 pidx;
-
- #pragma omp parallel for
- for (pidx = 0; pidx < g_capacity; pidx++) {
- if (!sal_proc_is_free(pidx)) {
- _sal_mem_set_ip(g_procs[pidx].ip);
- }
- }
- }
}
void sal_proc_kill(void)
@@ -394,7 +364,7 @@ void sal_proc_kill(void)
assert(g_first != UINT32_MAX);
assert(g_last != UINT32_MAX);
assert(!sal_proc_is_free(g_first));
- proc_kill(TRUE);
+ proc_kill();
}
static boolean block_is_allocated(uint32 address, uint32 size)
@@ -426,7 +396,6 @@ static boolean proc_is_valid(uint32 pidx)
assert(sal_mem_is_address_valid(g_procs[pidx].ip));
assert(sal_mem_is_address_valid(g_procs[pidx].sp));
assert(sal_mem_is_block_start(g_procs[pidx].mb1a));
- assert(sal_mem_is_ip(g_procs[pidx].ip));
assert(block_is_allocated(g_procs[pidx].mb1a, g_procs[pidx].mb1s));
if (g_procs[pidx].mb2s) {
@@ -449,7 +418,6 @@ static boolean module_is_valid(void)
uint32 alloc_count = 0;
uint32 block_count = 0;
assert(g_is_init);
- assert(g_count >= sal_mem_get_ip_count());
/* Check that each individual process is in a valid state. We can do this
in a multi-threaded way.
@@ -481,28 +449,6 @@ static boolean module_is_valid(void)
return TRUE;
}
-static void toggle_ip_flag(void (*toggler)(uint32 address))
-{
- /* At the start of each process module cycle, all memory addresses with the
- IP flag set get their IP flag turned off. Once all processes finish
- executing, the IP flags are turned on again on all addresses pointed by
- 'g_procs[pidx].ip'. I've found this is the easiest way to preserve
- correctness, given that more than one process can have their IPs pointed to
- the same address.
-
- This function simply iterates through all processes, setting the IP flag on
- or off on the address pointed to by their IP.
- */
- uint32 pidx;
- assert(g_is_init);
-
- for (pidx = 0; pidx < g_capacity; pidx++) {
- if (!sal_proc_is_free(pidx)) {
- toggler(g_procs[pidx].ip);
- }
- }
-}
-
static void on_fault(uint32 pidx)
{
/* For now, faults do nothing.
@@ -952,9 +898,7 @@ static void split(uint32 pidx)
assert(!sal_proc_is_free(pidx));
if (g_procs[pidx].mb2s) {
- proc_create(
- g_procs[pidx].mb2a, g_procs[pidx].mb2s, pidx, FALSE, FALSE
- );
+ proc_create(g_procs[pidx].mb2a, g_procs[pidx].mb2s, pidx, FALSE);
g_procs[pidx].mb2a = 0;
g_procs[pidx].mb2s = 0;
} else {
@@ -1358,12 +1302,6 @@ void _sal_proc_cycle(void)
*/
if (g_count) {
uint32 pidx = g_last;
-
- /* Turn off all IP flags in memory and cycle 'g_last'. Then, continue
- with all other organisms until we reach 'g_first'.
- */
- toggle_ip_flag(_sal_mem_unset_ip);
- assert(!sal_mem_get_ip_count());
proc_cycle(pidx);
while (pidx != g_first) {
@@ -1375,12 +1313,7 @@ void _sal_proc_cycle(void)
/* Kill oldest processes whenever memory gets filled over capacity.
*/
while (sal_mem_get_allocated_count() > sal_mem_get_capacity()) {
- proc_kill(FALSE);
+ proc_kill();
}
-
- /* Finally, turn IP flags back on. Keep in mind that IP flags exist
- for visualization purposes only. They are actually not really needed.
- */
- toggle_ip_flag(_sal_mem_set_ip);
}
}