Aligning Data
The code in Listing 21-4 on page 356 has a zero small data threshold.
Listing 21-4. Zero Small Data Threshold
lis r3,...bss.0@ha addi r3,r3,...bss.0@l li r0,1 stw r0,0(r3) li r0,2 stw r0,4(r3)
When pooled data is implemented, the first used variable of either the
.data
,
.bss
or
.rodata
section gets a two-instruction fetch of the first variable in that section.
Subsequent fetches in that function use the register containing the already-loaded section address with a calculated offset.
NOTE
You can access small data in assembly files with the twoinstruction fetch used with large data, because any data on your board can be accessed as if it were large data. The opposite is not true; large data can never be accessed with small data relocations (the linker issues an error if you try to do so).
External declarations of empty arrays (for example, extern int red []
;) are always treated as if they were large data. If you know that the size of the array fits into a small data section, specify the size in the brackets.
21.4 Aligning Data
This section contains these topics:
•
Alignment Attribute Syntax
•
Aligning a Variable Declaration
•
Alignment in a Structure Definition
•
Typedef Declaration
•
Structure Member
•
Bitfields
21.4.1 Alignment Attribute Syntax
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
356 Freescale Semiconductor, Inc.
Chapter 21 Power Architecture Code Generation
Use
__attribute__ ((aligned(...))) directive to specify to the compiler on what memory boundary to store data objects. This directive specifies which multiple of bytes to store an object.
The format of this directive is
__attribute__ ((aligned(
x )) where x is a decimal number of a power of 2 from 1 to 8192.
21.4.2 Aligning a Variable Declaration
Use the alignment attribute to specify a variable's alignment. For example, the following variable declaration aligns
V1
on a 16-byte boundary.
int V1[4] __attribute__ ((aligned (16)));
The following variable declaration aligns
V2
on a 2-byte boundary.
int V2[4] __attribute__ ((aligned (2)));
21.4.3 Alignment in a Structure Definition
Use the alignment attribute to specify how instances of a structure should be aligned. You must specify a minimum alignment of at least 4 bytes for structures. Specifying a lower number might cause alignment exceptions at runtime.
For example, this definition aligns all definitions of struct S1
on an 8-byte boundary.
struct S1 { short f[3]; }
__attribute__ ((aligned (8)));
struct S1 s1;
The following definition aligns all definitions of struct S2
on a 4-byte boundary.
struct S2 { short f[3]; }
__attribute__ ((aligned (1)));
struct S2 s2;
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
Freescale Semiconductor, Inc.
357
Aligning Data
21.4.4 Structure Member
Use the alignment attribute to specify how to align a member in a structure.
For example, the following structure member definition aligns all definitions of struct S3 on an 8-byte boundary, where a
is at offset 0 and b
is at offset 8.
struct S3 {
char a;
int b __attribute__ ((aligned (8)));
};
struct S3 s3;
The following struct member definition aligns all definitions of struct S4
on a 4-byte boundary, where a
is at offset 0 and b
is at offset 4.
struct S4 {
char a;
int b __attribute__ ((aligned (2)));
};
struct S4 s4;
NOTE
Specifying
__attribute__ ((aligned (2)))
does not affect the alignment of
S4
because 2 is less than the natural alignment of int
.
21.4.5 Typedef Declaration
Use the alignment attribute to specify how objects of a specific type should be aligned.
For example, the following typedef declaration aligns all definitions of
T1
on an 8-byte boundary.
typedef int T1 __attribute__ ((aligned (8)));
T1 t1;
The following typedef declaration aligns all definitions of
T2
on an 1-byte boundary.
typedef int T2 __attribute__ ((aligned (1)));
T2 t2;
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
358 Freescale Semiconductor, Inc.