comp.lang.ada
 help / color / mirror / Atom feed
* GNAT 4.4.5 Record Bit_Order Endian issues
@ 2013-01-14 17:43 awdorrin
  2013-01-15  0:38 ` Randy Brukardt
                   ` (4 more replies)
  0 siblings, 5 replies; 39+ messages in thread
From: awdorrin @ 2013-01-14 17:43 UTC (permalink / raw)


I have a record with specification definition that starts, using big endian notation, with:

for TRACK_RECORD_TYPE use
 record
  TRACK_ID at 0 range 0 .. 11;
  TRACK_ID_CNT at 1 range 4 .. 9;
   ...


The meaning being that the first 12 bits hold a track id and the next 6 bits hold the Count value.

I have had success in the past, using the gnat 4.4.5 compiler under Debian 6.0.6, to use the directive: for TRACK_RECORD_TYPE'Bit_Order use System.High_Order_First;
In order to continue using the definition in the big endian notation.

From the build output, the Bit_Order flag at first appears to be processed correctly, with the built compiler flags displaying to translated little endian definition as:

for TRACK_RECORD_TYPE use
 record
  TRACK_ID at 0 range 4 .. 15;
  TRACK_ID_CNT at 1 range 11 .. 6;
   ...

But the TRACK_ID_CNT range does not provide the proper definition.
I believe it should be: TRACK_ID_CNT at 1 range 5 .. 0

Using the following code:

TRK_REC.TRACK_ID := 1;
Text_IO.Put_Line("A: TRK_REC.TRACK_ID = " & Int32'Image(TRK_REC.TRACK_ID));
TRK_REC.TRACK_ID_CNT := 1;
Text_IO.Put_Line("B: TRK_REC.TRACK_ID = " & Int32'Image(TRK_REC.TRACK_ID));

The output displayed is:

A: TRK_REC.TRACK_ID = 1
B: TRK_REC.TRACK_ID = 1025

Apparently because the TRACK_ID field is being read as a 16-bit value where:

"0000 0100 0000 0001" -> "BBBB CCAA AAAA AAAA"
where the 'A' bits are the TRACK_ID and the B bits are part of the TRACK_ID_CNT field, and the 'C' bits are an overlap of the second variable, due to the improper definition translation.

Not sure if this 'bug' would be fixed in a newer version of the GNAT compiler or not.




^ permalink raw reply	[flat|nested] 39+ messages in thread
* Re: GNAT 4.4.5 Record Bit_Order Endian issues
@ 2013-01-22  3:21 Stephen Leake
  2013-01-22  5:14 ` Jeffrey Carter
  2013-01-22 22:40 ` Randy Brukardt
  0 siblings, 2 replies; 39+ messages in thread
From: Stephen Leake @ 2013-01-22  3:21 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

> "AdaMagica" <christ-usch.grein@t-online.de> wrote in message 
> news:9dc6d5fe-3382-44dd-8460-e042bd6b808e@googlegroups.com...
> On Saturday, January 19, 2013 2:43:03 AM UTC+1, Stephen Leake wrote:
> ...
>>> Then 13.5.2 talks about the Position attribute.
>>> Which just retreives the mysterious "position" number, it doesn't say
>>> what it _means_.
>
> Huh? 13.5.2(2/2) says in part:
> "denotes Denotes the same value as R.C'Address – R'Address". That makes it
> pretty clear what it represents (for the Default_Bit_Order).

The full paragraph is:

2/2
R.C'Position

               {AI95-00133-01AI95-00133-01} If the nondefault bit
               ordering applies to the composite type, and if a
               component_clause specifies the placement of C, denotes
               the value given for the position of the
               component_clause; otherwise, denotes the same value as
               R.C'Address - R'Address. The value of this attribute is
               of the type universal_integer.

Note the 'otherwise'; that's means the value is R.C'Address - R'Address
only if position is _not_ specified in a rep clause.

> For the non-default bit order, it just is whatever you specify (and
> that's all we can say, because it *doesn't* have a clear physical
> meaning - it defines the machine scalars to use, which makes it a
> totally confusing mess if you try to work the other way).

Cohen's paper (http://www.ada-auth.org/ai-files/grab_bag/bitorder.pdf)
gives it a clear meaning in that case.

>>> > I agree that the RM is confusing in this area.
>>> > It's partly my fault.  :-(
>>> Ok. What paragraphs do we add? (in five years; better late than never :)
>
> I don't think there is anything that would help. We surely tried when we 
> created the non-default bit order stuff.

Do you think Cohen's paper makes it clear? I gather not. Why not?

If that's too complex to put in the RM, maybe the implementation advice
could include a reference to a copy of Cohen's paper on the adaic
website (somehow I doubt ISO standards allow web references).

-- 
-- Stephe




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

end of thread, other threads:[~2013-01-28 13:39 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-14 17:43 GNAT 4.4.5 Record Bit_Order Endian issues awdorrin
2013-01-15  0:38 ` Randy Brukardt
2013-01-15  1:57 ` Adam Beneschan
2013-01-15 16:57 ` AdaMagica
2013-01-15 22:24 ` Stephen Leake
2013-01-16 10:44   ` Simon Wright
2013-01-16 19:00     ` AdaMagica
2013-01-16 21:34       ` Simon Wright
2013-01-16 23:14     ` Randy Brukardt
2013-01-17  3:49     ` Stephen Leake
2013-01-17 15:32       ` awdorrin
2013-01-18  9:49         ` Stephen Leake
2013-01-18 13:04           ` Robert A Duff
2013-01-19  1:43             ` Stephen Leake
2013-01-19 12:48               ` AdaMagica
2013-01-22  0:14                 ` Randy Brukardt
2013-01-17 17:28       ` Simon Wright
2013-01-18  9:56         ` Stephen Leake
2013-01-17 18:04 ` awdorrin
2013-01-17 19:50   ` awdorrin
2013-01-18  9:58     ` Stephen Leake
2013-01-17 20:58   ` Simon Wright
2013-01-17 21:29     ` awdorrin
2013-01-17 22:16       ` awdorrin
2013-01-18  6:15         ` J-P. Rosen
2013-01-18 15:28           ` Niklas Holsti
2013-01-18  9:37         ` Stephen Leake
2013-01-18 12:24         ` awdorrin
2013-01-18 15:11           ` awdorrin
2013-01-19  1:48             ` Stephen Leake
2013-01-18 17:19           ` Simon Wright
2013-01-22  9:49           ` quinot
2013-01-28 13:39             ` quinot
  -- strict thread matches above, loose matches on Subject: below --
2013-01-22  3:21 Stephen Leake
2013-01-22  5:14 ` Jeffrey Carter
2013-01-23  1:29   ` Stephen Leake
2013-01-22 22:40 ` Randy Brukardt
2013-01-23  1:38   ` Stephen Leake
2013-01-23 10:58     ` Simon Wright

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