what does the compiler know?
A student writes:
Hi Dr Patt,
I had a small doubt, are the compilers aware of the cycles per instruction
information when they are optimizing a code?
For eg for a code: ISA sequence one, may comprise less N count but higher CPI
values for each of the instructions & ISA sequence two may have higher N count
but instructions might have very less CPI values resulting in less execution
time for second sequence as compared to sequence 1.
If that's the case then compiler for a processor will be developed only after
basic hardware is done!
Please correct me if I have missed something in my understanding here.
Thanks & Regards,
<<name withheld to protect one wanting to know what the compiler knows>>
Years ago, compilers were not aware of how many cycles each instruction took. That
is part of the microarchitecture, and used to be hidden from the compiler. The
compiler knew the ISA, and generated a sequence optimizing some characteristic of
That has very much changed as more and more companies recognize the value of letting
the compiler know just what goes on "underneath the hood" -- that is, in the
microarchitecture. Such things as CPI (how many cycles each instruction requires) is
just one of those things. What can be done in parallel is another. The depth of the
pipeline and dependencies across instructions in a sequence is yet another. Before
we part company in May, we will examine several aspects of the microarchitecture that
can influence the execution time of one sequence.
By the way, a little terminology (so I can stop saying "sequence"). The compiler
(or assembler) generates a program expressed in the ISA of the machine, that is with
0s and 1s. We call that an object file (or, .obj file). Usually, many .obj files
are combined to form the unit that actually gets executed. We call that unit an
executable image (often, .exe file). The .obj file is produced by the compiler or
assembler. The .exe file is produced by the linker.
If understanding the underlying microarchitecture is a good idea, what does a company
do if it has multiple implementations of the same ISA. In the old days, the answer
was ONE compiler, from each specific high level language (C, C++, Java, etc.) to the
ISA. Today, many companies will produce a different compiler for each implementation,
so as to be able to optimize the .obj file for that implementation. That is,
performance is enhanced if the compiler knows what is going on in the specific
microarchitecture that will be used to execute the program it (the compiler) produces.