Mercurial > pub > dyncall > dyncall
changeset 654:0079a8fa894e
- arm64 tweaks/cleanups for callbacks:
* using 32b less of stack space
* saved one instruction
* simplified
* cosmetics
author | Tassilo Philipp |
---|---|
date | Thu, 07 Mar 2024 18:01:54 +0100 |
parents | 0c8838766866 |
children | fe907488e235 |
files | dyncallback/dyncall_args_arm64.c dyncallback/dyncall_args_arm64_apple.c dyncallback/dyncall_callback_arm64.S |
diffstat | 3 files changed, 57 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/dyncallback/dyncall_args_arm64.c Thu Mar 07 17:42:13 2024 +0100 +++ b/dyncallback/dyncall_args_arm64.c Thu Mar 07 18:01:54 2024 +0100 @@ -34,46 +34,32 @@ struct DCArgs { /* buffers and stack-pointer: */ - uint64_t I[8]; DCFPU_t F[8]; uint64_t* sp; - + /* counters: */ int i; int f; - int s; - int reserved; }; -DClonglong dcbArgLongLong (DCArgs* p) -{ - if (p->i < 8) { - return p->I[p->i++]; - } else { - return *(p->sp)++; - } -} -DCdouble dcbArgDouble (DCArgs* p) { - return (p->f < 8) ? p->F[p->f++].d.value : * ( (double*) (p->sp++) ); -} -DCfloat dcbArgFloat (DCArgs* p) { - return (p->f < 8) ? p->F[p->f++].f.value : * ( (float*) (p->sp++) ); -} +DClonglong dcbArgLongLong (DCArgs* p) { return (p->i < 8) ? p->I[p->i++] : *(p->sp)++; } +DCdouble dcbArgDouble (DCArgs* p) { return (p->f < 8) ? p->F[p->f++].d.value : * ( (double*) (p->sp++) ); } +DCfloat dcbArgFloat (DCArgs* p) { return (p->f < 8) ? p->F[p->f++].f.value : * ( (float*) (p->sp++) ); } -DClong dcbArgLong (DCArgs* p) { return (DClong) dcbArgLongLong(p); } -DCint dcbArgInt (DCArgs* p) { return (DCint) dcbArgLongLong(p); } -DCshort dcbArgShort (DCArgs* p) { return (DCshort) dcbArgLongLong(p); } -DCchar dcbArgChar (DCArgs* p) { return (DCchar) dcbArgLongLong(p); } -DCbool dcbArgBool (DCArgs* p) { return dcbArgLongLong(p) & 0x1; } -DCpointer dcbArgPointer(DCArgs* p) { return (DCpointer) dcbArgLongLong(p); } +DClong dcbArgLong (DCArgs* p) { return (DClong) dcbArgLongLong(p); } +DCint dcbArgInt (DCArgs* p) { return (DCint) dcbArgLongLong(p); } +DCshort dcbArgShort (DCArgs* p) { return (DCshort) dcbArgLongLong(p); } +DCchar dcbArgChar (DCArgs* p) { return (DCchar) dcbArgLongLong(p); } +DCbool dcbArgBool (DCArgs* p) { return dcbArgLongLong(p) & 0x1; } +DCpointer dcbArgPointer (DCArgs* p) { return (DCpointer)dcbArgLongLong(p); } -DCuint dcbArgUInt (DCArgs* p) { return (DCuint) dcbArgInt(p); } -DCuchar dcbArgUChar (DCArgs* p) { return (DCuchar) dcbArgChar(p); } -DCushort dcbArgUShort (DCArgs* p) { return (DCushort) dcbArgShort(p); } -DCulong dcbArgULong (DCArgs* p) { return (DCulong) dcbArgLong(p); } -DCulonglong dcbArgULongLong(DCArgs* p) { return (DCulonglong) dcbArgLongLong(p); } +DCuint dcbArgUInt (DCArgs* p) { return (DCuint) dcbArgInt(p); } +DCuchar dcbArgUChar (DCArgs* p) { return (DCuchar) dcbArgChar(p); } +DCushort dcbArgUShort (DCArgs* p) { return (DCushort) dcbArgShort(p); } +DCulong dcbArgULong (DCArgs* p) { return (DCulong) dcbArgLong(p); } +DCulonglong dcbArgULongLong(DCArgs* p) { return (DCulonglong)dcbArgLongLong(p); } DCpointer dcbArgAggr (DCArgs* p, DCpointer target) { /* @@@AGGR not impl */ return NULL; } void dcbReturnAggr (DCArgs *args, DCValue *result, DCpointer ret) { /* @@@AGGR not impl */ }
--- a/dyncallback/dyncall_args_arm64_apple.c Thu Mar 07 17:42:13 2024 +0100 +++ b/dyncallback/dyncall_args_arm64_apple.c Thu Mar 07 18:01:54 2024 +0100 @@ -35,16 +35,13 @@ struct DCArgs { /* buffers and stack-pointer: */ - uint64_t I[8]; DCFPU_t F[8]; uint8_t* sp; - + /* counters: */ int i; int f; - int s; - int reserved; }; static inline uint8_t* align(uint8_t* p, size_t v) @@ -53,7 +50,7 @@ } -DClonglong dcbArgLongLong (DCArgs* p) +DClonglong dcbArgLongLong(DCArgs* p) { if (p->i < 8) { return p->I[p->i++]; @@ -65,8 +62,10 @@ return value; } } -DCdouble dcbArgDouble (DCArgs* p) { - if (p->f < 8) { + +DCdouble dcbArgDouble(DCArgs* p) +{ + if (p->f < 8) { return p->F[p->f++].d.value; } else { DCdouble value; @@ -76,7 +75,9 @@ return value; } } -DCfloat dcbArgFloat (DCArgs* p) { + +DCfloat dcbArgFloat(DCArgs* p) +{ if (p->f < 8) { return p->F[p->f++].f.value; } else { @@ -88,7 +89,8 @@ } } -DClong dcbArgLong (DCArgs* p) { +DClong dcbArgLong(DCArgs* p) +{ if (p->i < 8) { return (DClong) p->I[p->i++]; } else { @@ -100,7 +102,8 @@ } } -DCint dcbArgInt (DCArgs* p) { +DCint dcbArgInt(DCArgs* p) +{ if (p->i < 8) { return (DCint) p->I[p->i++]; } else { @@ -112,7 +115,8 @@ } } -DCshort dcbArgShort (DCArgs* p) { +DCshort dcbArgShort(DCArgs* p) +{ if (p->i < 8) { return (DCshort) p->I[p->i++]; } else { @@ -124,7 +128,8 @@ } } -DCchar dcbArgChar (DCArgs* p) { +DCchar dcbArgChar(DCArgs* p) +{ if (p->i < 8) { return (DCchar) p->I[p->i++]; } else { @@ -136,7 +141,8 @@ } } -DCbool dcbArgBool (DCArgs* p) { +DCbool dcbArgBool(DCArgs* p) +{ if (p->i < 8) { return (DCbool) p->I[p->i++]; } else { @@ -148,8 +154,8 @@ } } -DCpointer dcbArgPointer(DCArgs* p) { - return (DCpointer) dcbArgLongLong(p); +DCpointer dcbArgPointer(DCArgs* p) { + return (DCpointer) dcbArgLongLong(p); } DCuint dcbArgUInt (DCArgs* p) { return (DCuint) dcbArgInt(p); }
--- a/dyncallback/dyncall_callback_arm64.S Thu Mar 07 17:42:13 2024 +0100 +++ b/dyncallback/dyncall_callback_arm64.S Thu Mar 07 18:01:54 2024 +0100 @@ -45,17 +45,17 @@ x0..x7 ?? GP regs d0..d7 ?? FP/SIMD regs sp... ?? arguments on stack - + locals: type off size ---------|------|------ Frame 0 16 - DCArgs 16 168 - DCValue 184 16 - - size 200 - aligned 208 - + DCArgs 16 144 + DCValue 160 16 + + size 176 + aligned 176 + locals: x10: sp @@ -63,17 +63,17 @@ */ mov x10, sp - stp x29, x30, [sp, #-208 ]! + stp x29, x30, [sp, #-176 ]! mov x29, sp add x11, x29 , #16 -/* save integer registers */ +/* save registers */ stp x0, x1, [x11, #0 ] stp x2, x3, [x11, #16] stp x4, x5, [x11, #32] - stp x6, x7, [x11, #48] + stp x6, x7, [x11, #48] stp d0, d1, [x11, #64] stp d2, d3, [x11, #80] @@ -83,38 +83,30 @@ eor x12, x12, x12 stp x10,x12,[x11, #128] /* sp=sp, i=0, f=0 */ - str x12, [x11, #144] /* s=0, reserved=0 */ - + +/* call handler/callback */ -/* call handler: - args: - x0: DCCallback* pcb - x1: DCArgs* args - x2: DCValue* result - x3: void* userdata -*/ - - mov x0 , x9 - add x1 , x29 , #16 - add x2 , x29 , #184 - ldr x3 , [x9 , #40] + mov x0 , x9 /* DCCallback* pcb */ + add x1 , x29 , #16 /* DCArgs* args */ + add x2 , x29 , #160 /* DCValue* result */ + ldr x3 , [x9 , #40] /* void* userdata */ ldr x11, [x9 , #32] - blr x11 + blr x11 and w0, w0, #255 cmp w0, 'f' b.eq LABELUSE(retf) cmp w0, 'd' b.eq LABELUSE(retf) - + LABELDEF(reti) - ldr x0, [x29, #184] + ldr x0, [x29, #160] b LABELUSE(ret) LABELDEF(retf) - ldr d0, [x29, #184] + ldr d0, [x29, #160] LABELDEF(ret) - ldp x29, x30, [sp], #208 + ldp x29, x30, [sp], #176 ret