News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

about data alignment in 64 bits

Started by felipe, May 29, 2019, 06:23:51 AM

Previous topic - Next topic

felipe

Is this accurate?=
QuoteAll data must be aligned on a "natural boundary". So a byte can be byte-aligned, a word should be 2-byte aligned, a dword should be 4-byte aligned, and a qword should be 8-byte aligned. A tword should also be qword aligned.

and then=
QuoteAs for strings, in accordance with the above rules, Unicode strings must be 2-byte aligned, whereas ANSI strings can be byte aligned.

Extracted from here:http://www.godevtool.com/GoasmHelp/64bits.htm

Please i will love to hear here about what that page/articule says about the structures aligments requierements, but i can't quote here all the text. Please comment about all those data alignments requierements if you can (including the structures)... :mrgreen:

Thanks for your help  :thup:


felipe

Ok seems like i already find the answer. According to microsoft docs this required alignments are only recommended to avoid performance losses. Here you can find that info from microsoft: https://docs.microsoft.com/es-es/cpp/build/x64-software-conventions?view=vs-2019#types-and-storage Please refere to the page of your language...  :icon_idea:

I'm starting to believe that i have already read that before  :rolleyes: But it's always good to refresh our memory  :tongue:

hutch--

In 32 bit it is a performance recommendation, in 64 bit data must be aligned with locals and memory addresses. 2 byte align is required for UNICODE and 1 byte alignment is automatic for byte data that can have any alignment when read or written at a byte level. If you are processing byte data in larger blocks, 4 byte align in 32 bit, 8 byte align in 64 bit.

felipe

what do you mean by "locals and memory addresses"? the stack and .data/.data? section respectively?

hutch--

Memory address = allocated memory, GlobalAlloc/HeapAlloc comes aligned but for some data sizes that are bigger that 4 or 8 bytes, you must align them yourself. Some SSE instructions require the data to be aligned to their native data size and will GP fault if not. Stack alignment is fine for 4 byte in 32 bit if you are using DWORD, WORD and BYTE but if you are using 64 bit or 128 bit sized data and use instructions that require native size alignment, you can get GP faults if they are not aligned.

jj2007

Quote from: hutch-- on May 29, 2019, 10:19:40 AM2 byte align is required for UNICODE

Is that documented? I made a quick test with non-aligned Unicode, it works fine.
txHi dw "H", "i", 0
db 0 ; unalign!
txHello dw "H", "e", "l", "l", "o", 0

jinvoke MessageBoxW, 0, addr txHello, addr txHi, MB_OK

felipe

I see. As often occurs with this complex processor architecture, things are not that simple. It's good to know about instructions that demand data aligment. Of course you have to know what you are doing when using this instructions and others too  :biggrin:. But more about this for me tomorrow since i have to go to the bed now... :tongue:

Raistlin

@hutch-- Hail master, I seem to remember you had a macro laying about to allocate memory
and align for the content data type ex. SSE, AVX impacted stuff. Would it still hold true for
MASM_64 bit implementations ? Sorry if I missed the plot completely .......
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

hutch--

With allocated memory the technique is reasonably simple. Allocate a block of memory + the length of the data items added on, then align the starting position at the next aligned interval and you have an array of aligned size that you require. Now the alignment can be just the data size but if you have unusual requirements where absolute speed matters, you can align at a 4k page boundary and while this may offend some, 4k on a 64 bit system is peanuts in terms of memory usage.

daydreamer

Raistlin,its easy to make such macros with AND ebx,0FFFFFFFFh -15 for SSE,-31 when you need align 32 on the registers that you use pointing to allocated data
its the same thing with 64bit registers start with max value it can hold and subtract with -15,-31 or whatever you need

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding