flat assembler
Message board for the users of flat assembler.
Index
> Linux > Alignment in Fasm, and using the Align directive |
Author |
|
revolution 14 Jun 2010, 04:33
If you are using message string then performance should be the last of your concerns. And aligning your "program" on a 4-byte boundary does not really make sense. The x86 opcodes have variable alignment so aligning any code, except the start of a procedure, will have no effect.
If your strings are bytes then no alignment is needed. If they are words (like in unicode) then you might like to use word alignment, but it is not needed, just tidier. |
|||
14 Jun 2010, 04:33 |
|
mudge 14 Jun 2010, 04:46
Thanks. When and why would the start of a procedure be aligned? Or do you mean that aligning the start of a procedure would have an effect until the procedure encountered an instruction that wasn't a multiple of 4?
What do you mean by message string? I define the messages in my program like this: usage db 'This program takes 2 arguments',0xA,0 Is this what you mean by message string? So it makes sense to align data, like in a data segment. But it doesn't make sense to align code because the instructions are variable length anyway? |
|||
14 Jun 2010, 04:46 |
|
revolution 14 Jun 2010, 04:55
mudge wrote: Thanks. When and why would the start of a procedure be aligned? Or do you mean that aligning the start of a procedure would have an effect until the procedure encountered an instruction that wasn't a multiple of 4? mudge wrote: So it makes sense to align data, like in a data segment. But it doesn't make sense to align code because the instructions are variable length anyway? Aligning code: Doesn't hurt, but mostly pointless except for some very exotic situations. |
|||
14 Jun 2010, 04:55 |
|
bzdashek 25 Mar 2012, 05:43
Why would someone need alignment? I'm inexperienced.
|
|||
25 Mar 2012, 05:43 |
|
gunblade 25 Mar 2012, 11:01
The main reason I can think of is for SIMD instructions like SSE's movaps (and probably others). Also some of the FPU instructions require aligned memory..
http://flatassembler.net/docs.php?article=manual The manual above mentions some of the instructions that require aligned memory. Normally, its SSE instructions, and normally its aligned to 16 bytes. For example: Quote:
This is not just a performance enhancement. its a requirement, if you try to execute those instructions on memory locations which are not aligned to 16 bytes, they WILL fail. As far as I know, no "standard" instruction REQUIRES alignment, only the extended sets like FPU, MMX, SSE, etc require it.. However you may be able to improve performance (whether you use SSE or not) by aligning data correctly. Here's a good article by intel on the subject: http://software.intel.com/en-us/articles/data-alignment-when-migrating-to-64-bit-intel-architecture/ Might also be worth grabbing a copy of the Intel Software Development Manual (if you dont already have it), as that will most likely mention alignment, or more specifically, grab the Optimization manual available on this page: http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-optimization-manual.html That mentions both Code alignment and Memory alignment (page 3-12 and page 3-61 respectively). |
|||
25 Mar 2012, 11:01 |
|
bzdashek 25 Mar 2012, 21:12
gunblade wrote: The main reason I can think of is for SIMD instructions like SSE's movaps (and probably others). Also some of the FPU instructions require aligned memory.. Wow! Thanks for such a detailed answer! |
|||
25 Mar 2012, 21:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.