jdsample-sse2.asm 23 KB

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