Getting the most out of -qdatalocal
You can see some examples that illustrate the use of the -qdatalocal option.
In the source for the following program file, A1 and A2 are global variables:
int A1;
int A2;
int main(){
A2=A1+1;
return A2;
}
Here is an excerpt of the listing file that is created if you specify -qlist without -qdatalocal:
| 000000 PDEF main
4| PROC
5| 000000 lwz 80620004 1 L4A gr3=.A1(gr2,0)
5| 000004 lwz 80630000 1 L4A gr3=A1(gr3,0)
5| 000008 addi 38630001 1 AI gr3=gr3,1
5| 00000C lwz 80820008 1 L4A gr4=.A2(gr2,0)
5| 000010 stw 90640000 1 ST4A A2(gr4,0)=gr3
Here is an excerpt of the listing file that is created if you specify -qlist with -qdatalocal:
| 000000 PDEF main
4| PROC
5| 000000 lwz 80620004 1 L4A gr3=A1(gr2,0)
5| 000004 addi 38630001 1 AI gr3=gr3,1
5| 000008 stw 90620008 1 ST4A A2(gr2,0)=gr3
When you specify -qdatalocal, the data is accessed by a single load instruction because the A1 and A2 variables are embedded in the TOC. When you do not specify -qdatalocal, A1 and A2 variables are accessed by two load instructions. In this example, you can use -qdatalocal=A1:A2 to specify local variables individually.
You can always see the >>>>> OPTIONS SECTION <<<<< of the .lst file that is created by -qlist to confirm the use of these options. For example, you can view DATALOCAL=<variables> or DATALOCAL when the option is specified.
- On 64-bit Linux, TOC entries are pointer size. When you specify -qdatalocal without arguments, the option is ignored for
variables that are larger than the pointer size. Conversely, data
smaller than pointer size is word-aligned. See the following example
of an objdump excerpt that shows when a char
(r3) is marked local. The offset between the byte and the
next data (r4) is still 4 bytes. The data is accessed
by a load byte instruction instead of a regular load.
10000380: 88 62 00 20 lbz r3,32(r2) 10000384: 80 82 00 24 l r4,36(r2) r2 (base address of the TOC), r3 (char), r4 (int)
- If you specify an unsuitable variable as a parameter to -qdatalocal, -qdatalocal is ignored. Unsuitable variables can be data that exceeds pointer-size bytes or variables that do not exist. When you specify -qdatalocal for a variable that is not a TOC candidate, the storage for that variable defaults to -qdataimported and the variable is not stored in the TOC.
- You must use the mangled names when you specify local variables. Otherwise, you might encounter an error message.
- Mark variables as local with care. If you specify -qdatalocal without any arguments, expect all global variables to be candidates for TOC direct placement, even those variables that are marked as external. Variables with static linkage do not have the same issues.
- Since each TOC structure is unique to a module or shared library, the utility of the -qdatalocal option is limited to data within that module or shared library.
- For programs with multiple modules, switching between multiple TOC structures might dilute the speedup that is associated with this option.