[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: killing registers



On Fri, May 31, 2002 at 03:55:27AM -0600, Theo de Raadt wrote:
> > while browsing the cvs logs I see, that ocassionally registers get wiped (e.g.
> > "register int c" -> "int c", example: src/bin/mt/mt.c revision 1.18 to 1.19).
> > What is the reason for that?
> 
> Compilers no longer need it.

To elaborate on it: 

Most compilers in fact ignores the ``register'' keyword, as they are
better of placing variables into registers than humans. Furthermore
different architectures have a different number of registers leading to
a very different policy for placing variables into registers. 

The task of allocating variables to registers are known as
register-allocation. The problem is NP-hard and is thus not something
simple to do. Normally one deploys a heuristical approach in allocating,
which often leads to better allocation than a human can do.  An
alternative is the linear-scan algorithm, which normally is used when
you have to do register allocation fast (eg Just-in-time compilation).
The allocator gives a less optimal solution but is a lot faster.

C isn't that low-level anymore. It completely lacks branching hints and
caching hints for instance. And register allocation can be done very
efficiently by a compiler nowadays

-- 
Jesper



Visit your host, monkey.org