pTAL Reference Manual (H06.08+)
Structures
HP pTAL Reference Manual—523746-006
9-4
Overview of Structure Alignment
Topics:
•
Overview of Structure Alignment on page 9-4
•
Structures Aligned at Odd-Byte Boundaries on page 9-5
Overview of Structure Alignment
The memory alignment of the fields of a structure is important to pTAL. A field that is
aligned for fastest access is said to be well-aligned. A field that is not aligned for
fastest access is said to be misaligned.
A structure is well-aligned if the address of the base of the structure in memory is a
multiple of its base alignment; otherwise, the structure is misaligned. If a structure is
misaligned, some or all of its fields will also be misaligned.
The layout of structures and the alignment options you specify affect the object code
generated by pTAL. If you specify that the fields of a structure are not well-aligned (by
specifying the FIELDALIGN clause with the SHARED2 parameter) pTAL generates
conservative code for each reference. Conservative code might require more
instructions to reference structure fields than references to well aligned fields.
Each structure declaration specifies whether pTAL generates fast code or conservative
code when your program references a field of the structure.
Fast code takes full advantage of the RISC and Itanium architectures and produces the
best performance, provided that the field being referenced is well-aligned. If the field is
misaligned, an exception occurs. Access to the misaligned field is handled by a
millicode exception handler that completes the access but at a significant performance
cost.
Conservative code is somewhat slower than fast code but does not cause exceptions
when it accesses misaligned data.
pTAL ensures that definition structures and referral structures are well-aligned;
however, if you declare a structure pointer and assign the address of a structure to it or
use a reference parameter to address structure data, the compiler cannot ensure that
the structure is well-aligned; therefore, when you declare a structure pointer, you can
specify what assumptions you want pTAL to make when it generates code to access
your data. You can specify a REFALIGNED clause (see REFALIGNED Clause on
page 9-28).
The overall guidelines for alignment for a native process are:
•
Accessing data in memory takes the least amount of time if the data is well-aligned
and either the compiler has allocated the data or you reference the data with a
pointer that specifies REFALIGNED(8). A data item is well-aligned if its byte
address is an integral multiple of its length. For example, an INT is well-aligned if it
begins at an even-byte address, an INT(32) at an address that is a multiple of four,
and so forth.










