Compiler Global Variable Address Offset Generation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
RISC architectures with fixed-length instructions face inefficiencies in loading 32-bit addresses into registers, requiring multiple instructions and hampering execution speed for programs with frequent memory accesses.
Innovation Solution
A compiler generates a global variable order list based on usage frequency and alignment to group variables likely to be on the same memory page, using a single instruction for the base address and offsets for other variables within the group, reducing the number of instructions needed to load addresses.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of manufacture
If fixed-length instructions are used in RISC architecture, then instruction fetching and parsing is simplified, but the ability to load large values (32-bit addresses) in a single operation is limited
Solution Approach 1:
The patent divides the address loading process into segments: the fixed-length instruction carries the upper portion of the address, and a subsequent instruction carries the lower portion. This segmentation allows the system to maintain fixed-length instructions while still achieving full 32-bit address loading capability.
Solution Approach 2:
The patent introduces a new dimension to address loading by using multiple instructions operating in sequence rather than attempting to fit the entire address in a single instruction. This transforms the problem from a spatial constraint (single instruction width) to a temporal solution (multiple instructions over time).
2Reliability
If multiple instructions are used to load 32-bit addresses, then full address capability is achieved, but execution speed is hampered by redundant instructions
Solution Approach 1:
The patent performs preliminary analysis during compilation to identify groups of global variables that are likely to be located on the same memory page. By pre-organizing variables into groups based on their usage patterns and proximity, the compiler can generate more efficient code that reduces the number of address loading operations needed at runtime.
Solution Approach 2:
The patent changes the parameter of address representation by introducing offset values relative to a base address. Instead of loading full 32-bit addresses for each global variable, the system loads a base address once and then uses smaller offset values to access individual variables, reducing the instruction count and improving execution speed.
3Productivity
If groups of global variables are aggregated based on memory page proximity, then fewer instructions are needed to load addresses, but compiler complexity increases
Solution Approach 1:
The patent replaces complex runtime address resolution mechanisms with a simpler compilation-time analysis approach. By using static analysis to determine variable grouping and offset calculation, the system eliminates the need for complex runtime address computation, achieving instruction reduction without excessive compiler complexity.
Data Source
AI summary
In order to reduce the number of instructions that the compiler generates to load the address of a global variable into a register, the compiler uses a technique that analyzes the global variables used in each function in order to estimate which global variables will be located within the same memory page and have a common base address. A base global variable is selected for each function whose address is fully resolved. The address of each subsequent global variable is constructed using an offset relative to the address of the base global variable that is based on the subsequent global variable's position in a global variable order list.


