jdsample-avx2.asm 27 KB

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