pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

You can control how the compiler aligns a structure in memory and the fields of a structure
within a structure by using the FIELDALIGN clause or FIELDALIGN compiler directive.
Definition structure and template structure declarations can optionally include a FIELDALIGN
clause. You cannot specify a FIELDALIGN clause on a referral structure declaration.
If you declare a structure pointer and assign the address of a structure to it or use a reference
parameter to address structure data you can specify a REFALIGNED clause to ensure that the
structure is well-aligned.
Topics:
Overview of Structure Alignment (page 116)
Structures Aligned at Odd-Byte Boundaries (page 117)
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 (page 134)).
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.
Accessing data is somewhat slower if the data is not well-aligned and you reference the data
using a pointer that specifies REFALIGNED(2).
Accessing data is significantly slower if the data is not well-aligned, but pTAL generates code
that functions as if the data is well-aligned. In this case, your program traps to the millicode
exception handler, which completes the data access and returns to your program.
116 Structures