pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-32
REFALIGNED(8)
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) on page 11-32. 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, and 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 as a native process—and the base of the structure is well-aligned, references to
the pointer will execute with optimal performance in both TNS and native processes.
STRUCT s(s_templ); ! Template
PROC p(struct_addr, p1);
WADDR struct_addr;
INT .p1(s_templ); ! Use template
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
INT a;
@p2 := @s; ! Ensure p2 is well-aligned
a := p1.i; ! Might incur significant overhead if p1.i
! is not well-aligned --
! see REFALIGNED(8) on page 11-32
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;
Example 11-14. REFALIGNED(2) (page 2 of 2)