0% found this document useful (0 votes)
9 views32 pages

TEAM 04 EVALUTION 02 Ediv

The document discusses two compiler optimization techniques: register allocation and expression simplification. It provides an example of optimizing a C program to check if a number is prime by using register allocation. Register allocation assigns variables to processor registers to reduce memory accesses and improve performance. Expression simplification simplifies complex expressions into more efficient forms while maintaining semantics. Both techniques help generate more optimized machine code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views32 pages

TEAM 04 EVALUTION 02 Ediv

The document discusses two compiler optimization techniques: register allocation and expression simplification. It provides an example of optimizing a C program to check if a number is prime by using register allocation. Register allocation assigns variables to processor registers to reduce memory accesses and improve performance. Expression simplification simplifies complex expressions into more efficient forms while maintaining semantics. Both techniques help generate more optimized machine code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

ARM

IMPLEMENTATION ASSIGNMENT OPTIMIZATION TECHNIQUES

EVALUATION 02

ARM PROCESSOR AND APPLICATIONS 1


TEAM 04

​SL NO. NAME ROLL NO. USN

1 AKASH NAYAK 519 01FE21BEC263

2 ANIRUDH NAYAK 562 01FE21BEC154

PRABHANJAN
3 551 01FE21BEC359
KATTI

4 VINAYAK NAYAK 556 01FE21BEC305

ARM PROCESSOR AND APPLICATIONS 2


Optimization using REGISTER
ALLOCATION

Example code 1

Optimization using EXPRESSION


SIMPLIFICATION

AGENDA
Example code 2

ARM PROCESSOR AND APPLICATIONS 3


REGISTER ALLOCATION

• Register allocation, an essential optimization technique employed by compilers,


plays a pivotal role in assigning variables and temporary values to processor
registers instead of memory locations. By leveraging this technique, compilers can
unlock a range of benefits and optimize code execution across different domains.

• In addition to its impact on code execution speed, register allocation optimization


also helps reduce memory access operations. By utilizing registers for frequently
accessed variables, the need to fetch data from memory is minimized, resulting in
improved overall performance. This optimization technique effectively reduces
memory latency and bandwidth usage, leading to more efficient utilization of
system resources.

ARM PROCESSOR AND APPLICATIONS 4


EXAMPLE 1 : C PROGRAM TO CHECK IF A NUMBER IS PRIME
OR NOT
#include <stdio.h>
// Function to check if a number is prime
int isPrime(int num)
{
int i; // Declare variable i
if (num <= 1)
return 0; // Not a prime number if number is less than or equal to 1
for (int i = 2; i < num; i++)
{
if (num%i==0)
return 0;
}
return 1; // Prime number
}

ARM PROCESSOR AND APPLICATIONS 5


void main()
{
int num;
printf("Enter the number to be checked: ");// The number to check for prime or not
scanf("%d",&num);
if (isPrime(num))
printf("%d is a prime number.\n",num);
else
printf("%d is not a prime number.\n",num);
}

ARM PROCESSOR AND APPLICATIONS 6


EXAMPLE CODE 1

ARM PROCESSOR AND APPLICATIONS 7


EXECUTION

ARM PROCESSOR AND APPLICATIONS 8


EXAMPLE 1 : C PROGRAM TO CHECK IF A NUMBER IS PRIME
OR NOT[OPTIMIZED]
#include <stdio.h>
int isPrime(int num) // Register used for optimization

{
register int i asm("ecx"); // inline assembly
// The asm("ecx") part is an inline assembly instruction that informs the compiler to assign the register ecx to the variable i.
if (num <= 1)
{
return 0;
}
for (int i = 2; i < num; i++)
{
if (num % i == 0)
{
return 0;
}
}
}
ARM PROCESSOR AND APPLICATIONS 9
int main()
{
int num;
printf("Enter the number to be checked: ");
scanf("%d",&num);
if (isPrime(num))
{
printf("%d is a prime number.", num);
}
else
{
printf("%d is not a prime number.", num);
}
return 0;
}

ARM PROCESSOR AND APPLICATIONS 10


OPTIMIZED CODE 1

ARM PROCESSOR AND APPLICATIONS 11


EXECUTION

ARM PROCESSOR AND APPLICATIONS 12


CODE COMPARISON

CODE TIME SPACE LOGIC

USE OF REGISTER
CODE 1 2.265 s 8 bytes
INSTRUCTION

USE OF REGISTER
OPTIMIZED
2.077 s 8 bytes INSTRUCTION WITH
CODE 1
ECX REGISTER

ARM PROCESSOR AND APPLICATIONS 13


BENEFITS OF REGISTER ALLOCATION

• Enhanced Performance: Register allocation optimization speeds up program


execution by reducing memory accesses. Storing data in registers closer to the
processor enables faster retrieval and processing, resulting in improved overall
performance of the compiled code.

• Reduced Memory Operations: Efficient utilization of registers minimizes the


need for frequent memory operations such as loading and storing data. By
reducing memory traffic, register allocation optimizes code efficiency and reduces
the overall computational overhead.

• Optimized Data Locality: Register allocation ensures that frequently accessed


variables are stored in registers, improving data locality. By maximizing the usage
of registers, the optimization technique takes advantage of cache hierarchies and
minimizes cache misses, leading to improved program efficiency.
ARM PROCESSOR AND APPLICATIONS 14
BENEFITS OF REGISTER ALLOCATION

• Increased Parallelism: Assigning variables to registers enables the compiler to


exploit available parallelism. Independent operations can be executed
concurrently using different registers, allowing for better utilization of the
processor's parallel processing capabilities. This results in improved throughput
and enhanced execution speed.

• Code Size Reduction: Register allocation plays a role in reducing the size of
compiled code. By utilizing registers to store and access variables, register
allocation reduces the need for explicit memory access instructions in the
generated code. This leads to a smaller code footprint, which is advantageous in
resource-constrained environments or when optimizing for limited storage
capacity.

ARM PROCESSOR AND APPLICATIONS 15


APPLICATIONS OF REGISTER ALLOCATION

• Compiler Optimization: Register allocation is a critical aspect of compiler design, enabling


compilers to optimize the performance and efficiency of machine code generated for various
programming languages. By efficiently assigning variables to registers, compilers can produce
optimized code that executes faster and utilizes available hardware resources more effectively.

• High-Performance Computing (HPC): Register allocation plays a vital role in optimizing code
for HPC applications. It allows for the exploitation of parallel processing capabilities present in
modern processors, enabling efficient utilization of computational resources. By minimizing
memory operations and maximizing register usage, register allocation enhances the performance
of compute-intensive tasks in HPC environments.

• Embedded Systems Development: Register allocation is particularly significant in the


development of software for embedded systems with limited resources. By reducing memory
accesses, register allocation improves the performance and efficiency of code running on resource-
constrained devices. It helps maximize the utilization of available hardware capabilities and
ensures optimal execution of software in embedded applications.

ARM PROCESSOR AND APPLICATIONS 16


APPLICATIONS OF REGISTER ALLOCATION

• Just-in-Time (JIT) Compilation: Register allocation finds application in JIT


compilers, which dynamically compile and optimize code during runtime. JIT
compilers leverage register allocation to generate efficient machine code on-the-
fly, tailoring it to the specific execution context. This technique enhances the
execution speed of dynamically generated code and enables efficient utilization of
system resources.

• Graphics Programming: Register allocation plays a crucial role in graphics


programming, particularly in performance-critical scenarios. Graphics
applications often involve intensive calculations and processing of large amounts
of data. By minimizing memory accesses and maximizing the usage of registers,
register allocation helps optimize rendering pipelines and enhance graphics
processing performance.
ARM PROCESSOR AND APPLICATIONS 17
EXPRESSION SIMPLIFICATION

• Expression simplification is a widely employed optimization technique in


computer programming and compiler design aimed at enhancing the efficiency
and reducing the complexity of expressions within a program.
• The primary objective of expression simplification is to streamline complex
expressions by converting them into simpler and more efficient forms, all while
maintaining their original semantics intact. This optimization process entails the
application of algebraic rules, mathematical identities, and logical equivalences to
restructure expressions into more concise and optimized representations.
• By leveraging various mathematical properties and simplification rules, the
transformed expressions can eliminate redundant computations, unnecessary
operations, and suboptimal arrangements of terms. This leads to improved
computational efficiency and a reduction in the overall complexity of the
program.

ARM PROCESSOR AND APPLICATIONS 18


EXAMPLE 2 : C PROGRAM TO SOLVE THE GIVEN
EXPRESIION(X*(A+B)+Y*(A+B)).
#include <stdio.h>
int simplifyExpression(int x, int y, int a, int b)
{
int result = x *(a + b)+ y*(a + b) ;
return result;
}
int main() {
int x, y, a, b;

printf("Enter the value of x: ");


scanf("%d", &x);
printf("Enter the value of y: ");
scanf("%d", &y);

ARM PROCESSOR AND APPLICATIONS 19


printf("Enter the value of a: ");
scanf("%d", &a);
printf("Enter the value of b: ");
scanf("%d", &b);
int simplifiedResult = simplifyExpression(x, y, a, b)
printf("The simplified expression is: %d\n", simplifiedResult);
return 0;
}

ARM PROCESSOR AND APPLICATIONS 20


EXAMPLE CODE 2

ARM PROCESSOR AND APPLICATIONS 21


EXECUTION

ARM PROCESSOR AND APPLICATIONS 22


EXAMPLE 2 : C PROGRAM TO SOLVE THE GIVEN
EXPRESIION(X*(A+B)+Y*(A+B)).[OPTIMIZED]
#include <stdio.h>

int simplifyExpression(int x, int y, int a, int b) {

int result = (x + y) * (a+b);

return result;
}

int main() {
int x, y, a, b;

printf("Enter the value of x: ");


scanf("%d", &x);

printf("Enter the value of y: ");


scanf("%d", &y);

printf("Enter the value of a: ");


scanf("%d", &a);

printf("Enter the value of b: ");


scanf("%d", &b);
ARM PROCESSOR AND APPLICATIONS 23
printf("Enter the value of a: ");
scanf("%d", &a);

printf("Enter the value of b: ");


scanf("%d", &b);

int simplifiedResult = simplifyExpression(x, y, a, b);

printf("The simplified expression is: %d\n", simplifiedResult);

return 0;
}

ARM PROCESSOR AND APPLICATIONS 24


OPTIMIZED CODE 2

ARM PROCESSOR AND APPLICATIONS 25


EXECUTION

ARM PROCESSOR AND APPLICATIONS 26


CODE COMPARISON

CODE TIME SPACE LOGIC

BOOLEAN ALGEBR
CODE 2 5.408 s 24 bytes
A

OPTIMIZED
4.685 s 24 bytes DE'MORGONS LAWS
CODE 2

ARM PROCESSOR AND APPLICATIONS 27


BENEFITS OF EXPRESSION SIMPLIFICATION

• Improved Efficiency: The process of expression simplification yields more


efficient code by eliminating unnecessary computations, removing common
subexpressions, and optimizing the evaluation process. By reducing redundant
operations and streamlining the logic, the resulting code executes more efficiently
and completes computations in a shorter time.

• Enhanced Readability: Simplified expressions are inherently easier to


comprehend and interpret. By reducing complexity and eliminating unnecessary
clutter, the code becomes more readable and maintainable. This enhanced
readability makes it easier for programmers to understand the logic and intent
behind the expressions, facilitating code maintenance and future modifications.

ARM PROCESSOR AND APPLICATIONS 28


BENEFITS OF EXPRESSION SIMPLIFICATION

• Optimized Performance: Expression simplification contributes to optimized


performance by reducing the number of operations required for evaluation. By
eliminating redundant or unnecessary computations, the code executes faster and
more efficiently. This optimization can have a significant impact on the overall
performance of the program, especially when dealing with complex expressions or
computationally intensive tasks.

• Code Size Reduction: Expression simplification helps reduce the size of the
generated code by eliminating unnecessary or redundant code segments. By
streamlining expressions and removing superfluous operations, the resulting
executable becomes more compact. This reduction in code size leads to benefits
such as reduced memory consumption, faster loading times, and improved overall
efficiency, particularly in resource-constrained environments or when deploying
the code on memory-limited devices.

ARM PROCESSOR AND APPLICATIONS 29


APPLICATIONS OF EXPRESSION SIMPLIFICATION

• Compiler Optimization: Expression simplification techniques find extensive use


in compiler optimization. Optimizing compilers employ these techniques to
enhance the performance and efficiency of compiled programs. By applying
simplification transformations, compilers reduce the complexity of expressions
and generate optimized machine code. This optimization step plays a crucial role
in improving the overall execution speed and resource utilization of programs.

• Symbolic Manipulation: Expression simplification is of significant importance in


symbolic manipulation systems, such as computer algebra systems (CAS). These
systems specialize in performing algebraic computations and simplifications on
mathematical expressions. By simplifying expressions, CAS enables users to
manipulate equations and formulas symbolically, facilitating tasks such as
simplifying equations, solving equations symbolically, and performing algebraic
manipulations.

ARM PROCESSOR AND APPLICATIONS 30


APPLICATIONS OF REGISTER ALLOCATION

• Formula Evaluation: Simplifying expressions is particularly valuable in


mathematical and scientific computing. In scenarios where complex formulas and
equations are involved, expression simplification helps streamline the evaluation
process. By reducing the complexity of expressions, mathematical computations
can be performed more efficiently, resulting in faster calculations and more
accurate results. This application is particularly relevant in domains such as
numerical analysis, physics simulations, and engineering computations.

• Program Analysis: Expression simplification techniques also play a role in


program analysis tools. These tools leverage expression simplification to simplify
complex expressions and perform static analysis on programs. By simplifying
expressions, program analysis tools aid in understanding the behavior of
programs, detecting potential bugs, and identifying opportunities for code
optimization. This application is beneficial in areas such as software debugging,
performance profiling, and program comprehension.
ARM PROCESSOR AND APPLICATIONS 31
THANK YOU

ARM PROCESSOR AND APPLICATIONS 32

You might also like