决定用asm和mmx指令编制一个快速进行内存复制的函数来代替C运行库的memcpy(),
请高手指点有没有错误.代码如下:void FastMemcpy(unsigned char * Src, unsigned char * Dest, unsigned int Len)
{
__asm{
mov esi, [Src]
mov edi, [Dest]
mov ecx, Len mov eax, ecx
sub ecx, edi
sub ecx, eax
and ecx, 7
sub eax, ecx
jle L2
emms
rep movsb
mov ecx, eax
and eax, 7
shr ecx, 3
jz L2
sub edi, esi
L1: movq mm0, [esi]
movq [edi+esi], mm0
add esi, 8
dec ecx
jnz L1
add edi, esi
emmsL2: add ecx, eax
rep movsb
}//end asm}
请高手指点有没有错误.代码如下:void FastMemcpy(unsigned char * Src, unsigned char * Dest, unsigned int Len)
{
__asm{
mov esi, [Src]
mov edi, [Dest]
mov ecx, Len mov eax, ecx
sub ecx, edi
sub ecx, eax
and ecx, 7
sub eax, ecx
jle L2
emms
rep movsb
mov ecx, eax
and eax, 7
shr ecx, 3
jz L2
sub edi, esi
L1: movq mm0, [esi]
movq [edi+esi], mm0
add esi, 8
dec ecx
jnz L1
add edi, esi
emmsL2: add ecx, eax
rep movsb
}//end asm}
解决方案 »
- 无模式对话框能不能当主窗口用?
- 大津法程序出现错误error C2064: 项不会计算为接受 1 个参数的函数
- 在线等!请大家看看一个比较简单的问题!!!
- 请问time占用cpu多么?
- 在做一个下载器,现在想借助迅雷的多资源下载来提高速度,但是他是如何获得相同资源的呢?那位高手解答一下?就剩30都给了
- 有关窗口销毁的问题
- 用VC打开一个Word文档,能不能将Word文档的一页全部内容包括表格,一次拷贝到另一页?
- 一个关于com线程的问题
- 在线:在程序中加载任一网页,用鼠标点击任一超连接,均能捕获所点击连接的文本。该如何做?
- 有谁能告诉我 怎么用RegQueryValue 函数去得到一个注册表里的数值呢!
- 各位高手,指点指点小妹吧,我写完了一个C,S,但我不知会有什么问题,比如线程安全等
- 开启若干个相同的线程,如何标志每一个进程呢/?
各位老大,还有没有潜能可挖.
;
; TinyPTC by Gaffer
; www.gaffer.org/tinyptc
; Modifications by Gladius
;bits 32global _mmx_memcpysection .data
align 16section .textalign 16_mmx_memcpy: push ebp
mov ebp,esp pushad mov edi,[ebp+8] ; destination
mov esi,[ebp+12] ; source
mov ecx,[ebp+16] ; bytes mov eax,ecx
shr ecx,6
mov ebx,ecx
shl ebx,6
sub eax,ebx cmp ecx,0
je .donealign 16
.loop movq mm0,[esi]
movq mm1,[esi+8]
movq mm2,[esi+16]
movq mm3,[esi+24]
movq mm4,[esi+32]
movq mm5,[esi+40]
movq mm6,[esi+48]
movq mm7,[esi+56]
movq [edi],mm0
movq [edi+8],mm1
movq [edi+16],mm2
movq [edi+24],mm3
movq [edi+32],mm4
movq [edi+40],mm5
movq [edi+48],mm6
movq [edi+56],mm7
add esi,8*8
add edi,8*8
dec ecx
jnz .loop .done
mov ecx,eax
rep movsb emms popad
pop ebp
ret
void FastMemcpy(unsigned char * Src, unsigned char * Dest, unsigned int Len)
{
__asm{
mov esi, Src
mov edi, Dest
mov ecx, Len
mov eax, ecx
sub ecx, edi
sub ecx, eax
and ecx, 7
sub eax, ecx
jle L2
emms
rep movsb
mov ecx, eax
and eax, 7
shr ecx, 3
jz L2
sub edi, esi
L1: movq mm0, [esi]
movq [edi+esi], mm0
add esi, 8
dec ecx
jnz L1
add edi, esi
emms
L2: add ecx, eax
rep movsb
}//end asm
}
sub ecx, edi ; ecx = Len - (INT)Dest
sub ecx, eax ; ecx = ecx - Len等价与 ecx = (Len - (INT)Dest) - Len = 0 - (INT)Dest,直接用下面代码的不是更直观吗? mov ecx, edi
neg ecx