Skip to content

Commit

Permalink
No flonum
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Jun 5, 2024
1 parent 77b0dc5 commit 14ce518
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 24 deletions.
54 changes: 42 additions & 12 deletions libsrc/misc/longjmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

#elif defined(__x86_64__)
void longjmp(jmp_buf env, int result) {
#ifdef __NO_FLONUM
#define RESTORE_FREGS // Empty
#else
#define RESTORE_FREGS \
"movsd 64(%rdi), %xmm0\n" \
"movsd 72(%rdi), %xmm1\n" \
"movsd 80(%rdi), %xmm2\n" \
"movsd 88(%rdi), %xmm3\n" \
"movsd 96(%rdi), %xmm4\n" \
"movsd 104(%rdi), %xmm5\n" \
"movsd 112(%rdi), %xmm6\n" \
"movsd 120(%rdi), %xmm7\n"
#endif
__asm("mov 0(%rdi), %rax\n" // return address.
"mov 8(%rdi), %rbp\n"
"mov 16(%rdi), %rsp\n"
Expand All @@ -14,14 +27,7 @@ void longjmp(jmp_buf env, int result) {
"mov 40(%rdi), %r13\n"
"mov 48(%rdi), %r14\n"
"mov 56(%rdi), %r15\n"
"movsd 64(%rdi), %xmm0\n"
"movsd 72(%rdi), %xmm1\n"
"movsd 80(%rdi), %xmm2\n"
"movsd 88(%rdi), %xmm3\n"
"movsd 96(%rdi), %xmm4\n"
"movsd 104(%rdi), %xmm5\n"
"movsd 112(%rdi), %xmm6\n"
"movsd 120(%rdi), %xmm7\n"
RESTORE_FREGS
"mov %rax, (%rsp)\n" // Store return address onto top of the stack.
"mov %esi, %eax\n" // Result value.
"test %eax, %eax\n"
Expand All @@ -31,17 +37,23 @@ void longjmp(jmp_buf env, int result) {
}
#elif defined(__aarch64__)
void longjmp(jmp_buf env, int result) {
#ifdef __NO_FLONUM
#define RESTORE_FREGS // Empty
#else
#define RESTORE_FREGS \
"ldp d8, d9, [x0, 112]\n" \
"ldp d10, d11, [x0, 128]\n" \
"ldp d12, d13, [x0, 144]\n" \
"ldp d14, d15, [x0, 160]\n"
#endif
__asm("ldp fp, lr, [x0]\n"
"ldp x9, x19, [x0, 16]\n"
"ldp x20, x21, [x0, 32]\n"
"ldp x22, x23, [x0, 48]\n"
"ldp x24, x25, [x0, 64]\n"
"ldp x26, x27, [x0, 80]\n"
"ldp x28, x29, [x0, 96]\n"
"ldp d8, d9, [x0, 112]\n"
"ldp d10, d11, [x0, 128]\n"
"ldp d12, d13, [x0, 144]\n"
"ldp d14, d15, [x0, 160]\n"
RESTORE_FREGS
"mov sp, x9\n"
"mov w0, w1\n" // Result value.
"cmp w0, wzr\n"
Expand All @@ -51,6 +63,23 @@ void longjmp(jmp_buf env, int result) {
}
#elif defined(__riscv)
void longjmp(jmp_buf env, int result) {
#ifdef __NO_FLONUM
#define RESTORE_FREGS // Empty
#else
#define RESTORE_FREGS \
"fld fs0, 112(a0)\n" \
"fld fs1, 120(a0)\n" \
"fld fs2, 128(a0)\n" \
"fld fs3, 136(a0)\n" \
"fld fs4, 144(a0)\n" \
"fld fs5, 152(a0)\n" \
"fld fs6, 160(a0)\n" \
"fld fs7, 168(a0)\n" \
"fld fs8, 176(a0)\n" \
"fld fs9, 184(a0)\n" \
"fld fs10, 192(a0)\n" \
"fld fs11, 200(a0)\n"
#endif
__asm("ld ra, 0(a0)\n"
"ld sp, 8(a0)\n"
"ld fp, 16(a0)\n"
Expand All @@ -65,6 +94,7 @@ void longjmp(jmp_buf env, int result) {
"ld s9, 88(a0)\n"
"ld s10, 96(a0)\n"
"ld s11, 104(a0)\n"
RESTORE_FREGS
"mv a0, a1\n"
"bne a0, zero, .longjmp_0\n"
"li a0, 1\n"
Expand Down
54 changes: 42 additions & 12 deletions libsrc/misc/setjmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

#elif defined(__x86_64__)
int setjmp(jmp_buf env) {
#ifdef __NO_FLONUM
#define SAVE_FREGS // Empty
#else
#define SAVE_FREGS \
"movsd %xmm0, 64(%rdi)\n" \
"movsd %xmm1, 72(%rdi)\n" \
"movsd %xmm2, 80(%rdi)\n" \
"movsd %xmm3, 88(%rdi)\n" \
"movsd %xmm4, 96(%rdi)\n" \
"movsd %xmm5, 104(%rdi)\n" \
"movsd %xmm6, 112(%rdi)\n" \
"movsd %xmm7, 120(%rdi)\n"
#endif
__asm("mov (%rsp), %rax\n" // return address.
"mov %rax, 0(%rdi)\n"
"mov %rbp, 8(%rdi)\n"
Expand All @@ -15,18 +28,20 @@ int setjmp(jmp_buf env) {
"mov %r13, 40(%rdi)\n"
"mov %r14, 48(%rdi)\n"
"mov %r15, 56(%rdi)\n"
"movsd %xmm0, 64(%rdi)\n"
"movsd %xmm1, 72(%rdi)\n"
"movsd %xmm2, 80(%rdi)\n"
"movsd %xmm3, 88(%rdi)\n"
"movsd %xmm4, 96(%rdi)\n"
"movsd %xmm5, 104(%rdi)\n"
"movsd %xmm6, 112(%rdi)\n"
"movsd %xmm7, 120(%rdi)\n"
SAVE_FREGS
"xor %eax, %eax");
}
#elif defined(__aarch64__)
int setjmp(jmp_buf env) {
#ifdef __NO_FLONUM
#define SAVE_FREGS // Empty
#else
#define SAVE_FREGS \
"stp d8, d9, [x0, 112]\n" \
"stp d10, d11, [x0, 128]\n" \
"stp d12, d13, [x0, 144]\n" \
"stp d14, d15, [x0, 160]\n"
#endif
__asm("stp fp, lr, [x0]\n"
"mov x9, sp\n"
"stp x9, x19, [x0, 16]\n"
Expand All @@ -35,14 +50,28 @@ int setjmp(jmp_buf env) {
"stp x24, x25, [x0, 64]\n"
"stp x26, x27, [x0, 80]\n"
"stp x28, x29, [x0, 96]\n"
"stp d8, d9, [x0, 112]\n"
"stp d10, d11, [x0, 128]\n"
"stp d12, d13, [x0, 144]\n"
"stp d14, d15, [x0, 160]\n"
SAVE_FREGS
"mov w0, wzr");
}
#elif defined(__riscv)
int setjmp(jmp_buf env) {
#ifdef __NO_FLONUM
#define SAVE_FREGS // Empty
#else
#define SAVE_FREGS \
"fsd fs0, 112(a0)\n" \
"fsd fs1, 120(a0)\n" \
"fsd fs2, 128(a0)\n" \
"fsd fs3, 136(a0)\n" \
"fsd fs4, 144(a0)\n" \
"fsd fs5, 152(a0)\n" \
"fsd fs6, 160(a0)\n" \
"fsd fs7, 168(a0)\n" \
"fsd fs8, 176(a0)\n" \
"fsd fs9, 184(a0)\n" \
"fsd fs10, 192(a0)\n" \
"fsd fs11, 200(a0)\n"
#endif
__asm("sd ra, 0(a0)\n"
"sd sp, 8(a0)\n"
"sd fp, 16(a0)\n"
Expand All @@ -57,6 +86,7 @@ int setjmp(jmp_buf env) {
"sd s9, 88(a0)\n"
"sd s10, 96(a0)\n"
"sd s11, 104(a0)\n"
SAVE_FREGS
"li a0, 0\n");
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/cc/arch/aarch64/emit_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ static void move_params_to_assigned(Function *func) {
int offset = (i - MAX_REG_ARGS - MAX_FREG_ARGS) * POINTER_SIZE;
STR(kRegParam64s[i], IMMEDIATE_OFFSET(FP, offset));
}
#ifndef __NO_FLONUM
for (int i = fparam_count; i < MAX_FREG_ARGS; ++i) {
int offset = (i - MAX_FREG_ARGS) * POINTER_SIZE;
STR(kFRegParam64s[i], IMMEDIATE_OFFSET(FP, offset));
}
#endif
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/cc/arch/x64/emit_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ static void move_params_to_assigned(Function *func) {
int offset = (i - MAX_REG_ARGS - MAX_FREG_ARGS) * POINTER_SIZE;
MOV(kRegParam64s[i], OFFSET_INDIRECT(offset, RBP, NULL, 1));
}
#ifndef __NO_FLONUM
for (int i = fparam_count; i < MAX_FREG_ARGS; ++i) {
int offset = (i - MAX_FREG_ARGS) * POINTER_SIZE;
MOVSD(kFRegParam64s[i], OFFSET_INDIRECT(offset, RBP, NULL, 1));
}
#endif
}
}

Expand Down

0 comments on commit 14ce518

Please sign in to comment.