comp.lang.ada
 help / color / mirror / Atom feed
* C's register keyword
@ 1997-09-06  0:00 Tristan Ludowyk
  1997-09-06  0:00 ` Tarjei T. Jensen
  1997-09-08  0:00 ` Tucker Taft
  0 siblings, 2 replies; 7+ messages in thread
From: Tristan Ludowyk @ 1997-09-06  0:00 UTC (permalink / raw)



is there an ada equivelent to 'register' in C/C++?

Tristan.
-- 
    _/                 Tristan Ludowyk                               \_\_\_\_
   _/_/     RMIT Comp.Sys.Eng/Comp.Sci - 1st year   ____TTTc____/|    \_\_\_
  _/_/_/    Email: ludowyk@yallara.cs.rmit.edu.au    (_u|||_o_) \|     \_\_
 _/_/_/_/        "Donkeys live a long time"             ^^^             \_




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: C's register keyword
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Tarjei T. Jensen @ 1997-09-06  0:00 UTC (permalink / raw)



Tristan Ludowyk wrote:
> 
> is there an ada equivelent to 'register' in C/C++?
> 

You have the pragma optimize which is supposed to come in three
flavours:
pragma optimize(time);
pragma optimize(space);
pragma optimize(off);

The Ada 95 Reference Manual says that the pragma "applies until the end
of the immediately enclosing declarative region, or for a pragma at the
place of compilation_unit, to the end of the compilation."

The register keyword in C is considered obsolete. A compiler is supposed
to be better at allocating registers than most humans.

If you think the register keyword is sacred in C, read the GCC manual.
If my memory serves me right they say that they ignore it or strongly
dissaprove of its use.

Greetings,

-- 
// Tarjei T. Jensen 
//    tarjei@online.no || voice +47 51 62 85 58
//   Support you local rescue centre: GET LOST!




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: C's register keyword
  1997-09-08  0:00 ` Tucker Taft
@ 1997-09-08  0:00   ` David Weller
  1997-09-09  0:00     ` Fergus Henderson
  0 siblings, 1 reply; 7+ messages in thread
From: David Weller @ 1997-09-08  0:00 UTC (permalink / raw)



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




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: C's register keyword
  1997-09-06  0:00 C's register keyword Tristan Ludowyk
  1997-09-06  0:00 ` Tarjei T. Jensen
@ 1997-09-08  0:00 ` Tucker Taft
  1997-09-08  0:00   ` David Weller
  1 sibling, 1 reply; 7+ messages in thread
From: Tucker Taft @ 1997-09-08  0:00 UTC (permalink / raw)



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.

For global variables, some C compilers support the use of
the "register" keyword, but normally there is also some kind
of pragma to identify which register should be devoted to
the variable.  The same kind of pragma could certainly be
implemented in Ada (and may already be so in some compilers) for 
assigning a global variable to a machine register.

: Tristan.
: -- 
:     _/                 Tristan Ludowyk                               \_\_\_\_
:    _/_/     RMIT Comp.Sys.Eng/Comp.Sci - 1st year   ____TTTc____/|    \_\_\_
:   _/_/_/    Email: ludowyk@yallara.cs.rmit.edu.au    (_u|||_o_) \|     \_\_
:  _/_/_/_/        "Donkeys live a long time"             ^^^             \_

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: C's register keyword
  1997-09-08  0:00   ` David Weller
@ 1997-09-09  0:00     ` Fergus Henderson
  1997-09-11  0:00       ` Robert Dewar
  0 siblings, 1 reply; 7+ messages in thread
From: Fergus Henderson @ 1997-09-09  0:00 UTC (permalink / raw)




dweller@news.imagin.net (David Weller) writes:

>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".

I find that very hard to believe.
Perhaps I have misunderstood some of your assumptions.

Certainly if `i' and `j' are local (auto) variables whose
address is not taken, then gcc will (at -O1 or higher) put
them in registers, so I don't see why the Ada version would
be faster than the C version.

--
Fergus Henderson <fjh@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@128.250.37.3         |     -- the last words of T. S. Garp.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: C's register keyword
  1997-09-06  0:00 ` Tarjei T. Jensen
@ 1997-09-10  0:00   ` Richard Kenner
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Kenner @ 1997-09-10  0:00 UTC (permalink / raw)



In article <34111A70.2158@online.no> tarjei@online.no writes:
>If you think the register keyword is sacred in C, read the GCC manual.
>If my memory serves me right they say that they ignore it or strongly
>dissaprove of its use.

No.  The "register" keyword has precisely one semantic meaning in C, which
is to make it an error to take the address of an object with the keyword.
In other words, it is precisely the opposite of "aliased" in Ada.

GCC correctly implements this keyword.

It also has a historical aspect of suggestign which variables get placed
into registers.  Like all modern compilers, GCC ignores this purpose for
the keyword if optimizing, but does use it as a guide when not optimizing.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: C's register keyword
  1997-09-09  0:00     ` Fergus Henderson
@ 1997-09-11  0:00       ` Robert Dewar
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1997-09-11  0:00 UTC (permalink / raw)



Fergus says, replying to Dave

<<>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".

I find that very hard to believe.
Perhaps I have misunderstood some of your assumptions.

Certainly if `i' and `j' are local (auto) variables whose
address is not taken, then gcc will (at -O1 or higher) put
them in registers, so I don't see why the Ada version would
be faster than the C version.>>



Well certainly religeon as in belief is not necessary in discussing this
issue. Simply compile both examples, and you will see that in general
Fergus is correct, the assembler code is identical for the two cases. 
I did not see the original post, so I am not sure why Dave would have
thought otherwise.






^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1997-09-11  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
1997-09-09  0:00     ` Fergus Henderson
1997-09-11  0:00       ` Robert Dewar

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