希尔排序ASM辰哥超级改装版,提升100+%

来源:互联网 发布:手机淘宝用户名大全 编辑:程序博客网 时间:2024/04/29 04:37

头一次实用化汇编嵌入,测试结果运行时间8:18!!!!!!!!!同样的测试数据,同样的算法,基本上就是翻译来的。太爽了,本人总结,汇编辰哥超级改装版把基本上所有的操作都移到寄存器里,同时简化了N多无用代码,速度自然快很多,但也快的太多了...不过调试的过程异常痛苦@@@@吐血...连蒙带撞也算是挺过来了,哈哈,这就是成就感!
--2010-1-25--
原版:

Code:
  1. void shell(int src[],int l,int r){   
  2.  register int cmps;   
  3.  int ih,il,ir;   
  4.  for(ih=1;ih<r/9;ih=ih*3+1);   
  5.  for(;ih>0;ih/=3)   
  6.  for(il=ih-1;il<r;il++)   
  7.  {   
  8.   ir=il;   
  9.   cmps=src[ir];   
  10.   while(ir>ih-1&&cmps<src[ir-ih])   
  11.   {   
  12.    src[ir]=src[ir-ih];ir-=ih;   
  13.   }   
  14.   src[ir]=cmps;   
  15.  }   
  16. }  

 
汇编辰哥超级改装版:
 

Code:
  1. void shell(int src[],int l,int r){   
  2. int ih;   
  3. r++;   
  4. for(ih=1;ih<(r-l)/9;ih=ih*3+1);   
  5.  //eax,ih   
  6.  //ebx,il   
  7.  //ecx,ir   
  8.  //edx,cmps   
  9. _asm{   
  10.   push  eax   
  11.   push  ebx   
  12.   push  ecx   
  13.   push  edx   
  14.   push  esi   
  15.   push  edi;貌似这堆进栈用处不大哎   
  16.   mov  edi,src   
  17.   mov  eax,dword ptr [ih]   
  18. LIH:   
  19.   cmp  eax,0   
  20.   jna  EXIH   
  21.   mov  ebx,eax   
  22.   dec  ebx   
  23. LLH:   
  24.   cmp  ebx,dword ptr [r]   
  25.   jnb  EXLLH   
  26.   mov  ecx,ebx   
  27.   mov  edx,dword ptr [edi+ecx*4]   
  28. LCMP:   
  29.   mov  esi,eax   
  30.   dec  esi   
  31.   cmp  ecx,esi   
  32.   jna  EXCMP   
  33.   push  ecx   
  34.   sub  ecx,eax   
  35.   cmp  edx,dword ptr [edi+ecx*4]   
  36.   pop  ecx   
  37.   jnb  EXCMP   
  38.      
  39.   push  ebx   
  40.   push  ecx   
  41.   sub  ecx,eax   
  42.   mov  ebx,dword ptr [edi+ecx*4]   
  43.   pop  ecx   
  44.   mov  dword ptr [edi+ecx*4],ebx   
  45.   pop  ebx   
  46.   sub  ecx,eax   
  47.   jmp  LCMP   
  48. EXCMP:   
  49.   mov  dword ptr [edi+ecx*4],edx   
  50.   inc  ebx   
  51.   jmp  LLH   
  52. EXLLH:   
  53.   push  ecx   
  54.   mov  ecx,3   
  55.   push  edx   
  56.   cdq   
  57.   idiv  ecx   
  58.   pop  edx   
  59.   pop  ecx   
  60.   jmp  LIH   
  61. EXIH:   
  62.   pop  edi   
  63.   pop  esi   
  64.   pop  edx   
  65.   pop  ecx   
  66.   pop  ebx   
  67.   pop  eax   
  68.  }   
  69. }  

 

原创粉丝点击