pTAL Conversion Guide

Pointers
pTAL Conversion Guide527302-002
10-40
REFALIGNED(2)
REFALIGNED(2)
If a pointer specifies REFALIGNED(2), pTAL emits conservative code each time you
reference the pointer.
For example, you might specify a REFALIGNED(8) compiler directive because you
know that most data will be allocated by the compiler and, therefore, will be well-
aligned. You might have a pointer, however, that accesses a data item in a record on a
heap. Because you cannot be certain that the data item will be well-aligned, you might
specify a REFALIGNED(2) clause when you declare the pointer.
Use REFALIGNED(2) unless most of the fields the pointer references are well-aligned.
Similarly, declare formal reference parameters REFALIGNED(2) if the actual parameter
could reference data for which memory was not allocated by the native compiler.
REFALIGNED(8)
If a pointer specifies REFALIGNED(8), pTAL emits fast code each time you reference
the pointer.
If a pointer specifies REFALIGNED(8) but references data that is not well-aligned, your
program might run significantly slower than you anticipate. For a native process, each
reference to the pointer will cause a trap to the native millicode exception handler,
which will access the data and return to your program. Your program’s behavior will not
be affected by the exception except that its performance will be significantly degraded.
If you specify REFALIGNED(8) on a pointer declaration but the pTAL detects that a
trap will occur if it generates code for REFALIGNED(8) access, it overrides the
reference alignment you specify and generates conservative code.
You might have a program whose data is not, in general, well-aligned for access on
native architecture, but which includes a loop in which it references data that is well-
aligned. You can specify REFALIGNED(2) as the program’s default reference
alignment, but specify REFALIGNED(8) for the pointer that references well-aligned
data.
Example 10-17. Nonstructure Pointer With REFALIGNED(2) Clause
?REFALIGNED(8) ! Specify efault
...
INT .a[0:99]; ! a is an indirect array
INT .p1 REFALIGNED(2); ! Compiler emits conservative code
! for each reference to p1
INT .p2; ! Compiler emits fast code
! for each reference to p2
@p1 := @a; ! p1 points to array a
@p2 := a-heap-addr;
p2 ':=' p1 FOR 100 ELEMENTS; ! Compiler emits fast code
! for each reference to a
! and conservative code
! for each reference to p