jfdctflt-3dn.asm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. ;
  2. ; jfdctflt.asm - floating-point FDCT (3DNow!)
  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. SECTION SEG_CONST
  25. alignz 16
  26. global EXTN(jconst_fdct_float_3dnow)
  27. EXTN(jconst_fdct_float_3dnow):
  28. PD_0_382 times 2 dd 0.382683432365089771728460
  29. PD_0_707 times 2 dd 0.707106781186547524400844
  30. PD_0_541 times 2 dd 0.541196100146196984399723
  31. PD_1_306 times 2 dd 1.306562964876376527856643
  32. alignz 16
  33. ; --------------------------------------------------------------------------
  34. SECTION SEG_TEXT
  35. BITS 32
  36. ;
  37. ; Perform the forward DCT on one block of samples.
  38. ;
  39. ; GLOBAL(void)
  40. ; jsimd_fdct_float_3dnow (FAST_FLOAT *data)
  41. ;
  42. %define data(b) (b)+8 ; FAST_FLOAT *data
  43. %define original_ebp ebp+0
  44. %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM]
  45. %define WK_NUM 2
  46. align 16
  47. global EXTN(jsimd_fdct_float_3dnow)
  48. EXTN(jsimd_fdct_float_3dnow):
  49. push ebp
  50. mov eax,esp ; eax = original ebp
  51. sub esp, byte 4
  52. and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
  53. mov [esp],eax
  54. mov ebp,esp ; ebp = aligned ebp
  55. lea esp, [wk(0)]
  56. pushpic ebx
  57. ; push ecx ; need not be preserved
  58. ; push edx ; need not be preserved
  59. ; push esi ; unused
  60. ; push edi ; unused
  61. get_GOT ebx ; get GOT address
  62. ; ---- Pass 1: process rows.
  63. mov edx, POINTER [data(eax)] ; (FAST_FLOAT *)
  64. mov ecx, DCTSIZE/2
  65. alignx 16,7
  66. .rowloop:
  67. movq mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
  68. movq mm1, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
  69. movq mm2, MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)]
  70. movq mm3, MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)]
  71. ; mm0=(00 01), mm1=(10 11), mm2=(06 07), mm3=(16 17)
  72. movq mm4,mm0 ; transpose coefficients
  73. punpckldq mm0,mm1 ; mm0=(00 10)=data0
  74. punpckhdq mm4,mm1 ; mm4=(01 11)=data1
  75. movq mm5,mm2 ; transpose coefficients
  76. punpckldq mm2,mm3 ; mm2=(06 16)=data6
  77. punpckhdq mm5,mm3 ; mm5=(07 17)=data7
  78. movq mm6,mm4
  79. movq mm7,mm0
  80. pfsub mm4,mm2 ; mm4=data1-data6=tmp6
  81. pfsub mm0,mm5 ; mm0=data0-data7=tmp7
  82. pfadd mm6,mm2 ; mm6=data1+data6=tmp1
  83. pfadd mm7,mm5 ; mm7=data0+data7=tmp0
  84. movq mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
  85. movq mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
  86. movq mm2, MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)]
  87. movq mm5, MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)]
  88. ; mm1=(02 03), mm3=(12 13), mm2=(04 05), mm5=(14 15)
  89. movq MMWORD [wk(0)], mm4 ; wk(0)=tmp6
  90. movq MMWORD [wk(1)], mm0 ; wk(1)=tmp7
  91. movq mm4,mm1 ; transpose coefficients
  92. punpckldq mm1,mm3 ; mm1=(02 12)=data2
  93. punpckhdq mm4,mm3 ; mm4=(03 13)=data3
  94. movq mm0,mm2 ; transpose coefficients
  95. punpckldq mm2,mm5 ; mm2=(04 14)=data4
  96. punpckhdq mm0,mm5 ; mm0=(05 15)=data5
  97. movq mm3,mm4
  98. movq mm5,mm1
  99. pfadd mm4,mm2 ; mm4=data3+data4=tmp3
  100. pfadd mm1,mm0 ; mm1=data2+data5=tmp2
  101. pfsub mm3,mm2 ; mm3=data3-data4=tmp4
  102. pfsub mm5,mm0 ; mm5=data2-data5=tmp5
  103. ; -- Even part
  104. movq mm2,mm7
  105. movq mm0,mm6
  106. pfsub mm7,mm4 ; mm7=tmp13
  107. pfsub mm6,mm1 ; mm6=tmp12
  108. pfadd mm2,mm4 ; mm2=tmp10
  109. pfadd mm0,mm1 ; mm0=tmp11
  110. pfadd mm6,mm7
  111. pfmul mm6,[GOTOFF(ebx,PD_0_707)] ; mm6=z1
  112. movq mm4,mm2
  113. movq mm1,mm7
  114. pfsub mm2,mm0 ; mm2=data4
  115. pfsub mm7,mm6 ; mm7=data6
  116. pfadd mm4,mm0 ; mm4=data0
  117. pfadd mm1,mm6 ; mm1=data2
  118. movq MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)], mm2
  119. movq MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)], mm7
  120. movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], mm4
  121. movq MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)], mm1
  122. ; -- Odd part
  123. movq mm0, MMWORD [wk(0)] ; mm0=tmp6
  124. movq mm6, MMWORD [wk(1)] ; mm6=tmp7
  125. pfadd mm3,mm5 ; mm3=tmp10
  126. pfadd mm5,mm0 ; mm5=tmp11
  127. pfadd mm0,mm6 ; mm0=tmp12, mm6=tmp7
  128. pfmul mm5,[GOTOFF(ebx,PD_0_707)] ; mm5=z3
  129. movq mm2,mm3 ; mm2=tmp10
  130. pfsub mm3,mm0
  131. pfmul mm3,[GOTOFF(ebx,PD_0_382)] ; mm3=z5
  132. pfmul mm2,[GOTOFF(ebx,PD_0_541)] ; mm2=MULTIPLY(tmp10,FIX_0_54119610)
  133. pfmul mm0,[GOTOFF(ebx,PD_1_306)] ; mm0=MULTIPLY(tmp12,FIX_1_30656296)
  134. pfadd mm2,mm3 ; mm2=z2
  135. pfadd mm0,mm3 ; mm0=z4
  136. movq mm7,mm6
  137. pfsub mm6,mm5 ; mm6=z13
  138. pfadd mm7,mm5 ; mm7=z11
  139. movq mm4,mm6
  140. movq mm1,mm7
  141. pfsub mm6,mm2 ; mm6=data3
  142. pfsub mm7,mm0 ; mm7=data7
  143. pfadd mm4,mm2 ; mm4=data5
  144. pfadd mm1,mm0 ; mm1=data1
  145. movq MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)], mm6
  146. movq MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)], mm7
  147. movq MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)], mm4
  148. movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], mm1
  149. add edx, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
  150. dec ecx
  151. jnz near .rowloop
  152. ; ---- Pass 2: process columns.
  153. mov edx, POINTER [data(eax)] ; (FAST_FLOAT *)
  154. mov ecx, DCTSIZE/2
  155. alignx 16,7
  156. .columnloop:
  157. movq mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
  158. movq mm1, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
  159. movq mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)]
  160. movq mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)]
  161. ; mm0=(00 10), mm1=(01 11), mm2=(60 70), mm3=(61 71)
  162. movq mm4,mm0 ; transpose coefficients
  163. punpckldq mm0,mm1 ; mm0=(00 01)=data0
  164. punpckhdq mm4,mm1 ; mm4=(10 11)=data1
  165. movq mm5,mm2 ; transpose coefficients
  166. punpckldq mm2,mm3 ; mm2=(60 61)=data6
  167. punpckhdq mm5,mm3 ; mm5=(70 71)=data7
  168. movq mm6,mm4
  169. movq mm7,mm0
  170. pfsub mm4,mm2 ; mm4=data1-data6=tmp6
  171. pfsub mm0,mm5 ; mm0=data0-data7=tmp7
  172. pfadd mm6,mm2 ; mm6=data1+data6=tmp1
  173. pfadd mm7,mm5 ; mm7=data0+data7=tmp0
  174. movq mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)]
  175. movq mm3, MMWORD [MMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)]
  176. movq mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)]
  177. movq mm5, MMWORD [MMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)]
  178. ; mm1=(20 30), mm3=(21 31), mm2=(40 50), mm5=(41 51)
  179. movq MMWORD [wk(0)], mm4 ; wk(0)=tmp6
  180. movq MMWORD [wk(1)], mm0 ; wk(1)=tmp7
  181. movq mm4,mm1 ; transpose coefficients
  182. punpckldq mm1,mm3 ; mm1=(20 21)=data2
  183. punpckhdq mm4,mm3 ; mm4=(30 31)=data3
  184. movq mm0,mm2 ; transpose coefficients
  185. punpckldq mm2,mm5 ; mm2=(40 41)=data4
  186. punpckhdq mm0,mm5 ; mm0=(50 51)=data5
  187. movq mm3,mm4
  188. movq mm5,mm1
  189. pfadd mm4,mm2 ; mm4=data3+data4=tmp3
  190. pfadd mm1,mm0 ; mm1=data2+data5=tmp2
  191. pfsub mm3,mm2 ; mm3=data3-data4=tmp4
  192. pfsub mm5,mm0 ; mm5=data2-data5=tmp5
  193. ; -- Even part
  194. movq mm2,mm7
  195. movq mm0,mm6
  196. pfsub mm7,mm4 ; mm7=tmp13
  197. pfsub mm6,mm1 ; mm6=tmp12
  198. pfadd mm2,mm4 ; mm2=tmp10
  199. pfadd mm0,mm1 ; mm0=tmp11
  200. pfadd mm6,mm7
  201. pfmul mm6,[GOTOFF(ebx,PD_0_707)] ; mm6=z1
  202. movq mm4,mm2
  203. movq mm1,mm7
  204. pfsub mm2,mm0 ; mm2=data4
  205. pfsub mm7,mm6 ; mm7=data6
  206. pfadd mm4,mm0 ; mm4=data0
  207. pfadd mm1,mm6 ; mm1=data2
  208. movq MMWORD [MMBLOCK(4,0,edx,SIZEOF_FAST_FLOAT)], mm2
  209. movq MMWORD [MMBLOCK(6,0,edx,SIZEOF_FAST_FLOAT)], mm7
  210. movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)], mm4
  211. movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_FAST_FLOAT)], mm1
  212. ; -- Odd part
  213. movq mm0, MMWORD [wk(0)] ; mm0=tmp6
  214. movq mm6, MMWORD [wk(1)] ; mm6=tmp7
  215. pfadd mm3,mm5 ; mm3=tmp10
  216. pfadd mm5,mm0 ; mm5=tmp11
  217. pfadd mm0,mm6 ; mm0=tmp12, mm6=tmp7
  218. pfmul mm5,[GOTOFF(ebx,PD_0_707)] ; mm5=z3
  219. movq mm2,mm3 ; mm2=tmp10
  220. pfsub mm3,mm0
  221. pfmul mm3,[GOTOFF(ebx,PD_0_382)] ; mm3=z5
  222. pfmul mm2,[GOTOFF(ebx,PD_0_541)] ; mm2=MULTIPLY(tmp10,FIX_0_54119610)
  223. pfmul mm0,[GOTOFF(ebx,PD_1_306)] ; mm0=MULTIPLY(tmp12,FIX_1_30656296)
  224. pfadd mm2,mm3 ; mm2=z2
  225. pfadd mm0,mm3 ; mm0=z4
  226. movq mm7,mm6
  227. pfsub mm6,mm5 ; mm6=z13
  228. pfadd mm7,mm5 ; mm7=z11
  229. movq mm4,mm6
  230. movq mm1,mm7
  231. pfsub mm6,mm2 ; mm6=data3
  232. pfsub mm7,mm0 ; mm7=data7
  233. pfadd mm4,mm2 ; mm4=data5
  234. pfadd mm1,mm0 ; mm1=data1
  235. movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_FAST_FLOAT)], mm6
  236. movq MMWORD [MMBLOCK(7,0,edx,SIZEOF_FAST_FLOAT)], mm7
  237. movq MMWORD [MMBLOCK(5,0,edx,SIZEOF_FAST_FLOAT)], mm4
  238. movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)], mm1
  239. add edx, byte 2*SIZEOF_FAST_FLOAT
  240. dec ecx
  241. jnz near .columnloop
  242. femms ; empty MMX/3DNow! state
  243. ; pop edi ; unused
  244. ; pop esi ; unused
  245. ; pop edx ; need not be preserved
  246. ; pop ecx ; need not be preserved
  247. poppic ebx
  248. mov esp,ebp ; esp <- aligned ebp
  249. pop esp ; esp <- original ebp
  250. pop ebp
  251. ret
  252. ; For some reason, the OS X linker does not honor the request to align the
  253. ; segment unless we do this.
  254. align 16