On Wed, Nov 10, 2010 at 01:00:49PM +0100, David Brown wrote:
> Would it be possible to use the named address space syntax to
> implement reverse-endian data?  Conversion between little-endian and
> big-endian data structures is something that turns up regularly in
> embedded systems, where you might well be using two different
> architectures with different endianness.  Some compilers offer
> direct support for endian swapping, but gcc has no neat solution.
> You can use the __builtin_bswap32 (but no __builtin_bswap16?)
> function in recent versions of gcc, but you still need to handle the
> swapping explicitly.
> 
> Named address spaces would give a very neat syntax for using such
> byte-swapped areas.  Ideally you'd be able to write something like:
> 
> __swapendian stuct { int a; short b; } data;
> 
> and every access to data.a and data.b would be endian-swapped.  You
> could also have __bigendian and __litteendian defined to
> __swapendian or blank depending on the native ordering of the
> target.
> 
> 
> I've started reading a little about how named address spaces work,
> but I don't know enough to see whether this is feasible or not.
> 
> 
> Another addition in a similar vein would be __nonaligned, for
> targets which cannot directly access non-aligned data.  The loads
> and stores would be done byte-wise for slower but correct
> functionality.

Yes.  In fact when I gave the talk on named address spaces I mentioned this,
and during the summit last year, I made a toy demonstration set of patches in
the PowerPC to add cross endian support.

-- 
Michael Meissner, IBM
5 Technology Place Drive, M/S 2757, Westford, MA 01886-3141, USA
meiss...@linux.vnet.ibm.com

Reply via email to