Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | ; |
michael@0 | 2 | ; jcqnts2i-64.asm - sample data conversion and quantization (64-bit SSE2) |
michael@0 | 3 | ; |
michael@0 | 4 | ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
michael@0 | 5 | ; Copyright 2009 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 "jsimdext.inc" |
michael@0 | 21 | %include "jdct.inc" |
michael@0 | 22 | |
michael@0 | 23 | ; -------------------------------------------------------------------------- |
michael@0 | 24 | SECTION SEG_TEXT |
michael@0 | 25 | BITS 64 |
michael@0 | 26 | ; |
michael@0 | 27 | ; Load data into workspace, applying unsigned->signed conversion |
michael@0 | 28 | ; |
michael@0 | 29 | ; GLOBAL(void) |
michael@0 | 30 | ; jsimd_convsamp_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col, |
michael@0 | 31 | ; DCTELEM * workspace); |
michael@0 | 32 | ; |
michael@0 | 33 | |
michael@0 | 34 | ; r10 = JSAMPARRAY sample_data |
michael@0 | 35 | ; r11 = JDIMENSION start_col |
michael@0 | 36 | ; r12 = DCTELEM * workspace |
michael@0 | 37 | |
michael@0 | 38 | align 16 |
michael@0 | 39 | global EXTN(jsimd_convsamp_sse2) |
michael@0 | 40 | |
michael@0 | 41 | EXTN(jsimd_convsamp_sse2): |
michael@0 | 42 | push rbp |
michael@0 | 43 | mov rax,rsp |
michael@0 | 44 | mov rbp,rsp |
michael@0 | 45 | collect_args |
michael@0 | 46 | push rbx |
michael@0 | 47 | |
michael@0 | 48 | pxor xmm6,xmm6 ; xmm6=(all 0's) |
michael@0 | 49 | pcmpeqw xmm7,xmm7 |
michael@0 | 50 | psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..} |
michael@0 | 51 | |
michael@0 | 52 | mov rsi, r10 |
michael@0 | 53 | mov rax, r11 |
michael@0 | 54 | mov rdi, r12 |
michael@0 | 55 | mov rcx, DCTSIZE/4 |
michael@0 | 56 | .convloop: |
michael@0 | 57 | mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) |
michael@0 | 58 | mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) |
michael@0 | 59 | |
michael@0 | 60 | movq xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE] ; xmm0=(01234567) |
michael@0 | 61 | movq xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE] ; xmm1=(89ABCDEF) |
michael@0 | 62 | |
michael@0 | 63 | mov rbx, JSAMPROW [rsi+2*SIZEOF_JSAMPROW] ; (JSAMPLE *) |
michael@0 | 64 | mov rdx, JSAMPROW [rsi+3*SIZEOF_JSAMPROW] ; (JSAMPLE *) |
michael@0 | 65 | |
michael@0 | 66 | movq xmm2, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE] ; xmm2=(GHIJKLMN) |
michael@0 | 67 | movq xmm3, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE] ; xmm3=(OPQRSTUV) |
michael@0 | 68 | |
michael@0 | 69 | punpcklbw xmm0,xmm6 ; xmm0=(01234567) |
michael@0 | 70 | punpcklbw xmm1,xmm6 ; xmm1=(89ABCDEF) |
michael@0 | 71 | paddw xmm0,xmm7 |
michael@0 | 72 | paddw xmm1,xmm7 |
michael@0 | 73 | punpcklbw xmm2,xmm6 ; xmm2=(GHIJKLMN) |
michael@0 | 74 | punpcklbw xmm3,xmm6 ; xmm3=(OPQRSTUV) |
michael@0 | 75 | paddw xmm2,xmm7 |
michael@0 | 76 | paddw xmm3,xmm7 |
michael@0 | 77 | |
michael@0 | 78 | movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_DCTELEM)], xmm0 |
michael@0 | 79 | movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_DCTELEM)], xmm1 |
michael@0 | 80 | movdqa XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_DCTELEM)], xmm2 |
michael@0 | 81 | movdqa XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_DCTELEM)], xmm3 |
michael@0 | 82 | |
michael@0 | 83 | add rsi, byte 4*SIZEOF_JSAMPROW |
michael@0 | 84 | add rdi, byte 4*DCTSIZE*SIZEOF_DCTELEM |
michael@0 | 85 | dec rcx |
michael@0 | 86 | jnz short .convloop |
michael@0 | 87 | |
michael@0 | 88 | pop rbx |
michael@0 | 89 | uncollect_args |
michael@0 | 90 | pop rbp |
michael@0 | 91 | ret |
michael@0 | 92 | |
michael@0 | 93 | ; -------------------------------------------------------------------------- |
michael@0 | 94 | ; |
michael@0 | 95 | ; Quantize/descale the coefficients, and store into coef_block |
michael@0 | 96 | ; |
michael@0 | 97 | ; This implementation is based on an algorithm described in |
michael@0 | 98 | ; "How to optimize for the Pentium family of microprocessors" |
michael@0 | 99 | ; (http://www.agner.org/assem/). |
michael@0 | 100 | ; |
michael@0 | 101 | ; GLOBAL(void) |
michael@0 | 102 | ; jsimd_quantize_sse2 (JCOEFPTR coef_block, DCTELEM * divisors, |
michael@0 | 103 | ; DCTELEM * workspace); |
michael@0 | 104 | ; |
michael@0 | 105 | |
michael@0 | 106 | %define RECIPROCAL(m,n,b) XMMBLOCK(DCTSIZE*0+(m),(n),(b),SIZEOF_DCTELEM) |
michael@0 | 107 | %define CORRECTION(m,n,b) XMMBLOCK(DCTSIZE*1+(m),(n),(b),SIZEOF_DCTELEM) |
michael@0 | 108 | %define SCALE(m,n,b) XMMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM) |
michael@0 | 109 | |
michael@0 | 110 | ; r10 = JCOEFPTR coef_block |
michael@0 | 111 | ; r11 = DCTELEM * divisors |
michael@0 | 112 | ; r12 = DCTELEM * workspace |
michael@0 | 113 | |
michael@0 | 114 | align 16 |
michael@0 | 115 | global EXTN(jsimd_quantize_sse2) |
michael@0 | 116 | |
michael@0 | 117 | EXTN(jsimd_quantize_sse2): |
michael@0 | 118 | push rbp |
michael@0 | 119 | mov rax,rsp |
michael@0 | 120 | mov rbp,rsp |
michael@0 | 121 | collect_args |
michael@0 | 122 | |
michael@0 | 123 | mov rsi, r12 |
michael@0 | 124 | mov rdx, r11 |
michael@0 | 125 | mov rdi, r10 |
michael@0 | 126 | mov rax, DCTSIZE2/32 |
michael@0 | 127 | .quantloop: |
michael@0 | 128 | movdqa xmm4, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_DCTELEM)] |
michael@0 | 129 | movdqa xmm5, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_DCTELEM)] |
michael@0 | 130 | movdqa xmm6, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_DCTELEM)] |
michael@0 | 131 | movdqa xmm7, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_DCTELEM)] |
michael@0 | 132 | movdqa xmm0,xmm4 |
michael@0 | 133 | movdqa xmm1,xmm5 |
michael@0 | 134 | movdqa xmm2,xmm6 |
michael@0 | 135 | movdqa xmm3,xmm7 |
michael@0 | 136 | psraw xmm4,(WORD_BIT-1) |
michael@0 | 137 | psraw xmm5,(WORD_BIT-1) |
michael@0 | 138 | psraw xmm6,(WORD_BIT-1) |
michael@0 | 139 | psraw xmm7,(WORD_BIT-1) |
michael@0 | 140 | pxor xmm0,xmm4 |
michael@0 | 141 | pxor xmm1,xmm5 |
michael@0 | 142 | pxor xmm2,xmm6 |
michael@0 | 143 | pxor xmm3,xmm7 |
michael@0 | 144 | psubw xmm0,xmm4 ; if (xmm0 < 0) xmm0 = -xmm0; |
michael@0 | 145 | psubw xmm1,xmm5 ; if (xmm1 < 0) xmm1 = -xmm1; |
michael@0 | 146 | psubw xmm2,xmm6 ; if (xmm2 < 0) xmm2 = -xmm2; |
michael@0 | 147 | psubw xmm3,xmm7 ; if (xmm3 < 0) xmm3 = -xmm3; |
michael@0 | 148 | |
michael@0 | 149 | paddw xmm0, XMMWORD [CORRECTION(0,0,rdx)] ; correction + roundfactor |
michael@0 | 150 | paddw xmm1, XMMWORD [CORRECTION(1,0,rdx)] |
michael@0 | 151 | paddw xmm2, XMMWORD [CORRECTION(2,0,rdx)] |
michael@0 | 152 | paddw xmm3, XMMWORD [CORRECTION(3,0,rdx)] |
michael@0 | 153 | pmulhuw xmm0, XMMWORD [RECIPROCAL(0,0,rdx)] ; reciprocal |
michael@0 | 154 | pmulhuw xmm1, XMMWORD [RECIPROCAL(1,0,rdx)] |
michael@0 | 155 | pmulhuw xmm2, XMMWORD [RECIPROCAL(2,0,rdx)] |
michael@0 | 156 | pmulhuw xmm3, XMMWORD [RECIPROCAL(3,0,rdx)] |
michael@0 | 157 | pmulhuw xmm0, XMMWORD [SCALE(0,0,rdx)] ; scale |
michael@0 | 158 | pmulhuw xmm1, XMMWORD [SCALE(1,0,rdx)] |
michael@0 | 159 | pmulhuw xmm2, XMMWORD [SCALE(2,0,rdx)] |
michael@0 | 160 | pmulhuw xmm3, XMMWORD [SCALE(3,0,rdx)] |
michael@0 | 161 | |
michael@0 | 162 | pxor xmm0,xmm4 |
michael@0 | 163 | pxor xmm1,xmm5 |
michael@0 | 164 | pxor xmm2,xmm6 |
michael@0 | 165 | pxor xmm3,xmm7 |
michael@0 | 166 | psubw xmm0,xmm4 |
michael@0 | 167 | psubw xmm1,xmm5 |
michael@0 | 168 | psubw xmm2,xmm6 |
michael@0 | 169 | psubw xmm3,xmm7 |
michael@0 | 170 | movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_DCTELEM)], xmm0 |
michael@0 | 171 | movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_DCTELEM)], xmm1 |
michael@0 | 172 | movdqa XMMWORD [XMMBLOCK(2,0,rdi,SIZEOF_DCTELEM)], xmm2 |
michael@0 | 173 | movdqa XMMWORD [XMMBLOCK(3,0,rdi,SIZEOF_DCTELEM)], xmm3 |
michael@0 | 174 | |
michael@0 | 175 | add rsi, byte 32*SIZEOF_DCTELEM |
michael@0 | 176 | add rdx, byte 32*SIZEOF_DCTELEM |
michael@0 | 177 | add rdi, byte 32*SIZEOF_JCOEF |
michael@0 | 178 | dec rax |
michael@0 | 179 | jnz near .quantloop |
michael@0 | 180 | |
michael@0 | 181 | uncollect_args |
michael@0 | 182 | pop rbp |
michael@0 | 183 | ret |
michael@0 | 184 | |
michael@0 | 185 | ; For some reason, the OS X linker does not honor the request to align the |
michael@0 | 186 | ; segment unless we do this. |
michael@0 | 187 | align 16 |