[cfe-dev] struct copy

Mattias EngdegÄrd mattias at virtutech.se
Sun Sep 28 04:03:13 PDT 2008


Chris Lattner <clattner at apple.com> writes:

>This is true on the micro-level, but is false in the macro level.  For
>example, if the caller of a function does a one byte store into a
>struct field, and the callee does a memcpy (ending up with a 32-bit
>read), you get a store forwarding speculation failure on most out of
>order processors.

Thank you, I didn't think of that. I wonder to what extent that effect
depends on the existence of holes in the struct layout. Should structs
always be copied member-by-member, even if they consist of many small
bytes?

struct S {
    char c[7];
    double d;
}

Would seven byte copies really be faster than one 64-bit word copy?
If there were eight bytes in the array, there would be no hole but
the problem remains - at least if the entire array was not written to
before the struct copy.




More information about the cfe-dev mailing list