lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Misalignment problems on PowerPC (little endian mode)


From: David Empson
Subject: Re: [lwip-users] Misalignment problems on PowerPC (little endian mode)
Date: Mon, 26 May 2008 11:39:46 +1200

Simon Goldschmidt <address@hidden> wrote:
Still I cannot understand why your compiler (or rather its vendor) doesn't
support structure packing which is a rather common element of C (even
if it is not included in the C-standard, or is it?)

There is no requirement for an ANSI-compliant C compiler to support any kind of structure packing.

The only requirement is that structure members are located in memory in the order defined. There can be any amount of padding imposed by the compiler after any member for alignment efficiency or to comply with alignment requirements of the platform.

Packing is a GCC extension, also supported in some form by some other compilers, but it wouldn't surprise me that some don't implement it (even some GCC ports).

Some platforms (e.g. x86) can do misaligned accesses with only a small performance hit. In this case, packing is a convenient way to deal with external data structures that don't match the platform's alignment rules.

Some platforms only support 16-bit or 32-bit accesses to addresses that are appropriately aligned, and a misaligned access will cause an exception. The exception handler can then implement the misaligned access and resume execution, but this causes a major performance hit. It might still be feasible to support structure packing on this type of platform.

Some platforms have no warning of any kind: a misaligned access will address the wrong memory locations (e.g. a 16-bit read will always be 16-bit aligned, ignoring the low order bit of the supplied address). On such a platform, there is no way for the compiler to access a misaligned field in a structure short of doing multiple memory accesses with split/merge operations. If it is possible to have pointers to misaligned data, then every memory access via a pointer must use conditional code to check for misalignment and deal with it as appropriate. (If any compiler does this, I'd expect it to also implement a language extension to allow identifying pointer variables that require misaligned data handling.)

In a platform of the third type (and possibly the second), it would be better for the developer to pass the structure through a pack/unpack mechanism to allow efficient access to members (basically copying the structure).

I'm not particularly familar with PowerPC architecture at this low level, so I don't know where it falls in the degree of difficulty of accessing misaligned data. It it is quite possible that it is harder to access misaligned data in little-endian mode than in big-endian mode.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]