/[pcsx2_0.9.7]/trunk/pcsx2/IPU/mpeg2lib/Mpeg.h
ViewVC logotype

Diff of /trunk/pcsx2/IPU/mpeg2lib/Mpeg.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 31 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 22  Line 22 
22   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
23   */   */
24    
25  #ifndef __MPEG_H__  #pragma once
26  #define __MPEG_H__  
27    #include <xmmintrin.h>
28    
29    template< typename T >
30    __noinline void memzero_sse_a( T& dest )
31    {
32    #define MZFqwc (sizeof(dest)/16)
33    
34            C_ASSERT( (sizeof(dest) & 0xf) == 0 );
35    
36            __m128 zeroreg = _mm_setzero_ps();
37    
38            float (*destxmm)[4] = (float(*)[4])&dest;
39    
40    #define StoreDestIdx(idx) case idx: _mm_store_ps(&destxmm[idx][0], zeroreg)
41    
42            switch( MZFqwc & 0x07 )
43            {
44                    StoreDestIdx(0x07);
45                    StoreDestIdx(0x06);
46                    StoreDestIdx(0x05);
47                    StoreDestIdx(0x04);
48                    StoreDestIdx(0x03);
49                    StoreDestIdx(0x02);
50                    StoreDestIdx(0x01);
51            }
52    
53            destxmm += (MZFqwc & 0x07);
54            for( uint i=0; i<MZFqwc / 8; ++i, destxmm+=8 )
55            {
56                    _mm_store_ps(&destxmm[0][0], zeroreg);
57                    _mm_store_ps(&destxmm[1][0], zeroreg);
58                    _mm_store_ps(&destxmm[2][0], zeroreg);
59                    _mm_store_ps(&destxmm[3][0], zeroreg);
60                    _mm_store_ps(&destxmm[4][0], zeroreg);
61                    _mm_store_ps(&destxmm[5][0], zeroreg);
62                    _mm_store_ps(&destxmm[6][0], zeroreg);
63                    _mm_store_ps(&destxmm[7][0], zeroreg);
64            }
65    
66    #undef MZFqwc
67    };
68    
69    // the IPU is fixed to 16 byte strides (128-bit / QWC resolution):
70    static const uint decoder_stride = 16;
71    
72  enum macroblock_modes  enum macroblock_modes
73  {  {
# Line 64  enum picture_coding_type Line 108  enum picture_coding_type
108  };  };
109    
110  struct macroblock_8{  struct macroblock_8{
111          unsigned char Y[16][16];        //0          u8 Y[16][16];           //0
112          unsigned char Cb[8][8];         //1          u8 Cb[8][8];            //1
113          unsigned char Cr[8][8];         //2          u8 Cr[8][8];            //2
114  };  };
115    
116  struct macroblock_16{  struct macroblock_16{
117          short Y[16][16];                        //0          s16 Y[16][16];                  //0
118          short Cb[8][8];                         //1          s16 Cb[8][8];                   //1
119          short Cr[8][8];                         //2          s16 Cr[8][8];                   //2
120  };  };
121    
122  struct macroblock_rgb32{  struct macroblock_rgb32{
123          struct {          struct {
124                  unsigned char r, g, b, a;                  u8 r, g, b, a;
125          } c[16][16];          } c[16][16];
126  };  };
127    
128  struct rgb16{  struct rgb16_t{
129          unsigned short r:5, g:5, b:5, a:1;          u16 r:5, g:5, b:5, a:1;
130  };  };
131    
132  struct macroblock_rgb16{  struct macroblock_rgb16{
133          struct rgb16    c[16][16];          rgb16_t c[16][16];
134  };  };
135    
136  struct decoder_t {  struct decoder_t {
# Line 96  struct decoder_t { Line 140  struct decoder_t {
140          /* DCT coefficients - should be kept aligned ! */          /* DCT coefficients - should be kept aligned ! */
141          s16 DCTblock[64];          s16 DCTblock[64];
142    
143          /* bit parsing stuff */          u8 niq[64];                     //non-intraquant matrix (sequence header)
144          u32 bitstream_buf;              /* current 32 bit working set */          u8 iq[64];                      //intraquant matrix (sequence header)
         int bitstream_bits;                     /* used bits in working set */  
         u8 * bitstream_ptr;                     /* buffer with stream data; 128 bits buffer */  
145    
146          struct macroblock_8             *mb8;          macroblock_8 mb8;
147          struct macroblock_16    *mb16;          macroblock_16 mb16;
148          struct macroblock_rgb32 *rgb32;          macroblock_rgb32 rgb32;
149          struct macroblock_rgb16 *rgb16;          macroblock_rgb16 rgb16;
150    
151          int stride;          uint ipu0_data;
152            uint ipu0_idx;
153    
154          /* predictor for DC coefficients in intra blocks */          /* bit parsing stuff */
155          s16 dc_dct_pred[3];          u32 bitstream_buf;              /* current 32 bit working set */
156            int bitstream_bits;                     /* used bits in working set */
157    
158          int quantizer_scale;    /* remove */          int quantizer_scale;    /* remove */
159          int dmv_offset;         /* remove */          int dmv_offset;         /* remove */
160    
161          /* now non-slice-specific information */          /* now non-slice-specific information */
162    
         /* sequence header stuff */  
         u8 *intra_quantizer_matrix;  
         u8 *non_intra_quantizer_matrix;  
   
163          /* picture header stuff */          /* picture header stuff */
164    
165          /* what type of picture this is (I, P, B, D) */          /* what type of picture this is (I, P, B, D) */
# Line 127  struct decoder_t { Line 167  struct decoder_t {
167    
168          /* picture coding extension stuff */          /* picture coding extension stuff */
169    
170            /* predictor for DC coefficients in intra blocks */
171            s16 dc_dct_pred[3];
172    
173          /* quantization factor for intra dc coefficients */          /* quantization factor for intra dc coefficients */
174          int intra_dc_precision;          int intra_dc_precision;
175          /* top/bottom/both fields */          /* top/bottom/both fields */
# Line 159  struct decoder_t { Line 202  struct decoder_t {
202    
203          /* stuff derived from bitstream */          /* stuff derived from bitstream */
204    
205          /* pointer to the zigzag scan we're supposed to be using */          /* the zigzag scan we're supposed to be using, true for alt, false for normal */
206          const u8 * scan;          bool scantype;
207    
208          int second_field;          int second_field;
209    
210          int mpeg1;          int mpeg1;
211    
212            template< typename T >
213            void SetOutputTo( T& obj )
214            {
215                    uint mb_offset = ((uptr)&obj - (uptr)&mb8);
216                    pxAssume( (mb_offset & 15) == 0 );
217                    ipu0_idx        = mb_offset / 16;
218                    ipu0_data       = sizeof(obj)/16;
219            }
220    
221            u128* GetIpuDataPtr()
222            {
223                    return ((u128*)&mb8) + ipu0_idx;
224            }
225            
226            void AdvanceIpuDataBy(uint amt)
227            {
228                    pxAssumeDev(ipu0_data>=amt, "IPU FIFO Overflow on advance!" );
229                    ipu0_idx += amt;
230                    ipu0_data -= amt;
231            }
232            
233            bool ReadIpuData(u128* out);
234    };
235    
236    struct mpeg2_scan_pack
237    {
238            u8 norm[64];
239            u8 alt[64];
240    
241            mpeg2_scan_pack();
242  };  };
243    
244  extern void (__fastcall *mpeg2_idct_copy) (s16 * block, u8* dest, int stride);  extern void mpeg2_idct_copy(s16 * block, u8* dest, int stride);
245  extern void (__fastcall *mpeg2_idct_add) (int last, s16 * block, s16* dest, int stride);  extern void mpeg2_idct_add(int last, s16 * block, s16* dest, int stride);
246    
247  #define IDEC    0  #define IDEC    0
248  #define BDEC    1  #define BDEC    1
249    
250  void mpeg2sliceIDEC(void* pdone);  extern bool mpeg2sliceIDEC();
251  void mpeg2_slice(void* pdone);  extern bool mpeg2_slice();
252  int get_macroblock_address_increment(decoder_t * const decoder);  extern int get_macroblock_address_increment();
253  int get_macroblock_modes (decoder_t * const decoder);  extern int get_macroblock_modes();
254    
255  extern int get_motion_delta (decoder_t * const decoder, const int f_code);  extern int get_motion_delta(const int f_code);
256  extern int get_dmv (decoder_t * const decoder);  extern int get_dmv();
257    
258  extern int non_linear_quantizer_scale[];  extern void ipu_csc(macroblock_8& mb8, macroblock_rgb32& rgb32, int sgn);
259  extern decoder_t g_decoder;  extern void ipu_dither(const macroblock_rgb32& rgb32, macroblock_rgb16& rgb16, int dte);
260    extern void ipu_vq(macroblock_rgb16& rgb16, u8* indx4);
261  void __fastcall ipu_csc(macroblock_8 *mb8, macroblock_rgb32 *rgb32, int sgn);  extern void ipu_copy(const macroblock_8& mb8, macroblock_16& mb16);
262  void __fastcall ipu_dither(const macroblock_rgb32* rgb32, macroblock_rgb16 *rgb16, int dte);  
263  void __fastcall ipu_vq(macroblock_rgb16 *rgb16, u8* indx4);  extern int slice (u8 * buffer);
 void __fastcall ipu_copy(const macroblock_8 *mb8, macroblock_16 *mb16);  
   
 int slice (decoder_t * const decoder, u8 * buffer);  
 /* idct.c */  
 void mpeg2_idct_init ();  
264    
265  #ifdef _MSC_VER  #ifdef _MSC_VER
266  #define BigEndian(out, in) out = _byteswap_ulong(in)  #define BigEndian(out, in) out = _byteswap_ulong(in)
# Line 199  void mpeg2_idct_init (); Line 268  void mpeg2_idct_init ();
268  #define BigEndian(out, in) out = __builtin_bswap32(in) // or we could use the asm function bswap...  #define BigEndian(out, in) out = __builtin_bswap32(in) // or we could use the asm function bswap...
269  #endif  #endif
270    
271  #endif//__MPEG_H__  #ifdef _MSC_VER
272    #define BigEndian64(out, in) out = _byteswap_uint64(in)
273    #else
274    #define BigEndian64(out, in) out = __builtin_bswap64(in) // or we could use the asm function bswap...
275    #endif
276    
277    extern __aligned16 const mpeg2_scan_pack mpeg2_scan;
278    extern const int non_linear_quantizer_scale[];
279    
280    // The IPU can only do one task at once and never uses other buffers so all mpeg state variables
281    // are made available to mpeg/vlc modules as globals here:
282    
283    extern __aligned16 tIPU_BP g_BP;
284    extern __aligned16 decoder_t decoder;
285    

Legend:
Removed from v.31  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22