comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: ada and robots
Date: 1997/06/20
Date: 1997-06-20T00:00:00+00:00	[thread overview]
Message-ID: <dewar.866846641@merv> (raw)
In-Reply-To: gwinn-1706972242370001@dh5055155.res.ray.com


Joe said

<<"Sort of" is exactly right; neither correct nor consistent from compiler
to compiler.  Some compilers also provided pragma volatile, but
implementations varied, and some were deeply unclear on the concept of
volatile, so we couldn't use either shared or volatile.
>>


pragma Shared is well defined in the Ada 83 standard, and was correctly
implemented on all Ada 83 compilers that I have used. I can believe that
it is possible that Joe's group chose an ill-suited compiler that did not
get this important feature right (I have known plenty of C compilers get
things wrong -- and indeed know of one case in which a C compiler got
volatile seriously wrong).

However, the fact that I know a C compiler that did volatile wrong does not
make me say either of

  (a) C is useless for memory mapped IO
  (b) the volatile feature in C is useless because it is not implemented
	right on one compiler.

But that appears to be the dubious logic being used in this case for Ada.

Actually neither C nor Ada can guarantee to get memory mapped I/O "right"
at the language level, since the required semantics are of necessity at
the machine language level, and whether or not a given sequence in C or
Ada works is definitely bound to be implementation dependent. Yes, usually
in Ada (and C), doing the obvious thing works fine, and people often depend
on it, but it is a somewhat risky approach.

Let me give an example.

One customer of ours ported a large code from VADS to GNAT, and it did not work.
A huge amount of digging yielded the following "bug" report.

   type Bits is array (natural range <>) of Boolean;
   pragma pack (Bits);

   Bitvar : Bits (0 .. 31);
  
   ...

   Bitvar (17) := 1;

Now first, there is no guarantee of the order in which bits in such a packed
array are ordered, but there is a natural ordering, which both VADS and GNAT
followed (based on the endianness of the machine), so that was not a problem.

But the problem was that Bitvar had an address clause

  for Bitvar use at ...

which mapped it into the address space of some custom build hardware.

This hardware accepted ONLY word (4-byte) memory requests, and simply
malfunctioned in a completely unpredictable manner if byte memory requests
were received.

You guessed it, VADS used a loadword/or/storeword sequence, and GNAT used
a loadbyte/or/storebyte sequence.

Now there is nothing to say one of these is better than the other, they simply
represent two equally good ways of doing things.

The fix turned out to be simple, by changing the code to

  type Bits is array (0..31) of Boolean;

GNAT could be persuaded to generate the word sequence.

But there code was always relying in an undocumented way on the particular
choice of the compiler, and for that matter, still is.

Also, there is nothing really language independent here. Corresponding C
code would be equally subject to varying possible compilatoin possibilities.

For my taste, I rarely like the idea of using address clauses or the 
corresponding casts in C for this purpose. I would prefer to write two
small inlined routines that used machine language insertions to generate
EXACTLY the instructions that the IO hardware requires.





  parent reply	other threads:[~1997-06-20  0:00 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-16  0:00 ada and robots Marin David Condic, 561.796.8997, M/S 731-93
1997-06-17  0:00 ` Joe Gwinn
1997-06-18  0:00   ` Jon S Anthony
1997-06-18  0:00     ` Brian Rogoff
1997-06-20  0:00   ` Robert Dewar [this message]
1997-06-23  0:00     ` Geert Bosch
1997-07-02  0:00       ` Robert Dewar
1997-06-23  0:00     ` Richard Kenner
1997-06-23  0:00       ` Robert Dewar
1997-06-25  0:00   ` Jonathan Guthrie
1997-06-25  0:00   ` Will Rose
1997-06-21  0:00 ` Nick Roberts
  -- strict thread matches above, loose matches on Subject: below --
1997-07-02  0:00 Ada " Huy Vo
1997-07-04  0:00 ` Richard A. O'Keefe
1997-07-01  0:00 Huy Vo
1997-07-02  0:00 ` Wes Groleau
1997-06-30  0:00 Huy Vo
1997-07-01  0:00 ` Alan Brain
1997-07-11  0:00   ` Will Rose
1997-07-02  0:00 ` Mattias Sj�sv�rd
     [not found] <867541382.23405@dejanews.com>
1997-06-29  0:00 ` John Howard
1997-06-26  0:00 Huy Vo
1997-06-27  0:00 ` Alan Brain
1997-06-27  0:00   ` Wes Groleau
1997-06-27  0:00   ` Stephen Leake
1997-06-27  0:00 ` Richard A. O'Keefe
1997-06-27  0:00 ` Jon S Anthony
1997-06-27  0:00 ` Wes Groleau
1997-06-27  0:00 ` nma123
1997-06-24  0:00 Huy Vo
1997-06-25  0:00 ` Jon S Anthony
1997-06-25  0:00 ` Dale Stanbrough
1997-06-25  0:00 ` Alan Brain
1997-06-25  0:00 ` Wes Groleau
1997-06-26  0:00 ` Ken Garlington
1997-07-01  0:00   ` Tom Moran
1997-06-20  0:00 Huy Vo
1997-06-23  0:00 ` Jon S Anthony
1997-06-19  0:00 ada " Jon S Anthony
1997-06-19  0:00 ` Brian Rogoff
1997-06-20  0:00   ` Jon S Anthony
1997-06-22  0:00   ` John G. Volan
1997-06-25  0:00     ` Richard A. O'Keefe
1997-06-23  0:00   ` Robert Dewar
1997-06-24  0:00     ` Brian Rogoff
1997-06-16  0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-12  0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-09  0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-05  0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-06-09  0:00 ` Jerry Petrey
1997-06-10  0:00   ` Alan Brain
1997-06-10  0:00     ` Joe Gwinn
1997-06-11  0:00       ` Alan Brain
1997-06-11  0:00         ` Joe Gwinn
1997-06-11  0:00         ` Spam Hater
1997-06-11  0:00       ` Robert Dewar
1997-06-11  0:00         ` Samuel Mize
1997-06-13  0:00           ` Erik Magnuson
1997-06-17  0:00         ` Joe Gwinn
1997-06-18  0:00           ` Jon S Anthony
1997-06-19  0:00             ` Jonathan Guthrie
1997-06-20  0:00           ` Robert Dewar
1997-06-05  0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-05-28  0:00 John Bohn
1997-05-29  0:00 ` Michael F Brenner
1997-05-29  0:00 ` Stephen Leake
1997-05-30  0:00 ` John Cook
1997-05-30  0:00   ` Tom Moran
1997-06-01  0:00     ` Dale Stanbrough
1997-06-02  0:00       ` John G. Volan
     [not found]         ` <5mv984$7kn@news.emi.com>
1997-06-03  0:00           ` Martin A. Stembel
1997-06-03  0:00           ` Joe Gwinn
1997-06-04  0:00             ` Pat Rogers
1997-06-05  0:00               ` Joe Gwinn
1997-06-14  0:00                 ` Robert Dewar
1997-06-16  0:00                 ` Ken Garlington
1997-06-16  0:00                   ` Robert Dewar
1997-06-17  0:00                   ` Joe Gwinn
1997-06-28  0:00                     ` Mike Stark
1997-07-03  0:00                       ` Joe Gwinn
1997-06-04  0:00             ` John G. Volan
1997-06-05  0:00               ` Joe Gwinn
1997-06-14  0:00                 ` Robert Dewar
1997-06-17  0:00                   ` Joe Gwinn
1997-07-03  0:00                     ` Shmuel (Seymour J.) Metz
     [not found]               ` <9706052229.AA29554@jaguar.nmc.ed.ray.com>
1997-06-06  0:00                 ` John G. Volan
1997-06-07  0:00                   ` RC
1997-06-09  0:00                   ` Joe Gwinn
1997-06-05  0:00             ` Jon S Anthony
1997-06-05  0:00               ` Joe Gwinn
1997-06-14  0:00                 ` Robert Dewar
1997-06-10  0:00             ` Robert Dewar
1997-06-10  0:00               ` Joe Gwinn
1997-06-11  0:00                 ` Robert Dewar
1997-06-12  0:00                   ` George Haddad
1997-06-16  0:00                   ` Matthew S. Whiting
1997-06-17  0:00                     ` Stephen Leake
1997-06-17  0:00                       ` Robert A Duff
1997-06-20  0:00                       ` jim granville
1997-06-21  0:00                         ` Robert Dewar
1997-06-29  0:00                         ` Matthew Heaney
1997-07-03  0:00                           ` Shmuel (Seymour J.) Metz
1997-07-13  0:00                             ` Robert Dewar
1997-06-17  0:00                     ` Samuel Mize
1997-06-18  0:00                       ` Steve O'Neill
1997-06-19  0:00                         ` Anonymous
1997-06-19  0:00                       ` Kenneth W. Sodemann
1997-06-20  0:00                       ` Stephen Leake
1997-06-20  0:00                         ` Robert Dewar
1997-06-17  0:00                     ` Jon S Anthony
1997-06-17  0:00                       ` Matthew S. Whiting
1997-06-18  0:00                         ` Jon S Anthony
1997-06-22  0:00                           ` John G. Volan
1997-06-18  0:00                         ` Samuel Mize
1997-06-18  0:00                           ` Matthew S. Whiting
1997-06-18  0:00                         ` Robert A Duff
1997-06-17  0:00                     ` Robert Dewar
1997-06-17  0:00                     ` Robert A Duff
1997-06-18  0:00                       ` Ken Garlington
1997-07-17  0:00                         ` Shmuel (Seymour J.) Metz
1997-06-20  0:00                       ` Adam Beneschan
1997-06-20  0:00                       ` Robert Dewar
1997-06-04  0:00         ` RC
1997-06-04  0:00           ` Larry Kilgallen
1997-06-04  0:00           ` John G. Volan
1997-06-05  0:00           ` Jon S Anthony
1997-06-02  0:00     ` Nick Roberts
1997-06-04  0:00       ` Jan Galkowski
1997-06-05  0:00         ` Albert K. Lee
1997-06-06  0:00           ` dana
1997-06-07  0:00             ` John G. Volan
1997-06-10  0:00               ` dana
replies disabled

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