From 14ce51828f9181569b99f9bd06b91fa1782398b7 Mon Sep 17 00:00:00 2001 From: tyfkda Date: Tue, 28 May 2024 07:56:48 +0900 Subject: [PATCH] No flonum --- libsrc/misc/longjmp.c | 54 +++++++++++++++++++++++++-------- libsrc/misc/setjmp.c | 54 +++++++++++++++++++++++++-------- src/cc/arch/aarch64/emit_code.c | 2 ++ src/cc/arch/x64/emit_code.c | 2 ++ 4 files changed, 88 insertions(+), 24 deletions(-) diff --git a/libsrc/misc/longjmp.c b/libsrc/misc/longjmp.c index ee0d6c625..93c41b794 100644 --- a/libsrc/misc/longjmp.c +++ b/libsrc/misc/longjmp.c @@ -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" @@ -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" @@ -31,6 +37,15 @@ 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" @@ -38,10 +53,7 @@ void longjmp(jmp_buf env, int result) { "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" @@ -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" @@ -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" diff --git a/libsrc/misc/setjmp.c b/libsrc/misc/setjmp.c index 87a188cb1..bbfd44180 100644 --- a/libsrc/misc/setjmp.c +++ b/libsrc/misc/setjmp.c @@ -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" @@ -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" @@ -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" @@ -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 diff --git a/src/cc/arch/aarch64/emit_code.c b/src/cc/arch/aarch64/emit_code.c index 609fa3bc3..90503f894 100644 --- a/src/cc/arch/aarch64/emit_code.c +++ b/src/cc/arch/aarch64/emit_code.c @@ -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 } } diff --git a/src/cc/arch/x64/emit_code.c b/src/cc/arch/x64/emit_code.c index 27d5e3af0..88a71e26e 100644 --- a/src/cc/arch/x64/emit_code.c +++ b/src/cc/arch/x64/emit_code.c @@ -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 } }