News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help with alignment

Started by indiocolifa, September 04, 2007, 11:44:07 PM

Previous topic - Next topic

indiocolifa

I'm developing a very small fractal drawing application.

This is the data I'm using:


; structure for complex numbers,
; fractal parameters and data defs
;
COMPLEX STRUCT
x REAL8 ?
y REAL8 ?
COMPLEX ENDS

COMPLEXRECT STRUCT
x1y1 COMPLEX <?>
x2y2 COMPLEX <?>
COMPLEXRECT EndS

FRACTALPARAMS STRUCT
       extent COMPLEXRECT << -2.5, 2.5>,<0.5,0.5>>
       bailout DWORD 10
       iter DWORD 256
FRACTALPARAMS EndS

.data
wndrect RECT <?>
params FRACTALPARAMS <>
_TWO REAL8 2.0


; colormap array

colormap COLORREF 00080808h, 00100830h, 00101080h, 002020FFh,
004040FFh, 008040E0h, 00C040C0h, 00FF00C0h,
00FF0880h, 00FF1040h, 00FF2010h, 00FF4000h,
00FF8000h, 00FFC000h, 00FFFF00h, 00000000h


I know what alignment is and what are the penalities for accesing unaligned data. But I want a very quick explanation on how to align the data above (specially the Structs) to a proper value. Should I align all to DWORD boundaries?

Thank you very much!

hutch--

Properly you should align data on the data SIZE or a larger multiple of that data size. As long as you use .486 or higher you can align up to 16 bytes which will do most things but may miss some of the later exotic data sizes.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

raymond

The very first variable you declare in your .data section will automatically be aligned to a page boundary. Since your structs are all multiples of 8 bytes, positioning all your variables related to those structs (and those declared as REAL8) at the top of your .data section will guarantee that they will ALL be properly aligned without any need to instruct the assembler about alignement.

Then declaring all your DWORD variables will guarantee that those will all be aligned on a DWORD boundary. I always declare byte variables as the very last ones in the .data section.

If you also declare variables in the .data? section, you may only be certain that the first variable will be aligned on a DWORD boundary, but not necessarily on a paragraph or page boundary.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

jdoe

Quote from: raymond on September 06, 2007, 12:31:44 AM

If you also declare variables in the .data? section, you may only be certain that the first variable will be aligned on a DWORD boundary, but not necessarily on a paragraph or page boundary.

Raymond



What is the difference between a page and a paragraph boundary. I'm not really good when it comes to the internal details of a computer as you see by my question.

:red


Rockoon

Paragraph boundary is 16 bytes
Page boundary is 4096 bytes under Win32 / NT / Vista

You can achieve paragraph alignment with no muss and no fuss ..

If you need better than that then you cannot take advantage of the windows PE loader to do the grunt work for you via the masm align directive. It is not technically possible under Win32 / NT / Vista because the PE loader simply doesnt offer better.

Also of note is cache line boundaries .. which are 64 bytes on most modern CPU's
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.