comp.lang.ada
 help / color / mirror / Atom feed
From: Rex Reges <Rex.R.Reges@Boeing.com>
Subject: Re: An alternative to Unchecked Conversion
Date: 1999/12/18
Date: 1999-12-18T00:00:00+00:00	[thread overview]
Message-ID: <385AD199.D1428985@Boeing.com> (raw)
In-Reply-To: mhrj5s4qckk7rt1j3pu0s3r438e281pu37@4ax.com

Brian Orpin wrote:
> 
> Well the Tartan Ada (83) compiler we are using doesn't allow us to use
> address mapping as it requires all address statements to be static.
> 
> With SYSTEM;
> Use SYSTEM;
> 
>   Procedure TEST Is
>      Type TEST_TYPE Is New INTEGER;
>      For TEST_TYPE'Size Use 32;
> 
>      X : TEST_TYPE;
>      Y : TEST_TYPE;
>      For X Use At Y'Address;
> 
>   Begin
> 
>      X := 1;
> 
>   End TEST;
> 
>    9|     Y : TEST_TYPE;
> test.ada:10:1:
>   10|     For X Use At Y'Address;
>                         ^1
> ***  1 Error 3271: A static expression is expected here (RM83 4.9)
> 

This is a problem with Ada83, but it is a little more subtle. I think
the problem you have here is that you are trying to do this overlay (the
Jovial term) on two items on the stack.  If you put your declarations in
a package, it should work.

However, I had assumed the intent of an address rep clause was to
support device drivers and DMA.  Unchecked conversion works better than
overlays in many cases since it can detect things that an address
overlay can't (like mod boundaries, packed bits, packed items smaller
than a storage unit, etc.). Also, unchecked conversion can do more
efficient memory moves by switching to double register loads (64 bit
loads) as soon as a 64 bit boundary is hit. 

Also, to support overlays, the compiler writers had to add the Pragma
Volatile so that "tautology" errors didn't occur (checking the same
variable over and over when it can't change as far as the compiler
knows.  Some compilers would just optimize out the second test on a
variable that it didn't know was overlayed.

The static expression requirement is a problem when writing a device
driver since the device's location is located at a physical address and
the expression required is a logical address. One can call a system
routine to map the physical to logical, but then the address is not
static. I assume most compilers extended Ada83 with the ability to call
To_Logical_Address( Physical_Address : in System.Address ) return
System.Address.

For Ada95, it doesn't seem to be a problem to have a run-time value for
the address rep clause.  The "aliased" specification on a declaration
tells the compiler that you expect the variable to be volatile. We
create MMAP regions at run-time and overlay a data structure on these
memory regions for sharing between processes. As far as the compiler can
tell, data magically appears out of nowhere in these structures (mostly
queues).

However, several gurus here now claim that unchecked conversion should
never be used. Either they use overlays or they call the C library
routine "memmov" instead. Their claim is that "memmov" is faster and
more portable than unchecked conversion. I disagree. It seems to me that
overlaying stack items and block memory moves are poor programming
styles, but I'm not a guru.

--------------

Rex Reges

"De gustibus non est disputandum."




  parent reply	other threads:[~1999-12-18  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-16  0:00 An alternative to Unchecked Conversion Tom_Hargraves
1999-12-16  0:00 ` Matthew Heaney
1999-12-16  0:00   ` Tom Hargraves
1999-12-16  0:00     ` Matthew Heaney
1999-12-17  0:00       ` Lutz Donnerhacke
1999-12-17  0:00         ` Matthew Heaney
1999-12-16  0:00     ` DuckE
     [not found]     ` <mhrj5s4qckk7rt1j3pu0s3r438e281pu37@4ax.com>
1999-12-17  0:00       ` Simon Wright
     [not found]         ` <g9rr5s84eeov4vvp2v9v70jo9b5uporm0v@4ax.com>
1999-12-20  0:00           ` Simon Wright
1999-12-23  0:00             ` Robert Dewar
1999-12-18  0:00       ` Rex Reges [this message]
1999-12-18  0:00         ` Matthew Heaney
1999-12-19  0:00         ` Robert Dewar
1999-12-20  0:00     ` Charles H. Sampson
1999-12-16  0:00   ` Richard D Riehle
1999-12-17  0:00     ` Ted Dennison
1999-12-17  0:00       ` Richard D Riehle
1999-12-16  0:00 ` Mark A Biggar
1999-12-16  0:00 ` Jeff Creem
replies disabled

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