jdmrgext-avx2.asm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. ;
  2. ; jdmrgext.asm - merged upsampling/color conversion (64-bit AVX2)
  3. ;
  4. ; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ; Copyright (C) 2009, 2012, 2016, D. R. Commander.
  6. ; Copyright (C) 2015, Intel Corporation.
  7. ; Copyright (C) 2018, Matthias Räncker.
  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),
  14. ; can *not* be assembled with Microsoft's MASM or any compatible
  15. ; assembler (including Borland's Turbo Assembler).
  16. ; NASM is available from http://nasm.sourceforge.net/ or
  17. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  18. %include "jcolsamp.inc"
  19. ; --------------------------------------------------------------------------
  20. ;
  21. ; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
  22. ;
  23. ; GLOBAL(void)
  24. ; jsimd_h2v1_merged_upsample_avx2(JDIMENSION output_width,
  25. ; JSAMPIMAGE input_buf,
  26. ; JDIMENSION in_row_group_ctr,
  27. ; JSAMPARRAY output_buf);
  28. ;
  29. ; r10d = JDIMENSION output_width
  30. ; r11 = JSAMPIMAGE input_buf
  31. ; r12d = JDIMENSION in_row_group_ctr
  32. ; r13 = JSAMPARRAY output_buf
  33. %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_YMMWORD ; ymmword wk[WK_NUM]
  34. %define WK_NUM 3
  35. align 32
  36. GLOBAL_FUNCTION(jsimd_h2v1_merged_upsample_avx2)
  37. EXTN(jsimd_h2v1_merged_upsample_avx2):
  38. push rbp
  39. mov rax, rsp ; rax = original rbp
  40. sub rsp, byte 4
  41. and rsp, byte (-SIZEOF_YMMWORD) ; align to 256 bits
  42. mov [rsp], rax
  43. mov rbp, rsp ; rbp = aligned rbp
  44. lea rsp, [wk(0)]
  45. collect_args 4
  46. push rbx
  47. mov ecx, r10d ; col
  48. test rcx, rcx
  49. jz near .return
  50. push rcx
  51. mov rdi, r11
  52. mov ecx, r12d
  53. mov rsip, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
  54. mov rbxp, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
  55. mov rdxp, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
  56. mov rdi, r13
  57. mov rsip, JSAMPROW [rsi+rcx*SIZEOF_JSAMPROW] ; inptr0
  58. mov rbxp, JSAMPROW [rbx+rcx*SIZEOF_JSAMPROW] ; inptr1
  59. mov rdxp, JSAMPROW [rdx+rcx*SIZEOF_JSAMPROW] ; inptr2
  60. mov rdip, JSAMPROW [rdi] ; outptr
  61. pop rcx ; col
  62. .columnloop:
  63. vmovdqu ymm6, YMMWORD [rbx] ; ymm6=Cb(0123456789ABCDEFGHIJKLMNOPQRSTUV)
  64. vmovdqu ymm7, YMMWORD [rdx] ; ymm7=Cr(0123456789ABCDEFGHIJKLMNOPQRSTUV)
  65. vpxor ymm1, ymm1, ymm1 ; ymm1=(all 0's)
  66. vpcmpeqw ymm3, ymm3, ymm3
  67. vpsllw ymm3, ymm3, 7 ; ymm3={0xFF80 0xFF80 0xFF80 0xFF80 ..}
  68. vpermq ymm6, ymm6, 0xd8 ; ymm6=Cb(01234567GHIJKLMN89ABCDEFOPQRSTUV)
  69. vpermq ymm7, ymm7, 0xd8 ; ymm7=Cr(01234567GHIJKLMN89ABCDEFOPQRSTUV)
  70. vpunpcklbw ymm4, ymm6, ymm1 ; ymm4=Cb(0123456789ABCDEF)=CbL
  71. vpunpckhbw ymm6, ymm6, ymm1 ; ymm6=Cb(GHIJKLMNOPQRSTUV)=CbH
  72. vpunpcklbw ymm0, ymm7, ymm1 ; ymm0=Cr(0123456789ABCDEF)=CrL
  73. vpunpckhbw ymm7, ymm7, ymm1 ; ymm7=Cr(GHIJKLMNOPQRSTUV)=CrH
  74. vpaddw ymm5, ymm6, ymm3
  75. vpaddw ymm2, ymm4, ymm3
  76. vpaddw ymm1, ymm7, ymm3
  77. vpaddw ymm3, ymm0, ymm3
  78. ; (Original)
  79. ; R = Y + 1.40200 * Cr
  80. ; G = Y - 0.34414 * Cb - 0.71414 * Cr
  81. ; B = Y + 1.77200 * Cb
  82. ;
  83. ; (This implementation)
  84. ; R = Y + 0.40200 * Cr + Cr
  85. ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
  86. ; B = Y - 0.22800 * Cb + Cb + Cb
  87. vpaddw ymm6, ymm5, ymm5 ; ymm6=2*CbH
  88. vpaddw ymm4, ymm2, ymm2 ; ymm4=2*CbL
  89. vpaddw ymm7, ymm1, ymm1 ; ymm7=2*CrH
  90. vpaddw ymm0, ymm3, ymm3 ; ymm0=2*CrL
  91. vpmulhw ymm6, ymm6, [rel PW_MF0228] ; ymm6=(2*CbH * -FIX(0.22800))
  92. vpmulhw ymm4, ymm4, [rel PW_MF0228] ; ymm4=(2*CbL * -FIX(0.22800))
  93. vpmulhw ymm7, ymm7, [rel PW_F0402] ; ymm7=(2*CrH * FIX(0.40200))
  94. vpmulhw ymm0, ymm0, [rel PW_F0402] ; ymm0=(2*CrL * FIX(0.40200))
  95. vpaddw ymm6, ymm6, [rel PW_ONE]
  96. vpaddw ymm4, ymm4, [rel PW_ONE]
  97. vpsraw ymm6, ymm6, 1 ; ymm6=(CbH * -FIX(0.22800))
  98. vpsraw ymm4, ymm4, 1 ; ymm4=(CbL * -FIX(0.22800))
  99. vpaddw ymm7, ymm7, [rel PW_ONE]
  100. vpaddw ymm0, ymm0, [rel PW_ONE]
  101. vpsraw ymm7, ymm7, 1 ; ymm7=(CrH * FIX(0.40200))
  102. vpsraw ymm0, ymm0, 1 ; ymm0=(CrL * FIX(0.40200))
  103. vpaddw ymm6, ymm6, ymm5
  104. vpaddw ymm4, ymm4, ymm2
  105. vpaddw ymm6, ymm6, ymm5 ; ymm6=(CbH * FIX(1.77200))=(B-Y)H
  106. vpaddw ymm4, ymm4, ymm2 ; ymm4=(CbL * FIX(1.77200))=(B-Y)L
  107. vpaddw ymm7, ymm7, ymm1 ; ymm7=(CrH * FIX(1.40200))=(R-Y)H
  108. vpaddw ymm0, ymm0, ymm3 ; ymm0=(CrL * FIX(1.40200))=(R-Y)L
  109. vmovdqa YMMWORD [wk(0)], ymm6 ; wk(0)=(B-Y)H
  110. vmovdqa YMMWORD [wk(1)], ymm7 ; wk(1)=(R-Y)H
  111. vpunpckhwd ymm6, ymm5, ymm1
  112. vpunpcklwd ymm5, ymm5, ymm1
  113. vpmaddwd ymm5, ymm5, [rel PW_MF0344_F0285]
  114. vpmaddwd ymm6, ymm6, [rel PW_MF0344_F0285]
  115. vpunpckhwd ymm7, ymm2, ymm3
  116. vpunpcklwd ymm2, ymm2, ymm3
  117. vpmaddwd ymm2, ymm2, [rel PW_MF0344_F0285]
  118. vpmaddwd ymm7, ymm7, [rel PW_MF0344_F0285]
  119. vpaddd ymm5, ymm5, [rel PD_ONEHALF]
  120. vpaddd ymm6, ymm6, [rel PD_ONEHALF]
  121. vpsrad ymm5, ymm5, SCALEBITS
  122. vpsrad ymm6, ymm6, SCALEBITS
  123. vpaddd ymm2, ymm2, [rel PD_ONEHALF]
  124. vpaddd ymm7, ymm7, [rel PD_ONEHALF]
  125. vpsrad ymm2, ymm2, SCALEBITS
  126. vpsrad ymm7, ymm7, SCALEBITS
  127. vpackssdw ymm5, ymm5, ymm6 ; ymm5=CbH*-FIX(0.344)+CrH*FIX(0.285)
  128. vpackssdw ymm2, ymm2, ymm7 ; ymm2=CbL*-FIX(0.344)+CrL*FIX(0.285)
  129. vpsubw ymm5, ymm5, ymm1 ; ymm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H
  130. vpsubw ymm2, ymm2, ymm3 ; ymm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L
  131. vmovdqa YMMWORD [wk(2)], ymm5 ; wk(2)=(G-Y)H
  132. mov al, 2 ; Yctr
  133. jmp short .Yloop_1st
  134. .Yloop_2nd:
  135. vmovdqa ymm0, YMMWORD [wk(1)] ; ymm0=(R-Y)H
  136. vmovdqa ymm2, YMMWORD [wk(2)] ; ymm2=(G-Y)H
  137. vmovdqa ymm4, YMMWORD [wk(0)] ; ymm4=(B-Y)H
  138. .Yloop_1st:
  139. vmovdqu ymm7, YMMWORD [rsi] ; ymm7=Y(0123456789ABCDEFGHIJKLMNOPQRSTUV)
  140. vpcmpeqw ymm6, ymm6, ymm6
  141. vpsrlw ymm6, ymm6, BYTE_BIT ; ymm6={0xFF 0x00 0xFF 0x00 ..}
  142. vpand ymm6, ymm6, ymm7 ; ymm6=Y(02468ACEGIKMOQSU)=YE
  143. vpsrlw ymm7, ymm7, BYTE_BIT ; ymm7=Y(13579BDFHJLNPRTV)=YO
  144. vmovdqa ymm1, ymm0 ; ymm1=ymm0=(R-Y)(L/H)
  145. vmovdqa ymm3, ymm2 ; ymm3=ymm2=(G-Y)(L/H)
  146. vmovdqa ymm5, ymm4 ; ymm5=ymm4=(B-Y)(L/H)
  147. vpaddw ymm0, ymm0, ymm6 ; ymm0=((R-Y)+YE)=RE=R(02468ACEGIKMOQSU)
  148. vpaddw ymm1, ymm1, ymm7 ; ymm1=((R-Y)+YO)=RO=R(13579BDFHJLNPRTV)
  149. vpackuswb ymm0, ymm0, ymm0 ; ymm0=R(02468ACE********GIKMOQSU********)
  150. vpackuswb ymm1, ymm1, ymm1 ; ymm1=R(13579BDF********HJLNPRTV********)
  151. vpaddw ymm2, ymm2, ymm6 ; ymm2=((G-Y)+YE)=GE=G(02468ACEGIKMOQSU)
  152. vpaddw ymm3, ymm3, ymm7 ; ymm3=((G-Y)+YO)=GO=G(13579BDFHJLNPRTV)
  153. vpackuswb ymm2, ymm2, ymm2 ; ymm2=G(02468ACE********GIKMOQSU********)
  154. vpackuswb ymm3, ymm3, ymm3 ; ymm3=G(13579BDF********HJLNPRTV********)
  155. vpaddw ymm4, ymm4, ymm6 ; ymm4=((B-Y)+YE)=BE=B(02468ACEGIKMOQSU)
  156. vpaddw ymm5, ymm5, ymm7 ; ymm5=((B-Y)+YO)=BO=B(13579BDFHJLNPRTV)
  157. vpackuswb ymm4, ymm4, ymm4 ; ymm4=B(02468ACE********GIKMOQSU********)
  158. vpackuswb ymm5, ymm5, ymm5 ; ymm5=B(13579BDF********HJLNPRTV********)
  159. %if RGB_PIXELSIZE == 3 ; ---------------
  160. ; ymmA=(00 02 04 06 08 0A 0C 0E ** 0G 0I 0K 0M 0O 0Q 0S 0U **)
  161. ; ymmB=(01 03 05 07 09 0B 0D 0F ** 0H 0J 0L 0N 0P 0R 0T 0V **)
  162. ; ymmC=(10 12 14 16 18 1A 1C 1E ** 1G 1I 1K 1M 1O 1Q 1S 1U **)
  163. ; ymmD=(11 13 15 17 19 1B 1D 1F ** 1H 1J 1L 1N 1P 1R 1T 1V **)
  164. ; ymmE=(20 22 24 26 28 2A 2C 2E ** 2G 2I 2K 2M 2O 2Q 2S 2U **)
  165. ; ymmF=(21 23 25 27 29 2B 2D 2F ** 2H 2J 2L 2N 2P 2R 2T 2V **)
  166. ; ymmG=(** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **)
  167. ; ymmH=(** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **)
  168. vpunpcklbw ymmA, ymmA, ymmC ; ymmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E
  169. ; 0G 1G 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U)
  170. vpunpcklbw ymmE, ymmE, ymmB ; ymmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F
  171. ; 2G 0H 2I 0J 2K 0L 2M 0N 2O 0P 2Q 0R 2S 0T 2U 0V)
  172. vpunpcklbw ymmD, ymmD, ymmF ; ymmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F
  173. ; 1H 2H 1J 2J 1L 2L 1N 2N 1P 2P 1R 2R 1T 2T 1V 2V)
  174. vpsrldq ymmH, ymmA, 2 ; ymmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E 0G 1G
  175. ; 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U -- --)
  176. vpunpckhwd ymmG, ymmA, ymmE ; ymmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F
  177. ; 0O 1O 2O 0P 0Q 1Q 2Q 0R 0S 1S 2S 0T 0U 1U 2U 0V)
  178. vpunpcklwd ymmA, ymmA, ymmE ; ymmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07
  179. ; 0G 1G 2G 0H 0I 1I 2I 0J 0K 1K 2K 0L 0M 1M 2M 0N)
  180. vpsrldq ymmE, ymmE, 2 ; ymmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F 2G 0H
  181. ; 2I 0J 2K 0L 2M 0N 2O 0P 2Q 0R 2S 0T 2U 0V -- --)
  182. vpsrldq ymmB, ymmD, 2 ; ymmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F 1H 2H
  183. ; 1J 2J 1L 2L 1N 2N 1P 2P 1R 2R 1T 2T 1V 2V -- --)
  184. vpunpckhwd ymmC, ymmD, ymmH ; ymmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F 0G 1G
  185. ; 1P 2P 0Q 1Q 1R 2R 0S 1S 1T 2T 0U 1U 1V 2V -- --)
  186. vpunpcklwd ymmD, ymmD, ymmH ; ymmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18
  187. ; 1H 2H 0I 1I 1J 2J 0K 1K 1L 2L 0M 1M 1N 2N 0O 1O)
  188. vpunpckhwd ymmF, ymmE, ymmB ; ymmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F 2G 0H 1H 2H
  189. ; 2Q 0R 1R 2R 2S 0T 1T 2T 2U 0V 1V 2V -- -- -- --)
  190. vpunpcklwd ymmE, ymmE, ymmB ; ymmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29
  191. ; 2I 0J 1J 2J 2K 0L 1L 2L 2M 0N 1N 2N 2O 0P 1P 2P)
  192. vpshufd ymmH, ymmA, 0x4E ; ymmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03
  193. ; 0K 1K 2K 0L 0M 1M 2M 0N 0G 1G 2G 0H 0I 1I 2I 0J)
  194. vpunpckldq ymmA, ymmA, ymmD ; ymmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14
  195. ; 0G 1G 2G 0H 1H 2H 0I 1I 0I 1I 2I 0J 1J 2J 0K 1K)
  196. vpunpckhdq ymmD, ymmD, ymmE ; ymmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29
  197. ; 1L 2L 0M 1M 2M 0N 1N 2N 1N 2N 0O 1O 2O 0P 1P 2P)
  198. vpunpckldq ymmE, ymmE, ymmH ; ymmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07
  199. ; 2I 0J 1J 2J 0K 1K 2K 0L 2K 0L 1L 2L 0M 1M 2M 0N)
  200. vpshufd ymmH, ymmG, 0x4E ; ymmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B
  201. ; 0S 1S 2S 0T 0U 1U 2U 0V 0O 1O 2O 0P 0Q 1Q 2Q 0R)
  202. vpunpckldq ymmG, ymmG, ymmC ; ymmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C
  203. ; 0O 1O 2O 0P 1P 2P 0Q 1Q 0Q 1Q 2Q 0R 1R 2R 0S 1S)
  204. vpunpckhdq ymmC, ymmC, ymmF ; ymmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F 0G 1G 2G 0H 1H 2H
  205. ; 1T 2T 0U 1U 2U 0V 1V 2V 1V 2V -- -- -- -- -- --)
  206. vpunpckldq ymmF, ymmF, ymmH ; ymmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F
  207. ; 2Q 0R 1R 2R 0S 1S 2S 0T 2S 0T 1T 2T 0U 1U 2U 0V)
  208. vpunpcklqdq ymmH, ymmA, ymmE ; ymmH=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
  209. ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
  210. vpunpcklqdq ymmG, ymmD, ymmG ; ymmG=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A
  211. ; 1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q)
  212. vpunpcklqdq ymmC, ymmF, ymmC ; ymmC=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
  213. ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
  214. vperm2i128 ymmA, ymmH, ymmG, 0x20 ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
  215. ; 15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
  216. vperm2i128 ymmD, ymmC, ymmH, 0x30 ; ymmD=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
  217. ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
  218. vperm2i128 ymmF, ymmG, ymmC, 0x31 ; ymmF=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q
  219. ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
  220. cmp rcx, byte SIZEOF_YMMWORD
  221. jb short .column_st64
  222. test rdi, SIZEOF_YMMWORD-1
  223. jnz short .out1
  224. ; --(aligned)-------------------
  225. vmovntdq YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  226. vmovntdq YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  227. vmovntdq YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmF
  228. jmp short .out0
  229. .out1: ; --(unaligned)-----------------
  230. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  231. vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  232. vmovdqu YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmF
  233. .out0:
  234. add rdi, byte RGB_PIXELSIZE*SIZEOF_YMMWORD ; outptr
  235. sub rcx, byte SIZEOF_YMMWORD
  236. jz near .endcolumn
  237. add rsi, byte SIZEOF_YMMWORD ; inptr0
  238. dec al ; Yctr
  239. jnz near .Yloop_2nd
  240. add rbx, byte SIZEOF_YMMWORD ; inptr1
  241. add rdx, byte SIZEOF_YMMWORD ; inptr2
  242. jmp near .columnloop
  243. .column_st64:
  244. lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE
  245. cmp rcx, byte 2*SIZEOF_YMMWORD
  246. jb short .column_st32
  247. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  248. vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  249. add rdi, byte 2*SIZEOF_YMMWORD ; outptr
  250. vmovdqa ymmA, ymmF
  251. sub rcx, byte 2*SIZEOF_YMMWORD
  252. jmp short .column_st31
  253. .column_st32:
  254. cmp rcx, byte SIZEOF_YMMWORD
  255. jb short .column_st31
  256. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  257. add rdi, byte SIZEOF_YMMWORD ; outptr
  258. vmovdqa ymmA, ymmD
  259. sub rcx, byte SIZEOF_YMMWORD
  260. jmp short .column_st31
  261. .column_st31:
  262. cmp rcx, byte SIZEOF_XMMWORD
  263. jb short .column_st15
  264. vmovdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  265. add rdi, byte SIZEOF_XMMWORD ; outptr
  266. vperm2i128 ymmA, ymmA, ymmA, 1
  267. sub rcx, byte SIZEOF_XMMWORD
  268. .column_st15:
  269. ; Store the lower 8 bytes of xmmA to the output when it has enough
  270. ; space.
  271. cmp rcx, byte SIZEOF_MMWORD
  272. jb short .column_st7
  273. vmovq XMM_MMWORD [rdi], xmmA
  274. add rdi, byte SIZEOF_MMWORD
  275. sub rcx, byte SIZEOF_MMWORD
  276. vpsrldq xmmA, xmmA, SIZEOF_MMWORD
  277. .column_st7:
  278. ; Store the lower 4 bytes of xmmA to the output when it has enough
  279. ; space.
  280. cmp rcx, byte SIZEOF_DWORD
  281. jb short .column_st3
  282. vmovd XMM_DWORD [rdi], xmmA
  283. add rdi, byte SIZEOF_DWORD
  284. sub rcx, byte SIZEOF_DWORD
  285. vpsrldq xmmA, xmmA, SIZEOF_DWORD
  286. .column_st3:
  287. ; Store the lower 2 bytes of rax to the output when it has enough
  288. ; space.
  289. vmovd eax, xmmA
  290. cmp rcx, byte SIZEOF_WORD
  291. jb short .column_st1
  292. mov word [rdi], ax
  293. add rdi, byte SIZEOF_WORD
  294. sub rcx, byte SIZEOF_WORD
  295. shr rax, 16
  296. .column_st1:
  297. ; Store the lower 1 byte of rax to the output when it has enough
  298. ; space.
  299. test rcx, rcx
  300. jz short .endcolumn
  301. mov byte [rdi], al
  302. %else ; RGB_PIXELSIZE == 4 ; -----------
  303. %ifdef RGBX_FILLER_0XFF
  304. vpcmpeqb ymm6, ymm6, ymm6 ; ymm6=XE=X(02468ACE********GIKMOQSU********)
  305. vpcmpeqb ymm7, ymm7, ymm7 ; ymm7=XO=X(13579BDF********HJLNPRTV********)
  306. %else
  307. vpxor ymm6, ymm6, ymm6 ; ymm6=XE=X(02468ACE********GIKMOQSU********)
  308. vpxor ymm7, ymm7, ymm7 ; ymm7=XO=X(13579BDF********HJLNPRTV********)
  309. %endif
  310. ; ymmA=(00 02 04 06 08 0A 0C 0E ** 0G 0I 0K 0M 0O 0Q 0S 0U **)
  311. ; ymmB=(01 03 05 07 09 0B 0D 0F ** 0H 0J 0L 0N 0P 0R 0T 0V **)
  312. ; ymmC=(10 12 14 16 18 1A 1C 1E ** 1G 1I 1K 1M 1O 1Q 1S 1U **)
  313. ; ymmD=(11 13 15 17 19 1B 1D 1F ** 1H 1J 1L 1N 1P 1R 1T 1V **)
  314. ; ymmE=(20 22 24 26 28 2A 2C 2E ** 2G 2I 2K 2M 2O 2Q 2S 2U **)
  315. ; ymmF=(21 23 25 27 29 2B 2D 2F ** 2H 2J 2L 2N 2P 2R 2T 2V **)
  316. ; ymmG=(30 32 34 36 38 3A 3C 3E ** 3G 3I 3K 3M 3O 3Q 3S 3U **)
  317. ; ymmH=(31 33 35 37 39 3B 3D 3F ** 3H 3J 3L 3N 3P 3R 3T 3V **)
  318. vpunpcklbw ymmA, ymmA, ymmC ; ymmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E
  319. ; 0G 1G 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U)
  320. vpunpcklbw ymmE, ymmE, ymmG ; ymmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E
  321. ; 2G 3G 2I 3I 2K 3K 2M 3M 2O 3O 2Q 3Q 2S 3S 2U 3U)
  322. vpunpcklbw ymmB, ymmB, ymmD ; ymmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F
  323. ; 0H 1H 0J 1J 0L 1L 0N 1N 0P 1P 0R 1R 0T 1T 0V 1V)
  324. vpunpcklbw ymmF, ymmF, ymmH ; ymmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F
  325. ; 2H 3H 2J 3J 2L 3L 2N 3N 2P 3P 2R 3R 2T 3T 2V 3V)
  326. vpunpckhwd ymmC, ymmA, ymmE ; ymmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E
  327. ; 0O 1O 2O 3O 0Q 1Q 2Q 3Q 0S 1S 2S 3S 0U 1U 2U 3U)
  328. vpunpcklwd ymmA, ymmA, ymmE ; ymmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36
  329. ; 0G 1G 2G 3G 0I 1I 2I 3I 0K 1K 2K 3K 0M 1M 2M 3M)
  330. vpunpckhwd ymmG, ymmB, ymmF ; ymmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F
  331. ; 0P 1P 2P 3P 0R 1R 2R 3R 0T 1T 2T 3T 0V 1V 2V 3V)
  332. vpunpcklwd ymmB, ymmB, ymmF ; ymmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37
  333. ; 0H 1H 2H 3H 0J 1J 2J 3J 0L 1L 2L 3L 0N 1N 2N 3N)
  334. vpunpckhdq ymmE, ymmA, ymmB ; ymmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37
  335. ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
  336. vpunpckldq ymmB, ymmA, ymmB ; ymmB=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
  337. ; 0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J)
  338. vpunpckhdq ymmF, ymmC, ymmG ; ymmF=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F
  339. ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
  340. vpunpckldq ymmG, ymmC, ymmG ; ymmG=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
  341. ; 0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R)
  342. vperm2i128 ymmA, ymmB, ymmE, 0x20 ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
  343. ; 04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
  344. vperm2i128 ymmD, ymmG, ymmF, 0x20 ; ymmD=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
  345. ; 0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
  346. vperm2i128 ymmC, ymmB, ymmE, 0x31 ; ymmC=(0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J
  347. ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
  348. vperm2i128 ymmH, ymmG, ymmF, 0x31 ; ymmH=(0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R
  349. ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
  350. cmp rcx, byte SIZEOF_YMMWORD
  351. jb short .column_st64
  352. test rdi, SIZEOF_YMMWORD-1
  353. jnz short .out1
  354. ; --(aligned)-------------------
  355. vmovntdq YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  356. vmovntdq YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  357. vmovntdq YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmC
  358. vmovntdq YMMWORD [rdi+3*SIZEOF_YMMWORD], ymmH
  359. jmp short .out0
  360. .out1: ; --(unaligned)-----------------
  361. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  362. vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  363. vmovdqu YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmC
  364. vmovdqu YMMWORD [rdi+3*SIZEOF_YMMWORD], ymmH
  365. .out0:
  366. add rdi, RGB_PIXELSIZE*SIZEOF_YMMWORD ; outptr
  367. sub rcx, byte SIZEOF_YMMWORD
  368. jz near .endcolumn
  369. add rsi, byte SIZEOF_YMMWORD ; inptr0
  370. dec al
  371. jnz near .Yloop_2nd
  372. add rbx, byte SIZEOF_YMMWORD ; inptr1
  373. add rdx, byte SIZEOF_YMMWORD ; inptr2
  374. jmp near .columnloop
  375. .column_st64:
  376. cmp rcx, byte SIZEOF_YMMWORD/2
  377. jb short .column_st32
  378. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  379. vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  380. add rdi, byte 2*SIZEOF_YMMWORD ; outptr
  381. vmovdqa ymmA, ymmC
  382. vmovdqa ymmD, ymmH
  383. sub rcx, byte SIZEOF_YMMWORD/2
  384. .column_st32:
  385. cmp rcx, byte SIZEOF_YMMWORD/4
  386. jb short .column_st16
  387. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  388. add rdi, byte SIZEOF_YMMWORD ; outptr
  389. vmovdqa ymmA, ymmD
  390. sub rcx, byte SIZEOF_YMMWORD/4
  391. .column_st16:
  392. cmp rcx, byte SIZEOF_YMMWORD/8
  393. jb short .column_st15
  394. vmovdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  395. add rdi, byte SIZEOF_XMMWORD ; outptr
  396. vperm2i128 ymmA, ymmA, ymmA, 1
  397. sub rcx, byte SIZEOF_YMMWORD/8
  398. .column_st15:
  399. ; Store two pixels (8 bytes) of ymmA to the output when it has enough
  400. ; space.
  401. cmp rcx, byte SIZEOF_YMMWORD/16
  402. jb short .column_st7
  403. vmovq MMWORD [rdi], xmmA
  404. add rdi, byte SIZEOF_YMMWORD/16*4
  405. sub rcx, byte SIZEOF_YMMWORD/16
  406. vpsrldq xmmA, SIZEOF_YMMWORD/16*4
  407. .column_st7:
  408. ; Store one pixel (4 bytes) of ymmA to the output when it has enough
  409. ; space.
  410. test rcx, rcx
  411. jz short .endcolumn
  412. vmovd XMM_DWORD [rdi], xmmA
  413. %endif ; RGB_PIXELSIZE ; ---------------
  414. .endcolumn:
  415. sfence ; flush the write buffer
  416. .return:
  417. pop rbx
  418. vzeroupper
  419. uncollect_args 4
  420. mov rsp, rbp ; rsp <- aligned rbp
  421. pop rsp ; rsp <- original rbp
  422. pop rbp
  423. ret
  424. ; --------------------------------------------------------------------------
  425. ;
  426. ; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
  427. ;
  428. ; GLOBAL(void)
  429. ; jsimd_h2v2_merged_upsample_avx2(JDIMENSION output_width,
  430. ; JSAMPIMAGE input_buf,
  431. ; JDIMENSION in_row_group_ctr,
  432. ; JSAMPARRAY output_buf);
  433. ;
  434. ; r10d = JDIMENSION output_width
  435. ; r11 = JSAMPIMAGE input_buf
  436. ; r12d = JDIMENSION in_row_group_ctr
  437. ; r13 = JSAMPARRAY output_buf
  438. align 32
  439. GLOBAL_FUNCTION(jsimd_h2v2_merged_upsample_avx2)
  440. EXTN(jsimd_h2v2_merged_upsample_avx2):
  441. push rbp
  442. mov rax, rsp
  443. mov rbp, rsp
  444. collect_args 4
  445. push rbx
  446. mov eax, r10d
  447. mov rdi, r11
  448. mov ecx, r12d
  449. mov rsip, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
  450. mov rbxp, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
  451. mov rdxp, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
  452. mov rdi, r13
  453. lea rsi, [rsi+rcx*SIZEOF_JSAMPROW]
  454. sub rsp, SIZEOF_JSAMPARRAY*4
  455. mov JSAMPARRAY [rsp+0*SIZEOF_JSAMPARRAY], rsip ; intpr00
  456. mov JSAMPARRAY [rsp+1*SIZEOF_JSAMPARRAY], rbxp ; intpr1
  457. mov JSAMPARRAY [rsp+2*SIZEOF_JSAMPARRAY], rdxp ; intpr2
  458. mov rbx, rsp
  459. push rdi
  460. push rcx
  461. push rax
  462. %ifdef WIN64
  463. mov r8, rcx
  464. mov r9, rdi
  465. mov rcx, rax
  466. mov rdx, rbx
  467. %else
  468. mov rdx, rcx
  469. mov rcx, rdi
  470. mov rdi, rax
  471. mov rsi, rbx
  472. %endif
  473. call EXTN(jsimd_h2v1_merged_upsample_avx2)
  474. pop rax
  475. pop rcx
  476. pop rdi
  477. mov rsip, JSAMPARRAY [rsp+0*SIZEOF_JSAMPARRAY]
  478. mov rbxp, JSAMPARRAY [rsp+1*SIZEOF_JSAMPARRAY]
  479. mov rdxp, JSAMPARRAY [rsp+2*SIZEOF_JSAMPARRAY]
  480. add rdi, byte SIZEOF_JSAMPROW ; outptr1
  481. add rsi, byte SIZEOF_JSAMPROW ; inptr01
  482. mov JSAMPARRAY [rsp+0*SIZEOF_JSAMPARRAY], rsip ; intpr00
  483. mov JSAMPARRAY [rsp+1*SIZEOF_JSAMPARRAY], rbxp ; intpr1
  484. mov JSAMPARRAY [rsp+2*SIZEOF_JSAMPARRAY], rdxp ; intpr2
  485. mov rbx, rsp
  486. push rdi
  487. push rcx
  488. push rax
  489. %ifdef WIN64
  490. mov r8, rcx
  491. mov r9, rdi
  492. mov rcx, rax
  493. mov rdx, rbx
  494. %else
  495. mov rdx, rcx
  496. mov rcx, rdi
  497. mov rdi, rax
  498. mov rsi, rbx
  499. %endif
  500. call EXTN(jsimd_h2v1_merged_upsample_avx2)
  501. pop rax
  502. pop rcx
  503. pop rdi
  504. mov rsip, JSAMPARRAY [rsp+0*SIZEOF_JSAMPARRAY]
  505. mov rbxp, JSAMPARRAY [rsp+1*SIZEOF_JSAMPARRAY]
  506. mov rdxp, JSAMPARRAY [rsp+2*SIZEOF_JSAMPARRAY]
  507. add rsp, SIZEOF_JSAMPARRAY*4
  508. pop rbx
  509. uncollect_args 4
  510. pop rbp
  511. ret
  512. ; For some reason, the OS X linker does not honor the request to align the
  513. ; segment unless we do this.
  514. align 32