2 ms·
Generally speaking, if a memcpy's size argument is a constant expression equal to the size of a native integer type, it will be transformed to a native load fro
by comex 8y ago
Generally speaking, if a memcpy's size argument is a constant expression equal to the size of a native integer type, it will be transformed to a native load from the source pointer followed by a store to the destination pointer. After that, the load or store operation (or both) may itself be optimized away if the pointer points to a local variable. Thus, for example, given something like:
void write32(int *ptr, int val) {
memcpy(ptr, &val, 4);
}
…the load is removed entirely, and the store is kept but becomes a native store:
write32:
mov DWORD PTR [rdi], esi
ret
Godbolt link: https://godbolt.org/g/HYv24F https://godbolt.org/g/HYv24F