mirror of
https://github.com/reactos/reactos.git
synced 2025-06-01 15:38:37 +00:00
[RTL}
Replace RtlMoveMemory x86 asm code with the code from CRT's memmove, which is better. Now we can close bug #1941 svn path=/trunk/; revision=50116
This commit is contained in:
parent
c884962fb3
commit
e7f8fba710
1 changed files with 102 additions and 48 deletions
|
@ -210,70 +210,124 @@ ByteZero:
|
||||||
|
|
||||||
|
|
||||||
_RtlMoveMemory@12:
|
_RtlMoveMemory@12:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
|
||||||
/* Save volatiles */
|
/* Save non-volatiles */
|
||||||
push esi
|
push esi
|
||||||
push edi
|
push edi
|
||||||
|
|
||||||
/* Get pointers and size */
|
/* Get pointers and size */
|
||||||
mov esi, [esp+16]
|
mov edi, [ebp + 8]
|
||||||
mov edi, [esp+12]
|
mov esi, [ebp + 12]
|
||||||
mov ecx, [esp+20]
|
mov ecx, [ebp + 16]
|
||||||
cld
|
|
||||||
|
|
||||||
/* Check if the destination is higher (or equal) */
|
/* Use downward copy if source < dest and overlapping */
|
||||||
cmp esi, edi
|
cmp edi, esi
|
||||||
jbe Overlap
|
jbe .CopyUp
|
||||||
|
mov eax, ecx
|
||||||
|
add eax, esi
|
||||||
|
cmp edi, eax
|
||||||
|
jb .CopyDown
|
||||||
|
|
||||||
/* Set ULONG size and UCHAR remainder */
|
.CopyUp:
|
||||||
DoMove:
|
cld
|
||||||
mov edx, ecx
|
|
||||||
and edx, 3
|
|
||||||
shr ecx, 2
|
|
||||||
|
|
||||||
/* Do the move */
|
/* Check for small moves */
|
||||||
rep movsd
|
cmp ecx, 16
|
||||||
or ecx, edx
|
jb .CopyUpBytes
|
||||||
jnz ByteMove
|
|
||||||
|
|
||||||
/* Return */
|
/* Check if its already aligned */
|
||||||
pop edi
|
mov edx, ecx
|
||||||
pop esi
|
test edi, 3
|
||||||
ret 12
|
je .CopyUpDwords
|
||||||
|
|
||||||
ByteMove:
|
/* Make the destination dword aligned */
|
||||||
/* Move what's left */
|
mov ecx, edi
|
||||||
rep movsb
|
and ecx, 3
|
||||||
|
sub ecx, 5
|
||||||
|
not ecx
|
||||||
|
sub edx, ecx
|
||||||
|
rep movsb
|
||||||
|
mov ecx, edx
|
||||||
|
|
||||||
DoneMove:
|
.CopyUpDwords:
|
||||||
/* Restore volatiles */
|
shr ecx, 2
|
||||||
pop edi
|
rep movsd
|
||||||
pop esi
|
mov ecx, edx
|
||||||
ret 12
|
and ecx, 3
|
||||||
|
|
||||||
Overlap:
|
.CopyUpBytes:
|
||||||
/* Don't copy if they're equal */
|
test ecx, ecx
|
||||||
jz DoneMove
|
je .CopyUpEnd
|
||||||
|
rep movsb
|
||||||
|
|
||||||
/* Compare pointer distance with given length and check for overlap */
|
.CopyUpEnd:
|
||||||
mov eax, edi
|
mov eax, [ebp + 8]
|
||||||
sub eax, esi
|
pop edi
|
||||||
cmp ecx, eax
|
pop esi
|
||||||
jbe DoMove
|
pop ebp
|
||||||
|
ret 12
|
||||||
|
|
||||||
/* Set direction flag for backward move */
|
.CopyDown:
|
||||||
std
|
std
|
||||||
|
|
||||||
/* Copy byte-by-byte the non-overlapping distance */
|
/* Go to the end of the region */
|
||||||
add esi, ecx
|
add edi, ecx
|
||||||
add edi, ecx
|
add esi, ecx
|
||||||
dec esi
|
|
||||||
dec edi
|
/* Check for small moves */
|
||||||
|
cmp ecx, 16
|
||||||
|
jb .CopyDownSmall
|
||||||
|
|
||||||
|
/* Check if its already aligned */
|
||||||
|
mov edx, ecx
|
||||||
|
test edi, 3
|
||||||
|
je .CopyDownAligned
|
||||||
|
|
||||||
|
/* Make the destination dword aligned */
|
||||||
|
mov ecx, edi
|
||||||
|
and ecx, 3
|
||||||
|
sub edx, ecx
|
||||||
|
dec esi
|
||||||
|
dec edi
|
||||||
|
rep movsb
|
||||||
|
mov ecx, edx
|
||||||
|
sub esi, 3
|
||||||
|
sub edi, 3
|
||||||
|
|
||||||
|
.CopyDownDwords:
|
||||||
|
shr ecx, 2
|
||||||
|
rep movsd
|
||||||
|
mov ecx, edx
|
||||||
|
and ecx, 3
|
||||||
|
je .CopyDownEnd
|
||||||
|
add esi, 3
|
||||||
|
add edi, 3
|
||||||
|
|
||||||
|
.CopyDownBytes:
|
||||||
|
rep movsb
|
||||||
|
|
||||||
|
.CopyDownEnd:
|
||||||
|
cld
|
||||||
|
mov eax, [ebp + 8]
|
||||||
|
pop edi
|
||||||
|
pop esi
|
||||||
|
pop ebp
|
||||||
|
ret 12
|
||||||
|
|
||||||
|
.CopyDownAligned:
|
||||||
|
sub edi, 4
|
||||||
|
sub esi, 4
|
||||||
|
jmp .CopyDownDwords
|
||||||
|
|
||||||
|
.CopyDownSmall:
|
||||||
|
test ecx, ecx
|
||||||
|
je .CopyDownEnd
|
||||||
|
dec esi
|
||||||
|
dec edi
|
||||||
|
jmp .CopyDownBytes
|
||||||
|
|
||||||
/* Do the move, reset flag and return */
|
|
||||||
rep movsb
|
|
||||||
cld
|
|
||||||
jmp DoneMove
|
|
||||||
|
|
||||||
|
|
||||||
@RtlPrefetchMemoryNonTemporal@8:
|
@RtlPrefetchMemoryNonTemporal@8:
|
||||||
|
|
Loading…
Reference in a new issue