内联汇编优化的TAlpha::Mask 部分汇编

内联汇编优化版

 #ifdef _calpha_using_inlineasm_
    i = Height - 1;
    if (i < 0)
     return;

    __asm
     {
      mov ecx, Width
      mov eax, ptrDest
      mov edx, ptrSrc
      mov esi, idPixelAdd
      @2:
      mov edi, ecx
      @1:
      mov bl, byte ptr [eax]
      cmp bl, bmaskr
      je short @3
      mov bl, byte ptr [edx]
      cmp bl, bmaskb
      je short @4
      inc edx
      mov byte ptr [eax], bl
      inc eax
      mov bx, word ptr [edx]
      mov word ptr [eax], bx
      add eax, esi
      add edx, isPixelAdd
      jmp short @5
      @4:
      add eax, ld
      add edx, ls
      jmp short @5
      @3:
      mov bl, byte ptr [edx]
      inc edx
      mov byte ptr [eax], bl
      inc eax
      mov bx, word ptr [edx]
      mov word ptr [eax], bx
      add eax, esi
      add edx, isPixelAdd
      @5:
      dec edi
      test edi, edi
      jge short @1
      add eax, idLineAdd
      add edx, isLineAdd
      dec i
      cmp i, 00000000
      jge short @2
     }

汇编代码

:004252C5 48          dec eax
:004252C6 8945DC      mov dword ptr [ebp-24], eax ; dword ptr [ebp-24] = i
:004252C9 8B4DF4      mov ecx, dword ptr [ebp-0C] ; ecx = Width
:004252CC 8B45F0      mov eax, dword ptr [ebp-10] ; eax = ptrDest
:004252CF 8B55EC      mov edx, dword ptr [ebp-14] ; edx = ptrSrc
:004252D2 8B7514      mov esi, dword ptr [ebp+14] ; esi = idPixelAdd
:004252D5 89CF        mov edi, ecx ; edi = j
:004252D7 8A18        mov bl, byte ptr [eax]
:004252D9 3A5DE3      cmp bl, byte ptr [ebp-1D]
:004252DC 7420        je 004252FE
:004252DE 8A1A        mov bl, byte ptr [edx]
:004252E0 3A5DE2      cmp bl, byte ptr [ebp-1E]
:004252E3 7411        je 004252F6
:004252E5 42          inc edx ; ptrSrc++
:004252E6 8818        mov byte ptr [eax], bl
:004252E8 40          inc eax ; ptrDest++
:004252E9 668B1A      mov bx, word ptr [edx]
:004252EC 668918      mov word ptr [eax], bx
:004252EF 01F0        add eax, esi ; ptrDest += idPixelAdd
:004252F1 035510      add edx, dword ptr [ebp+10] ; ptrSrc += isPixelAdd
:004252F4 EB19        jmp 0042530F
:004252F6 0345E8      add eax, dword ptr [ebp-18] ; ptrDest += ld
:004252F9 0355E4      add edx, dword ptr [ebp-1C] ; ptrSrc += ls
:004252FC EB11        jmp 0042530F
:004252FE 8A1A        mov bl, byte ptr [edx]
:00425300 42          inc edx
:00425301 8818        mov byte ptr [eax], bl
:00425303 40          inc eax
:00425304 668B1A      mov bx, word ptr [edx]
:00425307 668918      mov word ptr [eax], bx
:0042530A 01F0        add eax, esi
:0042530C 035510      add edx, dword ptr [ebp+10]
:0042530F 4F          dec edi ; j--
:00425310 85FF        test edi, edi
:00425312 7DC3        jge 004252D7
:00425314 03451C      add eax, dword ptr [ebp+1C] ; ptrDest += idLineAdd
:00425317 035518      add edx, dword ptr [ebp+18] ; ptrSrc += isLineAdd
:0042531A FF4DDC      dec [ebp-24] ; i--
:0042531D 837DDC00    cmp dword ptr [ebp-24], 00000000
:00425321 7DB2        jge 004252D5
:00425323 E98F020000  jmp 004255B7

c++代码

   #else
      for (i = Height - 1; i >= 0; i--)
       {
        register int j = Width;
        do
         {
          if (*ptrDest != bmaskr) //bmaskrgb[0]:Dest background color[blue part]
           {
            if (*ptrSrc != bmaskb) //bmaskb:Src background color[blue part]
             {
              *ptrDest = *ptrSrc;
              ptrDest++;
              ptrSrc++;
              *((unsigned short int *)(ptrDest)) = *((unsigned short int *)(ptrSrc));

              ptrDest += idPixelAdd;
              ptrSrc += isPixelAdd;
             }
            else
             {
              ptrDest += ld;
              ptrSrc += ls;
             }
           }
          else
           {
            *ptrDest = *ptrSrc;
            ptrDest++;
            ptrSrc++;
            *((unsigned short int *)(ptrDest)) = *((unsigned short int *)(ptrSrc));

            ptrDest += idPixelAdd;
            ptrSrc += isPixelAdd;
           }
          j--;
         }while(j >= 0);

        ptrDest += idLineAdd;
        ptrSrc += isLineAdd;
       }
   #endif

汇编代码

:004252B8 4B            dec ebx ; i = Height - 1
:004252B9 895DE8        mov dword ptr [ebp-18], ebx ; dword ptr [ebp-18] = i
:004252BC 837DE800      cmp dword ptr [ebp-18], 00000000 ; for 的判断, inline asm 去掉了
:004252C0 0F8C90020000  jl 00425556
:004252C6 8BF9          mov edi, ecx ; j = Width
:004252C8 8A18          mov bl, byte ptr [eax]
:004252CA 3A5DEF        cmp bl, byte ptr [ebp-11]
:004252CD 7422          je 004252F1
:004252CF 8A1A          mov bl, byte ptr [edx]
:004252D1 3A5DEE        cmp bl, byte ptr [ebp-12]
:004252D4 7413          je 004252E9
:004252D6 8A1A          mov bl, byte ptr [edx] ; 重复, inline asm 去掉了
:004252D8 42            inc edx
:004252D9 8818          mov byte ptr [eax], bl
:004252DB 40            inc eax
:004252DC 668B1A        mov bx, word ptr [edx]
:004252DF 668918        mov word ptr [eax], bx
:004252E2 03C6          add eax, esi
:004252E4 035510        add edx, dword ptr [ebp+10]
:004252E7 EB19          jmp 00425302
:004252E9 0345F4        add eax, dword ptr [ebp-0C]
:004252EC 0355F0        add edx, dword ptr [ebp-10]
:004252EF EB11          jmp 00425302
:004252F1 8A1A          mov bl, byte ptr [edx]
:004252F3 42            inc edx
:004252F4 8818          mov byte ptr [eax], bl
:004252F6 40            inc eax
:004252F7 668B1A        mov bx, word ptr [edx]
:004252FA 668918        mov word ptr [eax], bx
:004252FD 03C6          add eax, esi
:004252FF 035510        add edx, dword ptr [ebp+10]
:00425302 4F            dec edi ; j--
:00425303 85FF          test edi, edi
:00425305 7DC1          jge 004252C8
:00425307 03451C        add eax, dword ptr [ebp+1C]
:0042530A 035518        add edx, dword ptr [ebp+18]
:0042530D FF4DE8        dec [ebp-18] ; i--
:00425310 837DE800      cmp dword ptr [ebp-18], 00000000
:00425314 7DB0          jge 004252C6
:00425316 E93B020000    jmp 00425556





 

你可能感兴趣的:(内联汇编优化的TAlpha::Mask 部分汇编)