jcsample-mmx.asm 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. ;
  2. ; Downsampling (MMX)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ; Copyright (C) 2016, 2024, 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) or Yasm.
  12. %include "jsimdext.inc"
  13. ; --------------------------------------------------------------------------
  14. SECTION SEG_TEXT
  15. BITS 32
  16. ;
  17. ; Downsample pixel values of a single component.
  18. ; This version handles the common case of 2:1 horizontal and 1:1 vertical,
  19. ; without smoothing.
  20. ;
  21. ; GLOBAL(void)
  22. ; jsimd_h2v1_downsample_mmx(JDIMENSION image_width, int max_v_samp_factor,
  23. ; JDIMENSION v_samp_factor,
  24. ; JDIMENSION width_in_blocks, JSAMPARRAY input_data,
  25. ; JSAMPARRAY output_data);
  26. ;
  27. %define img_width(b) (b) + 8 ; JDIMENSION image_width
  28. %define max_v_samp(b) (b) + 12 ; int max_v_samp_factor
  29. %define v_samp(b) (b) + 16 ; JDIMENSION v_samp_factor
  30. %define width_blks(b) (b) + 20 ; JDIMENSION width_in_blocks
  31. %define input_data(b) (b) + 24 ; JSAMPARRAY input_data
  32. %define output_data(b) (b) + 28 ; JSAMPARRAY output_data
  33. align 32
  34. GLOBAL_FUNCTION(jsimd_h2v1_downsample_mmx)
  35. EXTN(jsimd_h2v1_downsample_mmx):
  36. push ebp
  37. mov ebp, esp
  38. ; push ebx ; unused
  39. ; push ecx ; need not be preserved
  40. ; push edx ; need not be preserved
  41. push esi
  42. push edi
  43. mov ecx, JDIMENSION [width_blks(ebp)]
  44. shl ecx, 3 ; imul ecx,DCTSIZE (ecx = output_cols)
  45. jz near .return
  46. mov edx, JDIMENSION [img_width(ebp)]
  47. ; -- expand_right_edge
  48. push ecx
  49. shl ecx, 1 ; output_cols * 2
  50. sub ecx, edx
  51. jle short .expand_end
  52. mov eax, INT [max_v_samp(ebp)]
  53. test eax, eax
  54. jle short .expand_end
  55. cld
  56. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  57. ALIGNX 16, 7
  58. .expandloop:
  59. push eax
  60. push ecx
  61. mov edi, JSAMPROW [esi]
  62. add edi, edx
  63. mov al, JSAMPLE [edi-1]
  64. rep stosb
  65. pop ecx
  66. pop eax
  67. add esi, byte SIZEOF_JSAMPROW
  68. dec eax
  69. jg short .expandloop
  70. .expand_end:
  71. pop ecx ; output_cols
  72. ; -- h2v1_downsample
  73. mov eax, JDIMENSION [v_samp(ebp)] ; rowctr
  74. test eax, eax
  75. jle near .return
  76. mov edx, 0x00010000 ; bias pattern
  77. movd mm7, edx
  78. pcmpeqw mm6, mm6
  79. punpckldq mm7, mm7 ; mm7={0, 1, 0, 1}
  80. psrlw mm6, BYTE_BIT ; mm6={0xFF 0x00 0xFF 0x00 ..}
  81. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  82. mov edi, JSAMPARRAY [output_data(ebp)] ; output_data
  83. ALIGNX 16, 7
  84. .rowloop:
  85. push ecx
  86. push edi
  87. push esi
  88. mov esi, JSAMPROW [esi] ; inptr
  89. mov edi, JSAMPROW [edi] ; outptr
  90. ALIGNX 16, 7
  91. .columnloop:
  92. movq mm0, MMWORD [esi+0*SIZEOF_MMWORD]
  93. movq mm1, MMWORD [esi+1*SIZEOF_MMWORD]
  94. movq mm2, mm0
  95. movq mm3, mm1
  96. pand mm0, mm6
  97. psrlw mm2, BYTE_BIT
  98. pand mm1, mm6
  99. psrlw mm3, BYTE_BIT
  100. paddw mm0, mm2
  101. paddw mm1, mm3
  102. paddw mm0, mm7
  103. paddw mm1, mm7
  104. psrlw mm0, 1
  105. psrlw mm1, 1
  106. packuswb mm0, mm1
  107. movq MMWORD [edi+0*SIZEOF_MMWORD], mm0
  108. add esi, byte 2*SIZEOF_MMWORD ; inptr
  109. add edi, byte 1*SIZEOF_MMWORD ; outptr
  110. sub ecx, byte SIZEOF_MMWORD ; outcol
  111. jnz short .columnloop
  112. pop esi
  113. pop edi
  114. pop ecx
  115. add esi, byte SIZEOF_JSAMPROW ; input_data
  116. add edi, byte SIZEOF_JSAMPROW ; output_data
  117. dec eax ; rowctr
  118. jg short .rowloop
  119. emms ; empty MMX state
  120. .return:
  121. pop edi
  122. pop esi
  123. ; pop edx ; need not be preserved
  124. ; pop ecx ; need not be preserved
  125. ; pop ebx ; unused
  126. pop ebp
  127. ret
  128. ; --------------------------------------------------------------------------
  129. ;
  130. ; Downsample pixel values of a single component.
  131. ; This version handles the standard case of 2:1 horizontal and 2:1 vertical,
  132. ; without smoothing.
  133. ;
  134. ; GLOBAL(void)
  135. ; jsimd_h2v2_downsample_mmx(JDIMENSION image_width, int max_v_samp_factor,
  136. ; JDIMENSION v_samp_factor,
  137. ; JDIMENSION width_in_blocks, JSAMPARRAY input_data,
  138. ; JSAMPARRAY output_data);
  139. ;
  140. %define img_width(b) (b) + 8 ; JDIMENSION image_width
  141. %define max_v_samp(b) (b) + 12 ; int max_v_samp_factor
  142. %define v_samp(b) (b) + 16 ; JDIMENSION v_samp_factor
  143. %define width_blks(b) (b) + 20 ; JDIMENSION width_in_blocks
  144. %define input_data(b) (b) + 24 ; JSAMPARRAY input_data
  145. %define output_data(b) (b) + 28 ; JSAMPARRAY output_data
  146. align 32
  147. GLOBAL_FUNCTION(jsimd_h2v2_downsample_mmx)
  148. EXTN(jsimd_h2v2_downsample_mmx):
  149. push ebp
  150. mov ebp, esp
  151. ; push ebx ; unused
  152. ; push ecx ; need not be preserved
  153. ; push edx ; need not be preserved
  154. push esi
  155. push edi
  156. mov ecx, JDIMENSION [width_blks(ebp)]
  157. shl ecx, 3 ; imul ecx,DCTSIZE (ecx = output_cols)
  158. jz near .return
  159. mov edx, JDIMENSION [img_width(ebp)]
  160. ; -- expand_right_edge
  161. push ecx
  162. shl ecx, 1 ; output_cols * 2
  163. sub ecx, edx
  164. jle short .expand_end
  165. mov eax, INT [max_v_samp(ebp)]
  166. test eax, eax
  167. jle short .expand_end
  168. cld
  169. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  170. ALIGNX 16, 7
  171. .expandloop:
  172. push eax
  173. push ecx
  174. mov edi, JSAMPROW [esi]
  175. add edi, edx
  176. mov al, JSAMPLE [edi-1]
  177. rep stosb
  178. pop ecx
  179. pop eax
  180. add esi, byte SIZEOF_JSAMPROW
  181. dec eax
  182. jg short .expandloop
  183. .expand_end:
  184. pop ecx ; output_cols
  185. ; -- h2v2_downsample
  186. mov eax, JDIMENSION [v_samp(ebp)] ; rowctr
  187. test eax, eax
  188. jle near .return
  189. mov edx, 0x00020001 ; bias pattern
  190. movd mm7, edx
  191. pcmpeqw mm6, mm6
  192. punpckldq mm7, mm7 ; mm7={1, 2, 1, 2}
  193. psrlw mm6, BYTE_BIT ; mm6={0xFF 0x00 0xFF 0x00 ..}
  194. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  195. mov edi, JSAMPARRAY [output_data(ebp)] ; output_data
  196. ALIGNX 16, 7
  197. .rowloop:
  198. push ecx
  199. push edi
  200. push esi
  201. mov edx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; inptr0
  202. mov esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; inptr1
  203. mov edi, JSAMPROW [edi] ; outptr
  204. ALIGNX 16, 7
  205. .columnloop:
  206. movq mm0, MMWORD [edx+0*SIZEOF_MMWORD]
  207. movq mm1, MMWORD [esi+0*SIZEOF_MMWORD]
  208. movq mm2, MMWORD [edx+1*SIZEOF_MMWORD]
  209. movq mm3, MMWORD [esi+1*SIZEOF_MMWORD]
  210. movq mm4, mm0
  211. movq mm5, mm1
  212. pand mm0, mm6
  213. psrlw mm4, BYTE_BIT
  214. pand mm1, mm6
  215. psrlw mm5, BYTE_BIT
  216. paddw mm0, mm4
  217. paddw mm1, mm5
  218. movq mm4, mm2
  219. movq mm5, mm3
  220. pand mm2, mm6
  221. psrlw mm4, BYTE_BIT
  222. pand mm3, mm6
  223. psrlw mm5, BYTE_BIT
  224. paddw mm2, mm4
  225. paddw mm3, mm5
  226. paddw mm0, mm1
  227. paddw mm2, mm3
  228. paddw mm0, mm7
  229. paddw mm2, mm7
  230. psrlw mm0, 2
  231. psrlw mm2, 2
  232. packuswb mm0, mm2
  233. movq MMWORD [edi+0*SIZEOF_MMWORD], mm0
  234. add edx, byte 2*SIZEOF_MMWORD ; inptr0
  235. add esi, byte 2*SIZEOF_MMWORD ; inptr1
  236. add edi, byte 1*SIZEOF_MMWORD ; outptr
  237. sub ecx, byte SIZEOF_MMWORD ; outcol
  238. jnz near .columnloop
  239. pop esi
  240. pop edi
  241. pop ecx
  242. add esi, byte 2*SIZEOF_JSAMPROW ; input_data
  243. add edi, byte 1*SIZEOF_JSAMPROW ; output_data
  244. dec eax ; rowctr
  245. jg near .rowloop
  246. emms ; empty MMX state
  247. .return:
  248. pop edi
  249. pop esi
  250. ; pop edx ; need not be preserved
  251. ; pop ecx ; need not be preserved
  252. ; pop ebx ; unused
  253. pop ebp
  254. ret
  255. ; For some reason, the OS X linker does not honor the request to align the
  256. ; segment unless we do this.
  257. align 32