4 ms·
We used memcpy everywhere in our runtime and after the 10th or so time doing it, it becomes less awkward.
by tekknolagi 2y ago
We used memcpy everywhere in our runtime and after the 10th or so time doing it, it becomes less awkward.
- dahart 2y agoAnd it’s always reliably optimized out in release builds, I assume?
- LegionMammal978 2y agoOn platforms thar require aligned loads and stores (not x86 nor ARM), a direct pointer cast sometimes uses an aligned load/store where a memcpy uses multiple byte loads/stores, even on a good compiler, since memcpy() doesn't require that the pointers are aligned. This can be mitigated by going through a local variable, but it gets pretty verbose.
- stouset 2y agoSounds like a good place for a macro?
- mbitsnbites 2y agoWe have memcpy behind a C++ template function that mimics the interface of std::bit_cast.
- ack_complete 2y agoSome ARM CPUs do require aligned loads and stores, such as the Cortex-M0+ in a Raspberry Pi Pico.
- Asooka 2y agoFor MSVC you have to add "/Oi", otherwise it is always a function call at lower optimisation levels. Clang and GCC treat it as an intrinsic always, even in debug builds.
- tekknolagi 2y agoI haven't manually checked every case but it's normally folded into the load or shift or whatever and completely erased