zoukankan      html  css  js  c++  java
  • (转)DELPHI求乱序数组最小值快速算法(Delphi MMX优化算法应用之三)

    type

      PMyList 
    = ^TMylist;

      TMylist 
    = array of word;



    function GetMinValue(List: PMyList):Word; stdcall;

    var

      ForCount, ListCount,i: Dword;

      MAXVaule: int64;

      List0Address: Dword;



    begin

      Result :
    = $7FFF;

      ListCount :
    = High(List^) + 1;

      
    if (ListCount < 16or ((ListCount mod 16)<>0then

      
    begin

       
    for I := 0 to ListCount - 1 do

          
    begin

             
    if List^[i] <  Result then  Result := List^[i];

          
    end;

      
    end else

      
    begin

        MAXVaule :
    = $7FFF7FFF7FFF7FFF;

        List0Address :
    = Dword(@List^[0]);

        ForCount :
    = ListCount div 16//4*MMX

        
    asm

          push eax

          push ecx

          push esi

          mov esi, List0Address  
    //开始地址

          mov ecx, ForCount      
    //长度

          MOVQ MM0,MAXVaule

          mov eax,
    0

        @CmpLoop:

          prefetchnta [esi 
    + eax + 1024// fetch ahead by 1024 bytes

          movq mm1, qword [esi
    +eax]

          movq mm2, qword [esi
    +eax+8]

          movq mm3, qword [esi
    +eax+16]

          movq mm4, qword [esi
    +eax+24]

          PMINSW MM0,MM1

          PMINSW MM0,MM2

          PMINSW MM0,MM3

          PMINSW MM0,MM4

          add eax,
    32

          sub ecx, 
    1

        jnz @CmpLoop

          MOVQ MM1,MM0

          PSRLQ MM1,$
    20  //右移

          PMINSW MM0,MM1

          MOVQ MM1,MM0

          PSRLQ MM1,$
    10  //右移

          PMINSW MM0,MM1

          Movd eax,mm0

          Mov  Result,AX

          Sfence

          Emms

          pop esi

          pop ecx

          pop eax

        
    end;

      
    end;



    end;
  • 相关阅读:
    对我影响最大的老师
    介绍自己
    JavaScript 时间特效 显示当前时间
    js 获取函数的所有参数名
    node.js 在函数内获取当前函数
    js 实现二叉排序树
    命令行下mysql的部分操作
    浅析js的函数的按值传递参数
    返回上一页时,保存恢复浏览记录(模拟返回不刷新)
    让mongodb执行js文件
  • 原文地址:https://www.cnblogs.com/jxgxy/p/1595722.html
Copyright © 2011-2022 走看看