"That's a huge improvement in generated code size. The above two compiles used the same gcc flags"
It would have been awfully nice to state the version of the compiler and the flags being used. With gcc 10 on Linux/AMD64, libc 4.15.0, I get with '-Os':
GCC optimizations are also smart enough to remove memcpy calls for small numbers of bytes entirely and just output the unrolled movs/loads inline. If you're memcpy'ing a struct from a byte buffer and reading some fields, the optimizer is usually smart enough to output the minimum instructions necessary. As I recall, MSVC's optimizations perform similarly.
Comments
"That's a huge improvement in generated code size. The above two compiles used the same gcc flags"
It would have been awfully nice to state the version of the compiler and the flags being used. With gcc 10 on Linux/AMD64, libc 4.15.0, I get with '-Os':
Which doesn't seem so bad.GCC optimizations are also smart enough to remove memcpy calls for small numbers of bytes entirely and just output the unrolled movs/loads inline. If you're memcpy'ing a struct from a byte buffer and reading some fields, the optimizer is usually smart enough to output the minimum instructions necessary. As I recall, MSVC's optimizations perform similarly.