PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/libuvccamera/src/main/jni/libjpeg-turbo-1.4.0/simd/jquanti-sse2-64.asm

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