Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.asm.x86    |    Ahh, the lost art of x86 assembly    |    4,675 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 2,975 of 4,675    |
|    Andrew Cooper to Alex    |
|    Re: 64 bit stack alignment    |
|    30 Aug 17 00:35:10    |
      From: amc96@nospicedham.cam.ac.uk              On 29/08/2017 16:07, Alex wrote:       > On 64 bit Windows, stack alignment on a 16 byte boundary is required       > before calling all except a leaf function. In the called function, the       > stack is 8 mod 16.       >       > Now, I'm struggling to come up with a way of doing it beyond this code       > (which I didn't invent, but I can't for the life of me remember where I       > found it.)       >       > push rsp       > push [rsp]       > and spl $F0       > call funkychicken       > pop rsp       >       > It seems to be the only way of doing this without branches, flags or       > other expensive nonsense. But, as ever, there may be a better way. Any       > suggestions?              Why is the stack 8 mod 16? That is the bug in this scenario.              If every function sets up an ABI compatible stack for its callees, all a       callee needs to do is ensure it pushes/adjusts the stack pointer by an       even number of words.              I see from other replies that you are doing this in some Forth situation       with multiple stacks, but at any point that you have the above scenario,       a higher caller has screwed up. Things will definitely go wrong when       you call into a C library, but also with any signal handler which       intends to use the red zone.              Your above code will function correctly, but has a performance hit,       because a direct write to the stack pointer interrupts stack-engine       optimisations in the pipeline for adjacent pushes/pops/calls/rets.       Also, writes to 8-bit registers suffer a merge penalty back into the       register file. `and $~0xf, %rsp` would be more efficient; It encodes in       the same number of bytes, but doesn't suffer from merging.              As a minor note, you should use `leave` rather than pop %rsp, as it       takes less instruction bandwidth to execute.              ~Andrew              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca