回答編集履歴
1
加筆
answer
CHANGED
@@ -1,2 +1,43 @@
|
|
1
1
|
Visual Studio のデバッガでmemcpyに飛び込んでみた。
|
2
|
+
|
2
|
-

|
3
|
+

|
4
|
+
|
5
|
+
かたやコチラ↓が C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\crt\src\x64\memcpy.asm
|
6
|
+
|
7
|
+
```
|
8
|
+
mov r11, rcx ; save destination address
|
9
|
+
mov r10, rdx ; save source address
|
10
|
+
cmp r8, 16 ; if 16 bytes or less
|
11
|
+
jbe MoveBytes16 ; go move them quick
|
12
|
+
cmp r8, 32 ; check for length <= 32 (we know its > 16)
|
13
|
+
jbe Move17to32 ; go handle lengths 17-32 as a special case
|
14
|
+
sub rdx, rcx ; compute offset to source buffer
|
15
|
+
jae CopyUp ; if above or equal, go move up
|
16
|
+
mov rax, r10 ; else check that src+count < dst
|
17
|
+
add rax, r8 ; src + count
|
18
|
+
cmp rcx, rax ; (src + count) < dst
|
19
|
+
jl CopyDown ; no, buffers overlap go move downward
|
20
|
+
|
21
|
+
CopyUp:
|
22
|
+
cmp r8, 128
|
23
|
+
jbe XmmCopySmall
|
24
|
+
|
25
|
+
bt __favor, __FAVOR_ENFSTRG ; check for ENFSTRG (enhanced fast strings)
|
26
|
+
jnc XmmCopyUp ; If Enhanced Fast String not available, use XMM
|
27
|
+
|
28
|
+
; use Enhanced Fast Strings
|
29
|
+
; but first align the destination dst to 16 byte alignment
|
30
|
+
StringCopy:
|
31
|
+
mov rax, r11 ; return original destination pointer
|
32
|
+
mov r11, rdi ; save rdi in r11
|
33
|
+
mov rdi, rcx ; move destination pointer to rdi
|
34
|
+
mov rcx, r8 ; move length to rcx
|
35
|
+
mov r8, rsi ; save rsi in r8
|
36
|
+
mov rsi, r10 ; move source pointer to rsi
|
37
|
+
rep movsb ; copy source to destination buffer
|
38
|
+
mov rsi, r8 ; restore rsi
|
39
|
+
mov rdi, r11 ; restore rdi
|
40
|
+
ret
|
41
|
+
```
|
42
|
+
|
43
|
+
同じもんみたいやね、ッタリマエだけど。
|