pTAL Conversion Guide

Data Allocation
pTAL Conversion Guide527302-002
5-4
Reference Alignment
The REFALIGNED clause has one parameter, which must be either 2 or 8. The
parameter specifies whether the compiler is to generate fast code (REFALIGNED(8))
or conservative code (REFALIGNED(2)). If you specify REFALIGNED(2), the native
compilers generate conservative code—code that accesses data that is aligned on any
two-byte boundary. Because four-byte and eight-byte data might not be aligned on
four-byte and eight-byte boundaries, respectively, the native compiler generates
conservative code for each such reference.
Specify REFALIGNED(2) if the data referenced by the pointer might not be well-
aligned. The alignment of data items longer than two bytes in a TNS process is not, in
general, compatible with the requirements for well-aligned data in a native process. For
data that might not be well-aligned in a native process, specify REFALIGNED(2).
REFALIGNED(2) is supported by both the TAL and native compilers.
REFALIGNED(8) specifies that the data referenced by the pointer will be well-aligned
in native memory and that the compiler can emit fast code wherever the pointer is
used. REFALIGNED(8) specifies that all data items that are eight bytes or less are
aligned on a boundary that is an integral multiple of their width; therefore, the compiler
generates fast code for data referenced by a pointer that specifies REFALIGNED(8).
The native compilers enforce REFALIGNED(8) . The TAL compiler, on the other hand,
recognizes the REFALIGNED clause, but always treats REFALIGNED as if you
specified REFALIGNED(2), regardless of the actual value of the parameter to the
REFALIGNED clause.
You determine whether the compiler is to emit fast code or conservative code for each
pointer you declare, either explicitly by using the REFALIGNED clause on the pointer
declaration, or implicitly by the reference alignment that you specify in the
REFALIGNED compiler directive.
For more information on the REFALIGNED compiler directive, see REFALIGNED on
page 19-25.
The default reference-alignment value is 8 for pTAL. TAL allocates all data as if you
specified reference-alignment 2, even if, in fact, you specify 8.
Example 5-1 on page 5-4 shows how the REFALIGNED directive and REFALIGNED
clause affect the code the native compiler generates. All pointers reference four
consecutive characters in a 10-byte string.
Example 5-1. Reference Alignment (page1of2)
?REFALIGNED(8)
INT(32) i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12;
STRING str[0:9] := ["ABCDEFGHIJ"];
INT(32) .p1; ! References to these pointers
INT(32) .p2; ! generate fast code because of
INT(32) .p3; ! REFALIGNED(8) directive
INT(32) .p4;