Nios® V Processor Software Developer Handbook

ID 743810
Date 2/14/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

6.13.4. Global Pointer Register

The global pointer register enables fast access to global data structures in Nios® V programs. The Nios® V compiler implements the global pointer, and determines which data structures to access with it. You do not need to do anything unless you want to change the default compiler behavior.

The global pointer register can access a single contiguous region of 64 KB. To avoid overflowing this region, the compiler only uses the global pointer with small global data structures. A data structure is considered “small” if its size is less than or equal to a specified threshold. By default, this threshold is 8 bytes.

The small data structures are allocated to the small global data sections, .sdata, .sdata2, .sbss, and .sbss2. The small global data sections are subsections of the .rwdata and .bss sections.

Figure 12. Small Global Data Sections

If the total size of the small global data structures is more than 8 KB, these data structures overflow the global pointer region. The linker produces an error message saying "Unable to reach <variable name> ... from the global pointer ... because the offset ... is out of the allowed range, -4096 to 4095."

The best solution is to use fewer global variables of size 8 bytes or less. Another solution is to place only the frequently used global variables inside the .sdata + .sbss.

When the size of the global variable is greater than 8 bytes, by default, it gets placed outside of the .sdata + .sbss, and takes longer to access it. You can improve space-time performance by placing only the frequently used global variables inside the .sdata + .sbss leaving space available to add global variables greater than 8 bytes; and by annotating the code to place these global variables inside the .sdata + .sbss.

Annotating the code is show in Advanced Placement Options.

For information about manipulating project settings, refer to HAL BSP Settings.