From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: GNAT 4.4.5 Record Bit_Order Endian issues
Date: Wed, 16 Jan 2013 22:49:31 -0500
Date: 2013-01-16T22:49:31-05:00 [thread overview]
Message-ID: <85bocoqxis.fsf@stephe-leake.org> (raw)
In-Reply-To: lyfw21v24l.fsf@pushface.org
Simon Wright <simon@pushface.org> writes:
> Stephen Leake <stephen_leake@stephe-leake.org> writes:
>
>> awdorrin <awdorrin@gmail.com> writes:
>>
>>> 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.
>>
>> If you are allocating consecutive bits, then do this:
>>
>> for TRACK_RECORD_TYPE use
>> record
>> TRACK_ID at 0 range 0 .. 11;
>> TRACK_ID_CNT at 0 range 12 .. 17;
>> ...
>
> I don't see why this makes a difference?
The best explanation I have seen is in
http://www.ada-auth.org/ai-files/grab_bag/bitorder.pdf
That introduces the concept of "machine scalar", which helps a lot.
The problem is what does "the first twelve bits" mean, when the
"natural" size of a chunk of memory is 8 bits?
In this code:
TRACK_ID at 0 range 0 .. 11;
TRACK_ID_CNT at 1 range 4 .. 9;
if Storage_Unit = 8, the two fields overlap. I can't figure out a
storage arrangement that makes these fields contiguous; can you draw a
picture? Changing to a compiler/target with a different Storage_Size
changes the meaning.
In this code:
TRACK_ID at 0 range 0 .. 11;
TRACK_ID_CNT at 0 range 12 .. 17;
it's obvious that the fields are contiguous, and it's up to the compiler
to ensure that happens.
Note that gnat agrees with me:
> OP's way:
> awdorrin.ads:13:26: info: reverse bit order in machine scalar of length 16
> awdorrin.ads:13:26: info: little-endian range for component "Track_Id" is 4 .. 15
> awdorrin.ads:15:06: component "Track_Id_Cnt" overlaps "Track_Id" at line 13
> awdorrin.ads:15:30: info: reverse bit order in machine scalar of length 16
> awdorrin.ads:15:30: info: little-endian range for component "Track_Id_Cnt" is 6 .. 11
> gnatmake: "awdorrin.ads" compilation error
This says that the first code specifies overlapping fields, which is not
what you want.
> Your way:
> awdorrin.ads:13:26: info: reverse bit order in machine scalar of length 32
> awdorrin.ads:13:26: info: little-endian range for component "Track_Id" is 20 .. 31
> awdorrin.ads:14:30: info: reverse bit order in machine scalar of length 32
> awdorrin.ads:14:30: info: little-endian range for component "Track_Id_Cnt" is 14 .. 19
This says the two fields occupy the 16 bits numbered 31 .. 19, and are
consecutive.
Why do you say this is buggy?
--
-- Stephe
next prev parent reply other threads:[~2013-01-17 3:49 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox