jdsample-mmx.asm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. ;
  2. ; Upsampling (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_CONST
  15. ALIGNZ 32
  16. GLOBAL_DATA(jconst_fancy_upsample_mmx)
  17. EXTN(jconst_fancy_upsample_mmx):
  18. PW_ONE times 4 dw 1
  19. PW_TWO times 4 dw 2
  20. PW_THREE times 4 dw 3
  21. PW_SEVEN times 4 dw 7
  22. PW_EIGHT times 4 dw 8
  23. ALIGNZ 32
  24. ; --------------------------------------------------------------------------
  25. SECTION SEG_TEXT
  26. BITS 32
  27. ;
  28. ; Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
  29. ;
  30. ; The upsampling algorithm is linear interpolation between pixel centers,
  31. ; also known as a "triangle filter". This is a good compromise between
  32. ; speed and visual quality. The centers of the output pixels are 1/4 and 3/4
  33. ; of the way between input pixel centers.
  34. ;
  35. ; GLOBAL(void)
  36. ; jsimd_h2v1_fancy_upsample_mmx(int max_v_samp_factor,
  37. ; JDIMENSION downsampled_width,
  38. ; JSAMPARRAY input_data,
  39. ; JSAMPARRAY *output_data_ptr);
  40. ;
  41. %define max_v_samp(b) (b) + 8 ; int max_v_samp_factor
  42. %define downsamp_width(b) (b) + 12 ; JDIMENSION downsampled_width
  43. %define input_data(b) (b) + 16 ; JSAMPARRAY input_data
  44. %define output_data_ptr(b) (b) + 20 ; JSAMPARRAY *output_data_ptr
  45. align 32
  46. GLOBAL_FUNCTION(jsimd_h2v1_fancy_upsample_mmx)
  47. EXTN(jsimd_h2v1_fancy_upsample_mmx):
  48. push ebp
  49. mov ebp, esp
  50. PUSHPIC ebx
  51. ; push ecx ; need not be preserved
  52. ; push edx ; need not be preserved
  53. push esi
  54. push edi
  55. GET_GOT ebx ; get GOT address
  56. mov eax, JDIMENSION [downsamp_width(ebp)] ; colctr
  57. test eax, eax
  58. jz near .return
  59. mov ecx, INT [max_v_samp(ebp)] ; rowctr
  60. test ecx, ecx
  61. jz near .return
  62. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  63. mov edi, POINTER [output_data_ptr(ebp)]
  64. mov edi, JSAMPARRAY [edi] ; output_data
  65. ALIGNX 16, 7
  66. .rowloop:
  67. push eax ; colctr
  68. push edi
  69. push esi
  70. mov esi, JSAMPROW [esi] ; inptr
  71. mov edi, JSAMPROW [edi] ; outptr
  72. test eax, SIZEOF_MMWORD-1
  73. jz short .skip
  74. mov dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE]
  75. mov JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl ; insert a dummy sample
  76. .skip:
  77. pxor mm0, mm0 ; mm0=(all 0's)
  78. pcmpeqb mm7, mm7
  79. psrlq mm7, (SIZEOF_MMWORD-1)*BYTE_BIT
  80. pand mm7, MMWORD [esi+0*SIZEOF_MMWORD]
  81. add eax, byte SIZEOF_MMWORD-1
  82. and eax, byte -SIZEOF_MMWORD
  83. cmp eax, byte SIZEOF_MMWORD
  84. ja short .columnloop
  85. ALIGNX 16, 7
  86. .columnloop_last:
  87. pcmpeqb mm6, mm6
  88. psllq mm6, (SIZEOF_MMWORD-1)*BYTE_BIT
  89. pand mm6, MMWORD [esi+0*SIZEOF_MMWORD]
  90. jmp short .upsample
  91. ALIGNX 16, 7
  92. .columnloop:
  93. movq mm6, MMWORD [esi+1*SIZEOF_MMWORD]
  94. psllq mm6, (SIZEOF_MMWORD-1)*BYTE_BIT
  95. .upsample:
  96. movq mm1, MMWORD [esi+0*SIZEOF_MMWORD]
  97. movq mm2, mm1
  98. movq mm3, mm1 ; mm1=( 0 1 2 3 4 5 6 7)
  99. psllq mm2, BYTE_BIT ; mm2=( - 0 1 2 3 4 5 6)
  100. psrlq mm3, BYTE_BIT ; mm3=( 1 2 3 4 5 6 7 -)
  101. por mm2, mm7 ; mm2=(-1 0 1 2 3 4 5 6)
  102. por mm3, mm6 ; mm3=( 1 2 3 4 5 6 7 8)
  103. movq mm7, mm1
  104. psrlq mm7, (SIZEOF_MMWORD-1)*BYTE_BIT ; mm7=( 7 - - - - - - -)
  105. movq mm4, mm1
  106. punpcklbw mm1, mm0 ; mm1=( 0 1 2 3)
  107. punpckhbw mm4, mm0 ; mm4=( 4 5 6 7)
  108. movq mm5, mm2
  109. punpcklbw mm2, mm0 ; mm2=(-1 0 1 2)
  110. punpckhbw mm5, mm0 ; mm5=( 3 4 5 6)
  111. movq mm6, mm3
  112. punpcklbw mm3, mm0 ; mm3=( 1 2 3 4)
  113. punpckhbw mm6, mm0 ; mm6=( 5 6 7 8)
  114. pmullw mm1, [GOTOFF(ebx,PW_THREE)]
  115. pmullw mm4, [GOTOFF(ebx,PW_THREE)]
  116. paddw mm2, [GOTOFF(ebx,PW_ONE)]
  117. paddw mm5, [GOTOFF(ebx,PW_ONE)]
  118. paddw mm3, [GOTOFF(ebx,PW_TWO)]
  119. paddw mm6, [GOTOFF(ebx,PW_TWO)]
  120. paddw mm2, mm1
  121. paddw mm5, mm4
  122. psrlw mm2, 2 ; mm2=OutLE=( 0 2 4 6)
  123. psrlw mm5, 2 ; mm5=OutHE=( 8 10 12 14)
  124. paddw mm3, mm1
  125. paddw mm6, mm4
  126. psrlw mm3, 2 ; mm3=OutLO=( 1 3 5 7)
  127. psrlw mm6, 2 ; mm6=OutHO=( 9 11 13 15)
  128. psllw mm3, BYTE_BIT
  129. psllw mm6, BYTE_BIT
  130. por mm2, mm3 ; mm2=OutL=( 0 1 2 3 4 5 6 7)
  131. por mm5, mm6 ; mm5=OutH=( 8 9 10 11 12 13 14 15)
  132. movq MMWORD [edi+0*SIZEOF_MMWORD], mm2
  133. movq MMWORD [edi+1*SIZEOF_MMWORD], mm5
  134. sub eax, byte SIZEOF_MMWORD
  135. add esi, byte 1*SIZEOF_MMWORD ; inptr
  136. add edi, byte 2*SIZEOF_MMWORD ; outptr
  137. cmp eax, byte SIZEOF_MMWORD
  138. ja near .columnloop
  139. test eax, eax
  140. jnz near .columnloop_last
  141. pop esi
  142. pop edi
  143. pop eax
  144. add esi, byte SIZEOF_JSAMPROW ; input_data
  145. add edi, byte SIZEOF_JSAMPROW ; output_data
  146. dec ecx ; rowctr
  147. jg near .rowloop
  148. emms ; empty MMX state
  149. .return:
  150. pop edi
  151. pop esi
  152. ; pop edx ; need not be preserved
  153. ; pop ecx ; need not be preserved
  154. POPPIC ebx
  155. pop ebp
  156. ret
  157. ; --------------------------------------------------------------------------
  158. ;
  159. ; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
  160. ; Again a triangle filter; see comments for h2v1 case, above.
  161. ;
  162. ; GLOBAL(void)
  163. ; jsimd_h2v2_fancy_upsample_mmx(int max_v_samp_factor,
  164. ; JDIMENSION downsampled_width,
  165. ; JSAMPARRAY input_data,
  166. ; JSAMPARRAY *output_data_ptr);
  167. ;
  168. %define max_v_samp(b) (b) + 8 ; int max_v_samp_factor
  169. %define downsamp_width(b) (b) + 12 ; JDIMENSION downsampled_width
  170. %define input_data(b) (b) + 16 ; JSAMPARRAY input_data
  171. %define output_data_ptr(b) (b) + 20 ; JSAMPARRAY *output_data_ptr
  172. %define original_ebp ebp + 0
  173. %define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_MMWORD ; mmword wk[WK_NUM]
  174. %define WK_NUM 4
  175. %define gotptr wk(0) - SIZEOF_POINTER ; void *gotptr
  176. align 32
  177. GLOBAL_FUNCTION(jsimd_h2v2_fancy_upsample_mmx)
  178. EXTN(jsimd_h2v2_fancy_upsample_mmx):
  179. push ebp
  180. mov eax, esp ; eax = original ebp
  181. sub esp, byte 4
  182. and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
  183. mov [esp], eax
  184. mov ebp, esp ; ebp = aligned ebp
  185. lea esp, [wk(0)]
  186. PUSHPIC eax ; make a room for GOT address
  187. push ebx
  188. ; push ecx ; need not be preserved
  189. ; push edx ; need not be preserved
  190. push esi
  191. push edi
  192. GET_GOT ebx ; get GOT address
  193. MOVPIC POINTER [gotptr], ebx ; save GOT address
  194. mov edx, eax ; edx = original ebp
  195. mov eax, JDIMENSION [downsamp_width(edx)] ; colctr
  196. test eax, eax
  197. jz near .return
  198. mov ecx, INT [max_v_samp(edx)] ; rowctr
  199. test ecx, ecx
  200. jz near .return
  201. mov esi, JSAMPARRAY [input_data(edx)] ; input_data
  202. mov edi, POINTER [output_data_ptr(edx)]
  203. mov edi, JSAMPARRAY [edi] ; output_data
  204. ALIGNX 16, 7
  205. .rowloop:
  206. push eax ; colctr
  207. push ecx
  208. push edi
  209. push esi
  210. mov ecx, JSAMPROW [esi-1*SIZEOF_JSAMPROW] ; inptr1(above)
  211. mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; inptr0
  212. mov esi, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; inptr1(below)
  213. mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] ; outptr0
  214. mov edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] ; outptr1
  215. test eax, SIZEOF_MMWORD-1
  216. jz short .skip
  217. push edx
  218. mov dl, JSAMPLE [ecx+(eax-1)*SIZEOF_JSAMPLE]
  219. mov JSAMPLE [ecx+eax*SIZEOF_JSAMPLE], dl
  220. mov dl, JSAMPLE [ebx+(eax-1)*SIZEOF_JSAMPLE]
  221. mov JSAMPLE [ebx+eax*SIZEOF_JSAMPLE], dl
  222. mov dl, JSAMPLE [esi+(eax-1)*SIZEOF_JSAMPLE]
  223. mov JSAMPLE [esi+eax*SIZEOF_JSAMPLE], dl ; insert a dummy sample
  224. pop edx
  225. .skip:
  226. ; -- process the first column block
  227. movq mm0, MMWORD [ebx+0*SIZEOF_MMWORD] ; mm0=row[ 0][0]
  228. movq mm1, MMWORD [ecx+0*SIZEOF_MMWORD] ; mm1=row[-1][0]
  229. movq mm2, MMWORD [esi+0*SIZEOF_MMWORD] ; mm2=row[+1][0]
  230. PUSHPIC ebx
  231. MOVPIC ebx, POINTER [gotptr] ; load GOT address
  232. pxor mm3, mm3 ; mm3=(all 0's)
  233. movq mm4, mm0
  234. punpcklbw mm0, mm3 ; mm0=row[ 0][0]( 0 1 2 3)
  235. punpckhbw mm4, mm3 ; mm4=row[ 0][0]( 4 5 6 7)
  236. movq mm5, mm1
  237. punpcklbw mm1, mm3 ; mm1=row[-1][0]( 0 1 2 3)
  238. punpckhbw mm5, mm3 ; mm5=row[-1][0]( 4 5 6 7)
  239. movq mm6, mm2
  240. punpcklbw mm2, mm3 ; mm2=row[+1][0]( 0 1 2 3)
  241. punpckhbw mm6, mm3 ; mm6=row[+1][0]( 4 5 6 7)
  242. pmullw mm0, [GOTOFF(ebx,PW_THREE)]
  243. pmullw mm4, [GOTOFF(ebx,PW_THREE)]
  244. pcmpeqb mm7, mm7
  245. psrlq mm7, (SIZEOF_MMWORD-2)*BYTE_BIT
  246. paddw mm1, mm0 ; mm1=Int0L=( 0 1 2 3)
  247. paddw mm5, mm4 ; mm5=Int0H=( 4 5 6 7)
  248. paddw mm2, mm0 ; mm2=Int1L=( 0 1 2 3)
  249. paddw mm6, mm4 ; mm6=Int1H=( 4 5 6 7)
  250. movq MMWORD [edx+0*SIZEOF_MMWORD], mm1 ; temporarily save
  251. movq MMWORD [edx+1*SIZEOF_MMWORD], mm5 ; the intermediate data
  252. movq MMWORD [edi+0*SIZEOF_MMWORD], mm2
  253. movq MMWORD [edi+1*SIZEOF_MMWORD], mm6
  254. pand mm1, mm7 ; mm1=( 0 - - -)
  255. pand mm2, mm7 ; mm2=( 0 - - -)
  256. movq MMWORD [wk(0)], mm1
  257. movq MMWORD [wk(1)], mm2
  258. POPPIC ebx
  259. add eax, byte SIZEOF_MMWORD-1
  260. and eax, byte -SIZEOF_MMWORD
  261. cmp eax, byte SIZEOF_MMWORD
  262. ja short .columnloop
  263. ALIGNX 16, 7
  264. .columnloop_last:
  265. ; -- process the last column block
  266. PUSHPIC ebx
  267. MOVPIC ebx, POINTER [gotptr] ; load GOT address
  268. pcmpeqb mm1, mm1
  269. psllq mm1, (SIZEOF_MMWORD-2)*BYTE_BIT
  270. movq mm2, mm1
  271. pand mm1, MMWORD [edx+1*SIZEOF_MMWORD] ; mm1=( - - - 7)
  272. pand mm2, MMWORD [edi+1*SIZEOF_MMWORD] ; mm2=( - - - 7)
  273. movq MMWORD [wk(2)], mm1
  274. movq MMWORD [wk(3)], mm2
  275. jmp short .upsample
  276. ALIGNX 16, 7
  277. .columnloop:
  278. ; -- process the next column block
  279. movq mm0, MMWORD [ebx+1*SIZEOF_MMWORD] ; mm0=row[ 0][1]
  280. movq mm1, MMWORD [ecx+1*SIZEOF_MMWORD] ; mm1=row[-1][1]
  281. movq mm2, MMWORD [esi+1*SIZEOF_MMWORD] ; mm2=row[+1][1]
  282. PUSHPIC ebx
  283. MOVPIC ebx, POINTER [gotptr] ; load GOT address
  284. pxor mm3, mm3 ; mm3=(all 0's)
  285. movq mm4, mm0
  286. punpcklbw mm0, mm3 ; mm0=row[ 0][1]( 0 1 2 3)
  287. punpckhbw mm4, mm3 ; mm4=row[ 0][1]( 4 5 6 7)
  288. movq mm5, mm1
  289. punpcklbw mm1, mm3 ; mm1=row[-1][1]( 0 1 2 3)
  290. punpckhbw mm5, mm3 ; mm5=row[-1][1]( 4 5 6 7)
  291. movq mm6, mm2
  292. punpcklbw mm2, mm3 ; mm2=row[+1][1]( 0 1 2 3)
  293. punpckhbw mm6, mm3 ; mm6=row[+1][1]( 4 5 6 7)
  294. pmullw mm0, [GOTOFF(ebx,PW_THREE)]
  295. pmullw mm4, [GOTOFF(ebx,PW_THREE)]
  296. paddw mm1, mm0 ; mm1=Int0L=( 0 1 2 3)
  297. paddw mm5, mm4 ; mm5=Int0H=( 4 5 6 7)
  298. paddw mm2, mm0 ; mm2=Int1L=( 0 1 2 3)
  299. paddw mm6, mm4 ; mm6=Int1H=( 4 5 6 7)
  300. movq MMWORD [edx+2*SIZEOF_MMWORD], mm1 ; temporarily save
  301. movq MMWORD [edx+3*SIZEOF_MMWORD], mm5 ; the intermediate data
  302. movq MMWORD [edi+2*SIZEOF_MMWORD], mm2
  303. movq MMWORD [edi+3*SIZEOF_MMWORD], mm6
  304. psllq mm1, (SIZEOF_MMWORD-2)*BYTE_BIT ; mm1=( - - - 0)
  305. psllq mm2, (SIZEOF_MMWORD-2)*BYTE_BIT ; mm2=( - - - 0)
  306. movq MMWORD [wk(2)], mm1
  307. movq MMWORD [wk(3)], mm2
  308. .upsample:
  309. ; -- process the upper row
  310. movq mm7, MMWORD [edx+0*SIZEOF_MMWORD] ; mm7=Int0L=( 0 1 2 3)
  311. movq mm3, MMWORD [edx+1*SIZEOF_MMWORD] ; mm3=Int0H=( 4 5 6 7)
  312. movq mm0, mm7
  313. movq mm4, mm3
  314. psrlq mm0, 2*BYTE_BIT ; mm0=( 1 2 3 -)
  315. psllq mm4, (SIZEOF_MMWORD-2)*BYTE_BIT ; mm4=( - - - 4)
  316. movq mm5, mm7
  317. movq mm6, mm3
  318. psrlq mm5, (SIZEOF_MMWORD-2)*BYTE_BIT ; mm5=( 3 - - -)
  319. psllq mm6, 2*BYTE_BIT ; mm6=( - 4 5 6)
  320. por mm0, mm4 ; mm0=( 1 2 3 4)
  321. por mm5, mm6 ; mm5=( 3 4 5 6)
  322. movq mm1, mm7
  323. movq mm2, mm3
  324. psllq mm1, 2*BYTE_BIT ; mm1=( - 0 1 2)
  325. psrlq mm2, 2*BYTE_BIT ; mm2=( 5 6 7 -)
  326. movq mm4, mm3
  327. psrlq mm4, (SIZEOF_MMWORD-2)*BYTE_BIT ; mm4=( 7 - - -)
  328. por mm1, MMWORD [wk(0)] ; mm1=(-1 0 1 2)
  329. por mm2, MMWORD [wk(2)] ; mm2=( 5 6 7 8)
  330. movq MMWORD [wk(0)], mm4
  331. pmullw mm7, [GOTOFF(ebx,PW_THREE)]
  332. pmullw mm3, [GOTOFF(ebx,PW_THREE)]
  333. paddw mm1, [GOTOFF(ebx,PW_EIGHT)]
  334. paddw mm5, [GOTOFF(ebx,PW_EIGHT)]
  335. paddw mm0, [GOTOFF(ebx,PW_SEVEN)]
  336. paddw mm2, [GOTOFF(ebx,PW_SEVEN)]
  337. paddw mm1, mm7
  338. paddw mm5, mm3
  339. psrlw mm1, 4 ; mm1=Out0LE=( 0 2 4 6)
  340. psrlw mm5, 4 ; mm5=Out0HE=( 8 10 12 14)
  341. paddw mm0, mm7
  342. paddw mm2, mm3
  343. psrlw mm0, 4 ; mm0=Out0LO=( 1 3 5 7)
  344. psrlw mm2, 4 ; mm2=Out0HO=( 9 11 13 15)
  345. psllw mm0, BYTE_BIT
  346. psllw mm2, BYTE_BIT
  347. por mm1, mm0 ; mm1=Out0L=( 0 1 2 3 4 5 6 7)
  348. por mm5, mm2 ; mm5=Out0H=( 8 9 10 11 12 13 14 15)
  349. movq MMWORD [edx+0*SIZEOF_MMWORD], mm1
  350. movq MMWORD [edx+1*SIZEOF_MMWORD], mm5
  351. ; -- process the lower row
  352. movq mm6, MMWORD [edi+0*SIZEOF_MMWORD] ; mm6=Int1L=( 0 1 2 3)
  353. movq mm4, MMWORD [edi+1*SIZEOF_MMWORD] ; mm4=Int1H=( 4 5 6 7)
  354. movq mm7, mm6
  355. movq mm3, mm4
  356. psrlq mm7, 2*BYTE_BIT ; mm7=( 1 2 3 -)
  357. psllq mm3, (SIZEOF_MMWORD-2)*BYTE_BIT ; mm3=( - - - 4)
  358. movq mm0, mm6
  359. movq mm2, mm4
  360. psrlq mm0, (SIZEOF_MMWORD-2)*BYTE_BIT ; mm0=( 3 - - -)
  361. psllq mm2, 2*BYTE_BIT ; mm2=( - 4 5 6)
  362. por mm7, mm3 ; mm7=( 1 2 3 4)
  363. por mm0, mm2 ; mm0=( 3 4 5 6)
  364. movq mm1, mm6
  365. movq mm5, mm4
  366. psllq mm1, 2*BYTE_BIT ; mm1=( - 0 1 2)
  367. psrlq mm5, 2*BYTE_BIT ; mm5=( 5 6 7 -)
  368. movq mm3, mm4
  369. psrlq mm3, (SIZEOF_MMWORD-2)*BYTE_BIT ; mm3=( 7 - - -)
  370. por mm1, MMWORD [wk(1)] ; mm1=(-1 0 1 2)
  371. por mm5, MMWORD [wk(3)] ; mm5=( 5 6 7 8)
  372. movq MMWORD [wk(1)], mm3
  373. pmullw mm6, [GOTOFF(ebx,PW_THREE)]
  374. pmullw mm4, [GOTOFF(ebx,PW_THREE)]
  375. paddw mm1, [GOTOFF(ebx,PW_EIGHT)]
  376. paddw mm0, [GOTOFF(ebx,PW_EIGHT)]
  377. paddw mm7, [GOTOFF(ebx,PW_SEVEN)]
  378. paddw mm5, [GOTOFF(ebx,PW_SEVEN)]
  379. paddw mm1, mm6
  380. paddw mm0, mm4
  381. psrlw mm1, 4 ; mm1=Out1LE=( 0 2 4 6)
  382. psrlw mm0, 4 ; mm0=Out1HE=( 8 10 12 14)
  383. paddw mm7, mm6
  384. paddw mm5, mm4
  385. psrlw mm7, 4 ; mm7=Out1LO=( 1 3 5 7)
  386. psrlw mm5, 4 ; mm5=Out1HO=( 9 11 13 15)
  387. psllw mm7, BYTE_BIT
  388. psllw mm5, BYTE_BIT
  389. por mm1, mm7 ; mm1=Out1L=( 0 1 2 3 4 5 6 7)
  390. por mm0, mm5 ; mm0=Out1H=( 8 9 10 11 12 13 14 15)
  391. movq MMWORD [edi+0*SIZEOF_MMWORD], mm1
  392. movq MMWORD [edi+1*SIZEOF_MMWORD], mm0
  393. POPPIC ebx
  394. sub eax, byte SIZEOF_MMWORD
  395. add ecx, byte 1*SIZEOF_MMWORD ; inptr1(above)
  396. add ebx, byte 1*SIZEOF_MMWORD ; inptr0
  397. add esi, byte 1*SIZEOF_MMWORD ; inptr1(below)
  398. add edx, byte 2*SIZEOF_MMWORD ; outptr0
  399. add edi, byte 2*SIZEOF_MMWORD ; outptr1
  400. cmp eax, byte SIZEOF_MMWORD
  401. ja near .columnloop
  402. test eax, eax
  403. jnz near .columnloop_last
  404. pop esi
  405. pop edi
  406. pop ecx
  407. pop eax
  408. add esi, byte 1*SIZEOF_JSAMPROW ; input_data
  409. add edi, byte 2*SIZEOF_JSAMPROW ; output_data
  410. sub ecx, byte 2 ; rowctr
  411. jg near .rowloop
  412. emms ; empty MMX state
  413. .return:
  414. pop edi
  415. pop esi
  416. ; pop edx ; need not be preserved
  417. ; pop ecx ; need not be preserved
  418. pop ebx
  419. mov esp, ebp ; esp <- aligned ebp
  420. pop esp ; esp <- original ebp
  421. pop ebp
  422. ret
  423. ; --------------------------------------------------------------------------
  424. ;
  425. ; Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
  426. ; It's still a box filter.
  427. ;
  428. ; GLOBAL(void)
  429. ; jsimd_h2v1_upsample_mmx(int max_v_samp_factor, JDIMENSION output_width,
  430. ; JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr);
  431. ;
  432. %define max_v_samp(b) (b) + 8 ; int max_v_samp_factor
  433. %define output_width(b) (b) + 12 ; JDIMENSION output_width
  434. %define input_data(b) (b) + 16 ; JSAMPARRAY input_data
  435. %define output_data_ptr(b) (b) + 20 ; JSAMPARRAY *output_data_ptr
  436. align 32
  437. GLOBAL_FUNCTION(jsimd_h2v1_upsample_mmx)
  438. EXTN(jsimd_h2v1_upsample_mmx):
  439. push ebp
  440. mov ebp, esp
  441. ; push ebx ; unused
  442. ; push ecx ; need not be preserved
  443. ; push edx ; need not be preserved
  444. push esi
  445. push edi
  446. mov edx, JDIMENSION [output_width(ebp)]
  447. add edx, byte (2*SIZEOF_MMWORD)-1
  448. and edx, byte -(2*SIZEOF_MMWORD)
  449. jz short .return
  450. mov ecx, INT [max_v_samp(ebp)] ; rowctr
  451. test ecx, ecx
  452. jz short .return
  453. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  454. mov edi, POINTER [output_data_ptr(ebp)]
  455. mov edi, JSAMPARRAY [edi] ; output_data
  456. ALIGNX 16, 7
  457. .rowloop:
  458. push edi
  459. push esi
  460. mov esi, JSAMPROW [esi] ; inptr
  461. mov edi, JSAMPROW [edi] ; outptr
  462. mov eax, edx ; colctr
  463. ALIGNX 16, 7
  464. .columnloop:
  465. movq mm0, MMWORD [esi+0*SIZEOF_MMWORD]
  466. movq mm1, mm0
  467. punpcklbw mm0, mm0
  468. punpckhbw mm1, mm1
  469. movq MMWORD [edi+0*SIZEOF_MMWORD], mm0
  470. movq MMWORD [edi+1*SIZEOF_MMWORD], mm1
  471. sub eax, byte 2*SIZEOF_MMWORD
  472. jz short .nextrow
  473. movq mm2, MMWORD [esi+1*SIZEOF_MMWORD]
  474. movq mm3, mm2
  475. punpcklbw mm2, mm2
  476. punpckhbw mm3, mm3
  477. movq MMWORD [edi+2*SIZEOF_MMWORD], mm2
  478. movq MMWORD [edi+3*SIZEOF_MMWORD], mm3
  479. sub eax, byte 2*SIZEOF_MMWORD
  480. jz short .nextrow
  481. add esi, byte 2*SIZEOF_MMWORD ; inptr
  482. add edi, byte 4*SIZEOF_MMWORD ; outptr
  483. jmp short .columnloop
  484. ALIGNX 16, 7
  485. .nextrow:
  486. pop esi
  487. pop edi
  488. add esi, byte SIZEOF_JSAMPROW ; input_data
  489. add edi, byte SIZEOF_JSAMPROW ; output_data
  490. dec ecx ; rowctr
  491. jg short .rowloop
  492. emms ; empty MMX state
  493. .return:
  494. pop edi
  495. pop esi
  496. ; pop edx ; need not be preserved
  497. ; pop ecx ; need not be preserved
  498. ; pop ebx ; unused
  499. pop ebp
  500. ret
  501. ; --------------------------------------------------------------------------
  502. ;
  503. ; Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
  504. ; It's still a box filter.
  505. ;
  506. ; GLOBAL(void)
  507. ; jsimd_h2v2_upsample_mmx(int max_v_samp_factor, JDIMENSION output_width,
  508. ; JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr);
  509. ;
  510. %define max_v_samp(b) (b) + 8 ; int max_v_samp_factor
  511. %define output_width(b) (b) + 12 ; JDIMENSION output_width
  512. %define input_data(b) (b) + 16 ; JSAMPARRAY input_data
  513. %define output_data_ptr(b) (b) + 20 ; JSAMPARRAY *output_data_ptr
  514. align 32
  515. GLOBAL_FUNCTION(jsimd_h2v2_upsample_mmx)
  516. EXTN(jsimd_h2v2_upsample_mmx):
  517. push ebp
  518. mov ebp, esp
  519. push ebx
  520. ; push ecx ; need not be preserved
  521. ; push edx ; need not be preserved
  522. push esi
  523. push edi
  524. mov edx, JDIMENSION [output_width(ebp)]
  525. add edx, byte (2*SIZEOF_MMWORD)-1
  526. and edx, byte -(2*SIZEOF_MMWORD)
  527. jz near .return
  528. mov ecx, INT [max_v_samp(ebp)] ; rowctr
  529. test ecx, ecx
  530. jz short .return
  531. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  532. mov edi, POINTER [output_data_ptr(ebp)]
  533. mov edi, JSAMPARRAY [edi] ; output_data
  534. ALIGNX 16, 7
  535. .rowloop:
  536. push edi
  537. push esi
  538. mov esi, JSAMPROW [esi] ; inptr
  539. mov ebx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] ; outptr0
  540. mov edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] ; outptr1
  541. mov eax, edx ; colctr
  542. ALIGNX 16, 7
  543. .columnloop:
  544. movq mm0, MMWORD [esi+0*SIZEOF_MMWORD]
  545. movq mm1, mm0
  546. punpcklbw mm0, mm0
  547. punpckhbw mm1, mm1
  548. movq MMWORD [ebx+0*SIZEOF_MMWORD], mm0
  549. movq MMWORD [ebx+1*SIZEOF_MMWORD], mm1
  550. movq MMWORD [edi+0*SIZEOF_MMWORD], mm0
  551. movq MMWORD [edi+1*SIZEOF_MMWORD], mm1
  552. sub eax, byte 2*SIZEOF_MMWORD
  553. jz short .nextrow
  554. movq mm2, MMWORD [esi+1*SIZEOF_MMWORD]
  555. movq mm3, mm2
  556. punpcklbw mm2, mm2
  557. punpckhbw mm3, mm3
  558. movq MMWORD [ebx+2*SIZEOF_MMWORD], mm2
  559. movq MMWORD [ebx+3*SIZEOF_MMWORD], mm3
  560. movq MMWORD [edi+2*SIZEOF_MMWORD], mm2
  561. movq MMWORD [edi+3*SIZEOF_MMWORD], mm3
  562. sub eax, byte 2*SIZEOF_MMWORD
  563. jz short .nextrow
  564. add esi, byte 2*SIZEOF_MMWORD ; inptr
  565. add ebx, byte 4*SIZEOF_MMWORD ; outptr0
  566. add edi, byte 4*SIZEOF_MMWORD ; outptr1
  567. jmp short .columnloop
  568. ALIGNX 16, 7
  569. .nextrow:
  570. pop esi
  571. pop edi
  572. add esi, byte 1*SIZEOF_JSAMPROW ; input_data
  573. add edi, byte 2*SIZEOF_JSAMPROW ; output_data
  574. sub ecx, byte 2 ; rowctr
  575. jg short .rowloop
  576. emms ; empty MMX state
  577. .return:
  578. pop edi
  579. pop esi
  580. ; pop edx ; need not be preserved
  581. ; pop ecx ; need not be preserved
  582. pop ebx
  583. pop ebp
  584. ret
  585. ; For some reason, the OS X linker does not honor the request to align the
  586. ; segment unless we do this.
  587. align 32