MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 1 | ; |
DRC | 72130be | 2014-05-09 20:14:26 +0000 | [diff] [blame] | 2 | ; jcsample.asm - downsampling (SSE2) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 3 | ; |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 4 | ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
| 5 | ; |
| 6 | ; Based on |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 7 | ; 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 | ; |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 17 | ; [TAB8] |
| 18 | |
Pierre Ossman | 3a65ef4 | 2009-03-16 13:34:18 +0000 | [diff] [blame] | 19 | %include "jsimdext.inc" |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 20 | |
| 21 | ; -------------------------------------------------------------------------- |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 22 | SECTION SEG_TEXT |
| 23 | BITS 32 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 24 | ; |
| 25 | ; Downsample pixel values of a single component. |
| 26 | ; This version handles the common case of 2:1 horizontal and 1:1 vertical, |
| 27 | ; without smoothing. |
| 28 | ; |
| 29 | ; GLOBAL(void) |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 30 | ; jsimd_h2v1_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor, |
| 31 | ; JDIMENSION v_samp_factor, JDIMENSION width_blocks, |
| 32 | ; JSAMPARRAY input_data, JSAMPARRAY output_data); |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 33 | ; |
| 34 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 35 | %define img_width(b) (b)+8 ; JDIMENSION image_width |
| 36 | %define max_v_samp(b) (b)+12 ; int max_v_samp_factor |
| 37 | %define v_samp(b) (b)+16 ; JDIMENSION v_samp_factor |
| 38 | %define width_blks(b) (b)+20 ; JDIMENSION width_blocks |
| 39 | %define input_data(b) (b)+24 ; JSAMPARRAY input_data |
| 40 | %define output_data(b) (b)+28 ; JSAMPARRAY output_data |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 41 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 42 | align 16 |
| 43 | global EXTN(jsimd_h2v1_downsample_sse2) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 44 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 45 | EXTN(jsimd_h2v1_downsample_sse2): |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 46 | push ebp |
| 47 | mov ebp,esp |
| 48 | ; push ebx ; unused |
| 49 | ; push ecx ; need not be preserved |
| 50 | ; push edx ; need not be preserved |
| 51 | push esi |
| 52 | push edi |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 53 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 54 | mov ecx, JDIMENSION [width_blks(ebp)] |
| 55 | shl ecx,3 ; imul ecx,DCTSIZE (ecx = output_cols) |
| 56 | jz near .return |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 57 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 58 | mov edx, JDIMENSION [img_width(ebp)] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 59 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 60 | ; -- expand_right_edge |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 61 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 62 | push ecx |
| 63 | shl ecx,1 ; output_cols * 2 |
| 64 | sub ecx,edx |
| 65 | jle short .expand_end |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 66 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 67 | mov eax, INT [max_v_samp(ebp)] |
| 68 | test eax,eax |
| 69 | jle short .expand_end |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 70 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 71 | cld |
| 72 | mov esi, JSAMPARRAY [input_data(ebp)] ; input_data |
| 73 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 74 | .expandloop: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 75 | push eax |
| 76 | push ecx |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 77 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 78 | mov edi, JSAMPROW [esi] |
| 79 | add edi,edx |
| 80 | mov al, JSAMPLE [edi-1] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 81 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 82 | rep stosb |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 83 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 84 | pop ecx |
| 85 | pop eax |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 86 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 87 | add esi, byte SIZEOF_JSAMPROW |
| 88 | dec eax |
| 89 | jg short .expandloop |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 90 | |
| 91 | .expand_end: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 92 | pop ecx ; output_cols |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 93 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 94 | ; -- h2v1_downsample |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 95 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 96 | mov eax, JDIMENSION [v_samp(ebp)] ; rowctr |
| 97 | test eax,eax |
| 98 | jle near .return |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 99 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 100 | mov edx, 0x00010000 ; bias pattern |
| 101 | movd xmm7,edx |
| 102 | pcmpeqw xmm6,xmm6 |
| 103 | pshufd xmm7,xmm7,0x00 ; xmm7={0, 1, 0, 1, 0, 1, 0, 1} |
| 104 | psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 105 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 106 | mov esi, JSAMPARRAY [input_data(ebp)] ; input_data |
| 107 | mov edi, JSAMPARRAY [output_data(ebp)] ; output_data |
| 108 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 109 | .rowloop: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 110 | push ecx |
| 111 | push edi |
| 112 | push esi |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 113 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 114 | mov esi, JSAMPROW [esi] ; inptr |
| 115 | mov edi, JSAMPROW [edi] ; outptr |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 116 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 117 | cmp ecx, byte SIZEOF_XMMWORD |
| 118 | jae short .columnloop |
| 119 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 120 | |
| 121 | .columnloop_r8: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 122 | movdqa xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD] |
| 123 | pxor xmm1,xmm1 |
| 124 | mov ecx, SIZEOF_XMMWORD |
| 125 | jmp short .downsample |
| 126 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 127 | |
| 128 | .columnloop: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 129 | movdqa xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD] |
| 130 | movdqa xmm1, XMMWORD [esi+1*SIZEOF_XMMWORD] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 131 | |
| 132 | .downsample: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 133 | movdqa xmm2,xmm0 |
| 134 | movdqa xmm3,xmm1 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 135 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 136 | pand xmm0,xmm6 |
| 137 | psrlw xmm2,BYTE_BIT |
| 138 | pand xmm1,xmm6 |
| 139 | psrlw xmm3,BYTE_BIT |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 140 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 141 | paddw xmm0,xmm2 |
| 142 | paddw xmm1,xmm3 |
| 143 | paddw xmm0,xmm7 |
| 144 | paddw xmm1,xmm7 |
| 145 | psrlw xmm0,1 |
| 146 | psrlw xmm1,1 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 147 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 148 | packuswb xmm0,xmm1 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 149 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 150 | movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 151 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 152 | sub ecx, byte SIZEOF_XMMWORD ; outcol |
| 153 | add esi, byte 2*SIZEOF_XMMWORD ; inptr |
| 154 | add edi, byte 1*SIZEOF_XMMWORD ; outptr |
| 155 | cmp ecx, byte SIZEOF_XMMWORD |
| 156 | jae short .columnloop |
| 157 | test ecx,ecx |
| 158 | jnz short .columnloop_r8 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 159 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 160 | pop esi |
| 161 | pop edi |
| 162 | pop ecx |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 163 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 164 | add esi, byte SIZEOF_JSAMPROW ; input_data |
| 165 | add edi, byte SIZEOF_JSAMPROW ; output_data |
| 166 | dec eax ; rowctr |
| 167 | jg near .rowloop |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 168 | |
| 169 | .return: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 170 | pop edi |
| 171 | pop esi |
| 172 | ; pop edx ; need not be preserved |
| 173 | ; pop ecx ; need not be preserved |
| 174 | ; pop ebx ; unused |
| 175 | pop ebp |
| 176 | ret |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 177 | |
| 178 | ; -------------------------------------------------------------------------- |
| 179 | ; |
| 180 | ; Downsample pixel values of a single component. |
| 181 | ; This version handles the standard case of 2:1 horizontal and 2:1 vertical, |
| 182 | ; without smoothing. |
| 183 | ; |
| 184 | ; GLOBAL(void) |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 185 | ; jsimd_h2v2_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor, |
| 186 | ; JDIMENSION v_samp_factor, JDIMENSION width_blocks, |
| 187 | ; JSAMPARRAY input_data, JSAMPARRAY output_data); |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 188 | ; |
| 189 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 190 | %define img_width(b) (b)+8 ; JDIMENSION image_width |
| 191 | %define max_v_samp(b) (b)+12 ; int max_v_samp_factor |
| 192 | %define v_samp(b) (b)+16 ; JDIMENSION v_samp_factor |
| 193 | %define width_blks(b) (b)+20 ; JDIMENSION width_blocks |
| 194 | %define input_data(b) (b)+24 ; JSAMPARRAY input_data |
| 195 | %define output_data(b) (b)+28 ; JSAMPARRAY output_data |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 196 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 197 | align 16 |
| 198 | global EXTN(jsimd_h2v2_downsample_sse2) |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 199 | |
Pierre Ossman | eea7215 | 2009-03-09 13:34:17 +0000 | [diff] [blame] | 200 | EXTN(jsimd_h2v2_downsample_sse2): |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 201 | push ebp |
| 202 | mov ebp,esp |
| 203 | ; push ebx ; unused |
| 204 | ; push ecx ; need not be preserved |
| 205 | ; push edx ; need not be preserved |
| 206 | push esi |
| 207 | push edi |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 208 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 209 | mov ecx, JDIMENSION [width_blks(ebp)] |
| 210 | shl ecx,3 ; imul ecx,DCTSIZE (ecx = output_cols) |
| 211 | jz near .return |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 212 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 213 | mov edx, JDIMENSION [img_width(ebp)] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 214 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 215 | ; -- expand_right_edge |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 216 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 217 | push ecx |
| 218 | shl ecx,1 ; output_cols * 2 |
| 219 | sub ecx,edx |
| 220 | jle short .expand_end |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 221 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 222 | mov eax, INT [max_v_samp(ebp)] |
| 223 | test eax,eax |
| 224 | jle short .expand_end |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 225 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 226 | cld |
| 227 | mov esi, JSAMPARRAY [input_data(ebp)] ; input_data |
| 228 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 229 | .expandloop: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 230 | push eax |
| 231 | push ecx |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 232 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 233 | mov edi, JSAMPROW [esi] |
| 234 | add edi,edx |
| 235 | mov al, JSAMPLE [edi-1] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 236 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 237 | rep stosb |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 238 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 239 | pop ecx |
| 240 | pop eax |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 241 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 242 | add esi, byte SIZEOF_JSAMPROW |
| 243 | dec eax |
| 244 | jg short .expandloop |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 245 | |
| 246 | .expand_end: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 247 | pop ecx ; output_cols |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 248 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 249 | ; -- h2v2_downsample |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 250 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 251 | mov eax, JDIMENSION [v_samp(ebp)] ; rowctr |
| 252 | test eax,eax |
| 253 | jle near .return |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 254 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 255 | mov edx, 0x00020001 ; bias pattern |
| 256 | movd xmm7,edx |
| 257 | pcmpeqw xmm6,xmm6 |
| 258 | pshufd xmm7,xmm7,0x00 ; xmm7={1, 2, 1, 2, 1, 2, 1, 2} |
| 259 | psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 260 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 261 | mov esi, JSAMPARRAY [input_data(ebp)] ; input_data |
| 262 | mov edi, JSAMPARRAY [output_data(ebp)] ; output_data |
| 263 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 264 | .rowloop: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 265 | push ecx |
| 266 | push edi |
| 267 | push esi |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 268 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 269 | mov edx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; inptr0 |
| 270 | mov esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; inptr1 |
| 271 | mov edi, JSAMPROW [edi] ; outptr |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 272 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 273 | cmp ecx, byte SIZEOF_XMMWORD |
| 274 | jae short .columnloop |
| 275 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 276 | |
| 277 | .columnloop_r8: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 278 | movdqa xmm0, XMMWORD [edx+0*SIZEOF_XMMWORD] |
| 279 | movdqa xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD] |
| 280 | pxor xmm2,xmm2 |
| 281 | pxor xmm3,xmm3 |
| 282 | mov ecx, SIZEOF_XMMWORD |
| 283 | jmp short .downsample |
| 284 | alignx 16,7 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 285 | |
| 286 | .columnloop: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 287 | movdqa xmm0, XMMWORD [edx+0*SIZEOF_XMMWORD] |
| 288 | movdqa xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD] |
| 289 | movdqa xmm2, XMMWORD [edx+1*SIZEOF_XMMWORD] |
| 290 | movdqa xmm3, XMMWORD [esi+1*SIZEOF_XMMWORD] |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 291 | |
| 292 | .downsample: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 293 | movdqa xmm4,xmm0 |
| 294 | movdqa xmm5,xmm1 |
| 295 | pand xmm0,xmm6 |
| 296 | psrlw xmm4,BYTE_BIT |
| 297 | pand xmm1,xmm6 |
| 298 | psrlw xmm5,BYTE_BIT |
| 299 | paddw xmm0,xmm4 |
| 300 | paddw xmm1,xmm5 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 301 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 302 | movdqa xmm4,xmm2 |
| 303 | movdqa xmm5,xmm3 |
| 304 | pand xmm2,xmm6 |
| 305 | psrlw xmm4,BYTE_BIT |
| 306 | pand xmm3,xmm6 |
| 307 | psrlw xmm5,BYTE_BIT |
| 308 | paddw xmm2,xmm4 |
| 309 | paddw xmm3,xmm5 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 310 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 311 | paddw xmm0,xmm1 |
| 312 | paddw xmm2,xmm3 |
| 313 | paddw xmm0,xmm7 |
| 314 | paddw xmm2,xmm7 |
| 315 | psrlw xmm0,2 |
| 316 | psrlw xmm2,2 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 317 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 318 | packuswb xmm0,xmm2 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 319 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 320 | movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 321 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 322 | sub ecx, byte SIZEOF_XMMWORD ; outcol |
| 323 | add edx, byte 2*SIZEOF_XMMWORD ; inptr0 |
| 324 | add esi, byte 2*SIZEOF_XMMWORD ; inptr1 |
| 325 | add edi, byte 1*SIZEOF_XMMWORD ; outptr |
| 326 | cmp ecx, byte SIZEOF_XMMWORD |
| 327 | jae near .columnloop |
| 328 | test ecx,ecx |
| 329 | jnz near .columnloop_r8 |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 330 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 331 | pop esi |
| 332 | pop edi |
| 333 | pop ecx |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 334 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 335 | add esi, byte 2*SIZEOF_JSAMPROW ; input_data |
| 336 | add edi, byte 1*SIZEOF_JSAMPROW ; output_data |
| 337 | dec eax ; rowctr |
| 338 | jg near .rowloop |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 339 | |
| 340 | .return: |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 341 | pop edi |
| 342 | pop esi |
| 343 | ; pop edx ; need not be preserved |
| 344 | ; pop ecx ; need not be preserved |
| 345 | ; pop ebx ; unused |
| 346 | pop ebp |
| 347 | ret |
MIYASAKA Masaru | a2e6a9d | 2006-02-04 00:00:00 +0000 | [diff] [blame] | 348 | |
DRC | 132b5fd | 2009-10-08 09:04:56 +0000 | [diff] [blame] | 349 | ; For some reason, the OS X linker does not honor the request to align the |
| 350 | ; segment unless we do this. |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 351 | align 16 |