2013年6月11日 星期二

Global Data Mechanism in RISC Architecture

Some architectures for which the size of their machine instructions cannot contain the full immediate absolute memory addresses as operands, use offsets from a certain base address held in a register to refer the memory addresses.

For such architectures, reference to global variables, functions and data is usually via a global table - ToC (Table of Contents). ToC is a table of offsets. The concept of ToC is very similar to GOT (global offset table) in ARM and X86 architecture. Both of they stores the offset of the global variables and functions. Compilers and linkers must know the start addresses of these tables to calculate the absolute address of the global variables and functions.

The difference between ToC and GOT is the mechanism to extract the absolute addresses. The architectures using GOT usually use a special symbol to hold the address of GOT. For each GOT entry, there is a corresponding dynamic relocation entry to tell loaders how to calculate the correct absolute address. Such architectures usually have a single, centralized GOT and loaders can easily access GOT via special segment.

However, the architectures using ToC usually have special purpose register to hold the address of ToC. The start address of ToC can be re-assigned at run time. This allows such architectures to have multiple ToCs in the same program and simplify the compiler implementation. However, assemblers or linkers thus have additional overhead during instruction relaxing.

In ARM architecture, constant pool (aka address pool) is another mechanism to access variables that is far away. ARM does not want to sacrifice a general-purpose register for holding the start address, so they do not have ToC. Moreover, the immediate operands in ARM are very small, the GOT would not be able to store much addresses. For these two reasons, ARM architecture stores addresses in between the code and extracts these addresses through PC-relative loads.

Reference

Gadi Haber, et al., "Optimization Opportunities Created by Global Data Reordering," 2003.
@inproceedings{Haber:2003:OOC:776261.776286,
 author = {Haber, Gadi and Klausner, Moshe and Eisenberg, Vadim and Mendelson, Bilha and Gurevich, Maxim},
 title = {Optimization opportunities created by global data reordering},
 booktitle = {Proceedings of the international symposium on Code generation and optimization: feedback-directed and runtime optimization},
 series = {CGO '03},
 year = {2003},
 isbn = {0-7695-1913-X},
 location = {San Francisco, California},
 pages = {228--237},
 numpages = {10},
 url = {http://dl.acm.org/citation.cfm?id=776261.776286},
 acmid = {776286},
 publisher = {IEEE Computer Society},
 address = {Washington, DC, USA},
} 

沒有留言:

張貼留言