pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-20
Using Field Alignment
pTAL requires you to explicitly declare filler items to optimally align a SHARED8
structure’s fields for native architecture. pTAL does not add filler automatically to
SHARED8 structures and reports a syntax error if you do not declare filler where a
structure requires it. The native compiler listing shows where each structure
requires filler. You must add filler:
°
Before a field if the field’s offset from the beginning of the structure is not an
integral multiple of the field’s width (see Table 5-1 on page 5-2)
°
If the total length of the structure or substructure would not be an integral
multiple of the structure or substructure’s widest field
°
If an UNSIGNED(1-16) field would otherwise cross an even-byte address
°
If an UNSIGNED(17-31) field would otherwise cross a four-byte address
The address type of pointers in a SHARED8 structure must be EXTADDR,
SGBADDR, or SGWADDR.
If the data type of a field in a SHARED8 structure is an address type, the type must
be EXTADDR, SGBADDR, or SGWADDR:
STRUCT s FIELDALIGN(SHARED8);
BEGIN
EXTADDR x; ! OK: EXTADDR field
INT .EXT i; ! OK: EXTADDR pointer
INT .SG j; ! OK: SGWADDR pointer
STRING .s; ! ERROR: BADDR pointer is invalid
END;
If a field in a SHARED8 structure is not well-aligned, you must explicitly declare filler to
force the field to be well-aligned, as in Example 11-3 on page 11-20.
The first filler item (FILLER 2) forces b to begin at a four-byte address. The second
filler item (FILLER 5) forces d to begin at an eight-byte address. The third filler item
(BIT_FILLER 11) forces h to begin at a four-byte address.
Example 11-3. Alignment of Fields
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT a; ! 0 a uses 2 bytes
FILLER 2; ! 2 Forces b to a 4-byte offset
INT(32) b; ! 4 b uses 4 bytes
STRING c [0:2]; ! 8 c uses 3 bytes
FILLER 5; ! 11 Forces d to an 8-byte offset
FIXED d; ! 16 d uses 8 bytes
INT(32) e[0:1]; ! 24 e uses 8 bytes
INT f; ! 32 f uses 2 bytes
UNSIGNED(5) g; ! 34 g uses 5 bits
BIT_FILLER 11; ! Forces h to a 4-byte offset
UNSIGNED(17) h; ! 36 h uses 2 bytes plus 1 bit
UNSIGNED(15) i; ! 38 i uses 15 bits
END; ! Total structure length: 40 bytes