pTAL Reference Manual (H06.08+)

Structures
HP pTAL Reference Manual523746-006
9-30
REFALIGNED(2)
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.
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.
Example 9-26. 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) on page 9-31
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;