Optimizations with Respect to C Loop
Structures
Definition: Loop optimization is a technique used by the compiler to improve the
speed and efficiency of loops by reducing unnecessary instructions, memory accesses,
and execution time in ARM processors.
The main aim is:
• Faster execution
• Reduced CPU cycles
• Better register utilization
• Reduced branching overhead
1. Types of Loop Optimization
(a) Fixed Number of Iterations
A fixed iteration loop is a loop in which the number of repetitions is known before
execution starts.
Example:
for(int i=0; i<4; i++) { sum = sum + a[i]; }
Optimization: Compiler may remove loop counter checking, reduce branch instructions,
and use registers efficiently.
(b) Variable Number of Iterations
A variable iteration loop is a loop in which the number of repetitions depends on user
input or runtime values.
Example:
for(int i=0; i
(c) Loop Unrolling
Loop unrolling expands the loop body multiple times to reduce loop
control instructions and branching overhead.
2. Pointer Aliasing Optimization
Pointer aliasing occurs when two or more pointers point to the same
memory location. The restrict keyword is used to inform the compiler
that pointers do not overlap, allowing for aggressive optimization.
3. Structure Arrangement in ARM
Organizing structure members in memory reduces padding and improves
cache performance. Proper alignment ensures data is stored at memory
addresses that the processor can access faster.
4. Basic C Data Types Used in ARM
Data Type Definition
char Stores single character
short Stores small integers
int Stores integer values
long Stores large integers
float Stores decimal numbers
double Stores double precision decimal values
5. Checksum
Definition: Checksum is an error detection method in which all data
words are added together to verify data integrity during
transmission.
6. Function Calls in ARM
ARM uses registers for parameter passing and the Link Register (LR) to
store the return address. The BL (Branch with Link) instruction is
used for calls, and BX LR for returning.
7. Register Allocation in ARM
Register allocation assigns program variables to CPU registers to
reduce memory access. If registers are insufficient, Register Spilling
occurs, where variables are moved to stack memory.