OLD | NEW |
(Empty) | |
| 1 ; |
| 2 ; jdclrss2-64.asm - colorspace conversion (64-bit SSE2) |
| 3 ; |
| 4 ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
| 5 ; Copyright 2009 D. R. Commander |
| 6 ; |
| 7 ; Based on |
| 8 ; x86 SIMD extension for IJG JPEG library |
| 9 ; Copyright (C) 1999-2006, MIYASAKA Masaru. |
| 10 ; For conditions of distribution and use, see copyright notice in jsimdext.inc |
| 11 ; |
| 12 ; This file should be assembled with NASM (Netwide Assembler), |
| 13 ; can *not* be assembled with Microsoft's MASM or any compatible |
| 14 ; assembler (including Borland's Turbo Assembler). |
| 15 ; NASM is available from http://nasm.sourceforge.net/ or |
| 16 ; http://sourceforge.net/project/showfiles.php?group_id=6208 |
| 17 ; |
| 18 ; [TAB8] |
| 19 |
| 20 %include "jcolsamp.inc" |
| 21 |
| 22 ; -------------------------------------------------------------------------- |
| 23 SECTION SEG_TEXT |
| 24 BITS 64 |
| 25 ; |
| 26 ; Convert some rows of samples to the output colorspace. |
| 27 ; |
| 28 ; GLOBAL(void) |
| 29 ; jsimd_ycc_rgb_convert_sse2 (JDIMENSION out_width, |
| 30 ; JSAMPIMAGE input_buf, JDIMENSION input_row, |
| 31 ; JSAMPARRAY output_buf, int num_rows) |
| 32 ; |
| 33 |
| 34 ; r10 = JDIMENSION out_width |
| 35 ; r11 = JSAMPIMAGE input_buf |
| 36 ; r12 = JDIMENSION input_row |
| 37 ; r13 = JSAMPARRAY output_buf |
| 38 ; r14 = int num_rows |
| 39 |
| 40 %define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] |
| 41 %define WK_NUM 2 |
| 42 |
| 43 align 16 |
| 44 global EXTN(jsimd_ycc_rgb_convert_sse2) |
| 45 |
| 46 EXTN(jsimd_ycc_rgb_convert_sse2): |
| 47 push rbp |
| 48 mov rax,rsp ; rax = original rbp |
| 49 sub rsp, byte 4 |
| 50 and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits |
| 51 mov [rsp],rax |
| 52 mov rbp,rsp ; rbp = aligned rbp |
| 53 lea rsp, [wk(0)] |
| 54 collect_args |
| 55 push rbx |
| 56 |
| 57 mov rcx, r10 ; num_cols |
| 58 test rcx,rcx |
| 59 jz near .return |
| 60 |
| 61 push rcx |
| 62 |
| 63 mov rdi, r11 |
| 64 mov rcx, r12 |
| 65 mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY] |
| 66 mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY] |
| 67 mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY] |
| 68 lea rsi, [rsi+rcx*SIZEOF_JSAMPROW] |
| 69 lea rbx, [rbx+rcx*SIZEOF_JSAMPROW] |
| 70 lea rdx, [rdx+rcx*SIZEOF_JSAMPROW] |
| 71 |
| 72 pop rcx |
| 73 |
| 74 mov rdi, r13 |
| 75 mov eax, r14d |
| 76 test rax,rax |
| 77 jle near .return |
| 78 .rowloop: |
| 79 push rax |
| 80 push rdi |
| 81 push rdx |
| 82 push rbx |
| 83 push rsi |
| 84 push rcx ; col |
| 85 |
| 86 mov rsi, JSAMPROW [rsi] ; inptr0 |
| 87 mov rbx, JSAMPROW [rbx] ; inptr1 |
| 88 mov rdx, JSAMPROW [rdx] ; inptr2 |
| 89 mov rdi, JSAMPROW [rdi] ; outptr |
| 90 .columnloop: |
| 91 |
| 92 movdqa xmm5, XMMWORD [rbx] ; xmm5=Cb(0123456789ABCDEF) |
| 93 movdqa xmm1, XMMWORD [rdx] ; xmm1=Cr(0123456789ABCDEF) |
| 94 |
| 95 pcmpeqw xmm4,xmm4 |
| 96 pcmpeqw xmm7,xmm7 |
| 97 psrlw xmm4,BYTE_BIT |
| 98 psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..} |
| 99 movdqa xmm0,xmm4 ; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..} |
| 100 |
| 101 pand xmm4,xmm5 ; xmm4=Cb(02468ACE)=CbE |
| 102 psrlw xmm5,BYTE_BIT ; xmm5=Cb(13579BDF)=CbO |
| 103 pand xmm0,xmm1 ; xmm0=Cr(02468ACE)=CrE |
| 104 psrlw xmm1,BYTE_BIT ; xmm1=Cr(13579BDF)=CrO |
| 105 |
| 106 paddw xmm4,xmm7 |
| 107 paddw xmm5,xmm7 |
| 108 paddw xmm0,xmm7 |
| 109 paddw xmm1,xmm7 |
| 110 |
| 111 ; (Original) |
| 112 ; R = Y + 1.40200 * Cr |
| 113 ; G = Y - 0.34414 * Cb - 0.71414 * Cr |
| 114 ; B = Y + 1.77200 * Cb |
| 115 ; |
| 116 ; (This implementation) |
| 117 ; R = Y + 0.40200 * Cr + Cr |
| 118 ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr |
| 119 ; B = Y - 0.22800 * Cb + Cb + Cb |
| 120 |
| 121 movdqa xmm2,xmm4 ; xmm2=CbE |
| 122 movdqa xmm3,xmm5 ; xmm3=CbO |
| 123 paddw xmm4,xmm4 ; xmm4=2*CbE |
| 124 paddw xmm5,xmm5 ; xmm5=2*CbO |
| 125 movdqa xmm6,xmm0 ; xmm6=CrE |
| 126 movdqa xmm7,xmm1 ; xmm7=CrO |
| 127 paddw xmm0,xmm0 ; xmm0=2*CrE |
| 128 paddw xmm1,xmm1 ; xmm1=2*CrO |
| 129 |
| 130 pmulhw xmm4,[rel PW_MF0228] ; xmm4=(2*CbE * -FIX(0.22800)) |
| 131 pmulhw xmm5,[rel PW_MF0228] ; xmm5=(2*CbO * -FIX(0.22800)) |
| 132 pmulhw xmm0,[rel PW_F0402] ; xmm0=(2*CrE * FIX(0.40200)) |
| 133 pmulhw xmm1,[rel PW_F0402] ; xmm1=(2*CrO * FIX(0.40200)) |
| 134 |
| 135 paddw xmm4,[rel PW_ONE] |
| 136 paddw xmm5,[rel PW_ONE] |
| 137 psraw xmm4,1 ; xmm4=(CbE * -FIX(0.22800)) |
| 138 psraw xmm5,1 ; xmm5=(CbO * -FIX(0.22800)) |
| 139 paddw xmm0,[rel PW_ONE] |
| 140 paddw xmm1,[rel PW_ONE] |
| 141 psraw xmm0,1 ; xmm0=(CrE * FIX(0.40200)) |
| 142 psraw xmm1,1 ; xmm1=(CrO * FIX(0.40200)) |
| 143 |
| 144 paddw xmm4,xmm2 |
| 145 paddw xmm5,xmm3 |
| 146 paddw xmm4,xmm2 ; xmm4=(CbE * FIX(1.77200))=(B-Y)E |
| 147 paddw xmm5,xmm3 ; xmm5=(CbO * FIX(1.77200))=(B-Y)O |
| 148 paddw xmm0,xmm6 ; xmm0=(CrE * FIX(1.40200))=(R-Y)E |
| 149 paddw xmm1,xmm7 ; xmm1=(CrO * FIX(1.40200))=(R-Y)O |
| 150 |
| 151 movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=(B-Y)E |
| 152 movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(B-Y)O |
| 153 |
| 154 movdqa xmm4,xmm2 |
| 155 movdqa xmm5,xmm3 |
| 156 punpcklwd xmm2,xmm6 |
| 157 punpckhwd xmm4,xmm6 |
| 158 pmaddwd xmm2,[rel PW_MF0344_F0285] |
| 159 pmaddwd xmm4,[rel PW_MF0344_F0285] |
| 160 punpcklwd xmm3,xmm7 |
| 161 punpckhwd xmm5,xmm7 |
| 162 pmaddwd xmm3,[rel PW_MF0344_F0285] |
| 163 pmaddwd xmm5,[rel PW_MF0344_F0285] |
| 164 |
| 165 paddd xmm2,[rel PD_ONEHALF] |
| 166 paddd xmm4,[rel PD_ONEHALF] |
| 167 psrad xmm2,SCALEBITS |
| 168 psrad xmm4,SCALEBITS |
| 169 paddd xmm3,[rel PD_ONEHALF] |
| 170 paddd xmm5,[rel PD_ONEHALF] |
| 171 psrad xmm3,SCALEBITS |
| 172 psrad xmm5,SCALEBITS |
| 173 |
| 174 packssdw xmm2,xmm4 ; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285) |
| 175 packssdw xmm3,xmm5 ; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285) |
| 176 psubw xmm2,xmm6 ; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E |
| 177 psubw xmm3,xmm7 ; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O |
| 178 |
| 179 movdqa xmm5, XMMWORD [rsi] ; xmm5=Y(0123456789ABCDEF) |
| 180 |
| 181 pcmpeqw xmm4,xmm4 |
| 182 psrlw xmm4,BYTE_BIT ; xmm4={0xFF 0x00 0xFF 0x00 ..} |
| 183 pand xmm4,xmm5 ; xmm4=Y(02468ACE)=YE |
| 184 psrlw xmm5,BYTE_BIT ; xmm5=Y(13579BDF)=YO |
| 185 |
| 186 paddw xmm0,xmm4 ; xmm0=((R-Y)E+YE)=RE=R(02468ACE) |
| 187 paddw xmm1,xmm5 ; xmm1=((R-Y)O+YO)=RO=R(13579BDF) |
| 188 packuswb xmm0,xmm0 ; xmm0=R(02468ACE********) |
| 189 packuswb xmm1,xmm1 ; xmm1=R(13579BDF********) |
| 190 |
| 191 paddw xmm2,xmm4 ; xmm2=((G-Y)E+YE)=GE=G(02468ACE) |
| 192 paddw xmm3,xmm5 ; xmm3=((G-Y)O+YO)=GO=G(13579BDF) |
| 193 packuswb xmm2,xmm2 ; xmm2=G(02468ACE********) |
| 194 packuswb xmm3,xmm3 ; xmm3=G(13579BDF********) |
| 195 |
| 196 paddw xmm4, XMMWORD [wk(0)] ; xmm4=(YE+(B-Y)E)=BE=B(02468ACE) |
| 197 paddw xmm5, XMMWORD [wk(1)] ; xmm5=(YO+(B-Y)O)=BO=B(13579BDF) |
| 198 packuswb xmm4,xmm4 ; xmm4=B(02468ACE********) |
| 199 packuswb xmm5,xmm5 ; xmm5=B(13579BDF********) |
| 200 |
| 201 %if RGB_PIXELSIZE == 3 ; --------------- |
| 202 |
| 203 ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) |
| 204 ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) |
| 205 ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) |
| 206 ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **) |
| 207 |
| 208 punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1
C 0E 1E) |
| 209 punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0
D 2E 0F) |
| 210 punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2
D 1F 2F) |
| 211 |
| 212 movdqa xmmG,xmmA |
| 213 movdqa xmmH,xmmA |
| 214 punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 1
6 26 07) |
| 215 punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1
E 2E 0F) |
| 216 |
| 217 psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1
E -- --) |
| 218 psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0
F -- --) |
| 219 |
| 220 movdqa xmmC,xmmD |
| 221 movdqa xmmB,xmmD |
| 222 punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 2
7 08 18) |
| 223 punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2
F -- --) |
| 224 |
| 225 psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2
F -- --) |
| 226 |
| 227 movdqa xmmF,xmmE |
| 228 punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 0
9 19 29) |
| 229 punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -
- -- --) |
| 230 |
| 231 pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 1
2 22 03) |
| 232 movdqa xmmB,xmmE |
| 233 punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 2
3 04 14) |
| 234 punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 1
6 26 07) |
| 235 punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 0
9 19 29) |
| 236 |
| 237 pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1
A 2A 0B) |
| 238 movdqa xmmB,xmmF |
| 239 punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2
B 0C 1C) |
| 240 punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1
E 2E 0F) |
| 241 punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -
- -- --) |
| 242 |
| 243 punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 1
4 24 05) |
| 244 punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 2
9 0A 1A) |
| 245 punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0
F 1F 2F) |
| 246 |
| 247 cmp rcx, byte SIZEOF_XMMWORD |
| 248 jb short .column_st32 |
| 249 |
| 250 test rdi, SIZEOF_XMMWORD-1 |
| 251 jnz short .out1 |
| 252 ; --(aligned)------------------- |
| 253 movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA |
| 254 movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD |
| 255 movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF |
| 256 add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr |
| 257 jmp short .out0 |
| 258 .out1: ; --(unaligned)----------------- |
| 259 pcmpeqb xmmH,xmmH ; xmmH=(all 1's) |
| 260 maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [rdi], xmmA |
| 261 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 262 maskmovdqu xmmD,xmmH ; movntdqu XMMWORD [rdi], xmmD |
| 263 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 264 maskmovdqu xmmF,xmmH ; movntdqu XMMWORD [rdi], xmmF |
| 265 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 266 .out0: |
| 267 sub rcx, byte SIZEOF_XMMWORD |
| 268 jz near .nextrow |
| 269 |
| 270 add rsi, byte SIZEOF_XMMWORD ; inptr0 |
| 271 add rbx, byte SIZEOF_XMMWORD ; inptr1 |
| 272 add rdx, byte SIZEOF_XMMWORD ; inptr2 |
| 273 jmp near .columnloop |
| 274 |
| 275 .column_st32: |
| 276 pcmpeqb xmmH,xmmH ; xmmH=(all 1's) |
| 277 lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE |
| 278 cmp rcx, byte 2*SIZEOF_XMMWORD |
| 279 jb short .column_st16 |
| 280 maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [rdi], xmmA |
| 281 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 282 maskmovdqu xmmD,xmmH ; movntdqu XMMWORD [rdi], xmmD |
| 283 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 284 movdqa xmmA,xmmF |
| 285 sub rcx, byte 2*SIZEOF_XMMWORD |
| 286 jmp short .column_st15 |
| 287 .column_st16: |
| 288 cmp rcx, byte SIZEOF_XMMWORD |
| 289 jb short .column_st15 |
| 290 maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [rdi], xmmA |
| 291 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 292 movdqa xmmA,xmmD |
| 293 sub rcx, byte SIZEOF_XMMWORD |
| 294 .column_st15: |
| 295 mov rax,rcx |
| 296 xor rcx, byte 0x0F |
| 297 shl rcx, 2 |
| 298 movd xmmB,ecx |
| 299 psrlq xmmH,4 |
| 300 pcmpeqb xmmE,xmmE |
| 301 psrlq xmmH,xmmB |
| 302 psrlq xmmE,xmmB |
| 303 punpcklbw xmmE,xmmH |
| 304 ; ---------------- |
| 305 mov rcx,rdi |
| 306 and rcx, byte SIZEOF_XMMWORD-1 |
| 307 jz short .adj0 |
| 308 add rax,rcx |
| 309 cmp rax, byte SIZEOF_XMMWORD |
| 310 ja short .adj0 |
| 311 and rdi, byte (-SIZEOF_XMMWORD) ; align to 16-byte boundary |
| 312 shl rcx, 3 ; pslldq xmmA,ecx & pslldq xmmE,rcx |
| 313 movdqa xmmG,xmmA |
| 314 movdqa xmmC,xmmE |
| 315 pslldq xmmA, SIZEOF_XMMWORD/2 |
| 316 pslldq xmmE, SIZEOF_XMMWORD/2 |
| 317 movd xmmD,ecx |
| 318 sub rcx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT |
| 319 jb short .adj1 |
| 320 movd xmmF,ecx |
| 321 psllq xmmA,xmmF |
| 322 psllq xmmE,xmmF |
| 323 jmp short .adj0 |
| 324 .adj1: neg ecx |
| 325 movd xmmF,ecx |
| 326 psrlq xmmA,xmmF |
| 327 psrlq xmmE,xmmF |
| 328 psllq xmmG,xmmD |
| 329 psllq xmmC,xmmD |
| 330 por xmmA,xmmG |
| 331 por xmmE,xmmC |
| 332 .adj0: ; ---------------- |
| 333 maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA |
| 334 |
| 335 %else ; RGB_PIXELSIZE == 4 ; ----------- |
| 336 |
| 337 %ifdef RGBX_FILLER_0XFF |
| 338 pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********) |
| 339 pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********) |
| 340 %else |
| 341 pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********) |
| 342 pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********) |
| 343 %endif |
| 344 ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) |
| 345 ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) |
| 346 ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) |
| 347 ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **) |
| 348 |
| 349 punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1
C 0E 1E) |
| 350 punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3
C 2E 3E) |
| 351 punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1
D 0F 1F) |
| 352 punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3
D 2F 3F) |
| 353 |
| 354 movdqa xmmC,xmmA |
| 355 punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 1
6 26 36) |
| 356 punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1
E 2E 3E) |
| 357 movdqa xmmG,xmmB |
| 358 punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 1
7 27 37) |
| 359 punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1
F 2F 3F) |
| 360 |
| 361 movdqa xmmD,xmmA |
| 362 punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 1
3 23 33) |
| 363 punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 1
7 27 37) |
| 364 movdqa xmmH,xmmC |
| 365 punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1
B 2B 3B) |
| 366 punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1
F 2F 3F) |
| 367 |
| 368 cmp rcx, byte SIZEOF_XMMWORD |
| 369 jb short .column_st32 |
| 370 |
| 371 test rdi, SIZEOF_XMMWORD-1 |
| 372 jnz short .out1 |
| 373 ; --(aligned)------------------- |
| 374 movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA |
| 375 movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD |
| 376 movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC |
| 377 movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH |
| 378 add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr |
| 379 jmp short .out0 |
| 380 .out1: ; --(unaligned)----------------- |
| 381 pcmpeqb xmmE,xmmE ; xmmE=(all 1's) |
| 382 maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA |
| 383 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 384 maskmovdqu xmmD,xmmE ; movntdqu XMMWORD [rdi], xmmD |
| 385 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 386 maskmovdqu xmmC,xmmE ; movntdqu XMMWORD [rdi], xmmC |
| 387 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 388 maskmovdqu xmmH,xmmE ; movntdqu XMMWORD [rdi], xmmH |
| 389 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 390 .out0: |
| 391 sub rcx, byte SIZEOF_XMMWORD |
| 392 jz near .nextrow |
| 393 |
| 394 add rsi, byte SIZEOF_XMMWORD ; inptr0 |
| 395 add rbx, byte SIZEOF_XMMWORD ; inptr1 |
| 396 add rdx, byte SIZEOF_XMMWORD ; inptr2 |
| 397 jmp near .columnloop |
| 398 |
| 399 .column_st32: |
| 400 pcmpeqb xmmE,xmmE ; xmmE=(all 1's) |
| 401 cmp rcx, byte SIZEOF_XMMWORD/2 |
| 402 jb short .column_st16 |
| 403 maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA |
| 404 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 405 maskmovdqu xmmD,xmmE ; movntdqu XMMWORD [rdi], xmmD |
| 406 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 407 movdqa xmmA,xmmC |
| 408 movdqa xmmD,xmmH |
| 409 sub rcx, byte SIZEOF_XMMWORD/2 |
| 410 .column_st16: |
| 411 cmp rcx, byte SIZEOF_XMMWORD/4 |
| 412 jb short .column_st15 |
| 413 maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA |
| 414 add rdi, byte SIZEOF_XMMWORD ; outptr |
| 415 movdqa xmmA,xmmD |
| 416 sub rcx, byte SIZEOF_XMMWORD/4 |
| 417 .column_st15: |
| 418 cmp rcx, byte SIZEOF_XMMWORD/16 |
| 419 jb near .nextrow |
| 420 mov rax,rcx |
| 421 xor rcx, byte 0x03 |
| 422 inc rcx |
| 423 shl rcx, 4 |
| 424 movd xmmF,ecx |
| 425 psrlq xmmE,xmmF |
| 426 punpcklbw xmmE,xmmE |
| 427 ; ---------------- |
| 428 mov rcx,rdi |
| 429 and rcx, byte SIZEOF_XMMWORD-1 |
| 430 jz short .adj0 |
| 431 lea rax, [rcx+rax*4] ; RGB_PIXELSIZE |
| 432 cmp rax, byte SIZEOF_XMMWORD |
| 433 ja short .adj0 |
| 434 and rdi, byte (-SIZEOF_XMMWORD) ; align to 16-byte boundary |
| 435 shl rcx, 3 ; pslldq xmmA,ecx & pslldq xmmE,ecx |
| 436 movdqa xmmB,xmmA |
| 437 movdqa xmmG,xmmE |
| 438 pslldq xmmA, SIZEOF_XMMWORD/2 |
| 439 pslldq xmmE, SIZEOF_XMMWORD/2 |
| 440 movd xmmC,ecx |
| 441 sub rcx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT |
| 442 jb short .adj1 |
| 443 movd xmmH,ecx |
| 444 psllq xmmA,xmmH |
| 445 psllq xmmE,xmmH |
| 446 jmp short .adj0 |
| 447 .adj1: neg rcx |
| 448 movd xmmH,ecx |
| 449 psrlq xmmA,xmmH |
| 450 psrlq xmmE,xmmH |
| 451 psllq xmmB,xmmC |
| 452 psllq xmmG,xmmC |
| 453 por xmmA,xmmB |
| 454 por xmmE,xmmG |
| 455 .adj0: ; ---------------- |
| 456 maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA |
| 457 |
| 458 %endif ; RGB_PIXELSIZE ; --------------- |
| 459 |
| 460 .nextrow: |
| 461 pop rcx |
| 462 pop rsi |
| 463 pop rbx |
| 464 pop rdx |
| 465 pop rdi |
| 466 pop rax |
| 467 |
| 468 add rsi, byte SIZEOF_JSAMPROW |
| 469 add rbx, byte SIZEOF_JSAMPROW |
| 470 add rdx, byte SIZEOF_JSAMPROW |
| 471 add rdi, byte SIZEOF_JSAMPROW ; output_buf |
| 472 dec rax ; num_rows |
| 473 jg near .rowloop |
| 474 |
| 475 sfence ; flush the write buffer |
| 476 |
| 477 .return: |
| 478 pop rbx |
| 479 uncollect_args |
| 480 mov rsp,rbp ; rsp <- aligned rbp |
| 481 pop rsp ; rsp <- original rbp |
| 482 pop rbp |
| 483 ret |
| 484 |
| 485 ; For some reason, the OS X linker does not honor the request to align the |
| 486 ; segment unless we do this. |
| 487 align 16 |
OLD | NEW |