|
|
|
|
|
by haberman
3693 days ago
|
|
Can assert() actually function this way? Can you use assert to tell the optimizer it can assume something is true? I've noticed that memcpy(x, y, 4) on x86 can generate very efficient code (register move), but on ARM it expands to something much more verbose because the addresses might not be aligned. Could this effectively function as a way of promising to the compiler that the addresses are aligned? void move4_aligned(void *dst, const void *src) {
assert(((uintptr_t)dst & 0x3) == 0);
assert(((uintptr_t)src & 0x3) == 0);
memcpy(dst, src, 4);
}
|
|
Trivially.