Wrap calls to memcpy(3) in a function called block_copy(). This way,

and as long as we're not compiling with IPA, gcc(1) won't optimize
the call away. The whole purpose of using memcpy(3) is to avoid
misaligned loads and stores when we need to read or write the value
in the unaligned memory location. But if gcc(1) optimizes the call
to memcpy(3) away, it will typically introduce misaligned loads and
stores. In this context that's not a good idea.
This commit is contained in:
Marcel Moolenaar 2005-01-28 02:58:32 +00:00
parent c1195b0646
commit ad284e38a3

View File

@ -101,6 +101,13 @@ DATA_TYPE *aligned = &data.aligned;
DATA_TYPE *misaligned = (DATA_TYPE *)data.misaligned; DATA_TYPE *misaligned = (DATA_TYPE *)data.misaligned;
DATA_TYPE value = DATA_VALUE; DATA_TYPE value = DATA_VALUE;
void
block_copy(void *dst, void *src, size_t sz)
{
memcpy(dst, src, sz);
}
int int
main() main()
{ {
@ -112,7 +119,7 @@ main()
/* /*
* LOAD * LOAD
*/ */
memcpy(misaligned, &value, sizeof(DATA_TYPE)); block_copy(misaligned, &value, sizeof(DATA_TYPE));
# if POSTINC == NoPostInc # if POSTINC == NoPostInc
/* Misaligned load. */ /* Misaligned load. */
@ -179,7 +186,7 @@ main()
return (1); return (1);
# endif # endif
memcpy(aligned, data.misaligned, sizeof(DATA_TYPE)); block_copy(aligned, data.misaligned, sizeof(DATA_TYPE));
#endif #endif
if (*aligned != value) if (*aligned != value)