1; 2; jccolext.asm - colorspace conversion (AVX2) 3; 4; Copyright (C) 2015, Intel Corporation. 5; Copyright (C) 2016, D. R. Commander. 6; 7; Based on the x86 SIMD extension for IJG JPEG library 8; Copyright (C) 1999-2006, MIYASAKA Masaru. 9; For conditions of distribution and use, see copyright notice in jsimdext.inc 10; 11; This file should be assembled with NASM (Netwide Assembler), 12; can *not* be assembled with Microsoft's MASM or any compatible 13; assembler (including Borland's Turbo Assembler). 14; NASM is available from http://nasm.sourceforge.net/ or 15; http://sourceforge.net/project/showfiles.php?group_id=6208 16 17%include "jcolsamp.inc" 18 19; -------------------------------------------------------------------------- 20; 21; Convert some rows of samples to the output colorspace. 22; 23; GLOBAL(void) 24; jsimd_rgb_ycc_convert_avx2(JDIMENSION img_width, JSAMPARRAY input_buf, 25; JSAMPIMAGE output_buf, JDIMENSION output_row, 26; int num_rows); 27; 28 29%define img_width(b) (b) + 8 ; JDIMENSION img_width 30%define input_buf(b) (b) + 12 ; JSAMPARRAY input_buf 31%define output_buf(b) (b) + 16 ; JSAMPIMAGE output_buf 32%define output_row(b) (b) + 20 ; JDIMENSION output_row 33%define num_rows(b) (b) + 24 ; int num_rows 34 35%define original_ebp ebp + 0 36%define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_YMMWORD 37 ; ymmword wk[WK_NUM] 38%define WK_NUM 8 39%define gotptr wk(0) - SIZEOF_POINTER ; void * gotptr 40 41 align 32 42 GLOBAL_FUNCTION(jsimd_rgb_ycc_convert_avx2) 43 44EXTN(jsimd_rgb_ycc_convert_avx2): 45 push ebp 46 mov eax, esp ; eax = original ebp 47 sub esp, byte 4 48 and esp, byte (-SIZEOF_YMMWORD) ; align to 256 bits 49 mov [esp], eax 50 mov ebp, esp ; ebp = aligned ebp 51 lea esp, [wk(0)] 52 pushpic eax ; make a room for GOT address 53 push ebx 54; push ecx ; need not be preserved 55; push edx ; need not be preserved 56 push esi 57 push edi 58 59 get_GOT ebx ; get GOT address 60 movpic POINTER [gotptr], ebx ; save GOT address 61 62 mov ecx, JDIMENSION [img_width(eax)] 63 test ecx, ecx 64 jz near .return 65 66 push ecx 67 68 mov esi, JSAMPIMAGE [output_buf(eax)] 69 mov ecx, JDIMENSION [output_row(eax)] 70 mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] 71 mov ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY] 72 mov edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY] 73 lea edi, [edi+ecx*SIZEOF_JSAMPROW] 74 lea ebx, [ebx+ecx*SIZEOF_JSAMPROW] 75 lea edx, [edx+ecx*SIZEOF_JSAMPROW] 76 77 pop ecx 78 79 mov esi, JSAMPARRAY [input_buf(eax)] 80 mov eax, INT [num_rows(eax)] 81 test eax, eax 82 jle near .return 83 alignx 16, 7 84.rowloop: 85 pushpic eax 86 push edx 87 push ebx 88 push edi 89 push esi 90 push ecx ; col 91 92 mov esi, JSAMPROW [esi] ; inptr 93 mov edi, JSAMPROW [edi] ; outptr0 94 mov ebx, JSAMPROW [ebx] ; outptr1 95 mov edx, JSAMPROW [edx] ; outptr2 96 movpic eax, POINTER [gotptr] ; load GOT address (eax) 97 98 cmp ecx, byte SIZEOF_YMMWORD 99 jae near .columnloop 100 alignx 16, 7 101 102%if RGB_PIXELSIZE == 3 ; --------------- 103 104.column_ld1: 105 push eax 106 push edx 107 lea ecx, [ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE 108 test cl, SIZEOF_BYTE 109 jz short .column_ld2 110 sub ecx, byte SIZEOF_BYTE 111 movzx eax, byte [esi+ecx] 112.column_ld2: 113 test cl, SIZEOF_WORD 114 jz short .column_ld4 115 sub ecx, byte SIZEOF_WORD 116 movzx edx, word [esi+ecx] 117 shl eax, WORD_BIT 118 or eax, edx 119.column_ld4: 120 vmovd xmmA, eax 121 pop edx 122 pop eax 123 test cl, SIZEOF_DWORD 124 jz short .column_ld8 125 sub ecx, byte SIZEOF_DWORD 126 vmovd xmmF, XMM_DWORD [esi+ecx] 127 vpslldq xmmA, xmmA, SIZEOF_DWORD 128 vpor xmmA, xmmA, xmmF 129.column_ld8: 130 test cl, SIZEOF_MMWORD 131 jz short .column_ld16 132 sub ecx, byte SIZEOF_MMWORD 133 vmovq xmmB, XMM_MMWORD [esi+ecx] 134 vpslldq xmmA, xmmA, SIZEOF_MMWORD 135 vpor xmmA, xmmA, xmmB 136.column_ld16: 137 test cl, SIZEOF_XMMWORD 138 jz short .column_ld32 139 sub ecx, byte SIZEOF_XMMWORD 140 vmovdqu xmmB, XMM_MMWORD [esi+ecx] 141 vperm2i128 ymmA, ymmA, ymmA, 1 142 vpor ymmA, ymmB 143.column_ld32: 144 test cl, SIZEOF_YMMWORD 145 jz short .column_ld64 146 sub ecx, byte SIZEOF_YMMWORD 147 vmovdqa ymmF, ymmA 148 vmovdqu ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD] 149.column_ld64: 150 test cl, 2*SIZEOF_YMMWORD 151 mov ecx, SIZEOF_YMMWORD 152 jz short .rgb_ycc_cnv 153 vmovdqa ymmB, ymmA 154 vmovdqu ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD] 155 vmovdqu ymmF, YMMWORD [esi+1*SIZEOF_YMMWORD] 156 jmp short .rgb_ycc_cnv 157 alignx 16, 7 158 159.columnloop: 160 vmovdqu ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD] 161 vmovdqu ymmF, YMMWORD [esi+1*SIZEOF_YMMWORD] 162 vmovdqu ymmB, YMMWORD [esi+2*SIZEOF_YMMWORD] 163 164.rgb_ycc_cnv: 165 ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05 166 ; 15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) 167 ; ymmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F 168 ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L) 169 ; ymmB=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q 170 ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V) 171 172 vmovdqu ymmC, ymmA 173 vinserti128 ymmA, ymmF, xmmA, 0 ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05 174 ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L) 175 vinserti128 ymmC, ymmC, xmmB, 0 ; ymmC=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q 176 ; 15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) 177 vinserti128 ymmB, ymmB, xmmF, 0 ; ymmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F 178 ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V) 179 vperm2i128 ymmF, ymmC, ymmC, 1 ; ymmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A 180 ; 1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q) 181 182 vmovdqa ymmG, ymmA 183 vpslldq ymmA, ymmA, 8 ; ymmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12 184 ; 22 03 13 23 04 14 24 05 0G 1G 2G 0H 1H 2H 0I 1I) 185 vpsrldq ymmG, ymmG, 8 ; ymmG=(22 03 13 23 04 14 24 05 0G 1G 2G 0H 1H 2H 0I 1I 186 ; 2I 0J 1J 2J 0K 1K 2K 0L -- -- -- -- -- -- -- --) 187 188 vpunpckhbw ymmA, ymmA, ymmF ; ymmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A 189 ; 0G 0O 1G 1O 2G 2O 0H 0P 1H 1P 2H 2P 0I 0Q 1I 1Q) 190 vpslldq ymmF, ymmF, 8 ; ymmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27 191 ; 08 18 28 09 19 29 0A 1A 1L 2L 0M 1M 2M 0N 1N 2N) 192 193 vpunpcklbw ymmG, ymmG, ymmB ; ymmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D 194 ; 2I 2Q 0J 0R 1J 1R 2J 2R 0K 0S 1K 1S 2K 2S 0L 0T) 195 vpunpckhbw ymmF, ymmF, ymmB ; ymmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F 196 ; 1L 1T 2L 2T 0M 0U 1M 1U 2M 2U 0N 0V 1N 1V 2N 2V) 197 198 vmovdqa ymmD, ymmA 199 vpslldq ymmA, ymmA, 8 ; ymmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09 200 ; 11 19 21 29 02 0A 12 1A 0G 0O 1G 1O 2G 2O 0H 0P) 201 vpsrldq ymmD, ymmD, 8 ; ymmD=(11 19 21 29 02 0A 12 1A 0G 0O 1G 1O 2G 2O 0H 0P 202 ; 1H 1P 2H 2P 0I 0Q 1I 1Q -- -- -- -- -- -- -- --) 203 204 vpunpckhbw ymmA, ymmA, ymmG ; ymmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D 205 ; 0G 0K 0O 0S 1G 1K 1O 1S 2G 2K 2O 2S 0H 0L 0P 0T) 206 vpslldq ymmG, ymmG, 8 ; ymmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B 207 ; 04 0C 14 1C 24 2C 05 0D 2I 2Q 0J 0R 1J 1R 2J 2R) 208 209 vpunpcklbw ymmD, ymmD, ymmF ; ymmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E 210 ; 1H 1L 1P 1T 2H 2L 2P 2T 0I 0M 0Q 0U 1I 1M 1Q 1U) 211 vpunpckhbw ymmG, ymmG, ymmF ; ymmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 212 ; 2I 2M 2Q 2U 0J 0N 0R 0V 1J 1N 1R 1V 2J 2N 2R 2V) 213 214 vmovdqa ymmE, ymmA 215 vpslldq ymmA, ymmA, 8 ; ymmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C 216 ; 20 24 28 2C 01 05 09 0D 0G 0K 0O 0S 1G 1K 1O 1S) 217 vpsrldq ymmE, ymmE, 8 ; ymmE=(20 24 28 2C 01 05 09 0D 0G 0K 0O 0S 1G 1K 1O 1S 218 ; 2G 2K 2O 2S 0H 0L 0P 0T -- -- -- -- -- -- -- --) 219 220 vpunpckhbw ymmA, ymmA, ymmD ; ymmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E 221 ; 0G 0I 0K 0M 0O 0Q 0S 0U 1G 1I 1K 1M 1O 1Q 1S 1U) 222 vpslldq ymmD, ymmD, 8 ; ymmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D 223 ; 02 06 0A 0E 12 16 1A 1E 1H 1L 1P 1T 2H 2L 2P 2T) 224 225 vpunpcklbw ymmE, ymmE, ymmG ; ymmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F 226 ; 2G 2I 2K 2M 2O 2Q 2S 2U 0H 0J 0L 0N 0P 0R 0T 0V) 227 vpunpckhbw ymmD, ymmD, ymmG ; ymmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F 228 ; 1H 1J 1L 1N 1P 1R 1T 1V 2H 2J 2L 2N 2P 2R 2T 2V) 229 230 vpxor ymmH, ymmH, ymmH 231 232 vmovdqa ymmC, ymmA 233 vpunpcklbw ymmA, ymmA, ymmH ; ymmA=(00 02 04 06 08 0A 0C 0E 0G 0I 0K 0M 0O 0Q 0S 0U) 234 vpunpckhbw ymmC, ymmC, ymmH ; ymmC=(10 12 14 16 18 1A 1C 1E 1G 1I 1K 1M 1O 1Q 1S 1U) 235 236 vmovdqa ymmB, ymmE 237 vpunpcklbw ymmE, ymmE, ymmH ; ymmE=(20 22 24 26 28 2A 2C 2E 2G 2I 2K 2M 2O 2Q 2S 2U) 238 vpunpckhbw ymmB, ymmB, ymmH ; ymmB=(01 03 05 07 09 0B 0D 0F 0H 0J 0L 0N 0P 0R 0T 0V) 239 240 vmovdqa ymmF, ymmD 241 vpunpcklbw ymmD, ymmD, ymmH ; ymmD=(11 13 15 17 19 1B 1D 1F 1H 1J 1L 1N 1P 1R 1T 1V) 242 vpunpckhbw ymmF, ymmF, ymmH ; ymmF=(21 23 25 27 29 2B 2D 2F 2H 2J 2L 2N 2P 2R 2T 2V) 243 244%else ; RGB_PIXELSIZE == 4 ; ----------- 245 246.column_ld1: 247 test cl, SIZEOF_XMMWORD/16 248 jz short .column_ld2 249 sub ecx, byte SIZEOF_XMMWORD/16 250 vmovd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE] 251.column_ld2: 252 test cl, SIZEOF_XMMWORD/8 253 jz short .column_ld4 254 sub ecx, byte SIZEOF_XMMWORD/8 255 vmovq xmmF, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE] 256 vpslldq xmmA, xmmA, SIZEOF_MMWORD 257 vpor xmmA, xmmA, xmmF 258.column_ld4: 259 test cl, SIZEOF_XMMWORD/4 260 jz short .column_ld8 261 sub ecx, byte SIZEOF_XMMWORD/4 262 vmovdqa xmmF, xmmA 263 vperm2i128 ymmF, ymmF, ymmF, 1 264 vmovdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE] 265 vpor ymmA, ymmA, ymmF 266.column_ld8: 267 test cl, SIZEOF_XMMWORD/2 268 jz short .column_ld16 269 sub ecx, byte SIZEOF_XMMWORD/2 270 vmovdqa ymmF, ymmA 271 vmovdqu ymmA, YMMWORD [esi+ecx*RGB_PIXELSIZE] 272.column_ld16: 273 test cl, SIZEOF_XMMWORD 274 mov ecx, SIZEOF_YMMWORD 275 jz short .rgb_ycc_cnv 276 vmovdqa ymmE, ymmA 277 vmovdqa ymmH, ymmF 278 vmovdqu ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD] 279 vmovdqu ymmF, YMMWORD [esi+1*SIZEOF_YMMWORD] 280 jmp short .rgb_ycc_cnv 281 alignx 16, 7 282 283.columnloop: 284 vmovdqu ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD] 285 vmovdqu ymmF, YMMWORD [esi+1*SIZEOF_YMMWORD] 286 vmovdqu ymmE, YMMWORD [esi+2*SIZEOF_YMMWORD] 287 vmovdqu ymmH, YMMWORD [esi+3*SIZEOF_YMMWORD] 288 289.rgb_ycc_cnv: 290 ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33 291 ; 04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) 292 ; ymmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B 293 ; 0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) 294 ; ymmE=(0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J 295 ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N) 296 ; ymmH=(0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R 297 ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V) 298 299 vmovdqa ymmB, ymmA 300 vinserti128 ymmA, ymmA, xmmE, 1 ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33 301 ; 0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J) 302 vperm2i128 ymmE, ymmB, ymmE, 0x31 ; ymmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37 303 ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N) 304 305 vmovdqa ymmB, ymmF 306 vinserti128 ymmF, ymmF, xmmH, 1 ; ymmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B 307 ; 0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R) 308 vperm2i128 ymmH, ymmB, ymmH, 0x31 ; ymmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F 309 ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V) 310 311 vmovdqa ymmD, ymmA 312 vpunpcklbw ymmA, ymmA, ymmE ; ymmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35 313 ; 0G 0K 1G 1K 2G 2K 3G 3K 0H 0L 1H 1L 2H 2L 3H 3L) 314 vpunpckhbw ymmD, ymmD, ymmE ; ymmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37 315 ; 0I 0M 1I 1M 2I 2M 3I 3M 0J 0N 1J 1N 2J 2N 3J 3N) 316 317 vmovdqa ymmC, ymmF 318 vpunpcklbw ymmF, ymmF, ymmH ; ymmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D 319 ; 0O 0S 1O 1S 2O 2S 3O 3S 0P 0T 1P 1T 2P 2T 3P 3T) 320 vpunpckhbw ymmC, ymmC, ymmH ; ymmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F 321 ; 0Q 0U 1Q 1U 2Q 2U 3Q 3U 0R 0V 1R 1V 2R 2V 3R 3V) 322 323 vmovdqa ymmB, ymmA 324 vpunpcklwd ymmA, ymmA, ymmF ; ymmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C 325 ; 0G 0K 0O 0S 1G 1K 1O 1S 2G 2K 2O 2S 3G 3K 3O 3S) 326 vpunpckhwd ymmB, ymmB, ymmF ; ymmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D 327 ; 0H 0L 0P 0T 1H 1L 1P 1T 2H 2L 2P 2T 3H 3L 3P 3T) 328 329 vmovdqa ymmG, ymmD 330 vpunpcklwd ymmD, ymmD, ymmC ; ymmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E 331 ; 0I 0M 0Q 0U 1I 1M 1Q 1U 2I 2M 2Q 2U 3I 3M 3Q 3U) 332 vpunpckhwd ymmG, ymmG, ymmC ; ymmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F 333 ; 0J 0N 0R 0V 1J 1N 1R 1V 2J 2N 2R 2V 3J 3N 3R 3V) 334 335 vmovdqa ymmE, ymmA 336 vpunpcklbw ymmA, ymmA, ymmD ; ymmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E 337 ; 0G 0I 0K 0M 0O 0Q 0S 0U 1G 1I 1K 1M 1O 1Q 1S 1U) 338 vpunpckhbw ymmE, ymmE, ymmD ; ymmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E 339 ; 2G 2I 2K 2M 2O 2Q 2S 2U 3G 3I 3K 3M 3O 3Q 3S 3U) 340 341 vmovdqa ymmH, ymmB 342 vpunpcklbw ymmB, ymmB, ymmG ; ymmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F 343 ; 0H 0J 0L 0N 0P 0R 0T 0V 1H 1J 1L 1N 1P 1R 1T 1V) 344 vpunpckhbw ymmH, ymmH, ymmG ; ymmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F 345 ; 2H 2J 2L 2N 2P 2R 2T 2V 3H 3J 3L 3N 3P 3R 3T 3V) 346 347 vpxor ymmF, ymmF, ymmF 348 349 vmovdqa ymmC, ymmA 350 vpunpcklbw ymmA, ymmA, ymmF ; ymmA=(00 02 04 06 08 0A 0C 0E 0G 0I 0K 0M 0O 0Q 0S 0U) 351 vpunpckhbw ymmC, ymmC, ymmF ; ymmC=(10 12 14 16 18 1A 1C 1E 1G 1I 1K 1M 1O 1Q 1S 1U) 352 353 vmovdqa ymmD, ymmB 354 vpunpcklbw ymmB, ymmB, ymmF ; ymmB=(01 03 05 07 09 0B 0D 0F 0H 0J 0L 0N 0P 0R 0T 0V) 355 vpunpckhbw ymmD, ymmD, ymmF ; ymmD=(11 13 15 17 19 1B 1D 1F 1H 1J 1L 1N 1P 1R 1T 1V) 356 357 vmovdqa ymmG, ymmE 358 vpunpcklbw ymmE, ymmE, ymmF ; ymmE=(20 22 24 26 28 2A 2C 2E 2G 2I 2K 2M 2O 2Q 2S 2U) 359 vpunpckhbw ymmG, ymmG, ymmF ; ymmG=(30 32 34 36 38 3A 3C 3E 3G 3I 3K 3M 3O 3Q 3S 3U) 360 361 vpunpcklbw ymmF, ymmF, ymmH 362 vpunpckhbw ymmH, ymmH, ymmH 363 vpsrlw ymmF, ymmF, BYTE_BIT ; ymmF=(21 23 25 27 29 2B 2D 2F 2H 2J 2L 2N 2P 2R 2T 2V) 364 vpsrlw ymmH, ymmH, BYTE_BIT ; ymmH=(31 33 35 37 39 3B 3D 3F 3H 3J 3L 3N 3P 3R 3T 3V) 365 366%endif ; RGB_PIXELSIZE ; --------------- 367 368 ; ymm0=R(02468ACEGIKMOQSU)=RE, ymm2=G(02468ACEGIKMOQSU)=GE, ymm4=B(02468ACEGIKMOQSU)=BE 369 ; ymm1=R(13579BDFHJLNPRTV)=RO, ymm3=G(13579BDFHJLNPRTV)=GO, ymm5=B(13579BDFHJLNPRTV)=BO 370 371 ; (Original) 372 ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B 373 ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE 374 ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE 375 ; 376 ; (This implementation) 377 ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G 378 ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE 379 ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE 380 381 vmovdqa YMMWORD [wk(0)], ymm0 ; wk(0)=RE 382 vmovdqa YMMWORD [wk(1)], ymm1 ; wk(1)=RO 383 vmovdqa YMMWORD [wk(2)], ymm4 ; wk(2)=BE 384 vmovdqa YMMWORD [wk(3)], ymm5 ; wk(3)=BO 385 386 vmovdqa ymm6, ymm1 387 vpunpcklwd ymm1, ymm1, ymm3 388 vpunpckhwd ymm6, ymm6, ymm3 389 vmovdqa ymm7, ymm1 390 vmovdqa ymm4, ymm6 391 vpmaddwd ymm1, ymm1, [GOTOFF(eax,PW_F0299_F0337)] ; ymm1=ROL*FIX(0.299)+GOL*FIX(0.337) 392 vpmaddwd ymm6, ymm6, [GOTOFF(eax,PW_F0299_F0337)] ; ymm6=ROH*FIX(0.299)+GOH*FIX(0.337) 393 vpmaddwd ymm7, ymm7, [GOTOFF(eax,PW_MF016_MF033)] ; ymm7=ROL*-FIX(0.168)+GOL*-FIX(0.331) 394 vpmaddwd ymm4, ymm4, [GOTOFF(eax,PW_MF016_MF033)] ; ymm4=ROH*-FIX(0.168)+GOH*-FIX(0.331) 395 396 vmovdqa YMMWORD [wk(4)], ymm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337) 397 vmovdqa YMMWORD [wk(5)], ymm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337) 398 399 vpxor ymm1, ymm1, ymm1 400 vpxor ymm6, ymm6, ymm6 401 vpunpcklwd ymm1, ymm1, ymm5 ; ymm1=BOL 402 vpunpckhwd ymm6, ymm6, ymm5 ; ymm6=BOH 403 vpsrld ymm1, ymm1, 1 ; ymm1=BOL*FIX(0.500) 404 vpsrld ymm6, ymm6, 1 ; ymm6=BOH*FIX(0.500) 405 406 vmovdqa ymm5, [GOTOFF(eax,PD_ONEHALFM1_CJ)] ; ymm5=[PD_ONEHALFM1_CJ] 407 408 vpaddd ymm7, ymm7, ymm1 409 vpaddd ymm4, ymm4, ymm6 410 vpaddd ymm7, ymm7, ymm5 411 vpaddd ymm4, ymm4, ymm5 412 vpsrld ymm7, ymm7, SCALEBITS ; ymm7=CbOL 413 vpsrld ymm4, ymm4, SCALEBITS ; ymm4=CbOH 414 vpackssdw ymm7, ymm7, ymm4 ; ymm7=CbO 415 416 vmovdqa ymm1, YMMWORD [wk(2)] ; ymm1=BE 417 418 vmovdqa ymm6, ymm0 419 vpunpcklwd ymm0, ymm0, ymm2 420 vpunpckhwd ymm6, ymm6, ymm2 421 vmovdqa ymm5, ymm0 422 vmovdqa ymm4, ymm6 423 vpmaddwd ymm0, ymm0, [GOTOFF(eax,PW_F0299_F0337)] ; ymm0=REL*FIX(0.299)+GEL*FIX(0.337) 424 vpmaddwd ymm6, ymm6, [GOTOFF(eax,PW_F0299_F0337)] ; ymm6=REH*FIX(0.299)+GEH*FIX(0.337) 425 vpmaddwd ymm5, ymm5, [GOTOFF(eax,PW_MF016_MF033)] ; ymm5=REL*-FIX(0.168)+GEL*-FIX(0.331) 426 vpmaddwd ymm4, ymm4, [GOTOFF(eax,PW_MF016_MF033)] ; ymm4=REH*-FIX(0.168)+GEH*-FIX(0.331) 427 428 vmovdqa YMMWORD [wk(6)], ymm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337) 429 vmovdqa YMMWORD [wk(7)], ymm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337) 430 431 vpxor ymm0, ymm0, ymm0 432 vpxor ymm6, ymm6, ymm6 433 vpunpcklwd ymm0, ymm0, ymm1 ; ymm0=BEL 434 vpunpckhwd ymm6, ymm6, ymm1 ; ymm6=BEH 435 vpsrld ymm0, ymm0, 1 ; ymm0=BEL*FIX(0.500) 436 vpsrld ymm6, ymm6, 1 ; ymm6=BEH*FIX(0.500) 437 438 vmovdqa ymm1, [GOTOFF(eax,PD_ONEHALFM1_CJ)] ; ymm1=[PD_ONEHALFM1_CJ] 439 440 vpaddd ymm5, ymm5, ymm0 441 vpaddd ymm4, ymm4, ymm6 442 vpaddd ymm5, ymm5, ymm1 443 vpaddd ymm4, ymm4, ymm1 444 vpsrld ymm5, ymm5, SCALEBITS ; ymm5=CbEL 445 vpsrld ymm4, ymm4, SCALEBITS ; ymm4=CbEH 446 vpackssdw ymm5, ymm5, ymm4 ; ymm5=CbE 447 448 vpsllw ymm7, ymm7, BYTE_BIT 449 vpor ymm5, ymm5, ymm7 ; ymm5=Cb 450 vmovdqu YMMWORD [ebx], ymm5 ; Save Cb 451 452 vmovdqa ymm0, YMMWORD [wk(3)] ; ymm0=BO 453 vmovdqa ymm6, YMMWORD [wk(2)] ; ymm6=BE 454 vmovdqa ymm1, YMMWORD [wk(1)] ; ymm1=RO 455 456 vmovdqa ymm4, ymm0 457 vpunpcklwd ymm0, ymm0, ymm3 458 vpunpckhwd ymm4, ymm4, ymm3 459 vmovdqa ymm7, ymm0 460 vmovdqa ymm5, ymm4 461 vpmaddwd ymm0, ymm0, [GOTOFF(eax,PW_F0114_F0250)] ; ymm0=BOL*FIX(0.114)+GOL*FIX(0.250) 462 vpmaddwd ymm4, ymm4, [GOTOFF(eax,PW_F0114_F0250)] ; ymm4=BOH*FIX(0.114)+GOH*FIX(0.250) 463 vpmaddwd ymm7, ymm7, [GOTOFF(eax,PW_MF008_MF041)] ; ymm7=BOL*-FIX(0.081)+GOL*-FIX(0.418) 464 vpmaddwd ymm5, ymm5, [GOTOFF(eax,PW_MF008_MF041)] ; ymm5=BOH*-FIX(0.081)+GOH*-FIX(0.418) 465 466 vmovdqa ymm3, [GOTOFF(eax,PD_ONEHALF)] ; ymm3=[PD_ONEHALF] 467 468 vpaddd ymm0, ymm0, YMMWORD [wk(4)] 469 vpaddd ymm4, ymm4, YMMWORD [wk(5)] 470 vpaddd ymm0, ymm0, ymm3 471 vpaddd ymm4, ymm4, ymm3 472 vpsrld ymm0, ymm0, SCALEBITS ; ymm0=YOL 473 vpsrld ymm4, ymm4, SCALEBITS ; ymm4=YOH 474 vpackssdw ymm0, ymm0, ymm4 ; ymm0=YO 475 476 vpxor ymm3, ymm3, ymm3 477 vpxor ymm4, ymm4, ymm4 478 vpunpcklwd ymm3, ymm3, ymm1 ; ymm3=ROL 479 vpunpckhwd ymm4, ymm4, ymm1 ; ymm4=ROH 480 vpsrld ymm3, ymm3, 1 ; ymm3=ROL*FIX(0.500) 481 vpsrld ymm4, ymm4, 1 ; ymm4=ROH*FIX(0.500) 482 483 vmovdqa ymm1, [GOTOFF(eax,PD_ONEHALFM1_CJ)] ; ymm1=[PD_ONEHALFM1_CJ] 484 485 vpaddd ymm7, ymm7, ymm3 486 vpaddd ymm5, ymm5, ymm4 487 vpaddd ymm7, ymm7, ymm1 488 vpaddd ymm5, ymm5, ymm1 489 vpsrld ymm7, ymm7, SCALEBITS ; ymm7=CrOL 490 vpsrld ymm5, ymm5, SCALEBITS ; ymm5=CrOH 491 vpackssdw ymm7, ymm7, ymm5 ; ymm7=CrO 492 493 vmovdqa ymm3, YMMWORD [wk(0)] ; ymm3=RE 494 495 vmovdqa ymm4, ymm6 496 vpunpcklwd ymm6, ymm6, ymm2 497 vpunpckhwd ymm4, ymm4, ymm2 498 vmovdqa ymm1, ymm6 499 vmovdqa ymm5, ymm4 500 vpmaddwd ymm6, ymm6, [GOTOFF(eax,PW_F0114_F0250)] ; ymm6=BEL*FIX(0.114)+GEL*FIX(0.250) 501 vpmaddwd ymm4, ymm4, [GOTOFF(eax,PW_F0114_F0250)] ; ymm4=BEH*FIX(0.114)+GEH*FIX(0.250) 502 vpmaddwd ymm1, ymm1, [GOTOFF(eax,PW_MF008_MF041)] ; ymm1=BEL*-FIX(0.081)+GEL*-FIX(0.418) 503 vpmaddwd ymm5, ymm5, [GOTOFF(eax,PW_MF008_MF041)] ; ymm5=BEH*-FIX(0.081)+GEH*-FIX(0.418) 504 505 vmovdqa ymm2, [GOTOFF(eax,PD_ONEHALF)] ; ymm2=[PD_ONEHALF] 506 507 vpaddd ymm6, ymm6, YMMWORD [wk(6)] 508 vpaddd ymm4, ymm4, YMMWORD [wk(7)] 509 vpaddd ymm6, ymm6, ymm2 510 vpaddd ymm4, ymm4, ymm2 511 vpsrld ymm6, ymm6, SCALEBITS ; ymm6=YEL 512 vpsrld ymm4, ymm4, SCALEBITS ; ymm4=YEH 513 vpackssdw ymm6, ymm6, ymm4 ; ymm6=YE 514 515 vpsllw ymm0, ymm0, BYTE_BIT 516 vpor ymm6, ymm6, ymm0 ; ymm6=Y 517 vmovdqu YMMWORD [edi], ymm6 ; Save Y 518 519 vpxor ymm2, ymm2, ymm2 520 vpxor ymm4, ymm4, ymm4 521 vpunpcklwd ymm2, ymm2, ymm3 ; ymm2=REL 522 vpunpckhwd ymm4, ymm4, ymm3 ; ymm4=REH 523 vpsrld ymm2, ymm2, 1 ; ymm2=REL*FIX(0.500) 524 vpsrld ymm4, ymm4, 1 ; ymm4=REH*FIX(0.500) 525 526 vmovdqa ymm0, [GOTOFF(eax,PD_ONEHALFM1_CJ)] ; ymm0=[PD_ONEHALFM1_CJ] 527 528 vpaddd ymm1, ymm1, ymm2 529 vpaddd ymm5, ymm5, ymm4 530 vpaddd ymm1, ymm1, ymm0 531 vpaddd ymm5, ymm5, ymm0 532 vpsrld ymm1, ymm1, SCALEBITS ; ymm1=CrEL 533 vpsrld ymm5, ymm5, SCALEBITS ; ymm5=CrEH 534 vpackssdw ymm1, ymm1, ymm5 ; ymm1=CrE 535 536 vpsllw ymm7, ymm7, BYTE_BIT 537 vpor ymm1, ymm1, ymm7 ; ymm1=Cr 538 vmovdqu YMMWORD [edx], ymm1 ; Save Cr 539 540 sub ecx, byte SIZEOF_YMMWORD 541 add esi, RGB_PIXELSIZE*SIZEOF_YMMWORD ; inptr 542 add edi, byte SIZEOF_YMMWORD ; outptr0 543 add ebx, byte SIZEOF_YMMWORD ; outptr1 544 add edx, byte SIZEOF_YMMWORD ; outptr2 545 cmp ecx, byte SIZEOF_YMMWORD 546 jae near .columnloop 547 test ecx, ecx 548 jnz near .column_ld1 549 550 pop ecx ; col 551 pop esi 552 pop edi 553 pop ebx 554 pop edx 555 poppic eax 556 557 add esi, byte SIZEOF_JSAMPROW ; input_buf 558 add edi, byte SIZEOF_JSAMPROW 559 add ebx, byte SIZEOF_JSAMPROW 560 add edx, byte SIZEOF_JSAMPROW 561 dec eax ; num_rows 562 jg near .rowloop 563 564.return: 565 vzeroupper 566 pop edi 567 pop esi 568; pop edx ; need not be preserved 569; pop ecx ; need not be preserved 570 pop ebx 571 mov esp, ebp ; esp <- aligned ebp 572 pop esp ; esp <- original ebp 573 pop ebp 574 ret 575 576; For some reason, the OS X linker does not honor the request to align the 577; segment unless we do this. 578 align 32 579