Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#39 x64: alignment for Local variables

open
nobody
None
5
2013-11-08
2012-09-24
qWord
No

Hello,
What would you think about an alignment option for Local variables (x64, FASTCALL)?
This would be very useful in context to SSEx instructions that requires aligned memory.
e.g.
LOCAL myXmmWord::XMMWORD ; :: = align

Regards, qWord

Discussion

  • qWord
    qWord
    2012-09-24

    Supplement: a new bit for the option win64 is maybe more practical than an syntax extension.

     
  • japheth
    japheth
    2012-09-25

    the syntax extension looks rather hackish to me. OPTION WIN64 would be no problem, but this feature isn't useful for Win64 only. Probably the best is a new OPTION STACKALIGN.

     
  • qWord
    qWord
    2012-09-25

    OPTION STACKALIGN sound good :-D
    Would that option align according to the type's size? For arrays it can also be useful to have a grater alignment than the size of the elements (e.g. for copying the array).

    Regards, qWord

     
  • japheth
    japheth
    2013-11-07

    Automatic 16-byte alignment of stack variables will be implemented in next release.

    I choose OPTION WIN64:4 to activate this feature - despite the consideration that this feature might be also useful for non-win64 systems.

    There's a Win32 test version of jwasm available that you can try: http://www.japheth.de/Download/JWasm/JWasm212bw.zip

     
    Last edit: japheth 2013-11-07
  • qWord
    qWord
    2013-11-07

    Great, you've found a good solution by coupling the local's size with the alignment.
    There is only one thing that makes me currently a bit worried and is probably subject for the documentation: under which conditions does the option applies. What I've found is that it works for automatic generated frames (option frame:auto) or if at least one of the other win64 options is used. But it seem to not work for 'plain' PROCs (no FRAME keyword, win64:4).

    Also, in this context, I want to mention that it may be useful to have equates/symbols to read out the current option-settings.

    regards, qWord

    EDIT: the test procedure that fails:

    JWASM_STORE_REGISTER_ARGUMENTS EQU 1
    JWASM_STACK_SPACE_RESERVATION EQU 2
    JWASM_ALIGN16_STACK_VARIABLES EQU 4
    option frame:auto
    option win64: JWASM_ALIGN16_STACK_VARIABLES

    foo proc fo:DWORD
    LOCAL q:XMMWORD
    LOCAL x:DWORD
    LOCAL y:DWORD
    LOCAL r:XMMWORD

    movaps r,xmm0
    mov y,1
    mov x,2
    movaps q,xmm0
    
    xor eax,eax
    ret
    

    foo endp

     
    Last edit: qWord 2013-11-07
  • japheth
    japheth
    2013-11-08

    AFAICS it works for frame procs if frame:auto is set OR if option win64:2 is set. IOW, it works for those procedures where the registers in the USES clause are saved ABOVE the local variables.

    Looks not very consistent at first glance, but the remaining cases are those that are also supported by ML64 - and thus jwasm can sustain Masm-compatibility.

     
    Last edit: japheth 2013-11-08