jidctflt-sse.asm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. ;
  2. ; Floating-point IDCT (SSE & MMX)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ; Copyright (C) 2016, 2024, 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) or Yasm.
  12. ;
  13. ; This file contains a floating-point implementation of the inverse DCT
  14. ; (Discrete Cosine Transform). The following code is based directly on
  15. ; the IJG's original jidctflt.c; see the jidctflt.c for more details.
  16. %include "jsimdext.inc"
  17. %include "jdct.inc"
  18. ; --------------------------------------------------------------------------
  19. %macro UNPCKLPS2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
  20. shufps %1, %2, 0x44
  21. %endmacro
  22. %macro UNPCKHPS2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
  23. shufps %1, %2, 0xEE
  24. %endmacro
  25. ; --------------------------------------------------------------------------
  26. SECTION SEG_CONST
  27. ALIGNZ 32
  28. GLOBAL_DATA(jconst_idct_float_sse)
  29. EXTN(jconst_idct_float_sse):
  30. PD_1_414 times 4 dd 1.414213562373095048801689
  31. PD_1_847 times 4 dd 1.847759065022573512256366
  32. PD_1_082 times 4 dd 1.082392200292393968799446
  33. PD_M2_613 times 4 dd -2.613125929752753055713286
  34. PD_0_125 times 4 dd 0.125 ; 1/8
  35. PB_CENTERJSAMP times 8 db CENTERJSAMPLE
  36. ALIGNZ 32
  37. ; --------------------------------------------------------------------------
  38. SECTION SEG_TEXT
  39. BITS 32
  40. ;
  41. ; Perform dequantization and inverse DCT on one block of coefficients.
  42. ;
  43. ; GLOBAL(void)
  44. ; jsimd_idct_float_sse(void *dct_table, JCOEFPTR coef_block,
  45. ; JSAMPARRAY output_buf, JDIMENSION output_col)
  46. ;
  47. %define dct_table(b) (b) + 8 ; void *dct_table
  48. %define coef_block(b) (b) + 12 ; JCOEFPTR coef_block
  49. %define output_buf(b) (b) + 16 ; JSAMPARRAY output_buf
  50. %define output_col(b) (b) + 20 ; JDIMENSION output_col
  51. %define original_ebp ebp + 0
  52. %define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_XMMWORD
  53. ; xmmword wk[WK_NUM]
  54. %define WK_NUM 2
  55. %define workspace wk(0) - DCTSIZE2 * SIZEOF_FAST_FLOAT
  56. ; FAST_FLOAT workspace[DCTSIZE2]
  57. align 32
  58. GLOBAL_FUNCTION(jsimd_idct_float_sse)
  59. EXTN(jsimd_idct_float_sse):
  60. push ebp
  61. mov eax, esp ; eax = original ebp
  62. sub esp, byte 4
  63. and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
  64. mov [esp], eax
  65. mov ebp, esp ; ebp = aligned ebp
  66. lea esp, [workspace]
  67. push ebx
  68. ; push ecx ; need not be preserved
  69. ; push edx ; need not be preserved
  70. push esi
  71. push edi
  72. GET_GOT ebx ; get GOT address
  73. ; ---- Pass 1: process columns from input, store into work array.
  74. ; mov eax, [original_ebp]
  75. mov edx, POINTER [dct_table(eax)] ; quantptr
  76. mov esi, JCOEFPTR [coef_block(eax)] ; inptr
  77. lea edi, [workspace] ; FAST_FLOAT *wsptr
  78. mov ecx, DCTSIZE/4 ; ctr
  79. ALIGNX 16, 7
  80. .columnloop:
  81. %ifndef NO_ZERO_COLUMN_TEST_FLOAT_SSE
  82. mov eax, dword [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
  83. or eax, dword [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
  84. jnz near .columnDCT
  85. movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  86. movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  87. por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  88. por mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
  89. por mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  90. por mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  91. por mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  92. por mm1, mm0
  93. packsswb mm1, mm1
  94. movd eax, mm1
  95. test eax, eax
  96. jnz short .columnDCT
  97. ; -- AC terms all zero
  98. movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  99. punpckhwd mm1, mm0 ; mm1=(** 02 ** 03)
  100. punpcklwd mm0, mm0 ; mm0=(00 00 01 01)
  101. psrad mm1, (DWORD_BIT-WORD_BIT) ; mm1=in0H=(02 03)
  102. psrad mm0, (DWORD_BIT-WORD_BIT) ; mm0=in0L=(00 01)
  103. cvtpi2ps xmm3, mm1 ; xmm3=(02 03 ** **)
  104. cvtpi2ps xmm0, mm0 ; xmm0=(00 01 ** **)
  105. movlhps xmm0, xmm3 ; xmm0=in0=(00 01 02 03)
  106. mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  107. movaps xmm1, xmm0
  108. movaps xmm2, xmm0
  109. movaps xmm3, xmm0
  110. shufps xmm0, xmm0, 0x00 ; xmm0=(00 00 00 00)
  111. shufps xmm1, xmm1, 0x55 ; xmm1=(01 01 01 01)
  112. shufps xmm2, xmm2, 0xAA ; xmm2=(02 02 02 02)
  113. shufps xmm3, xmm3, 0xFF ; xmm3=(03 03 03 03)
  114. movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm0
  115. movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0
  116. movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm1
  117. movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1
  118. movaps XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm2
  119. movaps XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm2
  120. movaps XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm3
  121. movaps XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3
  122. jmp near .nextcolumn
  123. ALIGNX 16, 7
  124. %endif
  125. .columnDCT:
  126. ; -- Even part
  127. movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  128. movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  129. movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
  130. movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  131. punpckhwd mm4, mm0 ; mm4=(** 02 ** 03)
  132. punpcklwd mm0, mm0 ; mm0=(00 00 01 01)
  133. punpckhwd mm5, mm1 ; mm5=(** 22 ** 23)
  134. punpcklwd mm1, mm1 ; mm1=(20 20 21 21)
  135. psrad mm4, (DWORD_BIT-WORD_BIT) ; mm4=in0H=(02 03)
  136. psrad mm0, (DWORD_BIT-WORD_BIT) ; mm0=in0L=(00 01)
  137. cvtpi2ps xmm4, mm4 ; xmm4=(02 03 ** **)
  138. cvtpi2ps xmm0, mm0 ; xmm0=(00 01 ** **)
  139. psrad mm5, (DWORD_BIT-WORD_BIT) ; mm5=in2H=(22 23)
  140. psrad mm1, (DWORD_BIT-WORD_BIT) ; mm1=in2L=(20 21)
  141. cvtpi2ps xmm5, mm5 ; xmm5=(22 23 ** **)
  142. cvtpi2ps xmm1, mm1 ; xmm1=(20 21 ** **)
  143. punpckhwd mm6, mm2 ; mm6=(** 42 ** 43)
  144. punpcklwd mm2, mm2 ; mm2=(40 40 41 41)
  145. punpckhwd mm7, mm3 ; mm7=(** 62 ** 63)
  146. punpcklwd mm3, mm3 ; mm3=(60 60 61 61)
  147. psrad mm6, (DWORD_BIT-WORD_BIT) ; mm6=in4H=(42 43)
  148. psrad mm2, (DWORD_BIT-WORD_BIT) ; mm2=in4L=(40 41)
  149. cvtpi2ps xmm6, mm6 ; xmm6=(42 43 ** **)
  150. cvtpi2ps xmm2, mm2 ; xmm2=(40 41 ** **)
  151. psrad mm7, (DWORD_BIT-WORD_BIT) ; mm7=in6H=(62 63)
  152. psrad mm3, (DWORD_BIT-WORD_BIT) ; mm3=in6L=(60 61)
  153. cvtpi2ps xmm7, mm7 ; xmm7=(62 63 ** **)
  154. cvtpi2ps xmm3, mm3 ; xmm3=(60 61 ** **)
  155. movlhps xmm0, xmm4 ; xmm0=in0=(00 01 02 03)
  156. movlhps xmm1, xmm5 ; xmm1=in2=(20 21 22 23)
  157. mulps xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  158. mulps xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  159. movlhps xmm2, xmm6 ; xmm2=in4=(40 41 42 43)
  160. movlhps xmm3, xmm7 ; xmm3=in6=(60 61 62 63)
  161. mulps xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  162. mulps xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  163. movaps xmm4, xmm0
  164. movaps xmm5, xmm1
  165. subps xmm0, xmm2 ; xmm0=tmp11
  166. subps xmm1, xmm3
  167. addps xmm4, xmm2 ; xmm4=tmp10
  168. addps xmm5, xmm3 ; xmm5=tmp13
  169. mulps xmm1, [GOTOFF(ebx,PD_1_414)]
  170. subps xmm1, xmm5 ; xmm1=tmp12
  171. movaps xmm6, xmm4
  172. movaps xmm7, xmm0
  173. subps xmm4, xmm5 ; xmm4=tmp3
  174. subps xmm0, xmm1 ; xmm0=tmp2
  175. addps xmm6, xmm5 ; xmm6=tmp0
  176. addps xmm7, xmm1 ; xmm7=tmp1
  177. movaps XMMWORD [wk(1)], xmm4 ; tmp3
  178. movaps XMMWORD [wk(0)], xmm0 ; tmp2
  179. ; -- Odd part
  180. movq mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  181. movq mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  182. movq mm5, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  183. movq mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  184. punpckhwd mm6, mm4 ; mm6=(** 12 ** 13)
  185. punpcklwd mm4, mm4 ; mm4=(10 10 11 11)
  186. punpckhwd mm2, mm0 ; mm2=(** 32 ** 33)
  187. punpcklwd mm0, mm0 ; mm0=(30 30 31 31)
  188. psrad mm6, (DWORD_BIT-WORD_BIT) ; mm6=in1H=(12 13)
  189. psrad mm4, (DWORD_BIT-WORD_BIT) ; mm4=in1L=(10 11)
  190. cvtpi2ps xmm4, mm6 ; xmm4=(12 13 ** **)
  191. cvtpi2ps xmm2, mm4 ; xmm2=(10 11 ** **)
  192. psrad mm2, (DWORD_BIT-WORD_BIT) ; mm2=in3H=(32 33)
  193. psrad mm0, (DWORD_BIT-WORD_BIT) ; mm0=in3L=(30 31)
  194. cvtpi2ps xmm0, mm2 ; xmm0=(32 33 ** **)
  195. cvtpi2ps xmm3, mm0 ; xmm3=(30 31 ** **)
  196. punpckhwd mm7, mm5 ; mm7=(** 52 ** 53)
  197. punpcklwd mm5, mm5 ; mm5=(50 50 51 51)
  198. punpckhwd mm3, mm1 ; mm3=(** 72 ** 73)
  199. punpcklwd mm1, mm1 ; mm1=(70 70 71 71)
  200. movlhps xmm2, xmm4 ; xmm2=in1=(10 11 12 13)
  201. movlhps xmm3, xmm0 ; xmm3=in3=(30 31 32 33)
  202. psrad mm7, (DWORD_BIT-WORD_BIT) ; mm7=in5H=(52 53)
  203. psrad mm5, (DWORD_BIT-WORD_BIT) ; mm5=in5L=(50 51)
  204. cvtpi2ps xmm4, mm7 ; xmm4=(52 53 ** **)
  205. cvtpi2ps xmm5, mm5 ; xmm5=(50 51 ** **)
  206. psrad mm3, (DWORD_BIT-WORD_BIT) ; mm3=in7H=(72 73)
  207. psrad mm1, (DWORD_BIT-WORD_BIT) ; mm1=in7L=(70 71)
  208. cvtpi2ps xmm0, mm3 ; xmm0=(72 73 ** **)
  209. cvtpi2ps xmm1, mm1 ; xmm1=(70 71 ** **)
  210. mulps xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  211. mulps xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  212. movlhps xmm5, xmm4 ; xmm5=in5=(50 51 52 53)
  213. movlhps xmm1, xmm0 ; xmm1=in7=(70 71 72 73)
  214. mulps xmm5, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  215. mulps xmm1, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FLOAT_MULT_TYPE)]
  216. movaps xmm4, xmm2
  217. movaps xmm0, xmm5
  218. addps xmm2, xmm1 ; xmm2=z11
  219. addps xmm5, xmm3 ; xmm5=z13
  220. subps xmm4, xmm1 ; xmm4=z12
  221. subps xmm0, xmm3 ; xmm0=z10
  222. movaps xmm1, xmm2
  223. subps xmm2, xmm5
  224. addps xmm1, xmm5 ; xmm1=tmp7
  225. mulps xmm2, [GOTOFF(ebx,PD_1_414)] ; xmm2=tmp11
  226. movaps xmm3, xmm0
  227. addps xmm0, xmm4
  228. mulps xmm0, [GOTOFF(ebx,PD_1_847)] ; xmm0=z5
  229. mulps xmm3, [GOTOFF(ebx,PD_M2_613)] ; xmm3=(z10 * -2.613125930)
  230. mulps xmm4, [GOTOFF(ebx,PD_1_082)] ; xmm4=(z12 * 1.082392200)
  231. addps xmm3, xmm0 ; xmm3=tmp12
  232. subps xmm4, xmm0 ; xmm4=tmp10
  233. ; -- Final output stage
  234. subps xmm3, xmm1 ; xmm3=tmp6
  235. movaps xmm5, xmm6
  236. movaps xmm0, xmm7
  237. addps xmm6, xmm1 ; xmm6=data0=(00 01 02 03)
  238. addps xmm7, xmm3 ; xmm7=data1=(10 11 12 13)
  239. subps xmm5, xmm1 ; xmm5=data7=(70 71 72 73)
  240. subps xmm0, xmm3 ; xmm0=data6=(60 61 62 63)
  241. subps xmm2, xmm3 ; xmm2=tmp5
  242. movaps xmm1, xmm6 ; transpose coefficients(phase 1)
  243. unpcklps xmm6, xmm7 ; xmm6=(00 10 01 11)
  244. unpckhps xmm1, xmm7 ; xmm1=(02 12 03 13)
  245. movaps xmm3, xmm0 ; transpose coefficients(phase 1)
  246. unpcklps xmm0, xmm5 ; xmm0=(60 70 61 71)
  247. unpckhps xmm3, xmm5 ; xmm3=(62 72 63 73)
  248. movaps xmm7, XMMWORD [wk(0)] ; xmm7=tmp2
  249. movaps xmm5, XMMWORD [wk(1)] ; xmm5=tmp3
  250. movaps XMMWORD [wk(0)], xmm0 ; wk(0)=(60 70 61 71)
  251. movaps XMMWORD [wk(1)], xmm3 ; wk(1)=(62 72 63 73)
  252. addps xmm4, xmm2 ; xmm4=tmp4
  253. movaps xmm0, xmm7
  254. movaps xmm3, xmm5
  255. addps xmm7, xmm2 ; xmm7=data2=(20 21 22 23)
  256. addps xmm5, xmm4 ; xmm5=data4=(40 41 42 43)
  257. subps xmm0, xmm2 ; xmm0=data5=(50 51 52 53)
  258. subps xmm3, xmm4 ; xmm3=data3=(30 31 32 33)
  259. movaps xmm2, xmm7 ; transpose coefficients(phase 1)
  260. unpcklps xmm7, xmm3 ; xmm7=(20 30 21 31)
  261. unpckhps xmm2, xmm3 ; xmm2=(22 32 23 33)
  262. movaps xmm4, xmm5 ; transpose coefficients(phase 1)
  263. unpcklps xmm5, xmm0 ; xmm5=(40 50 41 51)
  264. unpckhps xmm4, xmm0 ; xmm4=(42 52 43 53)
  265. movaps xmm3, xmm6 ; transpose coefficients(phase 2)
  266. UNPCKLPS2 xmm6, xmm7 ; xmm6=(00 10 20 30)
  267. UNPCKHPS2 xmm3, xmm7 ; xmm3=(01 11 21 31)
  268. movaps xmm0, xmm1 ; transpose coefficients(phase 2)
  269. UNPCKLPS2 xmm1, xmm2 ; xmm1=(02 12 22 32)
  270. UNPCKHPS2 xmm0, xmm2 ; xmm0=(03 13 23 33)
  271. movaps xmm7, XMMWORD [wk(0)] ; xmm7=(60 70 61 71)
  272. movaps xmm2, XMMWORD [wk(1)] ; xmm2=(62 72 63 73)
  273. movaps XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm6
  274. movaps XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3
  275. movaps XMMWORD [XMMBLOCK(2,0,edi,SIZEOF_FAST_FLOAT)], xmm1
  276. movaps XMMWORD [XMMBLOCK(3,0,edi,SIZEOF_FAST_FLOAT)], xmm0
  277. movaps xmm6, xmm5 ; transpose coefficients(phase 2)
  278. UNPCKLPS2 xmm5, xmm7 ; xmm5=(40 50 60 70)
  279. UNPCKHPS2 xmm6, xmm7 ; xmm6=(41 51 61 71)
  280. movaps xmm3, xmm4 ; transpose coefficients(phase 2)
  281. UNPCKLPS2 xmm4, xmm2 ; xmm4=(42 52 62 72)
  282. UNPCKHPS2 xmm3, xmm2 ; xmm3=(43 53 63 73)
  283. movaps XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm5
  284. movaps XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm6
  285. movaps XMMWORD [XMMBLOCK(2,1,edi,SIZEOF_FAST_FLOAT)], xmm4
  286. movaps XMMWORD [XMMBLOCK(3,1,edi,SIZEOF_FAST_FLOAT)], xmm3
  287. .nextcolumn:
  288. add esi, byte 4*SIZEOF_JCOEF ; coef_block
  289. add edx, byte 4*SIZEOF_FLOAT_MULT_TYPE ; quantptr
  290. add edi, 4*DCTSIZE*SIZEOF_FAST_FLOAT ; wsptr
  291. dec ecx ; ctr
  292. jnz near .columnloop
  293. ; -- Prefetch the next coefficient block
  294. prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 0*32]
  295. prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 1*32]
  296. prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 2*32]
  297. prefetchnta [esi + (DCTSIZE2-8)*SIZEOF_JCOEF + 3*32]
  298. ; ---- Pass 2: process rows from work array, store into output array.
  299. mov eax, [original_ebp]
  300. lea esi, [workspace] ; FAST_FLOAT *wsptr
  301. mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *)
  302. mov eax, JDIMENSION [output_col(eax)]
  303. mov ecx, DCTSIZE/4 ; ctr
  304. ALIGNX 16, 7
  305. .rowloop:
  306. ; -- Even part
  307. movaps xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
  308. movaps xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_FAST_FLOAT)]
  309. movaps xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_FAST_FLOAT)]
  310. movaps xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_FAST_FLOAT)]
  311. movaps xmm4, xmm0
  312. movaps xmm5, xmm1
  313. subps xmm0, xmm2 ; xmm0=tmp11
  314. subps xmm1, xmm3
  315. addps xmm4, xmm2 ; xmm4=tmp10
  316. addps xmm5, xmm3 ; xmm5=tmp13
  317. mulps xmm1, [GOTOFF(ebx,PD_1_414)]
  318. subps xmm1, xmm5 ; xmm1=tmp12
  319. movaps xmm6, xmm4
  320. movaps xmm7, xmm0
  321. subps xmm4, xmm5 ; xmm4=tmp3
  322. subps xmm0, xmm1 ; xmm0=tmp2
  323. addps xmm6, xmm5 ; xmm6=tmp0
  324. addps xmm7, xmm1 ; xmm7=tmp1
  325. movaps XMMWORD [wk(1)], xmm4 ; tmp3
  326. movaps XMMWORD [wk(0)], xmm0 ; tmp2
  327. ; -- Odd part
  328. movaps xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
  329. movaps xmm3, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_FAST_FLOAT)]
  330. movaps xmm5, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_FAST_FLOAT)]
  331. movaps xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_FAST_FLOAT)]
  332. movaps xmm4, xmm2
  333. movaps xmm0, xmm5
  334. addps xmm2, xmm1 ; xmm2=z11
  335. addps xmm5, xmm3 ; xmm5=z13
  336. subps xmm4, xmm1 ; xmm4=z12
  337. subps xmm0, xmm3 ; xmm0=z10
  338. movaps xmm1, xmm2
  339. subps xmm2, xmm5
  340. addps xmm1, xmm5 ; xmm1=tmp7
  341. mulps xmm2, [GOTOFF(ebx,PD_1_414)] ; xmm2=tmp11
  342. movaps xmm3, xmm0
  343. addps xmm0, xmm4
  344. mulps xmm0, [GOTOFF(ebx,PD_1_847)] ; xmm0=z5
  345. mulps xmm3, [GOTOFF(ebx,PD_M2_613)] ; xmm3=(z10 * -2.613125930)
  346. mulps xmm4, [GOTOFF(ebx,PD_1_082)] ; xmm4=(z12 * 1.082392200)
  347. addps xmm3, xmm0 ; xmm3=tmp12
  348. subps xmm4, xmm0 ; xmm4=tmp10
  349. ; -- Final output stage
  350. subps xmm3, xmm1 ; xmm3=tmp6
  351. movaps xmm5, xmm6
  352. movaps xmm0, xmm7
  353. addps xmm6, xmm1 ; xmm6=data0=(00 10 20 30)
  354. addps xmm7, xmm3 ; xmm7=data1=(01 11 21 31)
  355. subps xmm5, xmm1 ; xmm5=data7=(07 17 27 37)
  356. subps xmm0, xmm3 ; xmm0=data6=(06 16 26 36)
  357. subps xmm2, xmm3 ; xmm2=tmp5
  358. movaps xmm1, [GOTOFF(ebx,PD_0_125)] ; xmm1=[PD_0_125]
  359. mulps xmm6, xmm1 ; descale(1/8)
  360. mulps xmm7, xmm1 ; descale(1/8)
  361. mulps xmm5, xmm1 ; descale(1/8)
  362. mulps xmm0, xmm1 ; descale(1/8)
  363. movhlps xmm3, xmm6
  364. movhlps xmm1, xmm7
  365. cvtps2pi mm0, xmm6 ; round to int32, mm0=data0L=(00 10)
  366. cvtps2pi mm1, xmm7 ; round to int32, mm1=data1L=(01 11)
  367. cvtps2pi mm2, xmm3 ; round to int32, mm2=data0H=(20 30)
  368. cvtps2pi mm3, xmm1 ; round to int32, mm3=data1H=(21 31)
  369. packssdw mm0, mm2 ; mm0=data0=(00 10 20 30)
  370. packssdw mm1, mm3 ; mm1=data1=(01 11 21 31)
  371. movhlps xmm6, xmm5
  372. movhlps xmm7, xmm0
  373. cvtps2pi mm4, xmm5 ; round to int32, mm4=data7L=(07 17)
  374. cvtps2pi mm5, xmm0 ; round to int32, mm5=data6L=(06 16)
  375. cvtps2pi mm6, xmm6 ; round to int32, mm6=data7H=(27 37)
  376. cvtps2pi mm7, xmm7 ; round to int32, mm7=data6H=(26 36)
  377. packssdw mm4, mm6 ; mm4=data7=(07 17 27 37)
  378. packssdw mm5, mm7 ; mm5=data6=(06 16 26 36)
  379. packsswb mm0, mm5 ; mm0=(00 10 20 30 06 16 26 36)
  380. packsswb mm1, mm4 ; mm1=(01 11 21 31 07 17 27 37)
  381. movaps xmm3, XMMWORD [wk(0)] ; xmm3=tmp2
  382. movaps xmm1, XMMWORD [wk(1)] ; xmm1=tmp3
  383. movaps xmm6, [GOTOFF(ebx,PD_0_125)] ; xmm6=[PD_0_125]
  384. addps xmm4, xmm2 ; xmm4=tmp4
  385. movaps xmm5, xmm3
  386. movaps xmm0, xmm1
  387. addps xmm3, xmm2 ; xmm3=data2=(02 12 22 32)
  388. addps xmm1, xmm4 ; xmm1=data4=(04 14 24 34)
  389. subps xmm5, xmm2 ; xmm5=data5=(05 15 25 35)
  390. subps xmm0, xmm4 ; xmm0=data3=(03 13 23 33)
  391. mulps xmm3, xmm6 ; descale(1/8)
  392. mulps xmm1, xmm6 ; descale(1/8)
  393. mulps xmm5, xmm6 ; descale(1/8)
  394. mulps xmm0, xmm6 ; descale(1/8)
  395. movhlps xmm7, xmm3
  396. movhlps xmm2, xmm1
  397. cvtps2pi mm2, xmm3 ; round to int32, mm2=data2L=(02 12)
  398. cvtps2pi mm3, xmm1 ; round to int32, mm3=data4L=(04 14)
  399. cvtps2pi mm6, xmm7 ; round to int32, mm6=data2H=(22 32)
  400. cvtps2pi mm7, xmm2 ; round to int32, mm7=data4H=(24 34)
  401. packssdw mm2, mm6 ; mm2=data2=(02 12 22 32)
  402. packssdw mm3, mm7 ; mm3=data4=(04 14 24 34)
  403. movhlps xmm4, xmm5
  404. movhlps xmm6, xmm0
  405. cvtps2pi mm5, xmm5 ; round to int32, mm5=data5L=(05 15)
  406. cvtps2pi mm4, xmm0 ; round to int32, mm4=data3L=(03 13)
  407. cvtps2pi mm6, xmm4 ; round to int32, mm6=data5H=(25 35)
  408. cvtps2pi mm7, xmm6 ; round to int32, mm7=data3H=(23 33)
  409. packssdw mm5, mm6 ; mm5=data5=(05 15 25 35)
  410. packssdw mm4, mm7 ; mm4=data3=(03 13 23 33)
  411. movq mm6, [GOTOFF(ebx,PB_CENTERJSAMP)] ; mm6=[PB_CENTERJSAMP]
  412. packsswb mm2, mm3 ; mm2=(02 12 22 32 04 14 24 34)
  413. packsswb mm4, mm5 ; mm4=(03 13 23 33 05 15 25 35)
  414. paddb mm0, mm6
  415. paddb mm1, mm6
  416. paddb mm2, mm6
  417. paddb mm4, mm6
  418. movq mm7, mm0 ; transpose coefficients(phase 1)
  419. punpcklbw mm0, mm1 ; mm0=(00 01 10 11 20 21 30 31)
  420. punpckhbw mm7, mm1 ; mm7=(06 07 16 17 26 27 36 37)
  421. movq mm3, mm2 ; transpose coefficients(phase 1)
  422. punpcklbw mm2, mm4 ; mm2=(02 03 12 13 22 23 32 33)
  423. punpckhbw mm3, mm4 ; mm3=(04 05 14 15 24 25 34 35)
  424. movq mm5, mm0 ; transpose coefficients(phase 2)
  425. punpcklwd mm0, mm2 ; mm0=(00 01 02 03 10 11 12 13)
  426. punpckhwd mm5, mm2 ; mm5=(20 21 22 23 30 31 32 33)
  427. movq mm6, mm3 ; transpose coefficients(phase 2)
  428. punpcklwd mm3, mm7 ; mm3=(04 05 06 07 14 15 16 17)
  429. punpckhwd mm6, mm7 ; mm6=(24 25 26 27 34 35 36 37)
  430. movq mm1, mm0 ; transpose coefficients(phase 3)
  431. punpckldq mm0, mm3 ; mm0=(00 01 02 03 04 05 06 07)
  432. punpckhdq mm1, mm3 ; mm1=(10 11 12 13 14 15 16 17)
  433. movq mm4, mm5 ; transpose coefficients(phase 3)
  434. punpckldq mm5, mm6 ; mm5=(20 21 22 23 24 25 26 27)
  435. punpckhdq mm4, mm6 ; mm4=(30 31 32 33 34 35 36 37)
  436. PUSHPIC ebx ; save GOT address
  437. mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
  438. mov ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
  439. movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm0
  440. movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm1
  441. mov edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
  442. mov ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
  443. movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm5
  444. movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm4
  445. POPPIC ebx ; restore GOT address
  446. add esi, byte 4*SIZEOF_FAST_FLOAT ; wsptr
  447. add edi, byte 4*SIZEOF_JSAMPROW
  448. dec ecx ; ctr
  449. jnz near .rowloop
  450. emms ; empty MMX state
  451. pop edi
  452. pop esi
  453. ; pop edx ; need not be preserved
  454. ; pop ecx ; need not be preserved
  455. pop ebx
  456. mov esp, ebp ; esp <- aligned ebp
  457. pop esp ; esp <- original ebp
  458. pop ebp
  459. ret
  460. ; For some reason, the OS X linker does not honor the request to align the
  461. ; segment unless we do this.
  462. align 32