jdsample-sse2.asm 23 KB

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