[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:
Justin C. Miller
2024-02-25 17:09:04 -08:00
parent bc46c9a7d5
commit f7ea46e49e
6 changed files with 28 additions and 27 deletions

View File

@@ -8,6 +8,7 @@ j6 = module("j6",
"condition.cpp",
"init.cpp",
"memutils.cpp",
"memutils.s",
"mutex.cpp",
"protocol_ids.cpp",
"protocols/service_locator.cpp",

View File

@@ -7,14 +7,6 @@
using namespace j6;
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) {
if (s1 == s2) return;

View File

@@ -0,0 +1,7 @@
global memcpy: function (memcpy.end - memcpy)
memcpy:
mov rax, rdi
mov rcx, rdx
rep movsb
ret
memcpy.end:

View File

@@ -9,16 +9,11 @@ extern cb __init_array_end;
namespace {
void
run_ctor_list(cb *array, cb *end)
run_ctor_list(cb *p, cb *end)
{
if (!array || !end)
return;
size_t i = 0;
while (true) {
const cb &ctor = array[i++];
if (&ctor == end) return;
if (ctor) ctor();
while (p && end && p < end) {
if (p) (*p)();
++p;
}
}
@@ -31,8 +26,8 @@ run_global_ctors()
} // namespace
extern "C"
void __init_libc()
extern "C" void
__init_libc()
{
run_global_ctors();
}