Encouraging preliminary results implementing memcpy in D
David Nadlinger
code at klickverbot.at
Sun Jun 17 17:00:00 UTC 2018
On Wednesday, 13 June 2018 at 06:46:43 UTC, Mike Franklin wrote:
> https://github.com/JinShil/memcpyD
>
> […]
>
> Feedback, advise, and pull requests to improve the
> implementation are most welcome.
The memcpyD implementation is buggy; it assumes that all
arguments are aligned to their size. This isn't necessarily true.
For example, `ubyte[1024].alignof == 1`, and struct alignment can
also be set explicitly using align(N).
On x86, you can get away with this in a lot of cases even though
it's undefined behaviour [1], but this is not necessarily the
case for SSE/AVX instructions. In fact, that's probably a pretty
good guess as to where those weird crashes you mentioned come
from.
On other architectures, unaligned accesses might be outright
unsupported.
For loading into vector registers, you can use
core.simd.loadUnaligned instead (ldc.simd.loadUnaligned for LDC –
LDC's druntime has not been updated yet after {load,
store}Unaligned were added upstream as well).
— David
[1] This is applying C rules to D, where creation of unaligned
pointers is undefined behaviour. The D specification doesn't
mention
More information about the Digitalmars-d-announce
mailing list