Path: blob/master/thirdparty/libtheora/x86_vc/mmxstate.c
9904 views
/********************************************************************1* *2* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *3* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *4* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *5* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *6* *7* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *8* by the Xiph.Org Foundation and contributors *9* https://www.xiph.org/ *10* *11********************************************************************1213function:1415********************************************************************/1617/*MMX acceleration of complete fragment reconstruction algorithm.18Originally written by Rudolf Marek.*/19#include <string.h>20#include "x86int.h"21#include "mmxloop.h"2223#if defined(OC_X86_ASM)2425void oc_state_frag_recon_mmx(const oc_theora_state *_state,ptrdiff_t _fragi,26int _pli,ogg_int16_t _dct_coeffs[128],int _last_zzi,ogg_uint16_t _dc_quant){27unsigned char *dst;28ptrdiff_t frag_buf_off;29int ystride;30int refi;31/*Apply the inverse transform.*/32/*Special case only having a DC component.*/33if(_last_zzi<2){34/*Note that this value must be unsigned, to keep the __asm__ block from35sign-extending it when it puts it in a register.*/36ogg_uint16_t p;37/*We round this dequant product (and not any of the others) because there's38no iDCT rounding.*/39p=(ogg_int16_t)(_dct_coeffs[0]*(ogg_int32_t)_dc_quant+15>>5);40/*Fill _dct_coeffs with p.*/41__asm{42#define Y eax43#define P ecx44mov Y,_dct_coeffs45movzx P,p46lea Y,[Y+128]47/*mm0=0000 0000 0000 AAAA*/48movd mm0,P49/*mm0=0000 0000 AAAA AAAA*/50punpcklwd mm0,mm051/*mm0=AAAA AAAA AAAA AAAA*/52punpckldq mm0,mm053movq [Y],mm054movq [8+Y],mm055movq [16+Y],mm056movq [24+Y],mm057movq [32+Y],mm058movq [40+Y],mm059movq [48+Y],mm060movq [56+Y],mm061movq [64+Y],mm062movq [72+Y],mm063movq [80+Y],mm064movq [88+Y],mm065movq [96+Y],mm066movq [104+Y],mm067movq [112+Y],mm068movq [120+Y],mm069#undef Y70#undef P71}72}73else{74/*Dequantize the DC coefficient.*/75_dct_coeffs[0]=(ogg_int16_t)(_dct_coeffs[0]*(int)_dc_quant);76oc_idct8x8_mmx(_dct_coeffs+64,_dct_coeffs,_last_zzi);77}78/*Fill in the target buffer.*/79frag_buf_off=_state->frag_buf_offs[_fragi];80refi=_state->frags[_fragi].refi;81ystride=_state->ref_ystride[_pli];82dst=_state->ref_frame_data[OC_FRAME_SELF]+frag_buf_off;83if(refi==OC_FRAME_SELF)oc_frag_recon_intra_mmx(dst,ystride,_dct_coeffs+64);84else{85const unsigned char *ref;86int mvoffsets[2];87ref=_state->ref_frame_data[refi]+frag_buf_off;88if(oc_state_get_mv_offsets(_state,mvoffsets,_pli,89_state->frag_mvs[_fragi])>1){90oc_frag_recon_inter2_mmx(dst,ref+mvoffsets[0],ref+mvoffsets[1],ystride,91_dct_coeffs+64);92}93else oc_frag_recon_inter_mmx(dst,ref+mvoffsets[0],ystride,_dct_coeffs+64);94}95}9697/*We copy these entire function to inline the actual MMX routines so that we98use only a single indirect call.*/99100void oc_loop_filter_init_mmx(signed char _bv[256],int _flimit){101memset(_bv,~(_flimit<<1),8);102}103104/*Apply the loop filter to a given set of fragment rows in the given plane.105The filter may be run on the bottom edge, affecting pixels in the next row of106fragments, so this row also needs to be available.107_bv: The bounding values array.108_refi: The index of the frame buffer to filter.109_pli: The color plane to filter.110_fragy0: The Y coordinate of the first fragment row to filter.111_fragy_end: The Y coordinate of the fragment row to stop filtering at.*/112void oc_state_loop_filter_frag_rows_mmx(const oc_theora_state *_state,113signed char _bv[256],int _refi,int _pli,int _fragy0,int _fragy_end){114const oc_fragment_plane *fplane;115const oc_fragment *frags;116const ptrdiff_t *frag_buf_offs;117unsigned char *ref_frame_data;118ptrdiff_t fragi_top;119ptrdiff_t fragi_bot;120ptrdiff_t fragi0;121ptrdiff_t fragi0_end;122int ystride;123int nhfrags;124fplane=_state->fplanes+_pli;125nhfrags=fplane->nhfrags;126fragi_top=fplane->froffset;127fragi_bot=fragi_top+fplane->nfrags;128fragi0=fragi_top+_fragy0*(ptrdiff_t)nhfrags;129fragi0_end=fragi_top+_fragy_end*(ptrdiff_t)nhfrags;130ystride=_state->ref_ystride[_pli];131frags=_state->frags;132frag_buf_offs=_state->frag_buf_offs;133ref_frame_data=_state->ref_frame_data[_refi];134/*The following loops are constructed somewhat non-intuitively on purpose.135The main idea is: if a block boundary has at least one coded fragment on136it, the filter is applied to it.137However, the order that the filters are applied in matters, and VP3 chose138the somewhat strange ordering used below.*/139while(fragi0<fragi0_end){140ptrdiff_t fragi;141ptrdiff_t fragi_end;142fragi=fragi0;143fragi_end=fragi+nhfrags;144while(fragi<fragi_end){145if(frags[fragi].coded){146unsigned char *ref;147ref=ref_frame_data+frag_buf_offs[fragi];148#define PIX eax149#define YSTRIDE3 edi150#define YSTRIDE ecx151#define LL edx152#define D esi153#define D_WORD si154if(fragi>fragi0)OC_LOOP_FILTER_H_MMX(ref,ystride,_bv);155if(fragi0>fragi_top)OC_LOOP_FILTER_V_MMX(ref,ystride,_bv);156if(fragi+1<fragi_end&&!frags[fragi+1].coded){157OC_LOOP_FILTER_H_MMX(ref+8,ystride,_bv);158}159if(fragi+nhfrags<fragi_bot&&!frags[fragi+nhfrags].coded){160OC_LOOP_FILTER_V_MMX(ref+(ystride*8),ystride,_bv);161}162#undef PIX163#undef YSTRIDE3164#undef YSTRIDE165#undef LL166#undef D167#undef D_WORD168}169fragi++;170}171fragi0+=nhfrags;172}173}174175#endif176177178