3 ms·
Functionally it seems equivalent, except that it doesn't work on big endian machines (assuming the ints are in native endian). On dumb compilers it may be fast
by qb45 10y ago
Functionally it seems equivalent, except that it doesn't work on big endian machines (assuming the ints are in native endian).
On dumb compilers it may be faster if a few bitops happen to be faster than a call to memcpy. Which sounds plausible.
On modern compilers it boils down to whether your compiler can optimize either one or both of these patterns into a single unaligned load. GCC for example certainly optimizes 4 byte memcpy, probably already at -O2, but whether it recognizes your pattern I don't know. Compile it and check.