comp.lang.ada
 help / color / mirror / Atom feed
From: quinot@adacore.com
Subject: Re: GNAT 4.4.5 Record Bit_Order Endian issues
Date: Tue, 22 Jan 2013 01:49:23 -0800 (PST)
Date: 2013-01-22T01:49:23-08:00	[thread overview]
Message-ID: <e79e7820-ed78-4b0d-9f00-c80d26f25bb9@googlegroups.com> (raw)
In-Reply-To: <8a7a9e6f-6f87-44a7-942b-2275a9ecf049@googlegroups.com>

On Friday, January 18, 2013 1:24:02 PM UTC+1, awdorrin wrote:
 
> I had a realization in the shower this morning:

That's often where great ideas are hatched! :-)

> The byte and bit ranges used in the specification clause is not describing memory locations, it is describing the location in the CPU register. The Bit_Order flag is being used to describe which end of the CPU register is bit zero.

Right, this is exactly correct.

> Due to the (byte level) endian differences, it would seem that it is not possible to describe the physical bit locations in memory, since it is the offset in the register that is being described.

Correct. If you have a record where some components cross a storage unit boundary, then no standard rep clause can make it so that the record has the same representation in memory on both big endian and little endian platforms.

> In order to get the record memory contents ordered the way I want them to be, I'm going to have to play some byte swap games and translate the record memory contents into a 'big endian buffer'. 
>
> Presumably, if the record contents can be defined in terms of a 32-bit 'machine scalar' - then this endian conversion can be done by starting at 'MyTrkRec'Address' and doing byte swaps on 4-byte (32-bit) groupings.

Yes, that's a correct approach.

> In C I'd simply make a 'uint32_t' pointer to the record address, and loop through till the end of the record doing 'htonl()' calls. But Ada doesn't make things quite so 'easy' ;-)

Well, easy enough :-) You can overlap an array of Interfaces.Unsigned_32 over
your record, and use GNAT.Byte_Swapping.Swap4 on each element.

Also note that the latest development version of GNAT Pro introduces a new implementation-defined attribute Scalar_Storage_Order which precisely aims at relieving programmers from having to do such byte-swapping "by hand" and provide a means to force a record to have the same representation whether the target is big-endian or little-endian (http://www.adacore.com/developers/development-log/NF-71-L207-008-gnat/).


An article about this feature will appear next week in our Ada Gems series (http://www.adacore.com/adaanswers/gems/), and we also have submitted a technical paper on this matter to the upcoming Ada Europe 2013 conference.

Thomas Quinot.



  parent reply	other threads:[~2013-01-22  9: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
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 [this message]
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