This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Idea - big and little endian data areas using named address spaces


C++ lets you define explicit-order integer types and hide all the conversions.  I used that a couple of jobs ago, back around 1996 or so -- worked nicely, and should work even better now that C++ is more mature.

	paul

On Nov 10, 2010, at 7:00 AM, 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.
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]