- 注册时间
 - 2008-2-6
 
- 最后登录
 - 1970-1-1
 
- 威望
 -  星
 
- 金币
 -  枚
 
- 贡献
 -  分
 
- 经验
 -  点
 
- 鲜花
 -  朵
 
- 魅力
 -  点
 
- 上传
 -  次
 
- 下载
 -  次
 
- 积分
 - 51605
 
- 在线时间
 -  小时
 
 
 
 
 
 
 | 
 
 楼主 |
发表于 2009-2-18 09:13:16
|
显示全部楼层
 
 
 
- 
 - double lbc_b32[] = {0.0,4294967296.0};
 - //实验证明zero5不能大于0.49999999999636
 - double zero5=        0.49999999999636;;
 - 
 - __declspec(naked)
 - DWORD __fastcall iSqrt_FPU1_lbc(DWORD n)
 - {
 -  __asm
 -  {
 -  push ecx
 -  
 -  shr ecx, 31
 -  fld qword ptr [lbc_b32 + ecx  * 8]
 -  fild dword ptr [esp]
 -  faddp  st(1),st
 -  fsqrt
 -  fsub  qword ptr [zero5]
 -  fistp  dword ptr [esp]
 -  pop eax
 -  ret
 -  }
 - }
 - 
 - __declspec(naked)
 - DWORD __fastcall iSqrt_FPU2_lbc(DWORD n)
 - {
 -  __asm
 -  {
 -  or ecx,ecx
 -  jnz next00
 -  mov eax,0
 -  ret
 - next00:
 -  push ecx
 -  
 -  shr ecx, 31
 -  fld qword ptr [lbc_b32 + ecx * 8]
 -  fild dword ptr [esp]
 -  faddp  st(1),st
 -  fsqrt
 -  fstp  qword ptr [esp-8]
 -  
 -  fwait
 -  mov  ecx,dword ptr [esp-4]
 -  mov  edx,0xfff00000
 -  mov  eax,0xfffff
 -  
 -  and  edx,ecx //阶码 
 -  and  eax,ecx //尾数 
 -  shr  edx,20 //得到阶段码
 -  add  eax,0x100000 //设置位数最高有效位
 -  mov  ecx,1043
 -  sub  ecx,edx
 -  shr  eax,cl //得到整数
 -  
 -  pop ecx
 -  ret
 -  }
 - }
 - 
 - __declspec(naked)
 - DWORD __fastcall iSqrt_FPU3_lbc(DWORD n)
 - {
 -  __asm
 -  {
 -  push ecx
 -  shr ecx, 31
 -  fld qword ptr [lbc_b32 + ecx * 8]
 -  fild dword ptr [esp]
 -  faddp  st(1),st
 -  fsqrt
 -  
 -  //设置FPU的取整方式  为了直接使用fistp浮点指令
 -  FNSTCW  [esp-4]            // 保存协处理器控制字,用来恢复
 -  mov word ptr [esp-6], 0x0E60     //截断, 64位浮点
 -  FLDCW   [esp-6]            // 载入协处理器控制字,RC场已经修改
 -  
 -  fistp   dword ptr [esp] //恢复FPU的取整方式
 -  FLDCW   [esp-4]
 -  
 -  pop eax
 -  ret
 -  }
 - }
 
  复制代码- 
 - double b32[] = {0.0,4294967296.0};
 - 
 - __declspec(naked)
 - DWORD __fastcall iSqrt_FPU_yaos(DWORD n)
 - {
 - __asm
 - {
 -    push ecx
 -    sub esp, 4
 -    mov word ptr [esp], 0x0E60
 -    fnstcw word ptr [esp + 2]
 -    mov eax, ecx  
 -    shr eax, 31
 -    fld qword ptr [b32 + eax * 8]
 -    fild dword ptr [esp + 4]
 -    faddp st(1), st
 -    fsqrt
 -    fldcw word ptr [esp]
 -    fistp dword ptr [esp + 4]
 -    fldcw word ptr [esp + 2]
 -    mov eax, [esp + 4]
 -    add esp, 8
 -    ret
 - 
 -    }
 - }
 - 
 - __declspec(naked)
 - DWORD __fastcall iSqrt_FPU1_yaos(DWORD n)
 - {
 -  __asm
 -  {
 -  push ecx  
 -  mov eax, ecx
 -     shr eax, 31
 -  fld qword ptr [b32 + eax * 8]
 -  fild dword ptr [esp]
 -     faddp st(1), st 
 -  fsqrt
 -  fisttp dword ptr [esp]
 -  fwait
 -  pop eax
 -  ret
 -  }
 - }
 - 
 - __declspec(naked)
 - DWORD __fastcall iSqrt_FPU2_yaos(DWORD n)
 - {
 - __asm
 - {
 -    push ecx
 -    mov eax, ecx   
 -    and eax, 0x80000000
 -    shr eax, 31
 -    fld qword ptr [b32 + eax * 8]
 -    fild dword ptr [esp]
 -    faddp st(1), st
 -    fsqrt
 -    sub esp, 8
 -    fstp qword ptr [esp]
 -    fwait
 -    mov edx, dword ptr [esp + 4]
 -    mov eax, edx
 -    and edx,0x7ff00000
 -    and eax,0xfffff
 -    shr edx, 20
 -    or eax, 0x100000
 -    xchg ecx, edx
 -    sub ecx, 1043
 -    neg ecx
 -    shr eax, cl
 -    xchg edx, ecx
 -    add esp, 12
 -    or ecx, ecx
 -    cmove eax, ecx
 -    ret
 -    }
 - }
 
  复制代码 完全测试
n: 0-0x10000
iSqt_FPU1_lbc#: 0.00234 s
iSqt_FPU2_lbc#: 0.00234 s
iSqt_FPU3_lbc#: 0.00234 s
iSqt_FPU_yaos#: 0.00234 s
iSqt_FPU1_yaos#: 0.00235 s
iSqt_FPU2_yaos#: 0.00234 s
n: 0-0x10000000
iSqt_FPU1_lbc#: 9.62084 s
iSqt_FPU2_lbc#: 9.64661 s
iSqt_FPU3_lbc#: 9.62920 s
iSqt_FPU_yaos#: 9.61824 s
iSqt_FPU1_yaos#: 9.62351 s
iSqt_FPU2_yaos#: 9.61847 s
================================
iSqrt_FPU1_yaos是SSE3指令 |   
 
 
 
 |