aboutsummaryrefslogtreecommitdiff
path: root/src/std
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-09-14 00:52:24 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit7d663615b2a44715e7447a40cae467d7d4e38b9c (patch)
tree612e81f55ca73c3da868bd2ab6cd96ae6ac30a15 /src/std
parent7103d3a1df6c7fee6e8efbe3588204d1e869004e (diff)
Start on opengl test, fix stack alignment before call (sys-v)
Diffstat (limited to 'src/std')
-rw-r--r--src/std/arena_allocator.c5
-rw-r--r--src/std/buffer.c8
-rw-r--r--src/std/buffer_view.c8
3 files changed, 14 insertions, 7 deletions
diff --git a/src/std/arena_allocator.c b/src/std/arena_allocator.c
index 11fb40d..8b0083d 100644
--- a/src/std/arena_allocator.c
+++ b/src/std/arena_allocator.c
@@ -74,7 +74,8 @@ static usize align_ptr_ceil_offset(void *ptr, uintptr_t alignment) {
return (uintptr_t)align_ptr_ceil(ptr, alignment) - (uintptr_t)ptr;
}
-#define ALLOC_ALIGNMENT 8
+/* 16-byte alignment allows SIMD instructions to be operated on the data */
+#define ALLOC_ALIGNMENT 16
int arena_allocator_alloc(ArenaAllocator *self, usize size, void **mem) {
ArenaAllocatorNode *current;
@@ -103,6 +104,6 @@ int arena_allocator_alloc(ArenaAllocator *self, usize size, void **mem) {
int arena_allocator_add_mem(ArenaAllocator *self, usize *result_index) {
void *null_data;
null_data = NULL;
- *result_index = buffer_get_size(&self->mems, void*);
+ *result_index = self->mems.size;
return buffer_append(&self->mems, &null_data, sizeof(void*));
}
diff --git a/src/std/buffer.c b/src/std/buffer.c
index 021fce8..dca3b26 100644
--- a/src/std/buffer.c
+++ b/src/std/buffer.c
@@ -28,7 +28,6 @@ void buffer_deinit(Buffer *self) {
static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) {
usize capacity;
void *new_mem;
- int alloc_result;
if(self->capacity >= new_capacity)
return BUFFER_OK;
@@ -45,15 +44,14 @@ static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity)
capacity = cap;
}
- alloc_result = am_realloc(self->data, capacity, &new_mem);
- if(alloc_result != ALLOC_OK)
+ if(am_realloc(self->data, capacity, &new_mem) != ALLOC_OK)
return BUFFER_ALLOC_FAIL;
self->data = new_mem;
self->capacity = capacity;
/* Update list of buffers in the allocator with the new address of the buffer data */
if(self->allocator)
- am_memcpy(self->allocator->mems.data + sizeof(void*) * self->allocator_index, &self->data, sizeof(void*));
+ am_memcpy(self->allocator->mems.data + self->allocator_index, &self->data, sizeof(void*));
return BUFFER_OK;
}
@@ -103,7 +101,7 @@ int buffer_set_capacity(Buffer *self, usize new_capacity) {
self->size = self->capacity;
/* Update list of buffers in the allocator with the new address of the buffer data */
if(self->allocator)
- am_memcpy(self->allocator->mems.data + sizeof(void*) * self->allocator_index, &self->data, sizeof(void*));
+ am_memcpy(self->allocator->mems.data + self->allocator_index, &self->data, sizeof(void*));
return BUFFER_OK;
}
diff --git a/src/std/buffer_view.c b/src/std/buffer_view.c
index 249928b..8763be2 100644
--- a/src/std/buffer_view.c
+++ b/src/std/buffer_view.c
@@ -1,5 +1,6 @@
#include "../../include/std/buffer_view.h"
#include "../../include/std/mem.h"
+#include <string.h>
BufferView create_buffer_view_null(void) {
BufferView buffer_view;
@@ -15,6 +16,13 @@ BufferView create_buffer_view(const char *data, usize size) {
return buffer_view;
}
+BufferView create_buffer_view_auto(const char *data) {
+ BufferView buffer_view;
+ buffer_view.data = data;
+ buffer_view.size = strlen(data);
+ return buffer_view;
+}
+
bool buffer_view_equals(const BufferView *self, const BufferView *other) {
return self->size == other->size && am_memeql(self->data, other->data, self->size);
}