[build] Get release mode optimizations working
Added a release config, and fixed a few spots where optimizations broke things: - Clang was generating incorrect code for run_ctor_list in libc's init.cpp (it ignored a check for the end of the list) - my rep movsb memcpy implementation used incorrect inline asm constraints, so it was returning a pointer to the end of the copied range instead of the start. Since this function was just inline asm anyway, I rewrote it in asm by hand in a new memutils.s file.
This commit is contained in:
3
assets/build/config.release.yaml
Normal file
3
assets/build/config.release.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
ccflags: [
|
||||||
|
"-O3",
|
||||||
|
]
|
||||||
@@ -123,6 +123,8 @@ isr_handler(cpu_state *regs)
|
|||||||
uintptr_t cr2 = 0;
|
uintptr_t cr2 = 0;
|
||||||
__asm__ __volatile__ ("mov %%cr2, %0" : "=r"(cr2));
|
__asm__ __volatile__ ("mov %%cr2, %0" : "=r"(cr2));
|
||||||
|
|
||||||
|
// The zero page is always invalid
|
||||||
|
if (cr2 > mem::frame_size) {
|
||||||
bool user = cr2 < mem::kernel_offset;
|
bool user = cr2 < mem::kernel_offset;
|
||||||
vm_space::fault_type ft =
|
vm_space::fault_type ft =
|
||||||
static_cast<vm_space::fault_type>(regs->errorcode);
|
static_cast<vm_space::fault_type>(regs->errorcode);
|
||||||
@@ -133,6 +135,7 @@ isr_handler(cpu_state *regs)
|
|||||||
|
|
||||||
if (cr2 && space.handle_fault(cr2, ft))
|
if (cr2 && space.handle_fault(cr2, ft))
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
util::format({message, sizeof(message)},
|
util::format({message, sizeof(message)},
|
||||||
"Page fault: %016lx%s%s%s%s%s", cr2,
|
"Page fault: %016lx%s%s%s%s%s", cr2,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ j6 = module("j6",
|
|||||||
"condition.cpp",
|
"condition.cpp",
|
||||||
"init.cpp",
|
"init.cpp",
|
||||||
"memutils.cpp",
|
"memutils.cpp",
|
||||||
|
"memutils.s",
|
||||||
"mutex.cpp",
|
"mutex.cpp",
|
||||||
"protocol_ids.cpp",
|
"protocol_ids.cpp",
|
||||||
"protocols/service_locator.cpp",
|
"protocols/service_locator.cpp",
|
||||||
|
|||||||
@@ -7,14 +7,6 @@
|
|||||||
using namespace j6;
|
using namespace j6;
|
||||||
using namespace __j6libc;
|
using namespace __j6libc;
|
||||||
|
|
||||||
void *memcpy(void * restrict dst, const void * restrict src, size_t n) {
|
|
||||||
asm volatile ("rep movsb"
|
|
||||||
:
|
|
||||||
: "D"(dst), "S"(src), "c"(n)
|
|
||||||
: "memory");
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void memmove_dispatch(char *s1, const char *s2, size_t n) {
|
static void memmove_dispatch(char *s1, const char *s2, size_t n) {
|
||||||
if (s1 == s2) return;
|
if (s1 == s2) return;
|
||||||
|
|
||||||
|
|||||||
7
src/libraries/j6/memutils.s
Normal file
7
src/libraries/j6/memutils.s
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
global memcpy: function (memcpy.end - memcpy)
|
||||||
|
memcpy:
|
||||||
|
mov rax, rdi
|
||||||
|
mov rcx, rdx
|
||||||
|
rep movsb
|
||||||
|
ret
|
||||||
|
memcpy.end:
|
||||||
@@ -9,16 +9,11 @@ extern cb __init_array_end;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void
|
void
|
||||||
run_ctor_list(cb *array, cb *end)
|
run_ctor_list(cb *p, cb *end)
|
||||||
{
|
{
|
||||||
if (!array || !end)
|
while (p && end && p < end) {
|
||||||
return;
|
if (p) (*p)();
|
||||||
|
++p;
|
||||||
size_t i = 0;
|
|
||||||
while (true) {
|
|
||||||
const cb &ctor = array[i++];
|
|
||||||
if (&ctor == end) return;
|
|
||||||
if (ctor) ctor();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,8 +26,8 @@ run_global_ctors()
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
extern "C"
|
extern "C" void
|
||||||
void __init_libc()
|
__init_libc()
|
||||||
{
|
{
|
||||||
run_global_ctors();
|
run_global_ctors();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user