/chromium/third_party/libjpeg_turbo/simd/jcqnts2i.asm

https://gitlab.com/f3822/qtwebengine-chromium · Assembly · 200 lines · 126 code · 25 blank · 49 comment · 0 complexity · d54d29d42a786da2fda7d8c186f4c790 MD5 · raw file

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