real_het

Blur

Sep 25th, 2013
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;--- assemble: jwasm -coff xxxx.asm
  2.  
  3.     .686
  4.     .xmm
  5.     .model flat
  6.  
  7.     .code
  8.  
  9. ;##########################################################################
  10. ;###   Macroes, consts                                                  ###
  11. ;##########################################################################
  12.  
  13. _ macro args:VARARG         ; multiple instructions per line macro
  14.         asm_txt TEXTEQU <>
  15.         FORC char,<&args>
  16.                 IFDIF <&char>,<!\>
  17.                         asm_txt CATSTR asm_txt,<&char>
  18.                 ELSE
  19.                         asm_txt
  20.                         asm_txt TEXTEQU <>
  21.                 ENDIF
  22.         ENDM
  23.         asm_txt
  24. endm
  25.  
  26. SHUFFLE_1230 equ 57
  27.  
  28.  
  29. ;##########################################################################
  30. ;###   SSE_Blur                                                         ###
  31. ;##########################################################################
  32.  
  33. mSSE_BlurLoadColumn macro src, width               ;--- xmm7:16bytes read from a column, xmm6:temp
  34. _   push ecx \ push src                            ;--- all regs are preserved
  35. _   mov cl,[src]         \ ror ecx,8
  36. _   mov cl,[src+width]   \ ror ecx,8  \lea src,[src+width*2]
  37. _   mov cl,[src]         \ ror ecx,8
  38. _   mov cl,[src+width]   \ ror ecx,8  \lea src,[src+width*2] \ movd xmm7,ecx
  39.  
  40. _   mov cl,[src]         \ ror ecx,8                         \ shufps xmm7,xmm7, SHUFFLE_1230
  41. _   mov cl,[src+width]   \ ror ecx,8  \lea src,[src+width*2]
  42. _   mov cl,[src]         \ ror ecx,8
  43. _   mov cl,[src+width]   \ ror ecx,8  \lea src,[src+width*2] \ movd xmm6,ecx
  44.  
  45. _   mov cl,[src]         \ ror ecx,8                         \ movss xmm7,xmm6
  46. _   mov cl,[src+width]   \ ror ecx,8  \lea src,[src+width*2] \ shufps xmm7,xmm7, SHUFFLE_1230
  47. _   mov cl,[src]         \ ror ecx,8
  48. _   mov cl,[src+width]   \ ror ecx,8  \lea src,[src+width*2] \ movd xmm6,ecx
  49.  
  50. _   mov cl,[src]         \ ror ecx,8                         \ movss xmm7,xmm6
  51. _   mov cl,[src+width]   \ ror ecx,8  \lea src,[src+width*2] \ shufps xmm7,xmm7, SHUFFLE_1230
  52. _   mov cl,[src]         \ ror ecx,8
  53. _   mov cl,[src+width]   \ ror ecx,8  \lea src,[src+width*2] \ movd xmm6,ecx
  54.     movss xmm7,xmm6
  55.     shufps xmm7,xmm7, SHUFFLE_1230
  56. _   pop src \ pop ecx
  57. endm
  58.  
  59. mSSE_BlurClearAccum macro                       ;--- Clear accum_lo, accum_hi (xmm0,xmm1)
  60.     pxor xmm0,xmm0
  61.     pxor xmm1,xmm1
  62. endm
  63.  
  64. mSSE_BlurAccumAdd macro                         ;--- Adds xmm7 bytes to (xmm0,xmm1) words
  65. _   movdqa xmm2,xmm7    \ movdqa xmm3,xmm7
  66. _   punpcklbw xmm2,xmm4 \ punpckhbw xmm3,xmm4
  67. _   paddw xmm0,xmm2     \ paddw xmm1,xmm3
  68. endm
  69.  
  70. mSSE_BlurAccumSub macro                         ;--- Sub xmm7 bytes from (xmm0,xmm1) words
  71. _   movdqa xmm2,xmm7    \ movdqa xmm3,xmm7
  72. _   punpcklbw xmm2,xmm4 \ punpckhbw xmm3,xmm4
  73. _   psubw xmm0,xmm2     \ psubw xmm1,xmm3
  74. endm
  75.  
  76. mSSE_BlurMulStoreRow macro dst                  ;--- Mul (xmm0,xmm1)words with Multiplier(xmm5) and store 16bytes az Dst
  77. _   movdqa xmm2, xmm5   \ movdqa xmm3, xmm5
  78. _   pmulhw xmm2, xmm0   \ pmulhw xmm3, xmm1
  79.     packuswb xmm2, xmm3
  80.     movdqa [dst],xmm2
  81. endm
  82.  
  83. ;void SSE_BlurProcess16Rows(char *src,char *dst,int y,int w,int h,int windowSize) //pseudo code
  84. ;{
  85. ;  src+=y*w; //calc src row address
  86. ;  dst+=y;   //calc dst column address
  87. ;
  88. ;  char *tail = src-windowSize;
  89. ;  int half = windowSize>>1;
  90. ;  SSE_BlurClearAccum();
  91. ;  for(int x=-half; x < w; x++, src++, tail++) {
  92. ;    if(x < w-half){ SSE_BlurLoadColumn(src , w); SSE_BlurAccumAdd(); }
  93. ;    if(x > half)  { SSE_BlurLoadColumn(tail, w); SSE_BlurAccumSub(); }
  94. ;    if(x >= 0) { SSE_BlurMulStoreRow(dst); dst += h; }
  95. ;  }
  96. ;}
  97.  
  98. SSE_BlurProcess16Rows proc c public ASrc:sdword, ADst:sdword, Ay:sdword, AWidth:sdword, AHeight:sdword, AWindowSize:sdword, AMult:sdword ;--- xmm5:multiplier
  99.     ; Processes 16 pixelrows of (AWidth x AHeight) image (ASrc), and blurs it,
  100.     ; then writes the result 16 pixelcolumns into (AHeight x AWidth) image (ADst)
  101.     ; Ay: the starting row index in ASrc, and also the column index in ADst
  102.     ; AMult: must be set to (0x10000/windowSize)*0x10001
  103.  
  104. _   push ebx \ push esi \ push edi
  105.  
  106.     movd xmm5,AMult
  107.     pshufd xmm5,xmm5,0
  108.  
  109. head textequ <esi>
  110. dst textequ <edi>
  111. _   mov eax,AWidth \ mov ebx,Ay \ mul ebx \ mov head,ASrc \ add head, eax   ;esi:src+y*w     calculate src row addr
  112. _   mov dst,ADst   \ add dst,Ay                                             ;edi:dst+y       calculate dst col addr
  113.  
  114. tail textequ <edx>
  115. half    textequ <ebx>
  116. w       textequ <eax>
  117. _   mov tail,head \ sub tail,AWindowSize    ; edx: tail
  118. _   mov half,AWindowSize \ shr half,1       ; ebx: half
  119. _   mov w,AWidth                            ; eax: width
  120. _   mSSE_BlurClearAccum                     ; clear accum
  121.  
  122. wHalf   textequ <[ebp-32]>
  123.     sub w,half
  124.     mov wHalf,w
  125.     add w,half                              ; wHalf = w-half
  126.  
  127. i       textequ <sdword ptr ecx>  ;x is reserved?
  128. _   mov i,half \ neg i                      ; ecx:x = -half
  129.  
  130.     .while sdword ptr i<eax
  131.  
  132.       .if i<wHalf                           ; i<w-half
  133.         mSSE_BlurLoadColumn head,w
  134.         mSSE_BlurAccumAdd
  135.       .endif
  136.  
  137.       .if i>half
  138.         mSSE_BlurLoadColumn tail,w
  139.         mSSE_BlurAccumSub
  140.       .endif
  141.  
  142.       .if i>=0
  143.         mSSE_BlurMulStoreRow dst
  144.         add dst,AHeight
  145.       .endif
  146.  
  147.       inc i
  148.       inc head
  149.       inc tail
  150.     .endw
  151.  
  152. _   pop edi \ pop esi \ pop ebx
  153.     ret
  154. SSE_BlurProcess16Rows endp
  155.  
  156.  
  157. ;##########################################################################
  158. ;###                                                                    ###
  159. ;##########################################################################
  160.  
  161. END
Advertisement
Add Comment
Please, Sign In to add comment