pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-36
pTAL Code Generation for Structure References
In Example 11-17 on page 11-35:
Because s1 specifies SHARED2 field alignment, pTAL generates conservative
code that ensures that an exception does not occur when you reference s1.s2.j.
p2 refers to t_s8, a SHARED8 substructure. p2 specifies a reference alignment of
2, which ensures that pTAL generates conservative code that will not cause
exceptions for misaligned memory references.
p3 does not have a REFALIGNED clause. Its reference alignment, therefore,
defaults to the field alignment of its referent, which is t_s8, which has SHARED8
field alignment. pTAL generates fast code for each reference to p3.j.
The formal parameter specification for a structure pointer must declare reference
alignment 2 unless you are certain that all pointers passed to the parameter reference
SHARED8 structures that you know are well-aligned. If you are not certain that all
references are well-aligned, use the same approach as that shown earlier to ensure
that references to structures passed as actual parameters do not cause a trap:
PROC p1a(sp);
INT .sp(t_s8) REFALIGNED(2);
BEGIN
...
END;
When you design routines that return addresses to their callers, you must, whenever
possible, return addresses that are well-aligned.
The native compiler always generates conservative code. References to s3.s4.j do
not cause traps because, although s3 is SHARED8, the offset of s3.s4.j is not a
multiple of 4. For each reference pTAL determines whether the referenced field is well-
aligned. References to fields in s4 using the pointer p4—for example, p4.j—do not
cause traps because the field alignment of s4 is SHARED2 and the compiler
generates conservative code for such references.
Example 11-18. SHARED2 Substructure in a SHARED8 Structure
STRUCT s3 FIELDALIGN(SHARED8);
BEGIN ! Base alignment of s3 is 4
INT i;
STRUCT s4(t_s2); ! s2 has SHARED8 alignment
END; ! Base alignment of s2 is 4
INT .p4(t_s2); ! Uses default alignment: 2
Example 11-19. Fast Code and Conservative Code (page 1 of 2)
STRUCT s3_shared2(*) FIELDALIGN(SHARED2);
BEGIN
INT(32) j;
INT l;
INT(32) m;
END;