jdcolext-avx2.asm 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. ;
  2. ; jdcolext.asm - colorspace 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. ; Convert some rows of samples to the output colorspace.
  22. ;
  23. ; GLOBAL(void)
  24. ; jsimd_ycc_rgb_convert_avx2(JDIMENSION out_width, JSAMPIMAGE input_buf,
  25. ; JDIMENSION input_row, JSAMPARRAY output_buf,
  26. ; int num_rows)
  27. ;
  28. ; r10d = JDIMENSION out_width
  29. ; r11 = JSAMPIMAGE input_buf
  30. ; r12d = JDIMENSION input_row
  31. ; r13 = JSAMPARRAY output_buf
  32. ; r14d = int num_rows
  33. %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_YMMWORD ; ymmword wk[WK_NUM]
  34. %define WK_NUM 2
  35. align 32
  36. GLOBAL_FUNCTION(jsimd_ycc_rgb_convert_avx2)
  37. EXTN(jsimd_ycc_rgb_convert_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 5
  46. push rbx
  47. mov ecx, r10d ; num_cols
  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. lea rsi, [rsi+rcx*SIZEOF_JSAMPROW]
  57. lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
  58. lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
  59. pop rcx
  60. mov rdi, r13
  61. mov eax, r14d
  62. test rax, rax
  63. jle near .return
  64. .rowloop:
  65. push rax
  66. push rdi
  67. push rdx
  68. push rbx
  69. push rsi
  70. push rcx ; col
  71. mov rsip, JSAMPROW [rsi] ; inptr0
  72. mov rbxp, JSAMPROW [rbx] ; inptr1
  73. mov rdxp, JSAMPROW [rdx] ; inptr2
  74. mov rdip, JSAMPROW [rdi] ; outptr
  75. .columnloop:
  76. vmovdqu ymm5, YMMWORD [rbx] ; ymm5=Cb(0123456789ABCDEFGHIJKLMNOPQRSTUV)
  77. vmovdqu ymm1, YMMWORD [rdx] ; ymm1=Cr(0123456789ABCDEFGHIJKLMNOPQRSTUV)
  78. vpcmpeqw ymm0, ymm0, ymm0
  79. vpcmpeqw ymm7, ymm7, ymm7
  80. vpsrlw ymm0, ymm0, BYTE_BIT ; ymm0={0xFF 0x00 0xFF 0x00 ..}
  81. vpsllw ymm7, ymm7, 7 ; ymm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
  82. vpand ymm4, ymm0, ymm5 ; ymm4=Cb(02468ACEGIKMOQSU)=CbE
  83. vpsrlw ymm5, ymm5, BYTE_BIT ; ymm5=Cb(13579BDFHJLNPRTV)=CbO
  84. vpand ymm0, ymm0, ymm1 ; ymm0=Cr(02468ACEGIKMOQSU)=CrE
  85. vpsrlw ymm1, ymm1, BYTE_BIT ; ymm1=Cr(13579BDFHJLNPRTV)=CrO
  86. vpaddw ymm2, ymm4, ymm7
  87. vpaddw ymm3, ymm5, ymm7
  88. vpaddw ymm6, ymm0, ymm7
  89. vpaddw ymm7, ymm1, ymm7
  90. ; (Original)
  91. ; R = Y + 1.40200 * Cr
  92. ; G = Y - 0.34414 * Cb - 0.71414 * Cr
  93. ; B = Y + 1.77200 * Cb
  94. ;
  95. ; (This implementation)
  96. ; R = Y + 0.40200 * Cr + Cr
  97. ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
  98. ; B = Y - 0.22800 * Cb + Cb + Cb
  99. vpaddw ymm4, ymm2, ymm2 ; ymm4=2*CbE
  100. vpaddw ymm5, ymm3, ymm3 ; ymm5=2*CbO
  101. vpaddw ymm0, ymm6, ymm6 ; ymm0=2*CrE
  102. vpaddw ymm1, ymm7, ymm7 ; ymm1=2*CrO
  103. vpmulhw ymm4, ymm4, [rel PW_MF0228] ; ymm4=(2*CbE * -FIX(0.22800))
  104. vpmulhw ymm5, ymm5, [rel PW_MF0228] ; ymm5=(2*CbO * -FIX(0.22800))
  105. vpmulhw ymm0, ymm0, [rel PW_F0402] ; ymm0=(2*CrE * FIX(0.40200))
  106. vpmulhw ymm1, ymm1, [rel PW_F0402] ; ymm1=(2*CrO * FIX(0.40200))
  107. vpaddw ymm4, ymm4, [rel PW_ONE]
  108. vpaddw ymm5, ymm5, [rel PW_ONE]
  109. vpsraw ymm4, ymm4, 1 ; ymm4=(CbE * -FIX(0.22800))
  110. vpsraw ymm5, ymm5, 1 ; ymm5=(CbO * -FIX(0.22800))
  111. vpaddw ymm0, ymm0, [rel PW_ONE]
  112. vpaddw ymm1, ymm1, [rel PW_ONE]
  113. vpsraw ymm0, ymm0, 1 ; ymm0=(CrE * FIX(0.40200))
  114. vpsraw ymm1, ymm1, 1 ; ymm1=(CrO * FIX(0.40200))
  115. vpaddw ymm4, ymm4, ymm2
  116. vpaddw ymm5, ymm5, ymm3
  117. vpaddw ymm4, ymm4, ymm2 ; ymm4=(CbE * FIX(1.77200))=(B-Y)E
  118. vpaddw ymm5, ymm5, ymm3 ; ymm5=(CbO * FIX(1.77200))=(B-Y)O
  119. vpaddw ymm0, ymm0, ymm6 ; ymm0=(CrE * FIX(1.40200))=(R-Y)E
  120. vpaddw ymm1, ymm1, ymm7 ; ymm1=(CrO * FIX(1.40200))=(R-Y)O
  121. vmovdqa YMMWORD [wk(0)], ymm4 ; wk(0)=(B-Y)E
  122. vmovdqa YMMWORD [wk(1)], ymm5 ; wk(1)=(B-Y)O
  123. vpunpckhwd ymm4, ymm2, ymm6
  124. vpunpcklwd ymm2, ymm2, ymm6
  125. vpmaddwd ymm2, ymm2, [rel PW_MF0344_F0285]
  126. vpmaddwd ymm4, ymm4, [rel PW_MF0344_F0285]
  127. vpunpckhwd ymm5, ymm3, ymm7
  128. vpunpcklwd ymm3, ymm3, ymm7
  129. vpmaddwd ymm3, ymm3, [rel PW_MF0344_F0285]
  130. vpmaddwd ymm5, ymm5, [rel PW_MF0344_F0285]
  131. vpaddd ymm2, ymm2, [rel PD_ONEHALF]
  132. vpaddd ymm4, ymm4, [rel PD_ONEHALF]
  133. vpsrad ymm2, ymm2, SCALEBITS
  134. vpsrad ymm4, ymm4, SCALEBITS
  135. vpaddd ymm3, ymm3, [rel PD_ONEHALF]
  136. vpaddd ymm5, ymm5, [rel PD_ONEHALF]
  137. vpsrad ymm3, ymm3, SCALEBITS
  138. vpsrad ymm5, ymm5, SCALEBITS
  139. vpackssdw ymm2, ymm2, ymm4 ; ymm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
  140. vpackssdw ymm3, ymm3, ymm5 ; ymm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
  141. vpsubw ymm2, ymm2, ymm6 ; ymm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
  142. vpsubw ymm3, ymm3, ymm7 ; ymm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
  143. vmovdqu ymm5, YMMWORD [rsi] ; ymm5=Y(0123456789ABCDEFGHIJKLMNOPQRSTUV)
  144. vpcmpeqw ymm4, ymm4, ymm4
  145. vpsrlw ymm4, ymm4, BYTE_BIT ; ymm4={0xFF 0x00 0xFF 0x00 ..}
  146. vpand ymm4, ymm4, ymm5 ; ymm4=Y(02468ACEGIKMOQSU)=YE
  147. vpsrlw ymm5, ymm5, BYTE_BIT ; ymm5=Y(13579BDFHJLNPRTV)=YO
  148. vpaddw ymm0, ymm0, ymm4 ; ymm0=((R-Y)E+YE)=RE=R(02468ACEGIKMOQSU)
  149. vpaddw ymm1, ymm1, ymm5 ; ymm1=((R-Y)O+YO)=RO=R(13579BDFHJLNPRTV)
  150. vpackuswb ymm0, ymm0, ymm0 ; ymm0=R(02468ACE********GIKMOQSU********)
  151. vpackuswb ymm1, ymm1, ymm1 ; ymm1=R(13579BDF********HJLNPRTV********)
  152. vpaddw ymm2, ymm2, ymm4 ; ymm2=((G-Y)E+YE)=GE=G(02468ACEGIKMOQSU)
  153. vpaddw ymm3, ymm3, ymm5 ; ymm3=((G-Y)O+YO)=GO=G(13579BDFHJLNPRTV)
  154. vpackuswb ymm2, ymm2, ymm2 ; ymm2=G(02468ACE********GIKMOQSU********)
  155. vpackuswb ymm3, ymm3, ymm3 ; ymm3=G(13579BDF********HJLNPRTV********)
  156. vpaddw ymm4, ymm4, YMMWORD [wk(0)] ; ymm4=(YE+(B-Y)E)=BE=B(02468ACEGIKMOQSU)
  157. vpaddw ymm5, ymm5, YMMWORD [wk(1)] ; ymm5=(YO+(B-Y)O)=BO=B(13579BDFHJLNPRTV)
  158. vpackuswb ymm4, ymm4, ymm4 ; ymm4=B(02468ACE********GIKMOQSU********)
  159. vpackuswb ymm5, ymm5, ymm5 ; ymm5=B(13579BDF********HJLNPRTV********)
  160. %if RGB_PIXELSIZE == 3 ; ---------------
  161. ; ymmA=(00 02 04 06 08 0A 0C 0E ** 0G 0I 0K 0M 0O 0Q 0S 0U **)
  162. ; ymmB=(01 03 05 07 09 0B 0D 0F ** 0H 0J 0L 0N 0P 0R 0T 0V **)
  163. ; ymmC=(10 12 14 16 18 1A 1C 1E ** 1G 1I 1K 1M 1O 1Q 1S 1U **)
  164. ; ymmD=(11 13 15 17 19 1B 1D 1F ** 1H 1J 1L 1N 1P 1R 1T 1V **)
  165. ; ymmE=(20 22 24 26 28 2A 2C 2E ** 2G 2I 2K 2M 2O 2Q 2S 2U **)
  166. ; ymmF=(21 23 25 27 29 2B 2D 2F ** 2H 2J 2L 2N 2P 2R 2T 2V **)
  167. ; ymmG=(** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **)
  168. ; ymmH=(** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **)
  169. vpunpcklbw ymmA, ymmA, ymmC ; ymmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E
  170. ; 0G 1G 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U)
  171. vpunpcklbw ymmE, ymmE, ymmB ; ymmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F
  172. ; 2G 0H 2I 0J 2K 0L 2M 0N 2O 0P 2Q 0R 2S 0T 2U 0V)
  173. vpunpcklbw ymmD, ymmD, ymmF ; ymmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F
  174. ; 1H 2H 1J 2J 1L 2L 1N 2N 1P 2P 1R 2R 1T 2T 1V 2V)
  175. vpsrldq ymmH, ymmA, 2 ; ymmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E 0G 1G
  176. ; 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U -- --)
  177. vpunpckhwd ymmG, ymmA, ymmE ; ymmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F
  178. ; 0O 1O 2O 0P 0Q 1Q 2Q 0R 0S 1S 2S 0T 0U 1U 2U 0V)
  179. vpunpcklwd ymmA, ymmA, ymmE ; ymmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07
  180. ; 0G 1G 2G 0H 0I 1I 2I 0J 0K 1K 2K 0L 0M 1M 2M 0N)
  181. vpsrldq ymmE, ymmE, 2 ; ymmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F 2G 0H
  182. ; 2I 0J 2K 0L 2M 0N 2O 0P 2Q 0R 2S 0T 2U 0V -- --)
  183. vpsrldq ymmB, ymmD, 2 ; ymmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F 1H 2H
  184. ; 1J 2J 1L 2L 1N 2N 1P 2P 1R 2R 1T 2T 1V 2V -- --)
  185. vpunpckhwd ymmC, ymmD, ymmH ; ymmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F 0G 1G
  186. ; 1P 2P 0Q 1Q 1R 2R 0S 1S 1T 2T 0U 1U 1V 2V -- --)
  187. vpunpcklwd ymmD, ymmD, ymmH ; ymmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18
  188. ; 1H 2H 0I 1I 1J 2J 0K 1K 1L 2L 0M 1M 1N 2N 0O 1O)
  189. vpunpckhwd ymmF, ymmE, ymmB ; ymmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F 2G 0H 1H 2H
  190. ; 2Q 0R 1R 2R 2S 0T 1T 2T 2U 0V 1V 2V -- -- -- --)
  191. vpunpcklwd ymmE, ymmE, ymmB ; ymmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29
  192. ; 2I 0J 1J 2J 2K 0L 1L 2L 2M 0N 1N 2N 2O 0P 1P 2P)
  193. vpshufd ymmH, ymmA, 0x4E ; ymmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03
  194. ; 0K 1K 2K 0L 0M 1M 2M 0N 0G 1G 2G 0H 0I 1I 2I 0J)
  195. vpunpckldq ymmA, ymmA, ymmD ; ymmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14
  196. ; 0G 1G 2G 0H 1H 2H 0I 1I 0I 1I 2I 0J 1J 2J 0K 1K)
  197. vpunpckhdq ymmD, ymmD, ymmE ; ymmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29
  198. ; 1L 2L 0M 1M 2M 0N 1N 2N 1N 2N 0O 1O 2O 0P 1P 2P)
  199. vpunpckldq ymmE, ymmE, ymmH ; ymmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07
  200. ; 2I 0J 1J 2J 0K 1K 2K 0L 2K 0L 1L 2L 0M 1M 2M 0N)
  201. vpshufd ymmH, ymmG, 0x4E ; ymmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B
  202. ; 0S 1S 2S 0T 0U 1U 2U 0V 0O 1O 2O 0P 0Q 1Q 2Q 0R)
  203. vpunpckldq ymmG, ymmG, ymmC ; ymmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C
  204. ; 0O 1O 2O 0P 1P 2P 0Q 1Q 0Q 1Q 2Q 0R 1R 2R 0S 1S)
  205. vpunpckhdq ymmC, ymmC, ymmF ; ymmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F 0G 1G 2G 0H 1H 2H
  206. ; 1T 2T 0U 1U 2U 0V 1V 2V 1V 2V -- -- -- -- -- --)
  207. vpunpckldq ymmF, ymmF, ymmH ; ymmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F
  208. ; 2Q 0R 1R 2R 0S 1S 2S 0T 2S 0T 1T 2T 0U 1U 2U 0V)
  209. vpunpcklqdq ymmH, ymmA, ymmE ; ymmH=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
  210. ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
  211. vpunpcklqdq ymmG, ymmD, ymmG ; ymmG=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A
  212. ; 1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q)
  213. vpunpcklqdq ymmC, ymmF, ymmC ; ymmC=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
  214. ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
  215. vperm2i128 ymmA, ymmH, ymmG, 0x20 ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
  216. ; 15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
  217. vperm2i128 ymmD, ymmC, ymmH, 0x30 ; ymmD=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
  218. ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
  219. vperm2i128 ymmF, ymmG, ymmC, 0x31 ; ymmF=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q
  220. ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
  221. cmp rcx, byte SIZEOF_YMMWORD
  222. jb short .column_st64
  223. test rdi, SIZEOF_YMMWORD-1
  224. jnz short .out1
  225. ; --(aligned)-------------------
  226. vmovntdq YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  227. vmovntdq YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  228. vmovntdq YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmF
  229. jmp short .out0
  230. .out1: ; --(unaligned)-----------------
  231. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  232. vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  233. vmovdqu YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmF
  234. .out0:
  235. add rdi, byte RGB_PIXELSIZE*SIZEOF_YMMWORD ; outptr
  236. sub rcx, byte SIZEOF_YMMWORD
  237. jz near .nextrow
  238. add rsi, byte SIZEOF_YMMWORD ; inptr0
  239. add rbx, byte SIZEOF_YMMWORD ; inptr1
  240. add rdx, byte SIZEOF_YMMWORD ; inptr2
  241. jmp near .columnloop
  242. .column_st64:
  243. lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE
  244. cmp rcx, byte 2*SIZEOF_YMMWORD
  245. jb short .column_st32
  246. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  247. vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  248. add rdi, byte 2*SIZEOF_YMMWORD ; outptr
  249. vmovdqa ymmA, ymmF
  250. sub rcx, byte 2*SIZEOF_YMMWORD
  251. jmp short .column_st31
  252. .column_st32:
  253. cmp rcx, byte SIZEOF_YMMWORD
  254. jb short .column_st31
  255. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  256. add rdi, byte SIZEOF_YMMWORD ; outptr
  257. vmovdqa ymmA, ymmD
  258. sub rcx, byte SIZEOF_YMMWORD
  259. jmp short .column_st31
  260. .column_st31:
  261. cmp rcx, byte SIZEOF_XMMWORD
  262. jb short .column_st15
  263. vmovdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  264. add rdi, byte SIZEOF_XMMWORD ; outptr
  265. vperm2i128 ymmA, ymmA, ymmA, 1
  266. sub rcx, byte SIZEOF_XMMWORD
  267. .column_st15:
  268. ; Store the lower 8 bytes of xmmA to the output when it has enough
  269. ; space.
  270. cmp rcx, byte SIZEOF_MMWORD
  271. jb short .column_st7
  272. vmovq XMM_MMWORD [rdi], xmmA
  273. add rdi, byte SIZEOF_MMWORD
  274. sub rcx, byte SIZEOF_MMWORD
  275. vpsrldq xmmA, xmmA, SIZEOF_MMWORD
  276. .column_st7:
  277. ; Store the lower 4 bytes of xmmA to the output when it has enough
  278. ; space.
  279. cmp rcx, byte SIZEOF_DWORD
  280. jb short .column_st3
  281. vmovd XMM_DWORD [rdi], xmmA
  282. add rdi, byte SIZEOF_DWORD
  283. sub rcx, byte SIZEOF_DWORD
  284. vpsrldq xmmA, xmmA, SIZEOF_DWORD
  285. .column_st3:
  286. ; Store the lower 2 bytes of rax to the output when it has enough
  287. ; space.
  288. vmovd eax, xmmA
  289. cmp rcx, byte SIZEOF_WORD
  290. jb short .column_st1
  291. mov word [rdi], ax
  292. add rdi, byte SIZEOF_WORD
  293. sub rcx, byte SIZEOF_WORD
  294. shr rax, 16
  295. .column_st1:
  296. ; Store the lower 1 byte of rax to the output when it has enough
  297. ; space.
  298. test rcx, rcx
  299. jz short .nextrow
  300. mov byte [rdi], al
  301. %else ; RGB_PIXELSIZE == 4 ; -----------
  302. %ifdef RGBX_FILLER_0XFF
  303. vpcmpeqb ymm6, ymm6, ymm6 ; ymm6=XE=X(02468ACE********GIKMOQSU********)
  304. vpcmpeqb ymm7, ymm7, ymm7 ; ymm7=XO=X(13579BDF********HJLNPRTV********)
  305. %else
  306. vpxor ymm6, ymm6, ymm6 ; ymm6=XE=X(02468ACE********GIKMOQSU********)
  307. vpxor ymm7, ymm7, ymm7 ; ymm7=XO=X(13579BDF********HJLNPRTV********)
  308. %endif
  309. ; ymmA=(00 02 04 06 08 0A 0C 0E ** 0G 0I 0K 0M 0O 0Q 0S 0U **)
  310. ; ymmB=(01 03 05 07 09 0B 0D 0F ** 0H 0J 0L 0N 0P 0R 0T 0V **)
  311. ; ymmC=(10 12 14 16 18 1A 1C 1E ** 1G 1I 1K 1M 1O 1Q 1S 1U **)
  312. ; ymmD=(11 13 15 17 19 1B 1D 1F ** 1H 1J 1L 1N 1P 1R 1T 1V **)
  313. ; ymmE=(20 22 24 26 28 2A 2C 2E ** 2G 2I 2K 2M 2O 2Q 2S 2U **)
  314. ; ymmF=(21 23 25 27 29 2B 2D 2F ** 2H 2J 2L 2N 2P 2R 2T 2V **)
  315. ; ymmG=(30 32 34 36 38 3A 3C 3E ** 3G 3I 3K 3M 3O 3Q 3S 3U **)
  316. ; ymmH=(31 33 35 37 39 3B 3D 3F ** 3H 3J 3L 3N 3P 3R 3T 3V **)
  317. vpunpcklbw ymmA, ymmA, ymmC ; ymmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E
  318. ; 0G 1G 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U)
  319. vpunpcklbw ymmE, ymmE, ymmG ; ymmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E
  320. ; 2G 3G 2I 3I 2K 3K 2M 3M 2O 3O 2Q 3Q 2S 3S 2U 3U)
  321. vpunpcklbw ymmB, ymmB, ymmD ; ymmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F
  322. ; 0H 1H 0J 1J 0L 1L 0N 1N 0P 1P 0R 1R 0T 1T 0V 1V)
  323. vpunpcklbw ymmF, ymmF, ymmH ; ymmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F
  324. ; 2H 3H 2J 3J 2L 3L 2N 3N 2P 3P 2R 3R 2T 3T 2V 3V)
  325. vpunpckhwd ymmC, ymmA, ymmE ; ymmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E
  326. ; 0O 1O 2O 3O 0Q 1Q 2Q 3Q 0S 1S 2S 3S 0U 1U 2U 3U)
  327. vpunpcklwd ymmA, ymmA, ymmE ; ymmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36
  328. ; 0G 1G 2G 3G 0I 1I 2I 3I 0K 1K 2K 3K 0M 1M 2M 3M)
  329. vpunpckhwd ymmG, ymmB, ymmF ; ymmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F
  330. ; 0P 1P 2P 3P 0R 1R 2R 3R 0T 1T 2T 3T 0V 1V 2V 3V)
  331. vpunpcklwd ymmB, ymmB, ymmF ; ymmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37
  332. ; 0H 1H 2H 3H 0J 1J 2J 3J 0L 1L 2L 3L 0N 1N 2N 3N)
  333. vpunpckhdq ymmE, ymmA, ymmB ; ymmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37
  334. ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
  335. vpunpckldq ymmB, ymmA, ymmB ; ymmB=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
  336. ; 0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J)
  337. vpunpckhdq ymmF, ymmC, ymmG ; ymmF=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F
  338. ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
  339. vpunpckldq ymmG, ymmC, ymmG ; ymmG=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
  340. ; 0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R)
  341. vperm2i128 ymmA, ymmB, ymmE, 0x20 ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
  342. ; 04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
  343. vperm2i128 ymmD, ymmG, ymmF, 0x20 ; ymmD=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
  344. ; 0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
  345. vperm2i128 ymmC, ymmB, ymmE, 0x31 ; ymmC=(0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J
  346. ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
  347. vperm2i128 ymmH, ymmG, ymmF, 0x31 ; ymmH=(0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R
  348. ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
  349. cmp rcx, byte SIZEOF_YMMWORD
  350. jb short .column_st64
  351. test rdi, SIZEOF_YMMWORD-1
  352. jnz short .out1
  353. ; --(aligned)-------------------
  354. vmovntdq YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  355. vmovntdq YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  356. vmovntdq YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmC
  357. vmovntdq YMMWORD [rdi+3*SIZEOF_YMMWORD], ymmH
  358. jmp short .out0
  359. .out1: ; --(unaligned)-----------------
  360. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  361. vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  362. vmovdqu YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmC
  363. vmovdqu YMMWORD [rdi+3*SIZEOF_YMMWORD], ymmH
  364. .out0:
  365. add rdi, RGB_PIXELSIZE*SIZEOF_YMMWORD ; outptr
  366. sub rcx, byte SIZEOF_YMMWORD
  367. jz near .nextrow
  368. add rsi, byte SIZEOF_YMMWORD ; inptr0
  369. add rbx, byte SIZEOF_YMMWORD ; inptr1
  370. add rdx, byte SIZEOF_YMMWORD ; inptr2
  371. jmp near .columnloop
  372. .column_st64:
  373. cmp rcx, byte SIZEOF_YMMWORD/2
  374. jb short .column_st32
  375. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  376. vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
  377. add rdi, byte 2*SIZEOF_YMMWORD ; outptr
  378. vmovdqa ymmA, ymmC
  379. vmovdqa ymmD, ymmH
  380. sub rcx, byte SIZEOF_YMMWORD/2
  381. .column_st32:
  382. cmp rcx, byte SIZEOF_YMMWORD/4
  383. jb short .column_st16
  384. vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
  385. add rdi, byte SIZEOF_YMMWORD ; outptr
  386. vmovdqa ymmA, ymmD
  387. sub rcx, byte SIZEOF_YMMWORD/4
  388. .column_st16:
  389. cmp rcx, byte SIZEOF_YMMWORD/8
  390. jb short .column_st15
  391. vmovdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  392. vperm2i128 ymmA, ymmA, ymmA, 1
  393. add rdi, byte SIZEOF_XMMWORD ; outptr
  394. sub rcx, byte SIZEOF_YMMWORD/8
  395. .column_st15:
  396. ; Store two pixels (8 bytes) of ymmA to the output when it has enough
  397. ; space.
  398. cmp rcx, byte SIZEOF_YMMWORD/16
  399. jb short .column_st7
  400. vmovq MMWORD [rdi], xmmA
  401. add rdi, byte SIZEOF_YMMWORD/16*4
  402. sub rcx, byte SIZEOF_YMMWORD/16
  403. vpsrldq xmmA, SIZEOF_YMMWORD/16*4
  404. .column_st7:
  405. ; Store one pixel (4 bytes) of ymmA to the output when it has enough
  406. ; space.
  407. test rcx, rcx
  408. jz short .nextrow
  409. vmovd XMM_DWORD [rdi], xmmA
  410. %endif ; RGB_PIXELSIZE ; ---------------
  411. .nextrow:
  412. pop rcx
  413. pop rsi
  414. pop rbx
  415. pop rdx
  416. pop rdi
  417. pop rax
  418. add rsi, byte SIZEOF_JSAMPROW
  419. add rbx, byte SIZEOF_JSAMPROW
  420. add rdx, byte SIZEOF_JSAMPROW
  421. add rdi, byte SIZEOF_JSAMPROW ; output_buf
  422. dec rax ; num_rows
  423. jg near .rowloop
  424. sfence ; flush the write buffer
  425. .return:
  426. pop rbx
  427. vzeroupper
  428. uncollect_args 5
  429. mov rsp, rbp ; rsp <- aligned rbp
  430. pop rsp ; rsp <- original rbp
  431. pop rbp
  432. ret
  433. ; For some reason, the OS X linker does not honor the request to align the
  434. ; segment unless we do this.
  435. align 32