jfdctflt-sse.asm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. ;
  2. ; jfdctflt.asm - floating-point FDCT (SSE)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ;
  6. ; Based on the x86 SIMD extension for IJG JPEG library
  7. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  8. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  9. ;
  10. ; This file should be assembled with NASM (Netwide Assembler),
  11. ; can *not* be assembled with Microsoft's MASM or any compatible
  12. ; assembler (including Borland's Turbo Assembler).
  13. ; NASM is available from http://nasm.sourceforge.net/ or
  14. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  15. ;
  16. ; This file contains a floating-point implementation of the forward DCT
  17. ; (Discrete Cosine Transform). The following code is based directly on
  18. ; the IJG's original jfdctflt.c; see the jfdctflt.c for more details.
  19. ;
  20. ; [TAB8]
  21. %include "jsimdext.inc"
  22. %include "jdct.inc"
  23. ; --------------------------------------------------------------------------
  24. %macro unpcklps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(0 1 4 5)
  25. shufps %1,%2,0x44
  26. %endmacro
  27. %macro unpckhps2 2 ; %1=(0 1 2 3) / %2=(4 5 6 7) => %1=(2 3 6 7)
  28. shufps %1,%2,0xEE
  29. %endmacro
  30. ; --------------------------------------------------------------------------
  31. SECTION SEG_CONST
  32. alignz 16
  33. global EXTN(jconst_fdct_float_sse)
  34. EXTN(jconst_fdct_float_sse):
  35. PD_0_382 times 4 dd 0.382683432365089771728460
  36. PD_0_707 times 4 dd 0.707106781186547524400844
  37. PD_0_541 times 4 dd 0.541196100146196984399723
  38. PD_1_306 times 4 dd 1.306562964876376527856643
  39. alignz 16
  40. ; --------------------------------------------------------------------------
  41. SECTION SEG_TEXT
  42. BITS 32
  43. ;
  44. ; Perform the forward DCT on one block of samples.
  45. ;
  46. ; GLOBAL(void)
  47. ; jsimd_fdct_float_sse (FAST_FLOAT *data)
  48. ;
  49. %define data(b) (b)+8 ; FAST_FLOAT *data
  50. %define original_ebp ebp+0
  51. %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
  52. %define WK_NUM 2
  53. align 16
  54. global EXTN(jsimd_fdct_float_sse)
  55. EXTN(jsimd_fdct_float_sse):
  56. push ebp
  57. mov eax,esp ; eax = original ebp
  58. sub esp, byte 4
  59. and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
  60. mov [esp],eax
  61. mov ebp,esp ; ebp = aligned ebp
  62. lea esp, [wk(0)]
  63. pushpic ebx
  64. ; push ecx ; need not be preserved
  65. ; push edx ; need not be preserved
  66. ; push esi ; unused
  67. ; push edi ; unused
  68. get_GOT ebx ; get GOT address
  69. ; ---- Pass 1: process rows.
  70. mov edx, POINTER [data(eax)] ; (FAST_FLOAT *)
  71. mov ecx, DCTSIZE/4
  72. alignx 16,7
  73. .rowloop:
  74. movaps xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)]
  75. movaps xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)]
  76. movaps xmm2, XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)]
  77. movaps xmm3, XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)]
  78. ; xmm0=(20 21 22 23), xmm2=(24 25 26 27)
  79. ; xmm1=(30 31 32 33), xmm3=(34 35 36 37)
  80. movaps xmm4,xmm0 ; transpose coefficients(phase 1)
  81. unpcklps xmm0,xmm1 ; xmm0=(20 30 21 31)
  82. unpckhps xmm4,xmm1 ; xmm4=(22 32 23 33)
  83. movaps xmm5,xmm2 ; transpose coefficients(phase 1)
  84. unpcklps xmm2,xmm3 ; xmm2=(24 34 25 35)
  85. unpckhps xmm5,xmm3 ; xmm5=(26 36 27 37)
  86. movaps xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
  87. movaps xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
  88. movaps xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
  89. movaps xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
  90. ; xmm6=(00 01 02 03), xmm1=(04 05 06 07)
  91. ; xmm7=(10 11 12 13), xmm3=(14 15 16 17)
  92. movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 32 23 33)
  93. movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(24 34 25 35)
  94. movaps xmm4,xmm6 ; transpose coefficients(phase 1)
  95. unpcklps xmm6,xmm7 ; xmm6=(00 10 01 11)
  96. unpckhps xmm4,xmm7 ; xmm4=(02 12 03 13)
  97. movaps xmm2,xmm1 ; transpose coefficients(phase 1)
  98. unpcklps xmm1,xmm3 ; xmm1=(04 14 05 15)
  99. unpckhps xmm2,xmm3 ; xmm2=(06 16 07 17)
  100. movaps xmm7,xmm6 ; transpose coefficients(phase 2)
  101. unpcklps2 xmm6,xmm0 ; xmm6=(00 10 20 30)=data0
  102. unpckhps2 xmm7,xmm0 ; xmm7=(01 11 21 31)=data1
  103. movaps xmm3,xmm2 ; transpose coefficients(phase 2)
  104. unpcklps2 xmm2,xmm5 ; xmm2=(06 16 26 36)=data6
  105. unpckhps2 xmm3,xmm5 ; xmm3=(07 17 27 37)=data7
  106. movaps xmm0,xmm7
  107. movaps xmm5,xmm6
  108. subps xmm7,xmm2 ; xmm7=data1-data6=tmp6
  109. subps xmm6,xmm3 ; xmm6=data0-data7=tmp7
  110. addps xmm0,xmm2 ; xmm0=data1+data6=tmp1
  111. addps xmm5,xmm3 ; xmm5=data0+data7=tmp0
  112. movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 32 23 33)
  113. movaps xmm3, XMMWORD [wk(1)] ; xmm3=(24 34 25 35)
  114. movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6
  115. movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7
  116. movaps xmm7,xmm4 ; transpose coefficients(phase 2)
  117. unpcklps2 xmm4,xmm2 ; xmm4=(02 12 22 32)=data2
  118. unpckhps2 xmm7,xmm2 ; xmm7=(03 13 23 33)=data3
  119. movaps xmm6,xmm1 ; transpose coefficients(phase 2)
  120. unpcklps2 xmm1,xmm3 ; xmm1=(04 14 24 34)=data4
  121. unpckhps2 xmm6,xmm3 ; xmm6=(05 15 25 35)=data5
  122. movaps xmm2,xmm7
  123. movaps xmm3,xmm4
  124. addps xmm7,xmm1 ; xmm7=data3+data4=tmp3
  125. addps xmm4,xmm6 ; xmm4=data2+data5=tmp2
  126. subps xmm2,xmm1 ; xmm2=data3-data4=tmp4
  127. subps xmm3,xmm6 ; xmm3=data2-data5=tmp5
  128. ; -- Even part
  129. movaps xmm1,xmm5
  130. movaps xmm6,xmm0
  131. subps xmm5,xmm7 ; xmm5=tmp13
  132. subps xmm0,xmm4 ; xmm0=tmp12
  133. addps xmm1,xmm7 ; xmm1=tmp10
  134. addps xmm6,xmm4 ; xmm6=tmp11
  135. addps xmm0,xmm5
  136. mulps xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1
  137. movaps xmm7,xmm1
  138. movaps xmm4,xmm5
  139. subps xmm1,xmm6 ; xmm1=data4
  140. subps xmm5,xmm0 ; xmm5=data6
  141. addps xmm7,xmm6 ; xmm7=data0
  142. addps xmm4,xmm0 ; xmm4=data2
  143. movaps XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)], xmm1
  144. movaps XMMWORD [XMMBLOCK(2,1,edx,SIZEOF_FAST_FLOAT)], xmm5
  145. movaps XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7
  146. movaps XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4
  147. ; -- Odd part
  148. movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6
  149. movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7
  150. addps xmm2,xmm3 ; xmm2=tmp10
  151. addps xmm3,xmm6 ; xmm3=tmp11
  152. addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7
  153. mulps xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3
  154. movaps xmm1,xmm2 ; xmm1=tmp10
  155. subps xmm2,xmm6
  156. mulps xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5
  157. mulps xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196)
  158. mulps xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562)
  159. addps xmm1,xmm2 ; xmm1=z2
  160. addps xmm6,xmm2 ; xmm6=z4
  161. movaps xmm5,xmm0
  162. subps xmm0,xmm3 ; xmm0=z13
  163. addps xmm5,xmm3 ; xmm5=z11
  164. movaps xmm7,xmm0
  165. movaps xmm4,xmm5
  166. subps xmm0,xmm1 ; xmm0=data3
  167. subps xmm5,xmm6 ; xmm5=data7
  168. addps xmm7,xmm1 ; xmm7=data5
  169. addps xmm4,xmm6 ; xmm4=data1
  170. movaps XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0
  171. movaps XMMWORD [XMMBLOCK(3,1,edx,SIZEOF_FAST_FLOAT)], xmm5
  172. movaps XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)], xmm7
  173. movaps XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4
  174. add edx, 4*DCTSIZE*SIZEOF_FAST_FLOAT
  175. dec ecx
  176. jnz near .rowloop
  177. ; ---- Pass 2: process columns.
  178. mov edx, POINTER [data(eax)] ; (FAST_FLOAT *)
  179. mov ecx, DCTSIZE/4
  180. alignx 16,7
  181. .columnloop:
  182. movaps xmm0, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)]
  183. movaps xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)]
  184. movaps xmm2, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)]
  185. movaps xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)]
  186. ; xmm0=(02 12 22 32), xmm2=(42 52 62 72)
  187. ; xmm1=(03 13 23 33), xmm3=(43 53 63 73)
  188. movaps xmm4,xmm0 ; transpose coefficients(phase 1)
  189. unpcklps xmm0,xmm1 ; xmm0=(02 03 12 13)
  190. unpckhps xmm4,xmm1 ; xmm4=(22 23 32 33)
  191. movaps xmm5,xmm2 ; transpose coefficients(phase 1)
  192. unpcklps xmm2,xmm3 ; xmm2=(42 43 52 53)
  193. unpckhps xmm5,xmm3 ; xmm5=(62 63 72 73)
  194. movaps xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
  195. movaps xmm7, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
  196. movaps xmm1, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)]
  197. movaps xmm3, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)]
  198. ; xmm6=(00 10 20 30), xmm1=(40 50 60 70)
  199. ; xmm7=(01 11 21 31), xmm3=(41 51 61 71)
  200. movaps XMMWORD [wk(0)], xmm4 ; wk(0)=(22 23 32 33)
  201. movaps XMMWORD [wk(1)], xmm2 ; wk(1)=(42 43 52 53)
  202. movaps xmm4,xmm6 ; transpose coefficients(phase 1)
  203. unpcklps xmm6,xmm7 ; xmm6=(00 01 10 11)
  204. unpckhps xmm4,xmm7 ; xmm4=(20 21 30 31)
  205. movaps xmm2,xmm1 ; transpose coefficients(phase 1)
  206. unpcklps xmm1,xmm3 ; xmm1=(40 41 50 51)
  207. unpckhps xmm2,xmm3 ; xmm2=(60 61 70 71)
  208. movaps xmm7,xmm6 ; transpose coefficients(phase 2)
  209. unpcklps2 xmm6,xmm0 ; xmm6=(00 01 02 03)=data0
  210. unpckhps2 xmm7,xmm0 ; xmm7=(10 11 12 13)=data1
  211. movaps xmm3,xmm2 ; transpose coefficients(phase 2)
  212. unpcklps2 xmm2,xmm5 ; xmm2=(60 61 62 63)=data6
  213. unpckhps2 xmm3,xmm5 ; xmm3=(70 71 72 73)=data7
  214. movaps xmm0,xmm7
  215. movaps xmm5,xmm6
  216. subps xmm7,xmm2 ; xmm7=data1-data6=tmp6
  217. subps xmm6,xmm3 ; xmm6=data0-data7=tmp7
  218. addps xmm0,xmm2 ; xmm0=data1+data6=tmp1
  219. addps xmm5,xmm3 ; xmm5=data0+data7=tmp0
  220. movaps xmm2, XMMWORD [wk(0)] ; xmm2=(22 23 32 33)
  221. movaps xmm3, XMMWORD [wk(1)] ; xmm3=(42 43 52 53)
  222. movaps XMMWORD [wk(0)], xmm7 ; wk(0)=tmp6
  223. movaps XMMWORD [wk(1)], xmm6 ; wk(1)=tmp7
  224. movaps xmm7,xmm4 ; transpose coefficients(phase 2)
  225. unpcklps2 xmm4,xmm2 ; xmm4=(20 21 22 23)=data2
  226. unpckhps2 xmm7,xmm2 ; xmm7=(30 31 32 33)=data3
  227. movaps xmm6,xmm1 ; transpose coefficients(phase 2)
  228. unpcklps2 xmm1,xmm3 ; xmm1=(40 41 42 43)=data4
  229. unpckhps2 xmm6,xmm3 ; xmm6=(50 51 52 53)=data5
  230. movaps xmm2,xmm7
  231. movaps xmm3,xmm4
  232. addps xmm7,xmm1 ; xmm7=data3+data4=tmp3
  233. addps xmm4,xmm6 ; xmm4=data2+data5=tmp2
  234. subps xmm2,xmm1 ; xmm2=data3-data4=tmp4
  235. subps xmm3,xmm6 ; xmm3=data2-data5=tmp5
  236. ; -- Even part
  237. movaps xmm1,xmm5
  238. movaps xmm6,xmm0
  239. subps xmm5,xmm7 ; xmm5=tmp13
  240. subps xmm0,xmm4 ; xmm0=tmp12
  241. addps xmm1,xmm7 ; xmm1=tmp10
  242. addps xmm6,xmm4 ; xmm6=tmp11
  243. addps xmm0,xmm5
  244. mulps xmm0,[GOTOFF(ebx,PD_0_707)] ; xmm0=z1
  245. movaps xmm7,xmm1
  246. movaps xmm4,xmm5
  247. subps xmm1,xmm6 ; xmm1=data4
  248. subps xmm5,xmm0 ; xmm5=data6
  249. addps xmm7,xmm6 ; xmm7=data0
  250. addps xmm4,xmm0 ; xmm4=data2
  251. movaps XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)], xmm1
  252. movaps XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)], xmm5
  253. movaps XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], xmm7
  254. movaps XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], xmm4
  255. ; -- Odd part
  256. movaps xmm6, XMMWORD [wk(0)] ; xmm6=tmp6
  257. movaps xmm0, XMMWORD [wk(1)] ; xmm0=tmp7
  258. addps xmm2,xmm3 ; xmm2=tmp10
  259. addps xmm3,xmm6 ; xmm3=tmp11
  260. addps xmm6,xmm0 ; xmm6=tmp12, xmm0=tmp7
  261. mulps xmm3,[GOTOFF(ebx,PD_0_707)] ; xmm3=z3
  262. movaps xmm1,xmm2 ; xmm1=tmp10
  263. subps xmm2,xmm6
  264. mulps xmm2,[GOTOFF(ebx,PD_0_382)] ; xmm2=z5
  265. mulps xmm1,[GOTOFF(ebx,PD_0_541)] ; xmm1=MULTIPLY(tmp10,FIX_0_541196)
  266. mulps xmm6,[GOTOFF(ebx,PD_1_306)] ; xmm6=MULTIPLY(tmp12,FIX_1_306562)
  267. addps xmm1,xmm2 ; xmm1=z2
  268. addps xmm6,xmm2 ; xmm6=z4
  269. movaps xmm5,xmm0
  270. subps xmm0,xmm3 ; xmm0=z13
  271. addps xmm5,xmm3 ; xmm5=z11
  272. movaps xmm7,xmm0
  273. movaps xmm4,xmm5
  274. subps xmm0,xmm1 ; xmm0=data3
  275. subps xmm5,xmm6 ; xmm5=data7
  276. addps xmm7,xmm1 ; xmm7=data5
  277. addps xmm4,xmm6 ; xmm4=data1
  278. movaps XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], xmm0
  279. movaps XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)], xmm5
  280. movaps XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)], xmm7
  281. movaps XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], xmm4
  282. add edx, byte 4*SIZEOF_FAST_FLOAT
  283. dec ecx
  284. jnz near .columnloop
  285. ; pop edi ; unused
  286. ; pop esi ; unused
  287. ; pop edx ; need not be preserved
  288. ; pop ecx ; need not be preserved
  289. poppic ebx
  290. mov esp,ebp ; esp <- aligned ebp
  291. pop esp ; esp <- original ebp
  292. pop ebp
  293. ret
  294. ; For some reason, the OS X linker does not honor the request to align the
  295. ; segment unless we do this.
  296. align 16