jquantf-sse2.asm 6.0 KB

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