Skip to content

Commit

Permalink
Use heap system calls directly
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed May 19, 2024
1 parent af9ebe7 commit 0573ec7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions engine/scripts/src/gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ PUBLIC(void public_donothing())
/* nothing */
}

static void bench_alloc_free()
{
auto x = std::make_unique_for_overwrite<char[]>(1024);
__asm__("" :: "m"(x[0]) : "memory");
}

PUBLIC(void benchmarks())
{
try
Expand All @@ -76,6 +82,8 @@ PUBLIC(void benchmarks())
measure("Dynamic call handler x4 (inline)", inline_dyncall_handler);
measure("Dynamic call handler x4 (call)", opaque_dyncall_handler);

measure("Allocate 1024-bytes, and free it", bench_alloc_free);

//benchmark_multiprocessing();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/libriscv
3 changes: 2 additions & 1 deletion programs/micro/api/api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ inline std::optional<intptr_t> Game::setting(std::string_view setting)

asm("ecall"
: "=r"(has_value), "=r"(result)
: "m"(*name_ptr), "r"(name_ptr), "r"(name_len), "r"(sysno));
: "m"(*(const char(*)[name_len])name_ptr),
"r"(name_ptr), "r"(name_len), "r"(sysno));

if (has_value) return int64_t(result);
return std::nullopt;
Expand Down
1 change: 1 addition & 0 deletions programs/micro/libc/engine.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "override/new"
#include <exception>
#include <source_location>
#include <utility>
Expand Down
5 changes: 2 additions & 3 deletions programs/micro/libc/override/new
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once
#include_next<new>
#include <cstddef>

#include <heap.hpp>

inline void* operator new(size_t size) {
inline void* operator new(std::size_t size) {
return sys_malloc(size);
}
inline void* operator new[](size_t size) {
inline void* operator new[](std::size_t size) {
return sys_malloc(size);
}
inline void operator delete(void* ptr) {
Expand Down

0 comments on commit 0573ec7

Please sign in to comment.