Commit 074f07b1 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

change memory allocation scheme to make it easier to inline

parent ad359cc6
......@@ -6,7 +6,6 @@
int desc_alloc;
int code_alloc;
int heap_alloc;
int nr_heap_alloc;
int stack_top_a;
......@@ -16,23 +15,24 @@ Thunk stack_b[STACK_SIZE_B];
#define heap_size 1024*1024*1024
char* heap_start;
char* heap_curr;
void print_stat() {
printf("\nallocation:\n");
printf("desc: %d\n", desc_alloc);
printf("code: %d\n", code_alloc);
printf("heap: %d (%d thunks)\n", heap_alloc, nr_heap_alloc);
printf("heap: %d (%d thunks)\n", heap_curr - heap_start, nr_heap_alloc);
}
void init_mem() {
desc_alloc = 0;
code_alloc = 0;
heap_alloc = 0;
nr_heap_alloc = 0;
stack_top_a = 0;
heap_start = (char*) malloc(heap_size);
heap_curr = heap_start;
assert(heap_start != NULL);
}
......@@ -48,15 +48,13 @@ void* alloc_code(int size) {
void* alloc_heap(int size) {
char* curr = heap_start + heap_alloc;
heap_alloc += size;
char* curr = heap_curr;
heap_curr += size;
#if DEBUG
#ifdef DEBUG
nr_heap_alloc++;
#endif
assert(heap_alloc < heap_size);
assert(heap_curr - heap_start < heap_size);
return curr;
}
\ No newline at end of file
......@@ -11,6 +11,8 @@ extern int stack_top_b;
extern Thunk* stack_a[STACK_SIZE_A];
extern Thunk stack_b[STACK_SIZE_B];
extern char* heap_curr;
#define peek_a() stack_a[stack_top_a-1]
#define pop_a() stack_a[--stack_top_a]
#define push_a(r) stack_a[stack_top_a++]=(r)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment