Hi...

Coming a bit late..

As you see, with -Os, this produces:
        /* THIS FIELD IS ONLY 16 BITS */
        movl    4(%ebx), %eax
        movw    %ax, (%esi)

While the no-optimizations code looks like this:
        movl    8(%ebp), %eax
        movzwl  4(%eax), %eax
        movl    %eax, %edx
        movl    12(%ebp), %eax
        movw    %dx, (%eax)

The first one is clearly loading a 32-bit value from an address that
may not have more than 16 bits written to it.

So, is it legal for the compiler to do that?

Interesting to look at this fact (never realize it before). Maybe in -Os, compiler (gcc in this case?) assumes there is padding, either inside the struct or between this struct and next variable/struct. Thus, treating them as 32 bit is fine since in most cases you get zeroed page when doing memory allocation. Clear advantage here, smaller code.

What if you put "packed" attribute at the the struct declaration? Still see the same thing?

regards,

Mulyadi


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to