内存拷贝的优化方法(草稿) [2]

WBOY
풀어 주다: 2016-06-07 15:44:15
원래의
1118명이 탐색했습니다.

以下为引用: global_fast_memcpy9 %defineparamesp124 %definesrcparam0 %definedstparam4 %definelenparam8 %defineCACHEBLOCK400h _fast_memcpy9: pushesi pushedi pushebx movesi,[src];sourcearray movedi,[dst];destinationarray movecx,[len];numbero

以下为引用:

 global _fast_memcpy9

 %define param       esp+12+4
 %define src         param+0
 %define dst         param+4
 %define len         param+8

 %define CACHEBLOCK 400h

 _fast_memcpy9:
   push esi
   push edi
   push ebx

   mov esi, [src]              ; source array
   mov edi, [dst]              ; destination array
   mov ecx, [len]              ; number of QWORDS (8 bytes) assumes len / CACHEBLOCK is an integer
   shr ecx, 3

   lea esi, [esi+ecx*8]        ; end of source
   lea edi, [edi+ecx*8]        ; end of destination
   neg ecx                     ; use a negative offset as a combo pointer-and-loop-counter

 .mainloop:
   mov eax, CACHEBLOCK / 16    ; note: .prefetchloop is unrolled 2X
   add ecx, CACHEBLOCK         ; move up to end of block

 .prefetchloop:
   mov ebx, [esi+ecx*8-64]     ; read one address in this cache line...
   mov ebx, [esi+ecx*8-128]    ; ... and one in the previous line
   sub ecx, 16                 ; 16 QWORDS = 2 64-byte cache lines
   dec eax
   jnz .prefetchloop

   mov eax, CACHEBLOCK / 8

 .writeloop:
   prefetchnta [esi+ecx*8 + 512] ; fetch ahead by 512 bytes

   movq mm0, qword [esi+ecx*8]
   movq mm1, qword [esi+ecx*8+8]
   movq mm2, qword [esi+ecx*8+16]
   movq mm3, qword [esi+ecx*8+24]
   movq mm4, qword [esi+ecx*8+32]
   movq mm5, qword [esi+ecx*8+40]
   movq mm6, qword [esi+ecx*8+48]
   movq mm7, qword [esi+ecx*8+56]

   movntq qword [edi+ecx*8], mm0
   movntq qword [edi+ecx*8+8], mm1
   movntq qword [edi+ecx*8+16], mm2
   movntq qword [edi+ecx*8+24], mm3
   movntq qword [edi+ecx*8+32], mm4
   movntq qword [edi+ecx*8+40], mm5
   movntq qword [edi+ecx*8+48], mm6
   movntq qword [edi+ecx*8+56], mm7

   add ecx, 8
   dec eax
   jnz .writeloop

   or ecx, ecx ; assumes integer number of cacheblocks
   jnz .mainloop

   sfence ; flush write buffer
   emms

   pop ebx
   pop edi
   pop esi

  ret
 

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!