comp.lang.ada
 help / color / mirror / Atom feed
From: dweller@news.imagin.net (David Weller)
Subject: Re: C's register keyword
Date: 1997/09/08
Date: 1997-09-08T00:00:00+00:00	[thread overview]
Message-ID: <5v1k1v$3mq6$1@prime.imagin.net> (raw)
In-Reply-To: EG71Ex.4D6.0.-s@inmet.camb.inmet.com


In article <EG71Ex.4D6.0.-s@inmet.camb.inmet.com>,
Tucker Taft <stt@houdini.camb.inmet.com> wrote:
>Tristan Ludowyk (ludowyk@yallara.cs.rmit.edu.au) wrote:
>: is there an ada equivelent to 'register' in C/C++?
>
>In Ada 95, any local variable not declared "aliased" is a candidate
>for living in a machine register.  The compiler decides based
>on usage.
>

As a modest, and perhaps slightly contrived example:
C version:

	for (int i = 0; i < 10000; i++)
		for (int j = 0; j < 10000; j++)
				/*some nontrivial statement*/

Ada version:

	for i in 0..9999 loop
		for j in 0..9999 loop
			--some nontrivial statement
		end loop;
	end loop;

Using gcc/GNAT, you find that the Ada executable yields faster
performance (assuming same optimization levels and identical times for
the "some nontrivial statement".  Only when you declare the i and j
variables in C as with the "register" keyword do you see identical
performance.

This is, IMHO, a fundamental point behind Ada -- the compiler can (and
does!) perform several optimizations that would otherwise be impossible
in C without "aggressive" programming (and considering that C requires
the developer to program "defensively", it should come as no surprise
that these highly skilled "aggressive-defensive" programmers also tend
to be "manic-depressive" :-)

As Tuck points out, "aliased" variables in Ada behave much like
"un-registered" variables in C, but also have a LOT more "protection"
to them than C variables.

Of course, having nattered away like this, it all really boils down to
the one mantra all programers should (and rarely) follow:

	Measure everything!


-- 
Booch Components Homepage: www.rivatech.com ||Ada Homepage: www.adahome.com
	Microsoft: The gasoline-powered engine of the 21st century




  reply	other threads:[~1997-09-08  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-06  0:00 C's register keyword Tristan Ludowyk
1997-09-06  0:00 ` Tarjei T. Jensen
1997-09-10  0:00   ` Richard Kenner
1997-09-08  0:00 ` Tucker Taft
1997-09-08  0:00   ` David Weller [this message]
1997-09-09  0:00     ` Fergus Henderson
1997-09-11  0:00       ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox