jdcolext-avx2.asm 23 KB

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