pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-19
Using Field Alignment
Example 11-2 on page 11-19 shows the byte offsets (in decimal) of each field in a
SHARED2 structure.
Using SHARED8 Field Alignment
Specify FIELDALIGN(SHARED8) for structures that:
°
Are accessed by processes running as both TNS processes and native
processes
°
Must have exactly the same layout when compiled with pTAL as they do when
compiled with TAL
°
You want to have optimal performance on native architecture
Note. If you include a FIELDALIGN(SHARED2) compiler directive, include a REFALIGNED(2)
compiler directive as well. The default for the REFALIGNED compiler directive is 8. With field
alignment SHARED2, pTAL can allocate a 32-bit or 64-bit field at any even-byte address. pTAL
generates optimal code for data references that use a pointer whose reference alignment is 8.
If the pointer is used to reference 32-bit or 64-bit data that is not well-aligned, each reference to
the data will be slow. By default, pTAL generates conservative code when you reference data
using a pointer that specifies REFALIGNED(2). The REFALIGNED(2) directive ensures that
pTAL generates conservative code for pointers that do not specify a REFALIGNED clause. For
example:
?FIELDALIGN( SHARED2 )
?REFALIGNED( 2 )
INT(32) .ptr; ! Global pointer Ptr
PROC p; ! Procedure P
BEGIN
@ptr := @str.F32; ! STR.F32 might or might not be aligned
! at a 32-bit address. The
.... := ptr + 3D; ! REFALIGNED directive ensures that
! pTAL generates conservative code
END; ! for references to PTR.
Example 11-2. Byte Offsets in SHARED2 Structure
STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT i; ! i begins at byte offset: 0
INT(32) j; ! j begins at byte offset: 2
STRING s1; ! s1 begins at byte offset: 6
UNSIGNED(3) u1; ! u1 begins at byte offset: 8
UNSIGNED(2) u2; ! u2 begins at byte offset: 8 + 3 bits
STRING s2; ! s2 begins at byte offset: 10
FIXED f; ! f begins at byte offset: 12
INT k; ! k begins at byte offset: 20
END;