[go: up one dir, main page]

0% found this document useful (0 votes)
6 views5 pages

Machine Dependent Code

Machines depends

Uploaded by

harami346820
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Machine Dependent Code

Machines depends

Uploaded by

harami346820
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

• Machine-dependent (also known as hardware-dependent) - Software or

components that are designed for a specifit type of hardware / architecture. This

is caused by the kind of work that it does, specifically interacting with hardware-

specific features or using instructions only found on this line of hardware.

• Machine dependent are used to describe characteristics of a program or system

that is necessarily tied to a particular hardware platform and thus not portable

from one machine architecture (or operating system or environment)to another.

• For example:- A machine-dependent program may use instructions or features

that are particular to a certain design of processor and will thus give

unpredictable results if run on another type. Low-level programming for a specific

hardware machine, written in assembly language commonly.

DEFINITION

• Machine dependent code optimization: Machine-Level Optimization takes place after

the source code has been converted to target code and then that machine-specific is

transformed. It can use CPU registers and before using relative reference instead of

absolute memory references Memory hierarchy is used by machine dependent

optimizers as much as possible.

• Code optimization that focuses on the performance of a given target machine. Such an

optimization is typically performed in assembly language, a very low-level programming

langue and generally tied to the hardware.

• If the hardware has certain features, and if you are aware of those features in your

code then it can be optimized to run faster or more efficiently. Direct benefits of

machine dependent code optimization are that it can be powerful and result in

dramatic performance improvements.

• The reason for this is that the code would be optimized to utilize hardware specific

features. The only catch is that this code can be executed solely using the specified

hardware and may not work with a different type of hardware without entirely

rewriting it.

ADVANTAGES

• Improved performance: Machine-dependent code is written to take advantage of

the specific hardware and software environment it will be running in. As a result,
it can be optimized for that environment, leading to improved performance.

• Greater control: When writing machine-dependent code, you have more control

over how the code will be executed. You can make use of specific hardware

features or take advantage of system-level APIs that may not be available to more

portable code.

• Reduced portability: One of the main drawbacks of machine-dependent code is

that it is not portable. It can only be run on the specific machine or environment

it was written for, which can be a limitation if you need to run the code on

multiple platforms.

• Higher maintenance costs: Machine-dependent code can be more difficult to

maintain and update, as it may require specific knowledge of the hardware and

software environment it was written for. This can lead to higher maintenance

costs over time.

ADVANTAGES

• Improved performance: Machine-dependent code is written to take advantage of

the specific hardware and software environment it will be running in. As a result,

it can be optimized for that environment, leading to improved performance.

• Greater control: When writing machine-dependent code, you have more control

over how the code will be executed. You can make use of specific hardware

features or take advantage of system-level APIs that may not be available to more

portable code.

• Reduced portability: One of the main drawbacks of machine-dependent code is

that it is not portable. It can only be run on the specific machine or environment

it was written for, which can be a limitation if you need to run the code on

multiple platforms.

• Higher maintenance costs: Machine-dependent code can be more difficult to

maintain and update, as it may require specific knowledge of the hardware and

software environment it was written for. This can lead to higher maintenance

costs over time.

DISADVANTAGES

• Lack of portability: Machine-dependent code is specific to a particular type of


computer or hardware architecture, which can make it difficult to port to other

platforms.

• Increased development and maintenance effort: Machine-dependent code may

need to be modified or rewritten for each specific platform, which can increase

the development and maintenance effort.

• Limited flexibility and scalability: Machine-dependent code is limited by the

specific hardware it is designed to run on, which can make it less flexible and

scalable.

• Vulnerability to hardware-specific attacks: Machine-dependent code is more

vulnerable to hardware-specific attacks, as it is tied to a specific hardware

platform.

• Reduced performance: Machine-dependent code may not be optimized by

compilers, which may result in reduced performance compared to machine-

independent code.

ORGANIZATION OF CODE OPTIMISER

• The techniques used are a combination of Control-Flow and Data-Flow analysis as

shown in fig.

• Control-Flow Analysis: Identifies loops in the flow graph of a program since such

loops are usually good candidates for improvement.

• Data-Flow Analysis: Collects information about the way variables are used in a

program.

PEEP HOLE OPTIMIZATION

• Optimizing a small portion of the code.

• It is possible to use these techniques on both target and intermediate codes.

• A number of claims undergo analysis and verification for the following potential

optimization.

• This approach attempts to optimise the performance of targeted code by looking

at a small window (peephole) in time and replacing that short sequence of target

instructions with a shorter, faster one whenever possible.

• Peephole optimization have the property of cascading, that is one improvement


may create new possibilities for other similar improvements. Therefore multiple

passes over the target program are required to gain optima benefit from this

technique.

TRANSFORMATION OF PEEP HOLE OPTIMIZATION

• In general peephole optimization involves the following six transformations:

• Redundant instruction elimination

• Unreachable code elimination

• Flow of control optimization

• Algebraic simplification

• Reduction in strength

• Use of machine idioms.

PEEP HOLE TRANSFORMATIONS

(1) Redundant instruction elimination: The processor looks for redundant instructions to be removed
by the compiler at

compilation level. Even if we remove some loading and storing of instructions, this does not change
the semantic equivalence. For instance:

MOV x, R0

MOV R0, R1

First instruction can be rewritten as

MOV x,R1

(2) Unreachable Code: It is the removal of unreachable instructions. An unlabeled instruction


immediately following an unconditional jump may be

removed. This operation can be repeated to eliminate a sequence of instructions.

For example:for debugging purposes, a large program may have within it certain segments that are
executed only if a variable debug is 1. In C, the source

code might look like

#define debug 0 .... If ( debug ) { Print debugging information 12 }

In the intermediate representations the if-statement may be translated as: If debug =1 goto L1

goto L2 L1: print debugging information L2: ..............................................................

(a) One obvious peephole optimization is to eliminate jumps over jumps .Thus no matter what

the value of debug; (a) can be replaced by: If debug ≠1 goto L2 Print debugging information

L2: .....................................................................
(b) If debug ≠0 goto L2 Print debugging information L2: ..................................

(c) As the argument of the statement of (c) evaluates to a constant true it can be replaced By

goto L2. Then all the statement that print debugging aids are manifestly unreachable and can

be eliminated one at a time.

• 4) Algebraic Simplification: Peephole optimization can apply continuous algebra

simplifications and there is no limit to how much you are going to do this. But

there are only a few algebraic identities that get exhibited enough to be worth

putting in some extra work.

• For example, simple intermediate code generation algorithms often emit

statements such as x := x+0 or x :=x * 1...these are of course easy to eliminate via

peephole optimization...but you get the point.

• Reduction in Strength: Reduction in strength replaces the expensive operations

by equivalent cheaper ones on target machine . Some machine instructions are

much cheaper than others and can be used as special cases of more expensive

operators. The canonical example here is x2; it costs significantly less (execution-

wise) to compute as the product of an operand with itself than as a call into some

exponentiation routine. Multiplication or division using powers of 2 for fixed-

point values can also be implemented as shifts. It is often a bit cheaper to

implement floating-point division by constant as multiplication by another known

factor. X2 → X*X

USE OF MACHINE IDIOMS

The target machine may have hardware instructions to implement certain

specific operations efficiently. For example, some machines have auto-increment

and auto-decrement addressing modes. These add or subtract one from an

operand before or after using its value. The use of these modes greatly improves

the quality of code when pushing or popping a stack, as in parameter passing.

These modes can also be used in code for statements like i : =i+1.

• i:=i+1 → i++

• i:=i-1 → i- -

You might also like