mmxstate.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
  9. * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function:
  13. last mod: $Id: mmxstate.c 17563 2010-10-25 17:40:54Z tterribe $
  14. ********************************************************************/
  15. /*MMX acceleration of complete fragment reconstruction algorithm.
  16. Originally written by Rudolf Marek.*/
  17. #include <string.h>
  18. #include "x86int.h"
  19. #include "mmxloop.h"
  20. #if defined(OC_X86_ASM)
  21. void oc_state_frag_recon_mmx(const oc_theora_state *_state,ptrdiff_t _fragi,
  22. int _pli,ogg_int16_t _dct_coeffs[128],int _last_zzi,ogg_uint16_t _dc_quant){
  23. unsigned char *dst;
  24. ptrdiff_t frag_buf_off;
  25. int ystride;
  26. int refi;
  27. /*Apply the inverse transform.*/
  28. /*Special case only having a DC component.*/
  29. if(_last_zzi<2){
  30. /*Note that this value must be unsigned, to keep the __asm__ block from
  31. sign-extending it when it puts it in a register.*/
  32. ogg_uint16_t p;
  33. int i;
  34. /*We round this dequant product (and not any of the others) because there's
  35. no iDCT rounding.*/
  36. p=(ogg_int16_t)(_dct_coeffs[0]*(ogg_int32_t)_dc_quant+15>>5);
  37. /*Fill _dct_coeffs with p.*/
  38. __asm__ __volatile__(
  39. /*mm0=0000 0000 0000 AAAA*/
  40. "movd %[p],%%mm0\n\t"
  41. /*mm0=0000 0000 AAAA AAAA*/
  42. "punpcklwd %%mm0,%%mm0\n\t"
  43. /*mm0=AAAA AAAA AAAA AAAA*/
  44. "punpckldq %%mm0,%%mm0\n\t"
  45. :
  46. :[p]"r"((unsigned)p)
  47. );
  48. for(i=0;i<4;i++){
  49. __asm__ __volatile__(
  50. "movq %%mm0,"OC_MEM_OFFS(0x00,y)"\n\t"
  51. "movq %%mm0,"OC_MEM_OFFS(0x08,y)"\n\t"
  52. "movq %%mm0,"OC_MEM_OFFS(0x10,y)"\n\t"
  53. "movq %%mm0,"OC_MEM_OFFS(0x18,y)"\n\t"
  54. :[y]"=m"OC_ARRAY_OPERAND(ogg_int16_t,_dct_coeffs+64+16*i,16)
  55. );
  56. }
  57. }
  58. else{
  59. /*Dequantize the DC coefficient.*/
  60. _dct_coeffs[0]=(ogg_int16_t)(_dct_coeffs[0]*(int)_dc_quant);
  61. oc_idct8x8(_state,_dct_coeffs+64,_dct_coeffs,_last_zzi);
  62. }
  63. /*Fill in the target buffer.*/
  64. frag_buf_off=_state->frag_buf_offs[_fragi];
  65. refi=_state->frags[_fragi].refi;
  66. ystride=_state->ref_ystride[_pli];
  67. dst=_state->ref_frame_data[OC_FRAME_SELF]+frag_buf_off;
  68. if(refi==OC_FRAME_SELF)oc_frag_recon_intra_mmx(dst,ystride,_dct_coeffs+64);
  69. else{
  70. const unsigned char *ref;
  71. int mvoffsets[2];
  72. ref=_state->ref_frame_data[refi]+frag_buf_off;
  73. if(oc_state_get_mv_offsets(_state,mvoffsets,_pli,
  74. _state->frag_mvs[_fragi])>1){
  75. oc_frag_recon_inter2_mmx(dst,ref+mvoffsets[0],ref+mvoffsets[1],ystride,
  76. _dct_coeffs+64);
  77. }
  78. else oc_frag_recon_inter_mmx(dst,ref+mvoffsets[0],ystride,_dct_coeffs+64);
  79. }
  80. }
  81. /*We copy these entire function to inline the actual MMX routines so that we
  82. use only a single indirect call.*/
  83. void oc_loop_filter_init_mmx(signed char _bv[256],int _flimit){
  84. memset(_bv,_flimit,8);
  85. }
  86. /*Apply the loop filter to a given set of fragment rows in the given plane.
  87. The filter may be run on the bottom edge, affecting pixels in the next row of
  88. fragments, so this row also needs to be available.
  89. _bv: The bounding values array.
  90. _refi: The index of the frame buffer to filter.
  91. _pli: The color plane to filter.
  92. _fragy0: The Y coordinate of the first fragment row to filter.
  93. _fragy_end: The Y coordinate of the fragment row to stop filtering at.*/
  94. void oc_state_loop_filter_frag_rows_mmx(const oc_theora_state *_state,
  95. signed char _bv[256],int _refi,int _pli,int _fragy0,int _fragy_end){
  96. OC_ALIGN8(unsigned char ll[8]);
  97. const oc_fragment_plane *fplane;
  98. const oc_fragment *frags;
  99. const ptrdiff_t *frag_buf_offs;
  100. unsigned char *ref_frame_data;
  101. ptrdiff_t fragi_top;
  102. ptrdiff_t fragi_bot;
  103. ptrdiff_t fragi0;
  104. ptrdiff_t fragi0_end;
  105. int ystride;
  106. int nhfrags;
  107. memset(ll,_state->loop_filter_limits[_state->qis[0]],sizeof(ll));
  108. fplane=_state->fplanes+_pli;
  109. nhfrags=fplane->nhfrags;
  110. fragi_top=fplane->froffset;
  111. fragi_bot=fragi_top+fplane->nfrags;
  112. fragi0=fragi_top+_fragy0*(ptrdiff_t)nhfrags;
  113. fragi0_end=fragi0+(_fragy_end-_fragy0)*(ptrdiff_t)nhfrags;
  114. ystride=_state->ref_ystride[_pli];
  115. frags=_state->frags;
  116. frag_buf_offs=_state->frag_buf_offs;
  117. ref_frame_data=_state->ref_frame_data[_refi];
  118. /*The following loops are constructed somewhat non-intuitively on purpose.
  119. The main idea is: if a block boundary has at least one coded fragment on
  120. it, the filter is applied to it.
  121. However, the order that the filters are applied in matters, and VP3 chose
  122. the somewhat strange ordering used below.*/
  123. while(fragi0<fragi0_end){
  124. ptrdiff_t fragi;
  125. ptrdiff_t fragi_end;
  126. fragi=fragi0;
  127. fragi_end=fragi+nhfrags;
  128. while(fragi<fragi_end){
  129. if(frags[fragi].coded){
  130. unsigned char *ref;
  131. ref=ref_frame_data+frag_buf_offs[fragi];
  132. if(fragi>fragi0){
  133. OC_LOOP_FILTER_H(OC_LOOP_FILTER8_MMX,ref,ystride,ll);
  134. }
  135. if(fragi0>fragi_top){
  136. OC_LOOP_FILTER_V(OC_LOOP_FILTER8_MMX,ref,ystride,ll);
  137. }
  138. if(fragi+1<fragi_end&&!frags[fragi+1].coded){
  139. OC_LOOP_FILTER_H(OC_LOOP_FILTER8_MMX,ref+8,ystride,ll);
  140. }
  141. if(fragi+nhfrags<fragi_bot&&!frags[fragi+nhfrags].coded){
  142. OC_LOOP_FILTER_V(OC_LOOP_FILTER8_MMX,ref+(ystride<<3),ystride,ll);
  143. }
  144. }
  145. fragi++;
  146. }
  147. fragi0+=nhfrags;
  148. }
  149. }
  150. void oc_loop_filter_init_mmxext(signed char _bv[256],int _flimit){
  151. memset(_bv,~(_flimit<<1),8);
  152. }
  153. /*Apply the loop filter to a given set of fragment rows in the given plane.
  154. The filter may be run on the bottom edge, affecting pixels in the next row of
  155. fragments, so this row also needs to be available.
  156. _bv: The bounding values array.
  157. _refi: The index of the frame buffer to filter.
  158. _pli: The color plane to filter.
  159. _fragy0: The Y coordinate of the first fragment row to filter.
  160. _fragy_end: The Y coordinate of the fragment row to stop filtering at.*/
  161. void oc_state_loop_filter_frag_rows_mmxext(const oc_theora_state *_state,
  162. signed char _bv[256],int _refi,int _pli,int _fragy0,int _fragy_end){
  163. const oc_fragment_plane *fplane;
  164. const oc_fragment *frags;
  165. const ptrdiff_t *frag_buf_offs;
  166. unsigned char *ref_frame_data;
  167. ptrdiff_t fragi_top;
  168. ptrdiff_t fragi_bot;
  169. ptrdiff_t fragi0;
  170. ptrdiff_t fragi0_end;
  171. int ystride;
  172. int nhfrags;
  173. fplane=_state->fplanes+_pli;
  174. nhfrags=fplane->nhfrags;
  175. fragi_top=fplane->froffset;
  176. fragi_bot=fragi_top+fplane->nfrags;
  177. fragi0=fragi_top+_fragy0*(ptrdiff_t)nhfrags;
  178. fragi0_end=fragi_top+_fragy_end*(ptrdiff_t)nhfrags;
  179. ystride=_state->ref_ystride[_pli];
  180. frags=_state->frags;
  181. frag_buf_offs=_state->frag_buf_offs;
  182. ref_frame_data=_state->ref_frame_data[_refi];
  183. /*The following loops are constructed somewhat non-intuitively on purpose.
  184. The main idea is: if a block boundary has at least one coded fragment on
  185. it, the filter is applied to it.
  186. However, the order that the filters are applied in matters, and VP3 chose
  187. the somewhat strange ordering used below.*/
  188. while(fragi0<fragi0_end){
  189. ptrdiff_t fragi;
  190. ptrdiff_t fragi_end;
  191. fragi=fragi0;
  192. fragi_end=fragi+nhfrags;
  193. while(fragi<fragi_end){
  194. if(frags[fragi].coded){
  195. unsigned char *ref;
  196. ref=ref_frame_data+frag_buf_offs[fragi];
  197. if(fragi>fragi0){
  198. OC_LOOP_FILTER_H(OC_LOOP_FILTER8_MMXEXT,ref,ystride,_bv);
  199. }
  200. if(fragi0>fragi_top){
  201. OC_LOOP_FILTER_V(OC_LOOP_FILTER8_MMXEXT,ref,ystride,_bv);
  202. }
  203. if(fragi+1<fragi_end&&!frags[fragi+1].coded){
  204. OC_LOOP_FILTER_H(OC_LOOP_FILTER8_MMXEXT,ref+8,ystride,_bv);
  205. }
  206. if(fragi+nhfrags<fragi_bot&&!frags[fragi+nhfrags].coded){
  207. OC_LOOP_FILTER_V(OC_LOOP_FILTER8_MMXEXT,ref+(ystride<<3),ystride,_bv);
  208. }
  209. }
  210. fragi++;
  211. }
  212. fragi0+=nhfrags;
  213. }
  214. }
  215. #endif