lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] wrong statement in lwip wiki page aboutstructure packin


From: Stephane Lesage
Subject: Re: [lwip-users] wrong statement in lwip wiki page aboutstructure packing
Date: Wed, 29 Aug 2012 13:06:14 +0200

> jblackarty wrote:
> > Structure alignment and packing of internal members are different
> > things.

Strictly speaking, packing would refer to "disable padding".
I know that even on x86 who can do misaligned accesses, a compiler will
pad 16 or 32 bits fields to improve performance, but ONLY if they are
not aligned inside the structure.

This is not our case for LwIP, IP/UDP/TCP fields are already packed.

> I'm not so sure about that (in the lwIP context, that is).
> > Author of those phrase was wrong in last words about packing.
> > Structure members may be padded relatively to each other in general
> case.
> > This is what I talking about. I don't know what means "packing" with
> > respect to whole structure but I'm sure each member must be packed
> > separately.
> So if you don't know that, how can you be sure that "Structure
> alignment and packing of internal members are different things"?

On the wiki, I meant packing for LwIP...

> I think that PACK_STRUCT_STRUCT and PACK_STRUCT_FIELD are just two
> different macros for different compilers: one compiler may need a
> struct marked as packed while another compiler may need the fields
> marked as packed (or both) while yet another compiler uses pragmas
(and
> thus has to declare the 2 include files).

Exactly.

> I know that there is a difference between structure packing and being
> able to access unaligned data. lwIP mixes up these two and relies on
> the fact that most compilers (all I know, at least) can access members
> of packed struct that are unaligned.

Yes I think this is the intent.
We "pack" structures so that we can access misaligned members.

In IP/UDP/TCP header structures, all fields are naturally aligned
because they are packed because it was designed this way.
Our problem is that the pointer to such a structure may not be 32 bits
aligned.
In LwIP we use "packing" to tell this to the compiler -> it will be
forced to use misaligned access instructions in case it's needed.


-- 
Stephane Lesage



reply via email to

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