Rev 1408 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1408 | Rev 1627 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | # _memmove() Author: Kees J. Bot 2 Jan 1994 |
1 | /* _memmove() Author: Kees J. Bot */ |
- | 2 | /* 2 Jan 1994 */ |
|
Line 2... | Line 3... | ||
2 | 3 | ||
3 | # void *_memmove(void *s1, const void *s2, size_t n) |
4 | /* void *_memmove(void *s1, const void *s2, size_t n) */ |
4 | # Copy a chunk of memory. Handle overlap. |
5 | /* Copy a chunk of memory. Handle overlap. */ |
5 | - | ||
6 | .intel_syntax |
6 | /* */ |
7 | 7 | ||
8 | .globl __memmove, __memcpy |
- | |
9 | - | ||
10 | .text |
8 | #include "asm.h" |
11 | - | ||
12 | .align 16 |
9 | |
13 | __memmove: |
10 | ENTRY(_memmove) |
14 | push ebp |
11 | push %ebp |
15 | mov ebp, esp |
- | |
16 | 12 | movl %esp, %ebp |
|
17 | push esi |
13 | push %esi |
18 | push edi |
- | |
19 | 14 | push %edi |
|
20 | mov edi, [ebp+8] # String s1 |
15 | movl 8(%ebp), %edi /* String s1 */ |
21 | mov esi, [ebp+12] # String s2 |
16 | movl 12(%ebp), %esi /* String s2 */ |
22 | mov ecx, [ebp+16] # Length |
- | |
23 | 17 | movl 16(%ebp), %ecx /* Length */ |
|
24 | mov eax, edi |
18 | movl %edi, %eax |
25 | sub eax, esi |
19 | subl %esi, %eax |
26 | cmp eax, ecx |
20 | cmpl %ecx, %eax |
27 | jb downwards # if (s2 - s1) < n then copy downwards |
21 | jb downwards /* if (s2 - s1) < n then copy downwards */ |
28 | __memcpy: |
22 | LABEL(_memcpy) |
29 | cld # Clear direction bit: upwards |
23 | cld /* Clear direction bit: upwards */ |
30 | cmp ecx, 16 |
24 | cmpl $16, %ecx |
31 | jb upbyte # Don't bother being smart with short arrays |
- | |
32 | 25 | jb upbyte /* Don't bother being smart with short arrays */ |
|
33 | mov eax, esi |
26 | movl %esi, %eax |
34 | or eax, edi |
27 | orl %edi, %eax |
35 | testb al, 1 |
28 | testb $1, %al |
36 | jnz upbyte # Bit 0 set, use byte copy |
- | |
37 | 29 | jne upbyte /* Bit 0 set, use byte copy */ |
|
38 | testb al, 2 |
- | |
39 | 30 | testb $2, %al |
|
40 | jnz upword # Bit 1 set, use word copy |
31 | jne upword /* Bit 1 set, use word copy */ |
41 | uplword: |
32 | uplword: |
42 | shrd eax, ecx, 2 # Save low 2 bits of ecx in eax |
33 | shrdl $2, %ecx, %eax /* Save low 2 bits of ecx in eax */ |
- | 34 | shrl $2, %ecx |
|
43 | shr ecx, 2 |
35 | |
44 | rep movsd # Copy longwords. |
36 | rep movsl /* Copy longwords. */ |
45 | shld ecx, eax, 2 # Restore excess count |
37 | shldl $2, %eax, %ecx /* Restore excess count */ |
46 | upword: |
38 | upword: |
- | 39 | shrl $1, %ecx |
|
47 | shr ecx, 1 |
40 | |
48 | rep movsw # Copy words |
41 | rep movsw /* Copy words */ |
49 | adc ecx, ecx # One more byte? |
42 | adcl %ecx, %ecx /* One more byte? */ |
50 | upbyte: |
43 | upbyte: |
51 | rep movsb # Copy bytes |
44 | rep movsb /* Copy bytes */ |
52 | done: |
45 | done: |
53 | mov eax, [ebp+8] # Absolutely noone cares about this value |
46 | movl 8(%ebp), %eax /* Absolutely noone cares about this value */ |
54 | pop edi |
47 | pop %edi |
55 | pop esi |
48 | pop %esi |
56 | pop ebp |
49 | pop %ebp |
Line 57... | Line 50... | ||
57 | ret |
50 | ret |
58 | - | ||
59 | # Handle bad overlap by copying downwards, don't bother to do word copies. |
51 | |
60 | 52 | /* Handle bad overlap by copying downwards, don't bother to do word copies. */ |
|
61 | downwards: |
53 | downwards: |
62 | std # Set direction bit: downwards |
54 | std /* Set direction bit: downwards */ |
- | 55 | leal -1(%esi,%ecx,1), %esi |
|
63 | lea esi, [esi+ecx-1] |
56 | leal -1(%edi,%ecx,1), %edi |
64 | lea edi, [edi+ecx-1] |
57 | |
65 | rep movsb # Copy bytes |
58 | rep movsb /* Copy bytes */ |