jdsample-sse2.asm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. ;
  2. ; Upsampling (SSE2)
  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_sse2)
  17. EXTN(jconst_fancy_upsample_sse2):
  18. PW_ONE times 8 dw 1
  19. PW_TWO times 8 dw 2
  20. PW_THREE times 8 dw 3
  21. PW_SEVEN times 8 dw 7
  22. PW_EIGHT times 8 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_sse2(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_sse2)
  47. EXTN(jsimd_h2v1_fancy_upsample_sse2):
  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_XMMWORD-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 xmm0, xmm0 ; xmm0=(all 0's)
  78. pcmpeqb xmm7, xmm7
  79. psrldq xmm7, (SIZEOF_XMMWORD-1)
  80. pand xmm7, XMMWORD [esi+0*SIZEOF_XMMWORD]
  81. add eax, byte SIZEOF_XMMWORD-1
  82. and eax, byte -SIZEOF_XMMWORD
  83. cmp eax, byte SIZEOF_XMMWORD
  84. ja short .columnloop
  85. ALIGNX 16, 7
  86. .columnloop_last:
  87. pcmpeqb xmm6, xmm6
  88. pslldq xmm6, (SIZEOF_XMMWORD-1)
  89. pand xmm6, XMMWORD [esi+0*SIZEOF_XMMWORD]
  90. jmp short .upsample
  91. ALIGNX 16, 7
  92. .columnloop:
  93. movdqa xmm6, XMMWORD [esi+1*SIZEOF_XMMWORD]
  94. pslldq xmm6, (SIZEOF_XMMWORD-1)
  95. .upsample:
  96. movdqa xmm1, XMMWORD [esi+0*SIZEOF_XMMWORD]
  97. movdqa xmm2, xmm1
  98. movdqa xmm3, xmm1 ; xmm1=( 0 1 2 ... 13 14 15)
  99. pslldq xmm2, 1 ; xmm2=(-- 0 1 ... 12 13 14)
  100. psrldq xmm3, 1 ; xmm3=( 1 2 3 ... 14 15 --)
  101. por xmm2, xmm7 ; xmm2=(-1 0 1 ... 12 13 14)
  102. por xmm3, xmm6 ; xmm3=( 1 2 3 ... 14 15 16)
  103. movdqa xmm7, xmm1
  104. psrldq xmm7, (SIZEOF_XMMWORD-1) ; xmm7=(15 -- -- ... -- -- --)
  105. movdqa xmm4, xmm1
  106. punpcklbw xmm1, xmm0 ; xmm1=( 0 1 2 3 4 5 6 7)
  107. punpckhbw xmm4, xmm0 ; xmm4=( 8 9 10 11 12 13 14 15)
  108. movdqa xmm5, xmm2
  109. punpcklbw xmm2, xmm0 ; xmm2=(-1 0 1 2 3 4 5 6)
  110. punpckhbw xmm5, xmm0 ; xmm5=( 7 8 9 10 11 12 13 14)
  111. movdqa xmm6, xmm3
  112. punpcklbw xmm3, xmm0 ; xmm3=( 1 2 3 4 5 6 7 8)
  113. punpckhbw xmm6, xmm0 ; xmm6=( 9 10 11 12 13 14 15 16)
  114. pmullw xmm1, [GOTOFF(ebx,PW_THREE)]
  115. pmullw xmm4, [GOTOFF(ebx,PW_THREE)]
  116. paddw xmm2, [GOTOFF(ebx,PW_ONE)]
  117. paddw xmm5, [GOTOFF(ebx,PW_ONE)]
  118. paddw xmm3, [GOTOFF(ebx,PW_TWO)]
  119. paddw xmm6, [GOTOFF(ebx,PW_TWO)]
  120. paddw xmm2, xmm1
  121. paddw xmm5, xmm4
  122. psrlw xmm2, 2 ; xmm2=OutLE=( 0 2 4 6 8 10 12 14)
  123. psrlw xmm5, 2 ; xmm5=OutHE=(16 18 20 22 24 26 28 30)
  124. paddw xmm3, xmm1
  125. paddw xmm6, xmm4
  126. psrlw xmm3, 2 ; xmm3=OutLO=( 1 3 5 7 9 11 13 15)
  127. psrlw xmm6, 2 ; xmm6=OutHO=(17 19 21 23 25 27 29 31)
  128. psllw xmm3, BYTE_BIT
  129. psllw xmm6, BYTE_BIT
  130. por xmm2, xmm3 ; xmm2=OutL=( 0 1 2 ... 13 14 15)
  131. por xmm5, xmm6 ; xmm5=OutH=(16 17 18 ... 29 30 31)
  132. movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm2
  133. movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm5
  134. sub eax, byte SIZEOF_XMMWORD
  135. add esi, byte 1*SIZEOF_XMMWORD ; inptr
  136. add edi, byte 2*SIZEOF_XMMWORD ; outptr
  137. cmp eax, byte SIZEOF_XMMWORD
  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. .return:
  149. pop edi
  150. pop esi
  151. ; pop edx ; need not be preserved
  152. ; pop ecx ; need not be preserved
  153. POPPIC ebx
  154. pop ebp
  155. ret
  156. ; --------------------------------------------------------------------------
  157. ;
  158. ; Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
  159. ; Again a triangle filter; see comments for h2v1 case, above.
  160. ;
  161. ; GLOBAL(void)
  162. ; jsimd_h2v2_fancy_upsample_sse2(int max_v_samp_factor,
  163. ; JDIMENSION downsampled_width,
  164. ; JSAMPARRAY input_data,
  165. ; JSAMPARRAY *output_data_ptr);
  166. ;
  167. %define max_v_samp(b) (b) + 8 ; int max_v_samp_factor
  168. %define downsamp_width(b) (b) + 12 ; JDIMENSION downsampled_width
  169. %define input_data(b) (b) + 16 ; JSAMPARRAY input_data
  170. %define output_data_ptr(b) (b) + 20 ; JSAMPARRAY *output_data_ptr
  171. %define original_ebp ebp + 0
  172. %define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_XMMWORD
  173. ; xmmword 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_sse2)
  178. EXTN(jsimd_h2v2_fancy_upsample_sse2):
  179. push ebp
  180. mov eax, esp ; eax = original ebp
  181. sub esp, byte 4
  182. and esp, byte (-SIZEOF_XMMWORD) ; align to 128 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_XMMWORD-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. movdqa xmm0, XMMWORD [ebx+0*SIZEOF_XMMWORD] ; xmm0=row[ 0][0]
  228. movdqa xmm1, XMMWORD [ecx+0*SIZEOF_XMMWORD] ; xmm1=row[-1][0]
  229. movdqa xmm2, XMMWORD [esi+0*SIZEOF_XMMWORD] ; xmm2=row[+1][0]
  230. PUSHPIC ebx
  231. MOVPIC ebx, POINTER [gotptr] ; load GOT address
  232. pxor xmm3, xmm3 ; xmm3=(all 0's)
  233. movdqa xmm4, xmm0
  234. punpcklbw xmm0, xmm3 ; xmm0=row[ 0]( 0 1 2 3 4 5 6 7)
  235. punpckhbw xmm4, xmm3 ; xmm4=row[ 0]( 8 9 10 11 12 13 14 15)
  236. movdqa xmm5, xmm1
  237. punpcklbw xmm1, xmm3 ; xmm1=row[-1]( 0 1 2 3 4 5 6 7)
  238. punpckhbw xmm5, xmm3 ; xmm5=row[-1]( 8 9 10 11 12 13 14 15)
  239. movdqa xmm6, xmm2
  240. punpcklbw xmm2, xmm3 ; xmm2=row[+1]( 0 1 2 3 4 5 6 7)
  241. punpckhbw xmm6, xmm3 ; xmm6=row[+1]( 8 9 10 11 12 13 14 15)
  242. pmullw xmm0, [GOTOFF(ebx,PW_THREE)]
  243. pmullw xmm4, [GOTOFF(ebx,PW_THREE)]
  244. pcmpeqb xmm7, xmm7
  245. psrldq xmm7, (SIZEOF_XMMWORD-2)
  246. paddw xmm1, xmm0 ; xmm1=Int0L=( 0 1 2 3 4 5 6 7)
  247. paddw xmm5, xmm4 ; xmm5=Int0H=( 8 9 10 11 12 13 14 15)
  248. paddw xmm2, xmm0 ; xmm2=Int1L=( 0 1 2 3 4 5 6 7)
  249. paddw xmm6, xmm4 ; xmm6=Int1H=( 8 9 10 11 12 13 14 15)
  250. movdqa XMMWORD [edx+0*SIZEOF_XMMWORD], xmm1 ; temporarily save
  251. movdqa XMMWORD [edx+1*SIZEOF_XMMWORD], xmm5 ; the intermediate data
  252. movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm2
  253. movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm6
  254. pand xmm1, xmm7 ; xmm1=( 0 -- -- -- -- -- -- --)
  255. pand xmm2, xmm7 ; xmm2=( 0 -- -- -- -- -- -- --)
  256. movdqa XMMWORD [wk(0)], xmm1
  257. movdqa XMMWORD [wk(1)], xmm2
  258. POPPIC ebx
  259. add eax, byte SIZEOF_XMMWORD-1
  260. and eax, byte -SIZEOF_XMMWORD
  261. cmp eax, byte SIZEOF_XMMWORD
  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 xmm1, xmm1
  269. pslldq xmm1, (SIZEOF_XMMWORD-2)
  270. movdqa xmm2, xmm1
  271. pand xmm1, XMMWORD [edx+1*SIZEOF_XMMWORD]
  272. pand xmm2, XMMWORD [edi+1*SIZEOF_XMMWORD]
  273. movdqa XMMWORD [wk(2)], xmm1 ; xmm1=(-- -- -- -- -- -- -- 15)
  274. movdqa XMMWORD [wk(3)], xmm2 ; xmm2=(-- -- -- -- -- -- -- 15)
  275. jmp near .upsample
  276. ALIGNX 16, 7
  277. .columnloop:
  278. ; -- process the next column block
  279. movdqa xmm0, XMMWORD [ebx+1*SIZEOF_XMMWORD] ; xmm0=row[ 0][1]
  280. movdqa xmm1, XMMWORD [ecx+1*SIZEOF_XMMWORD] ; xmm1=row[-1][1]
  281. movdqa xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD] ; xmm2=row[+1][1]
  282. PUSHPIC ebx
  283. MOVPIC ebx, POINTER [gotptr] ; load GOT address
  284. pxor xmm3, xmm3 ; xmm3=(all 0's)
  285. movdqa xmm4, xmm0
  286. punpcklbw xmm0, xmm3 ; xmm0=row[ 0]( 0 1 2 3 4 5 6 7)
  287. punpckhbw xmm4, xmm3 ; xmm4=row[ 0]( 8 9 10 11 12 13 14 15)
  288. movdqa xmm5, xmm1
  289. punpcklbw xmm1, xmm3 ; xmm1=row[-1]( 0 1 2 3 4 5 6 7)
  290. punpckhbw xmm5, xmm3 ; xmm5=row[-1]( 8 9 10 11 12 13 14 15)
  291. movdqa xmm6, xmm2
  292. punpcklbw xmm2, xmm3 ; xmm2=row[+1]( 0 1 2 3 4 5 6 7)
  293. punpckhbw xmm6, xmm3 ; xmm6=row[+1]( 8 9 10 11 12 13 14 15)
  294. pmullw xmm0, [GOTOFF(ebx,PW_THREE)]
  295. pmullw xmm4, [GOTOFF(ebx,PW_THREE)]
  296. paddw xmm1, xmm0 ; xmm1=Int0L=( 0 1 2 3 4 5 6 7)
  297. paddw xmm5, xmm4 ; xmm5=Int0H=( 8 9 10 11 12 13 14 15)
  298. paddw xmm2, xmm0 ; xmm2=Int1L=( 0 1 2 3 4 5 6 7)
  299. paddw xmm6, xmm4 ; xmm6=Int1H=( 8 9 10 11 12 13 14 15)
  300. movdqa XMMWORD [edx+2*SIZEOF_XMMWORD], xmm1 ; temporarily save
  301. movdqa XMMWORD [edx+3*SIZEOF_XMMWORD], xmm5 ; the intermediate data
  302. movdqa XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2
  303. movdqa XMMWORD [edi+3*SIZEOF_XMMWORD], xmm6
  304. pslldq xmm1, (SIZEOF_XMMWORD-2) ; xmm1=(-- -- -- -- -- -- -- 0)
  305. pslldq xmm2, (SIZEOF_XMMWORD-2) ; xmm2=(-- -- -- -- -- -- -- 0)
  306. movdqa XMMWORD [wk(2)], xmm1
  307. movdqa XMMWORD [wk(3)], xmm2
  308. .upsample:
  309. ; -- process the upper row
  310. movdqa xmm7, XMMWORD [edx+0*SIZEOF_XMMWORD]
  311. movdqa xmm3, XMMWORD [edx+1*SIZEOF_XMMWORD]
  312. movdqa xmm0, xmm7 ; xmm7=Int0L=( 0 1 2 3 4 5 6 7)
  313. movdqa xmm4, xmm3 ; xmm3=Int0H=( 8 9 10 11 12 13 14 15)
  314. psrldq xmm0, 2 ; xmm0=( 1 2 3 4 5 6 7 --)
  315. pslldq xmm4, (SIZEOF_XMMWORD-2) ; xmm4=(-- -- -- -- -- -- -- 8)
  316. movdqa xmm5, xmm7
  317. movdqa xmm6, xmm3
  318. psrldq xmm5, (SIZEOF_XMMWORD-2) ; xmm5=( 7 -- -- -- -- -- -- --)
  319. pslldq xmm6, 2 ; xmm6=(-- 8 9 10 11 12 13 14)
  320. por xmm0, xmm4 ; xmm0=( 1 2 3 4 5 6 7 8)
  321. por xmm5, xmm6 ; xmm5=( 7 8 9 10 11 12 13 14)
  322. movdqa xmm1, xmm7
  323. movdqa xmm2, xmm3
  324. pslldq xmm1, 2 ; xmm1=(-- 0 1 2 3 4 5 6)
  325. psrldq xmm2, 2 ; xmm2=( 9 10 11 12 13 14 15 --)
  326. movdqa xmm4, xmm3
  327. psrldq xmm4, (SIZEOF_XMMWORD-2) ; xmm4=(15 -- -- -- -- -- -- --)
  328. por xmm1, XMMWORD [wk(0)] ; xmm1=(-1 0 1 2 3 4 5 6)
  329. por xmm2, XMMWORD [wk(2)] ; xmm2=( 9 10 11 12 13 14 15 16)
  330. movdqa XMMWORD [wk(0)], xmm4
  331. pmullw xmm7, [GOTOFF(ebx,PW_THREE)]
  332. pmullw xmm3, [GOTOFF(ebx,PW_THREE)]
  333. paddw xmm1, [GOTOFF(ebx,PW_EIGHT)]
  334. paddw xmm5, [GOTOFF(ebx,PW_EIGHT)]
  335. paddw xmm0, [GOTOFF(ebx,PW_SEVEN)]
  336. paddw xmm2, [GOTOFF(ebx,PW_SEVEN)]
  337. paddw xmm1, xmm7
  338. paddw xmm5, xmm3
  339. psrlw xmm1, 4 ; xmm1=Out0LE=( 0 2 4 6 8 10 12 14)
  340. psrlw xmm5, 4 ; xmm5=Out0HE=(16 18 20 22 24 26 28 30)
  341. paddw xmm0, xmm7
  342. paddw xmm2, xmm3
  343. psrlw xmm0, 4 ; xmm0=Out0LO=( 1 3 5 7 9 11 13 15)
  344. psrlw xmm2, 4 ; xmm2=Out0HO=(17 19 21 23 25 27 29 31)
  345. psllw xmm0, BYTE_BIT
  346. psllw xmm2, BYTE_BIT
  347. por xmm1, xmm0 ; xmm1=Out0L=( 0 1 2 ... 13 14 15)
  348. por xmm5, xmm2 ; xmm5=Out0H=(16 17 18 ... 29 30 31)
  349. movdqa XMMWORD [edx+0*SIZEOF_XMMWORD], xmm1
  350. movdqa XMMWORD [edx+1*SIZEOF_XMMWORD], xmm5
  351. ; -- process the lower row
  352. movdqa xmm6, XMMWORD [edi+0*SIZEOF_XMMWORD]
  353. movdqa xmm4, XMMWORD [edi+1*SIZEOF_XMMWORD]
  354. movdqa xmm7, xmm6 ; xmm6=Int1L=( 0 1 2 3 4 5 6 7)
  355. movdqa xmm3, xmm4 ; xmm4=Int1H=( 8 9 10 11 12 13 14 15)
  356. psrldq xmm7, 2 ; xmm7=( 1 2 3 4 5 6 7 --)
  357. pslldq xmm3, (SIZEOF_XMMWORD-2) ; xmm3=(-- -- -- -- -- -- -- 8)
  358. movdqa xmm0, xmm6
  359. movdqa xmm2, xmm4
  360. psrldq xmm0, (SIZEOF_XMMWORD-2) ; xmm0=( 7 -- -- -- -- -- -- --)
  361. pslldq xmm2, 2 ; xmm2=(-- 8 9 10 11 12 13 14)
  362. por xmm7, xmm3 ; xmm7=( 1 2 3 4 5 6 7 8)
  363. por xmm0, xmm2 ; xmm0=( 7 8 9 10 11 12 13 14)
  364. movdqa xmm1, xmm6
  365. movdqa xmm5, xmm4
  366. pslldq xmm1, 2 ; xmm1=(-- 0 1 2 3 4 5 6)
  367. psrldq xmm5, 2 ; xmm5=( 9 10 11 12 13 14 15 --)
  368. movdqa xmm3, xmm4
  369. psrldq xmm3, (SIZEOF_XMMWORD-2) ; xmm3=(15 -- -- -- -- -- -- --)
  370. por xmm1, XMMWORD [wk(1)] ; xmm1=(-1 0 1 2 3 4 5 6)
  371. por xmm5, XMMWORD [wk(3)] ; xmm5=( 9 10 11 12 13 14 15 16)
  372. movdqa XMMWORD [wk(1)], xmm3
  373. pmullw xmm6, [GOTOFF(ebx,PW_THREE)]
  374. pmullw xmm4, [GOTOFF(ebx,PW_THREE)]
  375. paddw xmm1, [GOTOFF(ebx,PW_EIGHT)]
  376. paddw xmm0, [GOTOFF(ebx,PW_EIGHT)]
  377. paddw xmm7, [GOTOFF(ebx,PW_SEVEN)]
  378. paddw xmm5, [GOTOFF(ebx,PW_SEVEN)]
  379. paddw xmm1, xmm6
  380. paddw xmm0, xmm4
  381. psrlw xmm1, 4 ; xmm1=Out1LE=( 0 2 4 6 8 10 12 14)
  382. psrlw xmm0, 4 ; xmm0=Out1HE=(16 18 20 22 24 26 28 30)
  383. paddw xmm7, xmm6
  384. paddw xmm5, xmm4
  385. psrlw xmm7, 4 ; xmm7=Out1LO=( 1 3 5 7 9 11 13 15)
  386. psrlw xmm5, 4 ; xmm5=Out1HO=(17 19 21 23 25 27 29 31)
  387. psllw xmm7, BYTE_BIT
  388. psllw xmm5, BYTE_BIT
  389. por xmm1, xmm7 ; xmm1=Out1L=( 0 1 2 ... 13 14 15)
  390. por xmm0, xmm5 ; xmm0=Out1H=(16 17 18 ... 29 30 31)
  391. movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm1
  392. movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm0
  393. POPPIC ebx
  394. sub eax, byte SIZEOF_XMMWORD
  395. add ecx, byte 1*SIZEOF_XMMWORD ; inptr1(above)
  396. add ebx, byte 1*SIZEOF_XMMWORD ; inptr0
  397. add esi, byte 1*SIZEOF_XMMWORD ; inptr1(below)
  398. add edx, byte 2*SIZEOF_XMMWORD ; outptr0
  399. add edi, byte 2*SIZEOF_XMMWORD ; outptr1
  400. cmp eax, byte SIZEOF_XMMWORD
  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. .return:
  413. pop edi
  414. pop esi
  415. ; pop edx ; need not be preserved
  416. ; pop ecx ; need not be preserved
  417. pop ebx
  418. mov esp, ebp ; esp <- aligned ebp
  419. pop esp ; esp <- original ebp
  420. pop ebp
  421. ret
  422. ; --------------------------------------------------------------------------
  423. ;
  424. ; Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
  425. ; It's still a box filter.
  426. ;
  427. ; GLOBAL(void)
  428. ; jsimd_h2v1_upsample_sse2(int max_v_samp_factor, JDIMENSION output_width,
  429. ; JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr);
  430. ;
  431. %define max_v_samp(b) (b) + 8 ; int max_v_samp_factor
  432. %define output_width(b) (b) + 12 ; JDIMENSION output_width
  433. %define input_data(b) (b) + 16 ; JSAMPARRAY input_data
  434. %define output_data_ptr(b) (b) + 20 ; JSAMPARRAY *output_data_ptr
  435. align 32
  436. GLOBAL_FUNCTION(jsimd_h2v1_upsample_sse2)
  437. EXTN(jsimd_h2v1_upsample_sse2):
  438. push ebp
  439. mov ebp, esp
  440. ; push ebx ; unused
  441. ; push ecx ; need not be preserved
  442. ; push edx ; need not be preserved
  443. push esi
  444. push edi
  445. mov edx, JDIMENSION [output_width(ebp)]
  446. add edx, byte (2*SIZEOF_XMMWORD)-1
  447. and edx, byte -(2*SIZEOF_XMMWORD)
  448. jz short .return
  449. mov ecx, INT [max_v_samp(ebp)] ; rowctr
  450. test ecx, ecx
  451. jz short .return
  452. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  453. mov edi, POINTER [output_data_ptr(ebp)]
  454. mov edi, JSAMPARRAY [edi] ; output_data
  455. ALIGNX 16, 7
  456. .rowloop:
  457. push edi
  458. push esi
  459. mov esi, JSAMPROW [esi] ; inptr
  460. mov edi, JSAMPROW [edi] ; outptr
  461. mov eax, edx ; colctr
  462. ALIGNX 16, 7
  463. .columnloop:
  464. movdqa xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD]
  465. movdqa xmm1, xmm0
  466. punpcklbw xmm0, xmm0
  467. punpckhbw xmm1, xmm1
  468. movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0
  469. movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm1
  470. sub eax, byte 2*SIZEOF_XMMWORD
  471. jz short .nextrow
  472. movdqa xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD]
  473. movdqa xmm3, xmm2
  474. punpcklbw xmm2, xmm2
  475. punpckhbw xmm3, xmm3
  476. movdqa XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2
  477. movdqa XMMWORD [edi+3*SIZEOF_XMMWORD], xmm3
  478. sub eax, byte 2*SIZEOF_XMMWORD
  479. jz short .nextrow
  480. add esi, byte 2*SIZEOF_XMMWORD ; inptr
  481. add edi, byte 4*SIZEOF_XMMWORD ; outptr
  482. jmp short .columnloop
  483. ALIGNX 16, 7
  484. .nextrow:
  485. pop esi
  486. pop edi
  487. add esi, byte SIZEOF_JSAMPROW ; input_data
  488. add edi, byte SIZEOF_JSAMPROW ; output_data
  489. dec ecx ; rowctr
  490. jg short .rowloop
  491. .return:
  492. pop edi
  493. pop esi
  494. ; pop edx ; need not be preserved
  495. ; pop ecx ; need not be preserved
  496. ; pop ebx ; unused
  497. pop ebp
  498. ret
  499. ; --------------------------------------------------------------------------
  500. ;
  501. ; Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
  502. ; It's still a box filter.
  503. ;
  504. ; GLOBAL(void)
  505. ; jsimd_h2v2_upsample_sse2(int max_v_samp_factor, JDIMENSION output_width,
  506. ; JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr);
  507. ;
  508. %define max_v_samp(b) (b) + 8 ; int max_v_samp_factor
  509. %define output_width(b) (b) + 12 ; JDIMENSION output_width
  510. %define input_data(b) (b) + 16 ; JSAMPARRAY input_data
  511. %define output_data_ptr(b) (b) + 20 ; JSAMPARRAY *output_data_ptr
  512. align 32
  513. GLOBAL_FUNCTION(jsimd_h2v2_upsample_sse2)
  514. EXTN(jsimd_h2v2_upsample_sse2):
  515. push ebp
  516. mov ebp, esp
  517. push ebx
  518. ; push ecx ; need not be preserved
  519. ; push edx ; need not be preserved
  520. push esi
  521. push edi
  522. mov edx, JDIMENSION [output_width(ebp)]
  523. add edx, byte (2*SIZEOF_XMMWORD)-1
  524. and edx, byte -(2*SIZEOF_XMMWORD)
  525. jz near .return
  526. mov ecx, INT [max_v_samp(ebp)] ; rowctr
  527. test ecx, ecx
  528. jz near .return
  529. mov esi, JSAMPARRAY [input_data(ebp)] ; input_data
  530. mov edi, POINTER [output_data_ptr(ebp)]
  531. mov edi, JSAMPARRAY [edi] ; output_data
  532. ALIGNX 16, 7
  533. .rowloop:
  534. push edi
  535. push esi
  536. mov esi, JSAMPROW [esi] ; inptr
  537. mov ebx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] ; outptr0
  538. mov edi, JSAMPROW [edi+1*SIZEOF_JSAMPROW] ; outptr1
  539. mov eax, edx ; colctr
  540. ALIGNX 16, 7
  541. .columnloop:
  542. movdqa xmm0, XMMWORD [esi+0*SIZEOF_XMMWORD]
  543. movdqa xmm1, xmm0
  544. punpcklbw xmm0, xmm0
  545. punpckhbw xmm1, xmm1
  546. movdqa XMMWORD [ebx+0*SIZEOF_XMMWORD], xmm0
  547. movdqa XMMWORD [ebx+1*SIZEOF_XMMWORD], xmm1
  548. movdqa XMMWORD [edi+0*SIZEOF_XMMWORD], xmm0
  549. movdqa XMMWORD [edi+1*SIZEOF_XMMWORD], xmm1
  550. sub eax, byte 2*SIZEOF_XMMWORD
  551. jz short .nextrow
  552. movdqa xmm2, XMMWORD [esi+1*SIZEOF_XMMWORD]
  553. movdqa xmm3, xmm2
  554. punpcklbw xmm2, xmm2
  555. punpckhbw xmm3, xmm3
  556. movdqa XMMWORD [ebx+2*SIZEOF_XMMWORD], xmm2
  557. movdqa XMMWORD [ebx+3*SIZEOF_XMMWORD], xmm3
  558. movdqa XMMWORD [edi+2*SIZEOF_XMMWORD], xmm2
  559. movdqa XMMWORD [edi+3*SIZEOF_XMMWORD], xmm3
  560. sub eax, byte 2*SIZEOF_XMMWORD
  561. jz short .nextrow
  562. add esi, byte 2*SIZEOF_XMMWORD ; inptr
  563. add ebx, byte 4*SIZEOF_XMMWORD ; outptr0
  564. add edi, byte 4*SIZEOF_XMMWORD ; outptr1
  565. jmp short .columnloop
  566. ALIGNX 16, 7
  567. .nextrow:
  568. pop esi
  569. pop edi
  570. add esi, byte 1*SIZEOF_JSAMPROW ; input_data
  571. add edi, byte 2*SIZEOF_JSAMPROW ; output_data
  572. sub ecx, byte 2 ; rowctr
  573. jg short .rowloop
  574. .return:
  575. pop edi
  576. pop esi
  577. ; pop edx ; need not be preserved
  578. ; pop ecx ; need not be preserved
  579. pop ebx
  580. pop ebp
  581. ret
  582. ; For some reason, the OS X linker does not honor the request to align the
  583. ; segment unless we do this.
  584. align 32