jquantf-sse2.asm 5.1 KB

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