[mercury-users] Usage of global register variables on ix86

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Oct 11 20:13:12 AEST 1998


On 09-Oct-1998, Marko Schuetz <marko at ki.informatik.uni-frankfurt.de> wrote:
> Compiling 0.7.3 using FreeBSD 2.2.7 on a ix86 machine there was an
> error compiling label.c. This is due to stdio.h being included before
> regs.h and in stdio.h there is an inline function for
> __sputc. Including regs.h before stdio.h solves the problem.

Thanks for the bug report, although mercury-bugs at cs.mu.oz.au
is generally a more appropriate place to send them.  As it happens
this one has been fixed in our development version for some time now,
I believe.

> I did not
> think of this obvious solution and instead first posted to the
> freebsd-stable mailing list.
> 
> The comments in the thread basically say that on the ix86 there is not
> much to be gained using global register variables since a) it does not
> really have (m)any and b) gcc does such a good job allocating
> registers that a better register allocation is very difficult to
> achieve. 
>
> Ad a). I looked into regs.h and found that 2 or 3
> registers are used, depending on whether pic code is generated or not.

It is true that the x86 doesn't have very many registers.
However, using registers is still significantly faster than
using memory.

While gcc does a good job of allocation registers for typical C code,
it never puts global variables in registers unless explicitly asked,
and the sort of C code that the Mercury compiler generates makes
very frequent use of a few global variables, such as the Mercury
stack pointer.  If these variables are in registers rather than memory
then I'm sure you'll see a significant performance improvement.

It would be nice if we could generate higher-level C code,
but unfortunately C doesn't have any support for nondeterminism.
See the paper "Compiling logic programs to C using GNU C as a
portable assembler" on our WWW page for details.

> Ad b). The mercury docs claim that there is a great speed improvement
> when global register variables can be used. Does this also hold for
> the ix86? I do not have the resources to compare this myself (I am
> using a 90MHz laptop) but I am sure this has been compared. Can anyone
> give me a pointer/the facts?

I just tried comparing with and without the use of global register
variables (grades `asm_fast.gc' and `asm_jump.gc') on x86 for one tiny
benchmark which I chose at random from the various benchmarks sitting
around in my directories.  With global register variables, it took 4.5
seconds and without, it took 6.5 seconds; that's about a 45% speedup
for the use of global register variables.

That's only a single benchmark, but it accords fairly well with my very
vague memories of about a 50% speedup for the compiler itself (I did
some more detailed benchmarking a while back, but I don't have the
figures from that on hand now).

> On the side: has anyone compared the efficiency of using egcs instead of
> gcc with mercury?

Not that I know of.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the users mailing list