Skip to content

Conversation

@MaxGraey
Copy link
Member

Ref: https://git.musl-libc.org/cgit/musl/tree/src/string/memmove.c

  • I've read the contributing guidelines

@dcodeIO
Copy link
Member

dcodeIO commented Jul 30, 2020

Relevant musl commit for background:

the comparison must take place in the address space model as an
integer type, since comparing pointers that are not pointing into the
same array is undefined.

the subsequent d<s comparison however is valid, because it's only
reached in the case where the source and dest overlap, in which case
they are necessarily pointing to parts of the same array.

to make the comparison, use an unsigned range check for dist(s,d)>=n,
algebraically !(-n<s-d<n). subtracting n yields !(-2n<s-d-n<0), which
mapped into unsigned modular arithmetic is !(-2
n<s-d-n) or rather
-2*n>=s-d-n.

@dcodeIO dcodeIO merged commit b622400 into AssemblyScript:master Jul 30, 2020
@MaxGraey MaxGraey deleted the optimize-mem-move-copy branch July 30, 2020 14:57
@github-actions
Copy link

🎉 This PR is included in version 0.14.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants