Author Topic: Stack Alignment Without Stack Frame in 64-bit ABI  (Read 664 times)

johnsa

  • Member
  • ***
  • Posts: 437
    • Uasm
Re: Stack Alignment Without Stack Frame in 64-bit ABI
« Reply #15 on: April 10, 2017, 06:37:48 AM »
I've made a change to hjwasm (for the next update) to set stackbase:rbp as the default when nothing is specified. It's technically required, but shouldn't accidentally cause things to go off if omitted.
I've also put an option in to optimise the amount of stack used with win64:15 / stackbase:rsp but in all cases things will be aligned as planned.


nidud

  • Member
  • *****
  • Posts: 1265
    • https://github.com/nidud/asmc
Re: Stack Alignment Without Stack Frame in 64-bit ABI
« Reply #16 on: April 10, 2017, 06:52:02 AM »
l1: 16
l2: 64   - xmmword: should be >= 16
l3: 16
l4: 16   - ymmword: should be >= 32
l5: 16

nidud

  • Member
  • *****
  • Posts: 1265
    • https://github.com/nidud/asmc
Re: Stack Alignment Without Stack Frame in 64-bit ABI
« Reply #17 on: April 10, 2017, 07:04:14 AM »
Come to think of it this should probably also apply to 32-bit. Maybe 16-bit as well.

option alignlocals:[on|off]

johnsa

  • Member
  • ***
  • Posts: 437
    • Uasm
Re: Stack Alignment Without Stack Frame in 64-bit ABI
« Reply #18 on: April 10, 2017, 08:26:14 AM »
Come to think of it this should probably also apply to 32-bit. Maybe 16-bit as well.

option alignlocals:[on|off]

32 and 64 would still be correct, you're checking the alignment with bsf, so if something is aligned 64 doesn't preclude 16.. that's just by virtue of the fact that cyclic aligns to 16 will eventually be aligned to a > power 2. I'm not bothering to align 32 for ymmword, as the OS doesn't give you a 32byte aligned stack on entry, or at least it's not guaranteed. C/C++ use movups to refer to ymm locals so I'll do the same for now (until we get guaranteed 32byte entry alignment). You can manually compensate on entry into an asm app, but if you were making a library and using it from HLL without that, assuming ymm locals are aligned will probably not work ?

nidud

  • Member
  • *****
  • Posts: 1265
    • https://github.com/nidud/asmc
Re: Stack Alignment Without Stack Frame in 64-bit ABI
« Reply #19 on: April 10, 2017, 09:04:25 AM »
True, you have to apply code to achieve that so just rounding it up wont work.

habran

  • Member
  • ****
  • Posts: 985
    • uasm
Re: Stack Alignment Without Stack Frame in 64-bit ABI
« Reply #20 on: April 10, 2017, 09:48:41 AM »
here is an interesting explanation about AVX alignment requirement.
« Last Edit: April 10, 2017, 11:37:37 AM by habran »
Cod-Father

coder

  • Member
  • **
  • Posts: 93
Re: Stack Alignment Without Stack Frame in 64-bit ABI
« Reply #21 on: April 10, 2017, 11:21:03 AM »
Come to think of it this should probably also apply to 32-bit. Maybe 16-bit as well.

option alignlocals:[on|off]

32 and 64 would still be correct, you're checking the alignment with bsf, so if something is aligned 64 doesn't preclude 16.. that's just by virtue of the fact that cyclic aligns to 16 will eventually be aligned to a > power 2. I'm not bothering to align 32 for ymmword, as the OS doesn't give you a 32byte aligned stack on entry, or at least it's not guaranteed. C/C++ use movups to refer to ymm locals so I'll do the same for now (until we get guaranteed 32byte entry alignment). You can manually compensate on entry into an asm app, but if you were making a library and using it from HLL without that, assuming ymm locals are aligned will probably not work ?

Why bother bro? AVX don't take alignment too seriously anyway. HJWASM should just stick to the ABI requirements as specified, for now. Since M$ never stated that their ABI is closed-ended, it is highly likely that they would, in the future introduce the 32-byte or even 64-bytes extensions to the current ABI. Then you can put the finishing touch to HJWASM once and for all. 

coder

  • Member
  • **
  • Posts: 93
Re: Stack Alignment Without Stack Frame in 64-bit ABI
« Reply #22 on: April 10, 2017, 11:39:58 AM »
here is an interesting explanation about AVX alignment requirement.

My thoughts exactly!