media/libjpeg/simd/jcgrymmx.asm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 ;
michael@0 2 ; jcgrymmx.asm - grayscale colorspace conversion (MMX)
michael@0 3 ;
michael@0 4 ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
michael@0 5 ; Copyright 2011 D. R. Commander
michael@0 6 ;
michael@0 7 ; Based on
michael@0 8 ; x86 SIMD extension for IJG JPEG library
michael@0 9 ; Copyright (C) 1999-2006, MIYASAKA Masaru.
michael@0 10 ; For conditions of distribution and use, see copyright notice in jsimdext.inc
michael@0 11 ;
michael@0 12 ; This file should be assembled with NASM (Netwide Assembler),
michael@0 13 ; can *not* be assembled with Microsoft's MASM or any compatible
michael@0 14 ; assembler (including Borland's Turbo Assembler).
michael@0 15 ; NASM is available from http://nasm.sourceforge.net/ or
michael@0 16 ; http://sourceforge.net/project/showfiles.php?group_id=6208
michael@0 17 ;
michael@0 18 ; [TAB8]
michael@0 19
michael@0 20 %include "jcolsamp.inc"
michael@0 21
michael@0 22 ; --------------------------------------------------------------------------
michael@0 23 ;
michael@0 24 ; Convert some rows of samples to the output colorspace.
michael@0 25 ;
michael@0 26 ; GLOBAL(void)
michael@0 27 ; jsimd_rgb_gray_convert_mmx (JDIMENSION img_width,
michael@0 28 ; JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
michael@0 29 ; JDIMENSION output_row, int num_rows);
michael@0 30 ;
michael@0 31
michael@0 32 %define img_width(b) (b)+8 ; JDIMENSION img_width
michael@0 33 %define input_buf(b) (b)+12 ; JSAMPARRAY input_buf
michael@0 34 %define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf
michael@0 35 %define output_row(b) (b)+20 ; JDIMENSION output_row
michael@0 36 %define num_rows(b) (b)+24 ; int num_rows
michael@0 37
michael@0 38 %define original_ebp ebp+0
michael@0 39 %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM]
michael@0 40 %define WK_NUM 2
michael@0 41 %define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
michael@0 42
michael@0 43 align 16
michael@0 44 global EXTN(jsimd_rgb_gray_convert_mmx)
michael@0 45
michael@0 46 EXTN(jsimd_rgb_gray_convert_mmx):
michael@0 47 push ebp
michael@0 48 mov eax,esp ; eax = original ebp
michael@0 49 sub esp, byte 4
michael@0 50 and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
michael@0 51 mov [esp],eax
michael@0 52 mov ebp,esp ; ebp = aligned ebp
michael@0 53 lea esp, [wk(0)]
michael@0 54 pushpic eax ; make a room for GOT address
michael@0 55 push ebx
michael@0 56 ; push ecx ; need not be preserved
michael@0 57 ; push edx ; need not be preserved
michael@0 58 push esi
michael@0 59 push edi
michael@0 60
michael@0 61 get_GOT ebx ; get GOT address
michael@0 62 movpic POINTER [gotptr], ebx ; save GOT address
michael@0 63
michael@0 64 mov ecx, JDIMENSION [img_width(eax)] ; num_cols
michael@0 65 test ecx,ecx
michael@0 66 jz near .return
michael@0 67
michael@0 68 push ecx
michael@0 69
michael@0 70 mov esi, JSAMPIMAGE [output_buf(eax)]
michael@0 71 mov ecx, JDIMENSION [output_row(eax)]
michael@0 72 mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
michael@0 73 lea edi, [edi+ecx*SIZEOF_JSAMPROW]
michael@0 74
michael@0 75 pop ecx
michael@0 76
michael@0 77 mov esi, JSAMPARRAY [input_buf(eax)]
michael@0 78 mov eax, INT [num_rows(eax)]
michael@0 79 test eax,eax
michael@0 80 jle near .return
michael@0 81 alignx 16,7
michael@0 82 .rowloop:
michael@0 83 pushpic eax
michael@0 84 push edi
michael@0 85 push esi
michael@0 86 push ecx ; col
michael@0 87
michael@0 88 mov esi, JSAMPROW [esi] ; inptr
michael@0 89 mov edi, JSAMPROW [edi] ; outptr0
michael@0 90 movpic eax, POINTER [gotptr] ; load GOT address (eax)
michael@0 91
michael@0 92 cmp ecx, byte SIZEOF_MMWORD
michael@0 93 jae short .columnloop
michael@0 94 alignx 16,7
michael@0 95
michael@0 96 %if RGB_PIXELSIZE == 3 ; ---------------
michael@0 97
michael@0 98 .column_ld1:
michael@0 99 push eax
michael@0 100 push edx
michael@0 101 lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE
michael@0 102 test cl, SIZEOF_BYTE
michael@0 103 jz short .column_ld2
michael@0 104 sub ecx, byte SIZEOF_BYTE
michael@0 105 xor eax,eax
michael@0 106 mov al, BYTE [esi+ecx]
michael@0 107 .column_ld2:
michael@0 108 test cl, SIZEOF_WORD
michael@0 109 jz short .column_ld4
michael@0 110 sub ecx, byte SIZEOF_WORD
michael@0 111 xor edx,edx
michael@0 112 mov dx, WORD [esi+ecx]
michael@0 113 shl eax, WORD_BIT
michael@0 114 or eax,edx
michael@0 115 .column_ld4:
michael@0 116 movd mmA,eax
michael@0 117 pop edx
michael@0 118 pop eax
michael@0 119 test cl, SIZEOF_DWORD
michael@0 120 jz short .column_ld8
michael@0 121 sub ecx, byte SIZEOF_DWORD
michael@0 122 movd mmG, DWORD [esi+ecx]
michael@0 123 psllq mmA, DWORD_BIT
michael@0 124 por mmA,mmG
michael@0 125 .column_ld8:
michael@0 126 test cl, SIZEOF_MMWORD
michael@0 127 jz short .column_ld16
michael@0 128 movq mmG,mmA
michael@0 129 movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
michael@0 130 mov ecx, SIZEOF_MMWORD
michael@0 131 jmp short .rgb_gray_cnv
michael@0 132 .column_ld16:
michael@0 133 test cl, 2*SIZEOF_MMWORD
michael@0 134 mov ecx, SIZEOF_MMWORD
michael@0 135 jz short .rgb_gray_cnv
michael@0 136 movq mmF,mmA
michael@0 137 movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
michael@0 138 movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
michael@0 139 jmp short .rgb_gray_cnv
michael@0 140 alignx 16,7
michael@0 141
michael@0 142 .columnloop:
michael@0 143 movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
michael@0 144 movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
michael@0 145 movq mmF, MMWORD [esi+2*SIZEOF_MMWORD]
michael@0 146
michael@0 147 .rgb_gray_cnv:
michael@0 148 ; mmA=(00 10 20 01 11 21 02 12)
michael@0 149 ; mmG=(22 03 13 23 04 14 24 05)
michael@0 150 ; mmF=(15 25 06 16 26 07 17 27)
michael@0 151
michael@0 152 movq mmD,mmA
michael@0 153 psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 10 20 01)
michael@0 154 psrlq mmD,4*BYTE_BIT ; mmD=(11 21 02 12 -- -- -- --)
michael@0 155
michael@0 156 punpckhbw mmA,mmG ; mmA=(00 04 10 14 20 24 01 05)
michael@0 157 psllq mmG,4*BYTE_BIT ; mmG=(-- -- -- -- 22 03 13 23)
michael@0 158
michael@0 159 punpcklbw mmD,mmF ; mmD=(11 15 21 25 02 06 12 16)
michael@0 160 punpckhbw mmG,mmF ; mmG=(22 26 03 07 13 17 23 27)
michael@0 161
michael@0 162 movq mmE,mmA
michael@0 163 psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 04 10 14)
michael@0 164 psrlq mmE,4*BYTE_BIT ; mmE=(20 24 01 05 -- -- -- --)
michael@0 165
michael@0 166 punpckhbw mmA,mmD ; mmA=(00 02 04 06 10 12 14 16)
michael@0 167 psllq mmD,4*BYTE_BIT ; mmD=(-- -- -- -- 11 15 21 25)
michael@0 168
michael@0 169 punpcklbw mmE,mmG ; mmE=(20 22 24 26 01 03 05 07)
michael@0 170 punpckhbw mmD,mmG ; mmD=(11 13 15 17 21 23 25 27)
michael@0 171
michael@0 172 pxor mmH,mmH
michael@0 173
michael@0 174 movq mmC,mmA
michael@0 175 punpcklbw mmA,mmH ; mmA=(00 02 04 06)
michael@0 176 punpckhbw mmC,mmH ; mmC=(10 12 14 16)
michael@0 177
michael@0 178 movq mmB,mmE
michael@0 179 punpcklbw mmE,mmH ; mmE=(20 22 24 26)
michael@0 180 punpckhbw mmB,mmH ; mmB=(01 03 05 07)
michael@0 181
michael@0 182 movq mmF,mmD
michael@0 183 punpcklbw mmD,mmH ; mmD=(11 13 15 17)
michael@0 184 punpckhbw mmF,mmH ; mmF=(21 23 25 27)
michael@0 185
michael@0 186 %else ; RGB_PIXELSIZE == 4 ; -----------
michael@0 187
michael@0 188 .column_ld1:
michael@0 189 test cl, SIZEOF_MMWORD/8
michael@0 190 jz short .column_ld2
michael@0 191 sub ecx, byte SIZEOF_MMWORD/8
michael@0 192 movd mmA, DWORD [esi+ecx*RGB_PIXELSIZE]
michael@0 193 .column_ld2:
michael@0 194 test cl, SIZEOF_MMWORD/4
michael@0 195 jz short .column_ld4
michael@0 196 sub ecx, byte SIZEOF_MMWORD/4
michael@0 197 movq mmF,mmA
michael@0 198 movq mmA, MMWORD [esi+ecx*RGB_PIXELSIZE]
michael@0 199 .column_ld4:
michael@0 200 test cl, SIZEOF_MMWORD/2
michael@0 201 mov ecx, SIZEOF_MMWORD
michael@0 202 jz short .rgb_gray_cnv
michael@0 203 movq mmD,mmA
michael@0 204 movq mmC,mmF
michael@0 205 movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
michael@0 206 movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
michael@0 207 jmp short .rgb_gray_cnv
michael@0 208 alignx 16,7
michael@0 209
michael@0 210 .columnloop:
michael@0 211 movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
michael@0 212 movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
michael@0 213 movq mmD, MMWORD [esi+2*SIZEOF_MMWORD]
michael@0 214 movq mmC, MMWORD [esi+3*SIZEOF_MMWORD]
michael@0 215
michael@0 216 .rgb_gray_cnv:
michael@0 217 ; mmA=(00 10 20 30 01 11 21 31)
michael@0 218 ; mmF=(02 12 22 32 03 13 23 33)
michael@0 219 ; mmD=(04 14 24 34 05 15 25 35)
michael@0 220 ; mmC=(06 16 26 36 07 17 27 37)
michael@0 221
michael@0 222 movq mmB,mmA
michael@0 223 punpcklbw mmA,mmF ; mmA=(00 02 10 12 20 22 30 32)
michael@0 224 punpckhbw mmB,mmF ; mmB=(01 03 11 13 21 23 31 33)
michael@0 225
michael@0 226 movq mmG,mmD
michael@0 227 punpcklbw mmD,mmC ; mmD=(04 06 14 16 24 26 34 36)
michael@0 228 punpckhbw mmG,mmC ; mmG=(05 07 15 17 25 27 35 37)
michael@0 229
michael@0 230 movq mmE,mmA
michael@0 231 punpcklwd mmA,mmD ; mmA=(00 02 04 06 10 12 14 16)
michael@0 232 punpckhwd mmE,mmD ; mmE=(20 22 24 26 30 32 34 36)
michael@0 233
michael@0 234 movq mmH,mmB
michael@0 235 punpcklwd mmB,mmG ; mmB=(01 03 05 07 11 13 15 17)
michael@0 236 punpckhwd mmH,mmG ; mmH=(21 23 25 27 31 33 35 37)
michael@0 237
michael@0 238 pxor mmF,mmF
michael@0 239
michael@0 240 movq mmC,mmA
michael@0 241 punpcklbw mmA,mmF ; mmA=(00 02 04 06)
michael@0 242 punpckhbw mmC,mmF ; mmC=(10 12 14 16)
michael@0 243
michael@0 244 movq mmD,mmB
michael@0 245 punpcklbw mmB,mmF ; mmB=(01 03 05 07)
michael@0 246 punpckhbw mmD,mmF ; mmD=(11 13 15 17)
michael@0 247
michael@0 248 movq mmG,mmE
michael@0 249 punpcklbw mmE,mmF ; mmE=(20 22 24 26)
michael@0 250 punpckhbw mmG,mmF ; mmG=(30 32 34 36)
michael@0 251
michael@0 252 punpcklbw mmF,mmH
michael@0 253 punpckhbw mmH,mmH
michael@0 254 psrlw mmF,BYTE_BIT ; mmF=(21 23 25 27)
michael@0 255 psrlw mmH,BYTE_BIT ; mmH=(31 33 35 37)
michael@0 256
michael@0 257 %endif ; RGB_PIXELSIZE ; ---------------
michael@0 258
michael@0 259 ; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE
michael@0 260 ; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO
michael@0 261
michael@0 262 ; (Original)
michael@0 263 ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
michael@0 264 ;
michael@0 265 ; (This implementation)
michael@0 266 ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
michael@0 267
michael@0 268 movq mm6,mm1
michael@0 269 punpcklwd mm1,mm3
michael@0 270 punpckhwd mm6,mm3
michael@0 271 pmaddwd mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337)
michael@0 272 pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337)
michael@0 273
michael@0 274 movq mm7, mm6 ; mm7=ROH*FIX(0.299)+GOH*FIX(0.337)
michael@0 275
michael@0 276 movq mm6,mm0
michael@0 277 punpcklwd mm0,mm2
michael@0 278 punpckhwd mm6,mm2
michael@0 279 pmaddwd mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337)
michael@0 280 pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337)
michael@0 281
michael@0 282 movq MMWORD [wk(0)], mm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
michael@0 283 movq MMWORD [wk(1)], mm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
michael@0 284
michael@0 285 movq mm0, mm5 ; mm0=BO
michael@0 286 movq mm6, mm4 ; mm6=BE
michael@0 287
michael@0 288 movq mm4,mm0
michael@0 289 punpcklwd mm0,mm3
michael@0 290 punpckhwd mm4,mm3
michael@0 291 pmaddwd mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250)
michael@0 292 pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250)
michael@0 293
michael@0 294 movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF]
michael@0 295
michael@0 296 paddd mm0, mm1
michael@0 297 paddd mm4, mm7
michael@0 298 paddd mm0,mm3
michael@0 299 paddd mm4,mm3
michael@0 300 psrld mm0,SCALEBITS ; mm0=YOL
michael@0 301 psrld mm4,SCALEBITS ; mm4=YOH
michael@0 302 packssdw mm0,mm4 ; mm0=YO
michael@0 303
michael@0 304 movq mm4,mm6
michael@0 305 punpcklwd mm6,mm2
michael@0 306 punpckhwd mm4,mm2
michael@0 307 pmaddwd mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250)
michael@0 308 pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250)
michael@0 309
michael@0 310 movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF]
michael@0 311
michael@0 312 paddd mm6, MMWORD [wk(0)]
michael@0 313 paddd mm4, MMWORD [wk(1)]
michael@0 314 paddd mm6,mm2
michael@0 315 paddd mm4,mm2
michael@0 316 psrld mm6,SCALEBITS ; mm6=YEL
michael@0 317 psrld mm4,SCALEBITS ; mm4=YEH
michael@0 318 packssdw mm6,mm4 ; mm6=YE
michael@0 319
michael@0 320 psllw mm0,BYTE_BIT
michael@0 321 por mm6,mm0 ; mm6=Y
michael@0 322 movq MMWORD [edi], mm6 ; Save Y
michael@0 323
michael@0 324 sub ecx, byte SIZEOF_MMWORD
michael@0 325 add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr
michael@0 326 add edi, byte SIZEOF_MMWORD ; outptr0
michael@0 327 cmp ecx, byte SIZEOF_MMWORD
michael@0 328 jae near .columnloop
michael@0 329 test ecx,ecx
michael@0 330 jnz near .column_ld1
michael@0 331
michael@0 332 pop ecx ; col
michael@0 333 pop esi
michael@0 334 pop edi
michael@0 335 poppic eax
michael@0 336
michael@0 337 add esi, byte SIZEOF_JSAMPROW ; input_buf
michael@0 338 add edi, byte SIZEOF_JSAMPROW
michael@0 339 dec eax ; num_rows
michael@0 340 jg near .rowloop
michael@0 341
michael@0 342 emms ; empty MMX state
michael@0 343
michael@0 344 .return:
michael@0 345 pop edi
michael@0 346 pop esi
michael@0 347 ; pop edx ; need not be preserved
michael@0 348 ; pop ecx ; need not be preserved
michael@0 349 pop ebx
michael@0 350 mov esp,ebp ; esp <- aligned ebp
michael@0 351 pop esp ; esp <- original ebp
michael@0 352 pop ebp
michael@0 353 ret
michael@0 354
michael@0 355 ; For some reason, the OS X linker does not honor the request to align the
michael@0 356 ; segment unless we do this.
michael@0 357 align 16

mercurial