jquantf-sse2.asm 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ;
  2. ; jquantf.asm - sample data conversion and quantization (SSE & SSE2)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ;
  6. ; Based on the x86 SIMD extension for IJG JPEG library
  7. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  8. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  9. ;
  10. ; This file should be assembled with NASM (Netwide Assembler),
  11. ; can *not* be assembled with Microsoft's MASM or any compatible
  12. ; assembler (including Borland's Turbo Assembler).
  13. ; NASM is available from http://nasm.sourceforge.net/ or
  14. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  15. ;
  16. ; [TAB8]
  17. %include "jsimdext.inc"
  18. %include "jdct.inc"
  19. ; --------------------------------------------------------------------------
  20. SECTION SEG_TEXT
  21. BITS 32
  22. ;
  23. ; Load data into workspace, applying unsigned->signed conversion
  24. ;
  25. ; GLOBAL(void)
  26. ; jsimd_convsamp_float_sse2 (JSAMPARRAY sample_data, JDIMENSION start_col,
  27. ; FAST_FLOAT *workspace);
  28. ;
  29. %define sample_data ebp+8 ; JSAMPARRAY sample_data
  30. %define start_col ebp+12 ; JDIMENSION start_col
  31. %define workspace ebp+16 ; FAST_FLOAT *workspace
  32. align 16
  33. global EXTN(jsimd_convsamp_float_sse2)
  34. EXTN(jsimd_convsamp_float_sse2):
  35. push ebp
  36. mov ebp,esp
  37. push ebx
  38. ; push ecx ; need not be preserved
  39. ; push edx ; need not be preserved
  40. push esi
  41. push edi
  42. pcmpeqw xmm7,xmm7
  43. psllw xmm7,7
  44. packsswb xmm7,xmm7 ; xmm7 = PB_CENTERJSAMPLE (0x808080..)
  45. mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *)
  46. mov eax, JDIMENSION [start_col]
  47. mov edi, POINTER [workspace] ; (DCTELEM *)
  48. mov ecx, DCTSIZE/2
  49. alignx 16,7
  50. .convloop:
  51. mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *)
  52. mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *)
  53. movq xmm0, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE]
  54. movq xmm1, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE]
  55. psubb xmm0,xmm7 ; xmm0=(01234567)
  56. psubb xmm1,xmm7 ; xmm1=(89ABCDEF)
  57. punpcklbw xmm0,xmm0 ; xmm0=(*0*1*2*3*4*5*6*7)
  58. punpcklbw xmm1,xmm1 ; xmm1=(*8*9*A*B*C*D*E*F)
  59. punpcklwd xmm2,xmm0 ; xmm2=(***0***1***2***3)
  60. punpckhwd xmm0,xmm0 ; xmm0=(***4***5***6***7)
  61. punpcklwd xmm3,xmm1 ; xmm3=(***8***9***A***B)
  62. punpckhwd xmm1,xmm1 ; xmm1=(***C***D***E***F)
  63. psrad xmm2,(DWORD_BIT-BYTE_BIT) ; xmm2=(0123)
  64. psrad xmm0,(DWORD_BIT-BYTE_BIT) ; xmm0=(4567)
  65. cvtdq2ps xmm2,xmm2 ; xmm2=(0123)
  66. cvtdq2ps xmm0,xmm0 ; xmm0=(4567)
  67. psrad xmm3,(DWORD_BIT-BYTE_BIT) ; xmm3=(89AB)
  68. psrad xmm1,(DWORD_BIT-BYTE_BIT) ; xmm1=(CDEF)
  69. cvtdq2ps xmm3,xmm3 ; xmm3=(89AB)
  70. cvtdq2ps xmm1,xmm1 ; xmm1=(CDEF)
  71. movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm2
  72. movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0
  73. movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3
  74. movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1
  75. add esi, byte 2*SIZEOF_JSAMPROW
  76. add edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
  77. dec ecx
  78. jnz short .convloop
  79. pop edi
  80. pop esi
  81. ; pop edx ; need not be preserved
  82. ; pop ecx ; need not be preserved
  83. pop ebx
  84. pop ebp
  85. ret
  86. ; --------------------------------------------------------------------------
  87. ;
  88. ; Quantize/descale the coefficients, and store into coef_block
  89. ;
  90. ; GLOBAL(void)
  91. ; jsimd_quantize_float_sse2 (JCOEFPTR coef_block, FAST_FLOAT *divisors,
  92. ; FAST_FLOAT *workspace);
  93. ;
  94. %define coef_block ebp+8 ; JCOEFPTR coef_block
  95. %define divisors ebp+12 ; FAST_FLOAT *divisors
  96. %define workspace ebp+16 ; FAST_FLOAT *workspace
  97. align 16
  98. global EXTN(jsimd_quantize_float_sse2)
  99. EXTN(jsimd_quantize_float_sse2):
  100. push ebp
  101. mov ebp,esp
  102. ; push ebx ; unused
  103. ; push ecx ; unused
  104. ; push edx ; need not be preserved
  105. push esi
  106. push edi
  107. mov esi, POINTER [workspace]
  108. mov edx, POINTER [divisors]
  109. mov edi, JCOEFPTR [coef_block]
  110. mov eax, DCTSIZE2/16
  111. alignx 16,7
  112. .quantloop:
  113. movaps xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
  114. movaps xmm1, XMMWORD [XMMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)]
  115. mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
  116. mulps xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
  117. movaps xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
  118. movaps xmm3, XMMWORD [XMMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)]
  119. mulps xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
  120. mulps xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
  121. cvtps2dq xmm0,xmm0
  122. cvtps2dq xmm1,xmm1
  123. cvtps2dq xmm2,xmm2
  124. cvtps2dq xmm3,xmm3
  125. packssdw xmm0,xmm1
  126. packssdw xmm2,xmm3
  127. movdqa XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_JCOEF)], xmm0
  128. movdqa XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_JCOEF)], xmm2
  129. add esi, byte 16*SIZEOF_FAST_FLOAT
  130. add edx, byte 16*SIZEOF_FAST_FLOAT
  131. add edi, byte 16*SIZEOF_JCOEF
  132. dec eax
  133. jnz short .quantloop
  134. pop edi
  135. pop esi
  136. ; pop edx ; need not be preserved
  137. ; pop ecx ; unused
  138. ; pop ebx ; unused
  139. pop ebp
  140. ret
  141. ; For some reason, the OS X linker does not honor the request to align the
  142. ; segment unless we do this.
  143. align 16