Data Addressing

In absolute addressing, the compiler generates two instructions to fetch the address of a variable. For example the compiler translates Source Code into the instructions in Generated Code.

Listing 1. Source Code
int red;
int redsky;
void sky()
{
  red = 1;
  redsky = 2;
}
Listing 2. Generated Code
li   r3,1
lis  r4,red@ha
addi r4,r4,red@l
stw  r3,0(r4)
li   r5,2
lis  r6,redsky@ha
addi r6,r6,redsky@l
stw  r5,0(r6)

Each variable access takes two instructions and a total of four bytes to make a simple assignment. If you set the small data threshold to be at least the size of an int data type, the compiler generates instructions to fetch variables with one instruction ( Fetching variables with one instruction).

Listing 3. Fetching variables with one instruction
li   r3,1
stw  r3,red
li   r4,2
stw  r4,redsky

Because small data sections are limited in size you might not be able to put all of your application data into the small data and small data2 sections. We recommend that you make the threshold as high as possible until the linker reports that you have exceeded the size of the section.

If you do exceed the available small data space, consider using pooled data.

Because the linker can not deadstrip unused pooled data, you should:

  1. Check the Generate Link Map and List Unused Objects checkboxes in the CodeWarrior IDE's EPPC Linker Properties > C/C++ Build > Settings > Tool Settings > PowerPC Linker -> Output panel.
  2. Link and examine the map for data objects that are reported unused.
  3. Delete or comment out those used definitions in your source.
  4. Select Properties > C/C++ Build > Settings > Tool Settings > PowerPC Compiler > Processor, check Check the Pool Data checkbox.

The code in Zero Small Data Threshold has a zero small data threshold.

Listing 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 two-instruction 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.
Related information
ABI Conformance
Data Representation
Aligning Data
Small Data Area PIC/PID Support
Variable Length Encoding
Building a ROM Image
Embedded C++