64,677
社区成员
发帖
与我相关
我的任务
分享
_VEC_memzero:
78AB0184: 66 0F EF C0 pxor xmm0,xmm0
78AB0188: 51 push ecx
78AB0189: 53 push ebx
78AB018A: 8B C1 mov eax,ecx
78AB018C: 83 E0 0F and eax,0Fh
78AB018F: 85 C0 test eax,eax
78AB0191: 74 25 je 78AB01B8
78AB0193: 8B D8 mov ebx,eax
78AB0195: F7 DB neg ebx
78AB0197: 83 C3 10 add ebx,10h
78AB019A: 2B D3 sub edx,ebx
78AB019C: 33 C0 xor eax,eax
78AB019E: 52 push edx
78AB019F: 8B D3 mov edx,ebx
78AB01A1: 83 E2 03 and edx,3
78AB01A4: 0F 85 B4 01 00 00 jne 78AB035E
78AB01AA: C1 EB 02 shr ebx,2
78AB01AD: 74 08 je 78AB01B7
78AB01AF: 89 01 mov dword ptr [ecx],eax
78AB01B1: 8D 49 04 lea ecx,[ecx+4]
78AB01B4: 4B dec ebx
78AB01B5: 75 F8 jne 78AB01AF
78AB01B7: 5A pop edx
78AB01B8: 8B C2 mov eax,edx
78AB01BA: 83 E2 7F and edx,7Fh
78AB01BD: C1 E8 07 shr eax,7
78AB01C0: 74 3E je 78AB0200
78AB01C2: 8D 24 24 lea esp,[esp]
78AB01C5: 90 nop
78AB01C6: 90 nop
78AB01C7: 90 nop
78AB01C8: 90 nop
78AB01C9: 90 nop
78AB01CA: 90 nop
78AB01CB: 90 nop
78AB01CC: 90 nop
78AB01CD: 90 nop
78AB01CE: 90 nop
78AB01CF: 90 nop
78AB01D0: 66 0F 7F 01 movdqa xmmword ptr [ecx],xmm0
78AB01D4: 66 0F 7F 41 10 movdqa xmmword ptr [ecx+10h],xmm0
78AB01D9: 66 0F 7F 41 20 movdqa xmmword ptr [ecx+20h],xmm0
78AB01DE: 66 0F 7F 41 30 movdqa xmmword ptr [ecx+30h],xmm0
78AB01E3: 66 0F 7F 41 40 movdqa xmmword ptr [ecx+40h],xmm0
78AB01E8: 66 0F 7F 41 50 movdqa xmmword ptr [ecx+50h],xmm0
78AB01ED: 66 0F 7F 41 60 movdqa xmmword ptr [ecx+60h],xmm0
78AB01F2: 66 0F 7F 41 70 movdqa xmmword ptr [ecx+70h],xmm0
78AB01F7: 8D 89 80 00 00 00 lea ecx,[ecx+00000080h]
78AB01FD: 48 dec eax
78AB01FE: 75 D0 jne 78AB01D0
78AB0200: 85 D2 test edx,edx
78AB0202: 74 2C je 78AB0230
78AB0204: 8B C2 mov eax,edx
78AB0206: C1 E8 04 shr eax,4
78AB0209: 74 0A je 78AB0215
78AB020B: 66 0F 7F 01 movdqa xmmword ptr [ecx],xmm0
78AB020F: 8D 49 10 lea ecx,[ecx+10h]
78AB0212: 48 dec eax
78AB0213: 75 F6 jne 78AB020B
78AB0215: 83 E2 0F and edx,0Fh
78AB0218: 74 16 je 78AB0230
78AB021A: 8B C2 mov eax,edx
78AB021C: 33 DB xor ebx,ebx
78AB021E: C1 EA 02 shr edx,2
78AB0221: 74 08 je 78AB022B
78AB0223: 89 19 mov dword ptr [ecx],ebx
78AB0225: 8D 49 04 lea ecx,[ecx+4]
78AB0228: 4A dec edx
78AB0229: 75 F8 jne 78AB0223
78AB022B: 83 E0 03 and eax,3
78AB022E: 75 4A jne 78AB027A
78AB0230: 5B pop ebx
78AB0231: 58 pop eax
78AB0232: C3 ret
page ,132
title memset - set sections of memory all to one byte
;***
;memset.asm - set a section of memory to all one byte
;
; Copyright (c) Microsoft Corporation. All rights reserved.
;
;Purpose:
; contains the memset() routine
;
;*******************************************************************************
.xlist
include cruntime.inc
.list
page
;***
;char *memset(dst, value, count) - sets "count" bytes at "dst" to "value"
;
;Purpose:
; Sets the first "count" bytes of the memory starting
; at "dst" to the character value "value".
;
; Algorithm:
; char *
; memset (dst, value, count)
; char *dst;
; char value;
; unsigned int count;
; {
; char *start = dst;
;
; while (count--)
; *dst++ = value;
; return(start);
; }
;
;Entry:
; char *dst - pointer to memory to fill with value
; char value - value to put in dst bytes
; int count - number of bytes of dst to fill
;
;Exit:
; returns dst, with filled bytes
;
;Uses:
;
;Exceptions:
;
;*******************************************************************************
CODESEG
extrn _VEC_memzero:near
extrn __sse2_available:dword
public memset
memset proc \
dst:ptr byte, \
value:byte, \
count:dword
OPTION PROLOGUE:NONE, EPILOGUE:NONE
.FPO ( 0, 3, 0, 0, 0, 0 )
mov edx,[esp + 0ch] ; edx = "count"
mov ecx,[esp + 4] ; ecx points to "dst"
test edx,edx ; 0?
jz short toend ; if so, nothing to do
xor eax,eax
mov al,[esp + 8] ; the byte "value" to be stored
; Special case large block zeroing using SSE2 support
test al,al ; memset using zero initializer?
jne dword_align
cmp edx,080h ; block size exceeds size threshold?
jb dword_align
cmp DWORD PTR __sse2_available,0 ; SSE2 supported?
je dword_align
jmp _VEC_memzero ; use fast zero SSE2 implementation
; no return
; Align address on dword boundary
dword_align:
push edi ; preserve edi
mov edi,ecx ; edi = dest pointer
cmp edx,4 ; if it's less then 4 bytes
jb tail ; tail needs edi and edx to be initialized
neg ecx
and ecx,3 ; ecx = # bytes before dword boundary
jz short dwords ; jump if address already aligned
sub edx,ecx ; edx = adjusted count (for later)
adjust_loop:
mov [edi],al
add edi,1
sub ecx,1
jnz adjust_loop
dwords:
; set all 4 bytes of eax to [value]
mov ecx,eax ; ecx=0/0/0/value
shl eax,8 ; eax=0/0/value/0
add eax,ecx ; eax=0/0val/val
mov ecx,eax ; ecx=0/0/val/val
shl eax,10h ; eax=val/val/0/0
add eax,ecx ; eax = all 4 bytes = [value]
; Set dword-sized blocks
mov ecx,edx ; move original count to ecx
and edx,3 ; prepare in edx byte count (for tail loop)
shr ecx,2 ; adjust ecx to be dword count
jz tail ; jump if it was less then 4 bytes
rep stosd
main_loop_tail:
test edx,edx ; if there is no tail bytes,
jz finish ; we finish, and it's time to leave
; Set remaining bytes
tail:
mov [edi],al ; set remaining bytes
add edi,1
sub edx,1 ; if there is some more bytes
jnz tail ; continue to fill them
; Done
finish:
mov eax,[esp + 8] ; return dest pointer
pop edi ; restore edi
ret
toend:
mov eax,[esp + 4] ; return dest pointer
ret
memset endp
end
我是觉得memset()比clear()更快。[/quote]
比如下面的代码
class A{
int* a;
public:
A(){
a = new int[10];
}
~A(){
delete[] a;
}
}