From b481c11e5a7eb409c76f56873d6378e7ff1e3e05 Mon Sep 17 00:00:00 2001 From: Anthony Green Date: Fri, 20 Dec 2019 09:00:26 -0500 Subject: [PATCH] Optimize setjmp/longjmp for moxie. We don't need to save/restore every register -- just those we don't expect to be trashed by function calls. --- newlib/libc/include/machine/setjmp.h | 2 +- newlib/libc/machine/moxie/setjmp.S | 124 ++++++++------------------- 2 files changed, 39 insertions(+), 87 deletions(-) diff --git a/newlib/libc/include/machine/setjmp.h b/newlib/libc/include/machine/setjmp.h index 78a81b5d9..55152b0d7 100644 --- a/newlib/libc/include/machine/setjmp.h +++ b/newlib/libc/include/machine/setjmp.h @@ -238,7 +238,7 @@ _BEGIN_STD_C #endif #ifdef __moxie__ -#define _JBLEN 19 +#define _JBLEN 10 #endif #ifdef __CRX__ diff --git a/newlib/libc/machine/moxie/setjmp.S b/newlib/libc/machine/moxie/setjmp.S index ed261d54d..014368d64 100644 --- a/newlib/libc/machine/moxie/setjmp.S +++ b/newlib/libc/machine/moxie/setjmp.S @@ -14,53 +14,34 @@ # setjmp/longjmp for moxie. The jmpbuf looks like this: # # Register jmpbuf offset -# $r0 0x00 -# $r1 0x04 -# $r2 0x08 -# $r3 0x0c -# $r4 0x10 -# $r5 0x14 -# $r6 0x18 -# $r7 0x1c -# $r8 0x20 -# $r9 0x24 -# $r10 0x28 -# $r11 0x2c -# $r12 0x30 -# $r13 0x34 -# $fp 0x38 -# $sp 0x3c -# stack frame fp 0x40 -# stack frame ra 0x44 -# stack frame sc 0x48 +# $r6 0x00 +# $r7 0x04 +# $r8 0x08 +# $r9 0x0c +# $r10 0x10 +# $fp 0x14 +# $sp 0x18 +# stack frame fp 0x1c +# stack frame ra 0x20 +# stack frame sc 0x25 .text .global setjmp .type setjmp,@function setjmp: - st.l ($r0), $r0 - sto.l 0x04($r0), $r1 - sto.l 0x08($r0), $r2 - sto.l 0x0c($r0), $r3 - sto.l 0x10($r0), $r4 - sto.l 0x14($r0), $r5 - sto.l 0x18($r0), $r6 - sto.l 0x1c($r0), $r7 - sto.l 0x20($r0), $r8 - sto.l 0x24($r0), $r9 - sto.l 0x28($r0), $r10 - sto.l 0x2c($r0), $r11 - sto.l 0x30($r0), $r12 - sto.l 0x34($r0), $r13 - sto.l 0x38($r0), $sp - sto.l 0x3c($r0), $fp - ldo.l $r1, 0x0($fp) - sto.l 0x40($r0), $r1 + st.l ($r0), $r6 + sto.l 0x04($r0), $r7 + sto.l 0x08($r0), $r8 + sto.l 0x0c($r0), $r9 + sto.l 0x10($r0), $r10 + sto.l 0x14($r0), $sp + sto.l 0x18($r0), $fp + ldo.l $r1, 0x00($fp) + sto.l 0x1c($r0), $r1 ldo.l $r1, 0x04($fp) - sto.l 0x44($r0), $r1 + sto.l 0x20($r0), $r1 ldo.l $r1, 0x08($fp) - sto.l 0x48($r0), $r1 - ldo.l $r1, 0x04($r0) + sto.l 0x24($r0), $r1 xor $r0, $r0 ret .Lend1: @@ -69,56 +50,27 @@ setjmp: .global longjmp .type longjmp,@function longjmp: - ldi.l $r2, 0x00 - cmp $r1, $r2 - beq .Lreturn1 + ldo.l $r6, 0x00($r0) + ldo.l $r7, 0x04($r0) + ldo.l $r8, 0x08($r0) + ldo.l $r9, 0x0c($r0) + ldo.l $r10, 0x10($r0) + ldo.l $sp, 0x14($r0) + ldo.l $fp, 0x18($r0) + ldo.l $r2, 0x1c($r0) + sto.l 0x0($fp), $r2 + ldo.l $r2, 0x20($r0) + sto.l 0x4($fp), $r2 + ldo.l $r2, 0x24($r0) + sto.l 0x8($fp), $r2 ldo.l $r2, 0x08($r0) - ldo.l $r3, 0x0c($r0) - ldo.l $r4, 0x10($r0) - ldo.l $r5, 0x14($r0) - ldo.l $r6, 0x18($r0) - ldo.l $r7, 0x1c($r0) - ldo.l $r8, 0x20($r0) - ldo.l $r9, 0x24($r0) - ldo.l $r10, 0x28($r0) - ldo.l $r11, 0x2c($r0) - ldo.l $r12, 0x30($r0) - ldo.l $r13, 0x34($r0) - ldo.l $sp, 0x38($r0) - ldo.l $fp, 0x3c($r0) - ldo.l $r1, 0x40($r0) - sto.l 0x0($fp), $r1 - ldo.l $r1, 0x44($r0) - sto.l 0x4($fp), $r1 - ldo.l $r1, 0x48($r0) - sto.l 0x8($fp), $r1 - ldo.l $r1, 0x04($r0) mov $r0, $r1 + xor $r2, $r2 + cmp $r0, $r2 + beq .Lreturn1 ret .Lreturn1: - ldo.l $r1, 0x04($r0) - ldo.l $r2, 0x08($r0) - ldo.l $r3, 0x0c($r0) - ldo.l $r4, 0x10($r0) - ldo.l $r5, 0x14($r0) - ldo.l $r6, 0x18($r0) - ldo.l $r7, 0x1c($r0) - ldo.l $r8, 0x20($r0) - ldo.l $r9, 0x24($r0) - ldo.l $r10, 0x28($r0) - ldo.l $r11, 0x2c($r0) - ldo.l $r12, 0x30($r0) - ldo.l $r13, 0x34($r0) - ldo.l $sp, 0x38($r0) - ldo.l $fp, 0x3c($r0) - ldo.l $r1, 0x40($r0) - sto.l 0x0($fp), $r1 - ldo.l $r1, 0x44($r0) - sto.l 0x4($fp), $r1 - ldo.l $r1, 0x48($r0) - sto.l 0x8($fp), $r1 - ldo.l $r1, 0x04($r0) - ldi.l $r0, 0x01 + inc $r0, 1 ret .Lend2: .size longjmp,.Lend2-longjmp