pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
To ensure good performance, use REFALIGNED(2) to access the field, even if it happens to be
well-aligned. Always use REFALIGNED(2) unless you are certain that nearly all fields referenced
by the pointer are well-aligned.
Example 77 REFALIGNED(2)
WADDR a_str;
STRUCT s_templ(*) FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2;
INT(32) j;
END;
STRUCT s(s_templ);
PROC p(struct_addr, p1);
WADDR struct_addr;
INT .p1(s_templ); ! Use template for structure definition
BEGIN
INT .p2(s); ! Reference compiler-allocated structure with
! SHARED8 alignment
INT .p3(s_templ) REFALIGNED(2) = p2; ! Equivalence p3 to p2
INT .p4(s_templ) REFALIGNED(2) := struct_addr;
! Use template but use address passed as parameter
INT .p5(s_templ) REFALIGNED(2) := a_str;
! Use template but address stored in globals
@p2 := @s; ! Ensure p2 is well-aligned
a := p1.i; ! Might incur significant overhead if p1.i is not
! well-aligned. See REFALIGNED(8) (page 136)
a := p2.i; ! Optimal code: p2 references s which is known to
! be well-aligned
a := p3.i; ! Suboptimal access
a := p4.i; ! Suboptimal access
a := p5.i; ! Suboptimal access
END;
The field alignment of s_templ is SHARED8. Pointers p1, p3, p4, and p5 use s_templ to define
the layout of the structures they reference. p2 uses the global definition structure s to define its
layout.
The field alignment of s and s_templ is SHARED8. Because the declaration of p1 does not specify
a REFALIGNED clause, the statement a := p1.i might cause performance degradation. See
REFALIGNED(8) (page 136). The pointers p3, p4, and p5 specify REFALIGNED(2). Compared to
p1, references to p3, p4, and p5 will have somewhat degraded performance when the fields they
reference are well-aligned. When the fields they reference are not well-aligned, references to p1
will have significantly degraded performance compared p3, p4, or p5.
REFALIGNED(8)
When the reference alignment specified for a structure pointer is 8, the code generated by pTAL
for each reference to the pointer assumes that the base of the structure and the fields in the structure
are well-aligned in memory. If the field alignment of a structure is SHARED8—or is declared AUTO
and the program is compiled by pTAL to run on RISC and Itanium architecture—and the base of
the structure is well-aligned, references to the pointer will execute with optimal performance in both
pTAL and TAL.
If a structure pointer specifies REFALIGNED(8) or inherits its reference alignment from a SHARED8
structure, but the base of the structure is not well-aligned, your program might run significantly
slower than you anticipate. You will observe significantly degraded performance if your
REFALIGNED(8) pointer references a structure field that is not, in fact, well-aligned. Each such
reference in your program will cause a trap to the millicode exception handler, which accesses
the field your program is referencing and then returns to your program. Your program’s behavior
is not affected by having to access the field from the exception handler except that its performance
for each such trap is significantly degraded.
pTAL generates conservative code for references to a pointer that specifies REFALIGNED(8) if it
detects that a trap would occur if it generated optimal code.
136 Structures