jidctfst-sse2.asm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. ;
  2. ; jidctfst.asm - fast integer IDCT (64-bit SSE2)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ; Copyright (C) 2009, 2016, D. R. Commander.
  6. ;
  7. ; Based on the x86 SIMD extension for IJG JPEG library
  8. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  9. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  10. ;
  11. ; This file should be assembled with NASM (Netwide Assembler),
  12. ; can *not* be assembled with Microsoft's MASM or any compatible
  13. ; assembler (including Borland's Turbo Assembler).
  14. ; NASM is available from http://nasm.sourceforge.net/ or
  15. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  16. ;
  17. ; This file contains a fast, not so accurate integer implementation of
  18. ; the inverse DCT (Discrete Cosine Transform). The following code is
  19. ; based directly on the IJG's original jidctfst.c; see the jidctfst.c
  20. ; for more details.
  21. %include "jsimdext.inc"
  22. %include "jdct.inc"
  23. ; --------------------------------------------------------------------------
  24. %define CONST_BITS 8 ; 14 is also OK.
  25. %define PASS1_BITS 2
  26. %if IFAST_SCALE_BITS != PASS1_BITS
  27. %error "'IFAST_SCALE_BITS' must be equal to 'PASS1_BITS'."
  28. %endif
  29. %if CONST_BITS == 8
  30. F_1_082 equ 277 ; FIX(1.082392200)
  31. F_1_414 equ 362 ; FIX(1.414213562)
  32. F_1_847 equ 473 ; FIX(1.847759065)
  33. F_2_613 equ 669 ; FIX(2.613125930)
  34. F_1_613 equ (F_2_613 - 256) ; FIX(2.613125930) - FIX(1)
  35. %else
  36. ; NASM cannot do compile-time arithmetic on floating-point constants.
  37. %define DESCALE(x, n) (((x) + (1 << ((n) - 1))) >> (n))
  38. F_1_082 equ DESCALE(1162209775, 30 - CONST_BITS) ; FIX(1.082392200)
  39. F_1_414 equ DESCALE(1518500249, 30 - CONST_BITS) ; FIX(1.414213562)
  40. F_1_847 equ DESCALE(1984016188, 30 - CONST_BITS) ; FIX(1.847759065)
  41. F_2_613 equ DESCALE(2805822602, 30 - CONST_BITS) ; FIX(2.613125930)
  42. F_1_613 equ (F_2_613 - (1 << CONST_BITS)) ; FIX(2.613125930) - FIX(1)
  43. %endif
  44. ; --------------------------------------------------------------------------
  45. SECTION SEG_CONST
  46. ; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
  47. ; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
  48. %define PRE_MULTIPLY_SCALE_BITS 2
  49. %define CONST_SHIFT (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
  50. alignz 32
  51. GLOBAL_DATA(jconst_idct_ifast_sse2)
  52. EXTN(jconst_idct_ifast_sse2):
  53. PW_F1414 times 8 dw F_1_414 << CONST_SHIFT
  54. PW_F1847 times 8 dw F_1_847 << CONST_SHIFT
  55. PW_MF1613 times 8 dw -F_1_613 << CONST_SHIFT
  56. PW_F1082 times 8 dw F_1_082 << CONST_SHIFT
  57. PB_CENTERJSAMP times 16 db CENTERJSAMPLE
  58. alignz 32
  59. ; --------------------------------------------------------------------------
  60. SECTION SEG_TEXT
  61. BITS 64
  62. ;
  63. ; Perform dequantization and inverse DCT on one block of coefficients.
  64. ;
  65. ; GLOBAL(void)
  66. ; jsimd_idct_ifast_sse2(void *dct_table, JCOEFPTR coef_block,
  67. ; JSAMPARRAY output_buf, JDIMENSION output_col)
  68. ;
  69. ; r10 = jpeg_component_info *compptr
  70. ; r11 = JCOEFPTR coef_block
  71. ; r12 = JSAMPARRAY output_buf
  72. ; r13d = JDIMENSION output_col
  73. %define original_rbp rbp + 0
  74. %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_XMMWORD
  75. ; xmmword wk[WK_NUM]
  76. %define WK_NUM 2
  77. align 32
  78. GLOBAL_FUNCTION(jsimd_idct_ifast_sse2)
  79. EXTN(jsimd_idct_ifast_sse2):
  80. push rbp
  81. mov rax, rsp ; rax = original rbp
  82. sub rsp, byte 4
  83. and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
  84. mov [rsp], rax
  85. mov rbp, rsp ; rbp = aligned rbp
  86. lea rsp, [wk(0)]
  87. collect_args 4
  88. ; ---- Pass 1: process columns from input.
  89. mov rdx, r10 ; quantptr
  90. mov rsi, r11 ; inptr
  91. %ifndef NO_ZERO_COLUMN_TEST_IFAST_SSE2
  92. mov eax, dword [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
  93. or eax, dword [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
  94. jnz near .columnDCT
  95. movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
  96. movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
  97. por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
  98. por xmm1, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
  99. por xmm0, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
  100. por xmm1, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
  101. por xmm0, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
  102. por xmm1, xmm0
  103. packsswb xmm1, xmm1
  104. packsswb xmm1, xmm1
  105. movd eax, xmm1
  106. test rax, rax
  107. jnz short .columnDCT
  108. ; -- AC terms all zero
  109. movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
  110. pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  111. movdqa xmm7, xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07)
  112. punpcklwd xmm0, xmm0 ; xmm0=(00 00 01 01 02 02 03 03)
  113. punpckhwd xmm7, xmm7 ; xmm7=(04 04 05 05 06 06 07 07)
  114. pshufd xmm6, xmm0, 0x00 ; xmm6=col0=(00 00 00 00 00 00 00 00)
  115. pshufd xmm2, xmm0, 0x55 ; xmm2=col1=(01 01 01 01 01 01 01 01)
  116. pshufd xmm5, xmm0, 0xAA ; xmm5=col2=(02 02 02 02 02 02 02 02)
  117. pshufd xmm0, xmm0, 0xFF ; xmm0=col3=(03 03 03 03 03 03 03 03)
  118. pshufd xmm1, xmm7, 0x00 ; xmm1=col4=(04 04 04 04 04 04 04 04)
  119. pshufd xmm4, xmm7, 0x55 ; xmm4=col5=(05 05 05 05 05 05 05 05)
  120. pshufd xmm3, xmm7, 0xAA ; xmm3=col6=(06 06 06 06 06 06 06 06)
  121. pshufd xmm7, xmm7, 0xFF ; xmm7=col7=(07 07 07 07 07 07 07 07)
  122. movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=col1
  123. movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=col3
  124. jmp near .column_end
  125. %endif
  126. .columnDCT:
  127. ; -- Even part
  128. movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
  129. movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
  130. pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
  131. pmullw xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
  132. movdqa xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)]
  133. movdqa xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
  134. pmullw xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
  135. pmullw xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
  136. movdqa xmm4, xmm0
  137. movdqa xmm5, xmm1
  138. psubw xmm0, xmm2 ; xmm0=tmp11
  139. psubw xmm1, xmm3
  140. paddw xmm4, xmm2 ; xmm4=tmp10
  141. paddw xmm5, xmm3 ; xmm5=tmp13
  142. psllw xmm1, PRE_MULTIPLY_SCALE_BITS
  143. pmulhw xmm1, [rel PW_F1414]
  144. psubw xmm1, xmm5 ; xmm1=tmp12
  145. movdqa xmm6, xmm4
  146. movdqa xmm7, xmm0
  147. psubw xmm4, xmm5 ; xmm4=tmp3
  148. psubw xmm0, xmm1 ; xmm0=tmp2
  149. paddw xmm6, xmm5 ; xmm6=tmp0
  150. paddw xmm7, xmm1 ; xmm7=tmp1
  151. movdqa XMMWORD [wk(1)], xmm4 ; wk(1)=tmp3
  152. movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=tmp2
  153. ; -- Odd part
  154. movdqa xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
  155. movdqa xmm3, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
  156. pmullw xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
  157. pmullw xmm3, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
  158. movdqa xmm5, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
  159. movdqa xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
  160. pmullw xmm5, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
  161. pmullw xmm1, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_IFAST_MULT_TYPE)]
  162. movdqa xmm4, xmm2
  163. movdqa xmm0, xmm5
  164. psubw xmm2, xmm1 ; xmm2=z12
  165. psubw xmm5, xmm3 ; xmm5=z10
  166. paddw xmm4, xmm1 ; xmm4=z11
  167. paddw xmm0, xmm3 ; xmm0=z13
  168. movdqa xmm1, xmm5 ; xmm1=z10(unscaled)
  169. psllw xmm2, PRE_MULTIPLY_SCALE_BITS
  170. psllw xmm5, PRE_MULTIPLY_SCALE_BITS
  171. movdqa xmm3, xmm4
  172. psubw xmm4, xmm0
  173. paddw xmm3, xmm0 ; xmm3=tmp7
  174. psllw xmm4, PRE_MULTIPLY_SCALE_BITS
  175. pmulhw xmm4, [rel PW_F1414] ; xmm4=tmp11
  176. ; To avoid overflow...
  177. ;
  178. ; (Original)
  179. ; tmp12 = -2.613125930 * z10 + z5;
  180. ;
  181. ; (This implementation)
  182. ; tmp12 = (-1.613125930 - 1) * z10 + z5;
  183. ; = -1.613125930 * z10 - z10 + z5;
  184. movdqa xmm0, xmm5
  185. paddw xmm5, xmm2
  186. pmulhw xmm5, [rel PW_F1847] ; xmm5=z5
  187. pmulhw xmm0, [rel PW_MF1613]
  188. pmulhw xmm2, [rel PW_F1082]
  189. psubw xmm0, xmm1
  190. psubw xmm2, xmm5 ; xmm2=tmp10
  191. paddw xmm0, xmm5 ; xmm0=tmp12
  192. ; -- Final output stage
  193. psubw xmm0, xmm3 ; xmm0=tmp6
  194. movdqa xmm1, xmm6
  195. movdqa xmm5, xmm7
  196. paddw xmm6, xmm3 ; xmm6=data0=(00 01 02 03 04 05 06 07)
  197. paddw xmm7, xmm0 ; xmm7=data1=(10 11 12 13 14 15 16 17)
  198. psubw xmm1, xmm3 ; xmm1=data7=(70 71 72 73 74 75 76 77)
  199. psubw xmm5, xmm0 ; xmm5=data6=(60 61 62 63 64 65 66 67)
  200. psubw xmm4, xmm0 ; xmm4=tmp5
  201. movdqa xmm3, xmm6 ; transpose coefficients(phase 1)
  202. punpcklwd xmm6, xmm7 ; xmm6=(00 10 01 11 02 12 03 13)
  203. punpckhwd xmm3, xmm7 ; xmm3=(04 14 05 15 06 16 07 17)
  204. movdqa xmm0, xmm5 ; transpose coefficients(phase 1)
  205. punpcklwd xmm5, xmm1 ; xmm5=(60 70 61 71 62 72 63 73)
  206. punpckhwd xmm0, xmm1 ; xmm0=(64 74 65 75 66 76 67 77)
  207. movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp2
  208. movdqa xmm1, XMMWORD [wk(1)] ; xmm1=tmp3
  209. movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(60 70 61 71 62 72 63 73)
  210. movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(64 74 65 75 66 76 67 77)
  211. paddw xmm2, xmm4 ; xmm2=tmp4
  212. movdqa xmm5, xmm7
  213. movdqa xmm0, xmm1
  214. paddw xmm7, xmm4 ; xmm7=data2=(20 21 22 23 24 25 26 27)
  215. paddw xmm1, xmm2 ; xmm1=data4=(40 41 42 43 44 45 46 47)
  216. psubw xmm5, xmm4 ; xmm5=data5=(50 51 52 53 54 55 56 57)
  217. psubw xmm0, xmm2 ; xmm0=data3=(30 31 32 33 34 35 36 37)
  218. movdqa xmm4, xmm7 ; transpose coefficients(phase 1)
  219. punpcklwd xmm7, xmm0 ; xmm7=(20 30 21 31 22 32 23 33)
  220. punpckhwd xmm4, xmm0 ; xmm4=(24 34 25 35 26 36 27 37)
  221. movdqa xmm2, xmm1 ; transpose coefficients(phase 1)
  222. punpcklwd xmm1, xmm5 ; xmm1=(40 50 41 51 42 52 43 53)
  223. punpckhwd xmm2, xmm5 ; xmm2=(44 54 45 55 46 56 47 57)
  224. movdqa xmm0, xmm3 ; transpose coefficients(phase 2)
  225. punpckldq xmm3, xmm4 ; xmm3=(04 14 24 34 05 15 25 35)
  226. punpckhdq xmm0, xmm4 ; xmm0=(06 16 26 36 07 17 27 37)
  227. movdqa xmm5, xmm6 ; transpose coefficients(phase 2)
  228. punpckldq xmm6, xmm7 ; xmm6=(00 10 20 30 01 11 21 31)
  229. punpckhdq xmm5, xmm7 ; xmm5=(02 12 22 32 03 13 23 33)
  230. movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(60 70 61 71 62 72 63 73)
  231. movdqa xmm7, XMMWORD [wk(1)] ; xmm7=(64 74 65 75 66 76 67 77)
  232. movdqa XMMWORD [wk(0)], xmm3 ; wk(0)=(04 14 24 34 05 15 25 35)
  233. movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=(06 16 26 36 07 17 27 37)
  234. movdqa xmm3, xmm1 ; transpose coefficients(phase 2)
  235. punpckldq xmm1, xmm4 ; xmm1=(40 50 60 70 41 51 61 71)
  236. punpckhdq xmm3, xmm4 ; xmm3=(42 52 62 72 43 53 63 73)
  237. movdqa xmm0, xmm2 ; transpose coefficients(phase 2)
  238. punpckldq xmm2, xmm7 ; xmm2=(44 54 64 74 45 55 65 75)
  239. punpckhdq xmm0, xmm7 ; xmm0=(46 56 66 76 47 57 67 77)
  240. movdqa xmm4, xmm6 ; transpose coefficients(phase 3)
  241. punpcklqdq xmm6, xmm1 ; xmm6=col0=(00 10 20 30 40 50 60 70)
  242. punpckhqdq xmm4, xmm1 ; xmm4=col1=(01 11 21 31 41 51 61 71)
  243. movdqa xmm7, xmm5 ; transpose coefficients(phase 3)
  244. punpcklqdq xmm5, xmm3 ; xmm5=col2=(02 12 22 32 42 52 62 72)
  245. punpckhqdq xmm7, xmm3 ; xmm7=col3=(03 13 23 33 43 53 63 73)
  246. movdqa xmm1, XMMWORD [wk(0)] ; xmm1=(04 14 24 34 05 15 25 35)
  247. movdqa xmm3, XMMWORD [wk(1)] ; xmm3=(06 16 26 36 07 17 27 37)
  248. movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=col1
  249. movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=col3
  250. movdqa xmm4, xmm1 ; transpose coefficients(phase 3)
  251. punpcklqdq xmm1, xmm2 ; xmm1=col4=(04 14 24 34 44 54 64 74)
  252. punpckhqdq xmm4, xmm2 ; xmm4=col5=(05 15 25 35 45 55 65 75)
  253. movdqa xmm7, xmm3 ; transpose coefficients(phase 3)
  254. punpcklqdq xmm3, xmm0 ; xmm3=col6=(06 16 26 36 46 56 66 76)
  255. punpckhqdq xmm7, xmm0 ; xmm7=col7=(07 17 27 37 47 57 67 77)
  256. .column_end:
  257. ; -- Prefetch the next coefficient block
  258. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
  259. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
  260. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
  261. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
  262. ; ---- Pass 2: process rows from work array, store into output array.
  263. mov rax, [original_rbp]
  264. mov rdi, r12 ; (JSAMPROW *)
  265. mov eax, r13d
  266. ; -- Even part
  267. ; xmm6=col0, xmm5=col2, xmm1=col4, xmm3=col6
  268. movdqa xmm2, xmm6
  269. movdqa xmm0, xmm5
  270. psubw xmm6, xmm1 ; xmm6=tmp11
  271. psubw xmm5, xmm3
  272. paddw xmm2, xmm1 ; xmm2=tmp10
  273. paddw xmm0, xmm3 ; xmm0=tmp13
  274. psllw xmm5, PRE_MULTIPLY_SCALE_BITS
  275. pmulhw xmm5, [rel PW_F1414]
  276. psubw xmm5, xmm0 ; xmm5=tmp12
  277. movdqa xmm1, xmm2
  278. movdqa xmm3, xmm6
  279. psubw xmm2, xmm0 ; xmm2=tmp3
  280. psubw xmm6, xmm5 ; xmm6=tmp2
  281. paddw xmm1, xmm0 ; xmm1=tmp0
  282. paddw xmm3, xmm5 ; xmm3=tmp1
  283. movdqa xmm0, XMMWORD [wk(0)] ; xmm0=col1
  284. movdqa xmm5, XMMWORD [wk(1)] ; xmm5=col3
  285. movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp3
  286. movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=tmp2
  287. ; -- Odd part
  288. ; xmm0=col1, xmm5=col3, xmm4=col5, xmm7=col7
  289. movdqa xmm2, xmm0
  290. movdqa xmm6, xmm4
  291. psubw xmm0, xmm7 ; xmm0=z12
  292. psubw xmm4, xmm5 ; xmm4=z10
  293. paddw xmm2, xmm7 ; xmm2=z11
  294. paddw xmm6, xmm5 ; xmm6=z13
  295. movdqa xmm7, xmm4 ; xmm7=z10(unscaled)
  296. psllw xmm0, PRE_MULTIPLY_SCALE_BITS
  297. psllw xmm4, PRE_MULTIPLY_SCALE_BITS
  298. movdqa xmm5, xmm2
  299. psubw xmm2, xmm6
  300. paddw xmm5, xmm6 ; xmm5=tmp7
  301. psllw xmm2, PRE_MULTIPLY_SCALE_BITS
  302. pmulhw xmm2, [rel PW_F1414] ; xmm2=tmp11
  303. ; To avoid overflow...
  304. ;
  305. ; (Original)
  306. ; tmp12 = -2.613125930 * z10 + z5;
  307. ;
  308. ; (This implementation)
  309. ; tmp12 = (-1.613125930 - 1) * z10 + z5;
  310. ; = -1.613125930 * z10 - z10 + z5;
  311. movdqa xmm6, xmm4
  312. paddw xmm4, xmm0
  313. pmulhw xmm4, [rel PW_F1847] ; xmm4=z5
  314. pmulhw xmm6, [rel PW_MF1613]
  315. pmulhw xmm0, [rel PW_F1082]
  316. psubw xmm6, xmm7
  317. psubw xmm0, xmm4 ; xmm0=tmp10
  318. paddw xmm6, xmm4 ; xmm6=tmp12
  319. ; -- Final output stage
  320. psubw xmm6, xmm5 ; xmm6=tmp6
  321. movdqa xmm7, xmm1
  322. movdqa xmm4, xmm3
  323. paddw xmm1, xmm5 ; xmm1=data0=(00 10 20 30 40 50 60 70)
  324. paddw xmm3, xmm6 ; xmm3=data1=(01 11 21 31 41 51 61 71)
  325. psraw xmm1, (PASS1_BITS+3) ; descale
  326. psraw xmm3, (PASS1_BITS+3) ; descale
  327. psubw xmm7, xmm5 ; xmm7=data7=(07 17 27 37 47 57 67 77)
  328. psubw xmm4, xmm6 ; xmm4=data6=(06 16 26 36 46 56 66 76)
  329. psraw xmm7, (PASS1_BITS+3) ; descale
  330. psraw xmm4, (PASS1_BITS+3) ; descale
  331. psubw xmm2, xmm6 ; xmm2=tmp5
  332. packsswb xmm1, xmm4 ; xmm1=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76)
  333. packsswb xmm3, xmm7 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77)
  334. movdqa xmm5, XMMWORD [wk(1)] ; xmm5=tmp2
  335. movdqa xmm6, XMMWORD [wk(0)] ; xmm6=tmp3
  336. paddw xmm0, xmm2 ; xmm0=tmp4
  337. movdqa xmm4, xmm5
  338. movdqa xmm7, xmm6
  339. paddw xmm5, xmm2 ; xmm5=data2=(02 12 22 32 42 52 62 72)
  340. paddw xmm6, xmm0 ; xmm6=data4=(04 14 24 34 44 54 64 74)
  341. psraw xmm5, (PASS1_BITS+3) ; descale
  342. psraw xmm6, (PASS1_BITS+3) ; descale
  343. psubw xmm4, xmm2 ; xmm4=data5=(05 15 25 35 45 55 65 75)
  344. psubw xmm7, xmm0 ; xmm7=data3=(03 13 23 33 43 53 63 73)
  345. psraw xmm4, (PASS1_BITS+3) ; descale
  346. psraw xmm7, (PASS1_BITS+3) ; descale
  347. movdqa xmm2, [rel PB_CENTERJSAMP] ; xmm2=[rel PB_CENTERJSAMP]
  348. packsswb xmm5, xmm6 ; xmm5=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74)
  349. packsswb xmm7, xmm4 ; xmm7=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75)
  350. paddb xmm1, xmm2
  351. paddb xmm3, xmm2
  352. paddb xmm5, xmm2
  353. paddb xmm7, xmm2
  354. movdqa xmm0, xmm1 ; transpose coefficients(phase 1)
  355. punpcklbw xmm1, xmm3 ; xmm1=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71)
  356. punpckhbw xmm0, xmm3 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77)
  357. movdqa xmm6, xmm5 ; transpose coefficients(phase 1)
  358. punpcklbw xmm5, xmm7 ; xmm5=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73)
  359. punpckhbw xmm6, xmm7 ; xmm6=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75)
  360. movdqa xmm4, xmm1 ; transpose coefficients(phase 2)
  361. punpcklwd xmm1, xmm5 ; xmm1=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33)
  362. punpckhwd xmm4, xmm5 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73)
  363. movdqa xmm2, xmm6 ; transpose coefficients(phase 2)
  364. punpcklwd xmm6, xmm0 ; xmm6=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37)
  365. punpckhwd xmm2, xmm0 ; xmm2=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77)
  366. movdqa xmm3, xmm1 ; transpose coefficients(phase 3)
  367. punpckldq xmm1, xmm6 ; xmm1=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17)
  368. punpckhdq xmm3, xmm6 ; xmm3=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37)
  369. movdqa xmm7, xmm4 ; transpose coefficients(phase 3)
  370. punpckldq xmm4, xmm2 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57)
  371. punpckhdq xmm7, xmm2 ; xmm7=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77)
  372. pshufd xmm5, xmm1, 0x4E ; xmm5=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07)
  373. pshufd xmm0, xmm3, 0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27)
  374. pshufd xmm6, xmm4, 0x4E ; xmm6=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47)
  375. pshufd xmm2, xmm7, 0x4E ; xmm2=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67)
  376. mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
  377. mov rsi, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
  378. movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm1
  379. movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3
  380. mov rdx, JSAMPROW [rdi+4*SIZEOF_JSAMPROW]
  381. mov rsi, JSAMPROW [rdi+6*SIZEOF_JSAMPROW]
  382. movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4
  383. movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm7
  384. mov rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
  385. mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
  386. movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm5
  387. movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm0
  388. mov rdx, JSAMPROW [rdi+5*SIZEOF_JSAMPROW]
  389. mov rsi, JSAMPROW [rdi+7*SIZEOF_JSAMPROW]
  390. movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6
  391. movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm2
  392. uncollect_args 4
  393. mov rsp, rbp ; rsp <- aligned rbp
  394. pop rsp ; rsp <- original rbp
  395. pop rbp
  396. ret
  397. ret
  398. ; For some reason, the OS X linker does not honor the request to align the
  399. ; segment unless we do this.
  400. align 32