Skip to content

Commit

Permalink
Generate register moves when available
Browse files Browse the repository at this point in the history
  • Loading branch information
ParfenovIgor committed Jan 4, 2025
1 parent fe6abdb commit 4cafe86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions compiler/src/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ const char *regs[] = {
};

void compile_memcpy(const char *dst, const char *src, int sz, struct CPContext *context) {
_fputs3(context->fd_text, "lea rdi, ", dst, "\n");
_fputs3(context->fd_text, "lea rsi, ", src, "\n");
_fputsi(context->fd_text, "mov rcx, ", sz, "\n");
_fputs(context->fd_text, "rep movsb\n");
if (sz == 1) {
_fputs3(context->fd_text, "mov cl, ", src, "\n");
_fputs3(context->fd_text, "mov ", dst, ", cl\n");
}
else if (sz == 8) {
_fputs3(context->fd_text, "mov rcx, ", src, "\n");
_fputs3(context->fd_text, "mov ", dst, ", rcx\n");
}
else {
_fputs3(context->fd_text, "lea rdi, ", dst, "\n");
_fputs3(context->fd_text, "lea rsi, ", src, "\n");
_fputsi(context->fd_text, "mov rcx, ", sz, "\n");
_fputs(context->fd_text, "rep movsb\n");
}
}

int align_to_word(int x) {
Expand Down
2 changes: 1 addition & 1 deletion test/perf/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ALFLAGS=-i altlib ../../altlib/
CFLAGS=-g -fno-stack-protector -I include -I ../../stdlib/include
CFLAGS=-O2 -g -fno-stack-protector -I include -I ../../stdlib/include
LDFLAGS=-z noexecstack

SRCS_AL := $(wildcard *.al)
Expand Down

0 comments on commit 4cafe86

Please sign in to comment.