jquantf-sse2.asm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. ;
  2. ; 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, 2024, 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) or Yasm.
  13. %include "jsimdext.inc"
  14. %include "jdct.inc"
  15. ; --------------------------------------------------------------------------
  16. SECTION SEG_TEXT
  17. BITS 64
  18. ;
  19. ; Load data into workspace, applying unsigned->signed conversion
  20. ;
  21. ; GLOBAL(void)
  22. ; jsimd_convsamp_float_sse2(JSAMPARRAY sample_data, JDIMENSION start_col,
  23. ; FAST_FLOAT *workspace);
  24. ;
  25. ; r10 = JSAMPARRAY sample_data
  26. ; r11d = JDIMENSION start_col
  27. ; r12 = FAST_FLOAT *workspace
  28. align 32
  29. GLOBAL_FUNCTION(jsimd_convsamp_float_sse2)
  30. EXTN(jsimd_convsamp_float_sse2):
  31. ENDBR64
  32. push rbp
  33. mov rbp, rsp
  34. COLLECT_ARGS 3
  35. push rbx
  36. pcmpeqw xmm7, xmm7
  37. psllw xmm7, 7
  38. packsswb xmm7, xmm7 ; xmm7 = PB_CENTERJSAMPLE (0x808080..)
  39. mov rsi, r10
  40. mov eax, r11d
  41. mov rdi, r12
  42. mov rcx, DCTSIZE/2
  43. .convloop:
  44. mov rbxp, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *)
  45. mov rdxp, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *)
  46. movq xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE]
  47. movq xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE]
  48. psubb xmm0, xmm7 ; xmm0=(01234567)
  49. psubb xmm1, xmm7 ; xmm1=(89ABCDEF)
  50. punpcklbw xmm0, xmm0 ; xmm0=(*0*1*2*3*4*5*6*7)
  51. punpcklbw xmm1, xmm1 ; xmm1=(*8*9*A*B*C*D*E*F)
  52. punpcklwd xmm2, xmm0 ; xmm2=(***0***1***2***3)
  53. punpckhwd xmm0, xmm0 ; xmm0=(***4***5***6***7)
  54. punpcklwd xmm3, xmm1 ; xmm3=(***8***9***A***B)
  55. punpckhwd xmm1, xmm1 ; xmm1=(***C***D***E***F)
  56. psrad xmm2, (DWORD_BIT-BYTE_BIT) ; xmm2=(0123)
  57. psrad xmm0, (DWORD_BIT-BYTE_BIT) ; xmm0=(4567)
  58. cvtdq2ps xmm2, xmm2 ; xmm2=(0123)
  59. cvtdq2ps xmm0, xmm0 ; xmm0=(4567)
  60. psrad xmm3, (DWORD_BIT-BYTE_BIT) ; xmm3=(89AB)
  61. psrad xmm1, (DWORD_BIT-BYTE_BIT) ; xmm1=(CDEF)
  62. cvtdq2ps xmm3, xmm3 ; xmm3=(89AB)
  63. cvtdq2ps xmm1, xmm1 ; xmm1=(CDEF)
  64. movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm2
  65. movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0
  66. movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3
  67. movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1
  68. add rsi, byte 2*SIZEOF_JSAMPROW
  69. add rdi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
  70. dec rcx
  71. jnz short .convloop
  72. pop rbx
  73. UNCOLLECT_ARGS 3
  74. pop rbp
  75. ret
  76. ; --------------------------------------------------------------------------
  77. ;
  78. ; Quantize/descale the coefficients, and store into coef_block
  79. ;
  80. ; GLOBAL(void)
  81. ; jsimd_quantize_float_sse2(JCOEFPTR coef_block, FAST_FLOAT *divisors,
  82. ; FAST_FLOAT *workspace);
  83. ;
  84. ; r10 = JCOEFPTR coef_block
  85. ; r11 = FAST_FLOAT *divisors
  86. ; r12 = FAST_FLOAT *workspace
  87. align 32
  88. GLOBAL_FUNCTION(jsimd_quantize_float_sse2)
  89. EXTN(jsimd_quantize_float_sse2):
  90. ENDBR64
  91. push rbp
  92. mov rbp, rsp
  93. COLLECT_ARGS 3
  94. mov rsi, r12
  95. mov rdx, r11
  96. mov rdi, r10
  97. mov rax, DCTSIZE2/16
  98. .quantloop:
  99. movaps xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)]
  100. movaps xmm1, XMMWORD [XMMBLOCK(0,1,rsi,SIZEOF_FAST_FLOAT)]
  101. mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)]
  102. mulps xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)]
  103. movaps xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)]
  104. movaps xmm3, XMMWORD [XMMBLOCK(1,1,rsi,SIZEOF_FAST_FLOAT)]
  105. mulps xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)]
  106. mulps xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)]
  107. cvtps2dq xmm0, xmm0
  108. cvtps2dq xmm1, xmm1
  109. cvtps2dq xmm2, xmm2
  110. cvtps2dq xmm3, xmm3
  111. packssdw xmm0, xmm1
  112. packssdw xmm2, xmm3
  113. movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_JCOEF)], xmm0
  114. movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_JCOEF)], xmm2
  115. add rsi, byte 16*SIZEOF_FAST_FLOAT
  116. add rdx, byte 16*SIZEOF_FAST_FLOAT
  117. add rdi, byte 16*SIZEOF_JCOEF
  118. dec rax
  119. jnz short .quantloop
  120. UNCOLLECT_ARGS 3
  121. pop rbp
  122. ret
  123. ; For some reason, the OS X linker does not honor the request to align the
  124. ; segment unless we do this.
  125. align 32