[clug] assembly performance

Eyal Lebedinsky eyal at eyal.emu.id.au
Fri Jun 10 10:45:30 GMT 2005

Adrian Blake wrote:
> This is a question about microprocessor architecture.
> 10 or 20 years ago assembly code addressed physical hardware, registers
> ALUs and alike with an underlying simple microcode.
> This has changed. but to what extent?
> Does assembly code still operate on the physical hardware or is it  a
> virtual machine with one or more layers of microcode? What are the
> performance penalties if any?

As others said, it depends on how you look at it. Let me give a
trivial example. You say, in your favourite assembly
	load register 0 with the constant 5
and let us assume that this represents a single machine
instruction (some assemblers are rather smart).

When this hits the CPU, if you are lucky, maybe register 37
will be chosen to play register 5 for a while, and the constant
will go there.

If you are unlucky the hardware can see where "register 5" goes
next and the value "5" may never be placed in the silicon
(or whatever technology we use) register file, but rather bypass it
into some holding register (or a retiring queue etc.), following
one of many paths.

And on many modern CPUs it is even worse, your instruction will
be rewritten into a different machine language (not necessarily
microcode) and go into a holding queue/cache. This may happen
long before the instruction is actually executed, and even if it
never is (speculative execution, multiple execution paths and
what not). If it is executed in a loop then the whole loop is
likely to run directly of the decoded instruction cache without
being translated again.

If this is a multithreaded CPU then many of the standard silicon
(PC, SP and much more) have many instances and the proper one
is activated for your instruction.

Should I continue? A lot has changed in the last 20 years.

Eyal Lebedinsky (eyal at eyal.emu.id.au) <http://samba.org/eyal/>
	attach .zip as .dat

More information about the linux mailing list