void dct_unquantize_h263_altivec(MpegEncContext *s, 

                                 DCTELEM *block, int n, int qscale)

{

POWERPC_TBL_DECLARE(altivec_dct_unquantize_h263_num, 1);

    int i, level, qmul, qadd;

    int nCoeffs;

    

    assert(s->block_last_index[n]>=0);



POWERPC_TBL_START_COUNT(altivec_dct_unquantize_h263_num, 1);

    

    qadd = (qscale - 1) | 1;

    qmul = qscale << 1;

    

    if (s->mb_intra) {

        if (!s->h263_aic) {

            if (n < 4) 

                block[0] = block[0] * s->y_dc_scale;

            else

                block[0] = block[0] * s->c_dc_scale;

        }else

            qadd = 0;

        i = 1;

        nCoeffs= 63; //does not allways use zigzag table 

    } else {

        i = 0;

        nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];

    }



#ifdef ALTIVEC_USE_REFERENCE_C_CODE

    for(;i<=nCoeffs;i++) {

        level = block[i];

        if (level) {

            if (level < 0) {

                level = level * qmul - qadd;

            } else {

                level = level * qmul + qadd;

            }

            block[i] = level;

        }

    }

#else /* ALTIVEC_USE_REFERENCE_C_CODE */

    {

      register const vector short vczero = (const vector short)vec_splat_s16(0);

      short __attribute__ ((aligned(16))) qmul8[] =

          {

            qmul, qmul, qmul, qmul,

            qmul, qmul, qmul, qmul

          };

      short __attribute__ ((aligned(16))) qadd8[] =

          {

            qadd, qadd, qadd, qadd,

            qadd, qadd, qadd, qadd

          };

      short __attribute__ ((aligned(16))) nqadd8[] =

          {

            -qadd, -qadd, -qadd, -qadd,

            -qadd, -qadd, -qadd, -qadd

          };

      register vector short blockv, qmulv, qaddv, nqaddv, temp1;

      register vector bool short blockv_null, blockv_neg;

      register short backup_0 = block[0];

      register int j = 0;

      

      qmulv = vec_ld(0, qmul8);

      qaddv = vec_ld(0, qadd8);

      nqaddv = vec_ld(0, nqadd8);



#if 0 // block *is* 16 bytes-aligned, it seems.

      // first make sure block[j] is 16 bytes-aligned

      for(j = 0; (j <= nCoeffs) && ((((unsigned long)block) + (j << 1)) & 0x0000000F) ; j++) {

        level = block[j];

        if (level) {

          if (level < 0) {

                level = level * qmul - qadd;

            } else {

                level = level * qmul + qadd;

            }

            block[j] = level;

        }

      }

#endif

      

      // vectorize all the 16 bytes-aligned blocks

      // of 8 elements

      for(; (j + 7) <= nCoeffs ; j+=8)

      {

        blockv = vec_ld(j << 1, block);

        blockv_neg = vec_cmplt(blockv, vczero);

        blockv_null = vec_cmpeq(blockv, vczero);

        // choose between +qadd or -qadd as the third operand

        temp1 = vec_sel(qaddv, nqaddv, blockv_neg);

        // multiply & add (block{i,i+7} * qmul [+-] qadd)

        temp1 = vec_mladd(blockv, qmulv, temp1);

        // put 0 where block[{i,i+7} used to have 0

        blockv = vec_sel(temp1, blockv, blockv_null);

        vec_st(blockv, j << 1, block);

      }



      // if nCoeffs isn't a multiple of 8, finish the job

      // using good old scalar units.

      // (we could do it using a truncated vector,

      // but I'm not sure it's worth the hassle)

      for(; j <= nCoeffs ; j++) {

        level = block[j];

        if (level) {

          if (level < 0) {

                level = level * qmul - qadd;

            } else {

                level = level * qmul + qadd;

            }

            block[j] = level;

        }

      }

      

      if (i == 1)

      { // cheat. this avoid special-casing the first iteration

        block[0] = backup_0;

      }

    }

#endif /* ALTIVEC_USE_REFERENCE_C_CODE */



POWERPC_TBL_STOP_COUNT(altivec_dct_unquantize_h263_num, nCoeffs == 63);

}

void dct_unquantize_h263_altivec(MpegEncContext *s, 

                                 DCTELEM *block, int n, int qscale)

{

POWERPC_TBL_DECLARE(altivec_dct_unquantize_h263_num, 1);

    int i, level, qmul, qadd;

    int nCoeffs;

    

    assert(s->block_last_index[n]>=0);



POWERPC_TBL_START_COUNT(altivec_dct_unquantize_h263_num, 1);

    

    qadd = (qscale - 1) | 1;

    qmul = qscale << 1;

    

    if (s->mb_intra) {

        if (!s->h263_aic) {

            if (n < 4) 

                block[0] = block[0] * s->y_dc_scale;

            else

                block[0] = block[0] * s->c_dc_scale;

        }else

            qadd = 0;

        i = 1;

        nCoeffs= 63; 

    } else {

        i = 0;

        nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];

    }



#ifdef ALTIVEC_USE_REFERENCE_C_CODE

    for(;i<=nCoeffs;i++) {

        level = block[i];

        if (level) {

            if (level < 0) {

                level = level * qmul - qadd;

            } else {

                level = level * qmul + qadd;

            }

            block[i] = level;

        }

    }

#else 

    {

      register const vector short vczero = (const vector short)vec_splat_s16(0);

      short __attribute__ ((aligned(16))) qmul8[] =

          {

            qmul, qmul, qmul, qmul,

            qmul, qmul, qmul, qmul

          };

      short __attribute__ ((aligned(16))) qadd8[] =

          {

            qadd, qadd, qadd, qadd,

            qadd, qadd, qadd, qadd

          };

      short __attribute__ ((aligned(16))) nqadd8[] =

          {

            -qadd, -qadd, -qadd, -qadd,

            -qadd, -qadd, -qadd, -qadd

          };

      register vector short blockv, qmulv, qaddv, nqaddv, temp1;

      register vector bool short blockv_null, blockv_neg;

      register short backup_0 = block[0];

      register int j = 0;

      

      qmulv = vec_ld(0, qmul8);

      qaddv = vec_ld(0, qadd8);

      nqaddv = vec_ld(0, nqadd8);



#if 0 

      

      for(j = 0; (j <= nCoeffs) && ((((unsigned long)block) + (j << 1)) & 0x0000000F) ; j++) {

        level = block[j];

        if (level) {

          if (level < 0) {

                level = level * qmul - qadd;

            } else {

                level = level * qmul + qadd;

            }

            block[j] = level;

        }

      }

#endif

      

      

      

      for(; (j + 7) <= nCoeffs ; j+=8)

      {

        blockv = vec_ld(j << 1, block);

        blockv_neg = vec_cmplt(blockv, vczero);

        blockv_null = vec_cmpeq(blockv, vczero);

        

        temp1 = vec_sel(qaddv, nqaddv, blockv_neg);

        

        temp1 = vec_mladd(blockv, qmulv, temp1);

        

        blockv = vec_sel(temp1, blockv, blockv_null);

        vec_st(blockv, j << 1, block);

      }



      

      

      

      

      for(; j <= nCoeffs ; j++) {

        level = block[j];

        if (level) {

          if (level < 0) {

                level = level * qmul - qadd;

            } else {

                level = level * qmul + qadd;

            }

            block[j] = level;

        }

      }

      

      if (i == 1)

      { 

        block[0] = backup_0;

      }

    }

#endif 



POWERPC_TBL_STOP_COUNT(altivec_dct_unquantize_h263_num, nCoeffs == 63);

}

void FUNC_0(MpegEncContext *VAR_0, 

                                 DCTELEM *VAR_1, int VAR_2, int VAR_3)

{

POWERPC_TBL_DECLARE(altivec_dct_unquantize_h263_num, 1);

    int VAR_4, VAR_5, VAR_6, VAR_7;

    int VAR_8;

    

    assert(VAR_0->block_last_index[VAR_2]>=0);



POWERPC_TBL_START_COUNT(altivec_dct_unquantize_h263_num, 1);

    

    VAR_7 = (VAR_3 - 1) | 1;

    VAR_6 = VAR_3 << 1;

    

    if (VAR_0->mb_intra) {

        if (!VAR_0->h263_aic) {

            if (VAR_2 < 4) 

                VAR_1[0] = VAR_1[0] * VAR_0->y_dc_scale;

            else

                VAR_1[0] = VAR_1[0] * VAR_0->c_dc_scale;

        }else

            VAR_7 = 0;

        VAR_4 = 1;

        VAR_8= 63; 

    } else {

        VAR_4 = 0;

        VAR_8= VAR_0->intra_scantable.raster_end[ VAR_0->block_last_index[VAR_2] ];

    }



#ifdef ALTIVEC_USE_REFERENCE_C_CODE

    for(;VAR_4<=VAR_8;VAR_4++) {

        VAR_5 = VAR_1[VAR_4];

        if (VAR_5) {

            if (VAR_5 < 0) {

                VAR_5 = VAR_5 * VAR_6 - VAR_7;

            } else {

                VAR_5 = VAR_5 * VAR_6 + VAR_7;

            }

            VAR_1[VAR_4] = VAR_5;

        }

    }

#else 

    {

      register const vector short VAR_9 = (const vector short)vec_splat_s16(0);

      short __attribute__ ((aligned(16))) VAR_10[] =

          {

            VAR_6, VAR_6, VAR_6, VAR_6,

            VAR_6, VAR_6, VAR_6, VAR_6

          };

      short __attribute__ ((aligned(16))) VAR_11[] =

          {

            VAR_7, VAR_7, VAR_7, VAR_7,

            VAR_7, VAR_7, VAR_7, VAR_7

          };

      short __attribute__ ((aligned(16))) VAR_12[] =

          {

            -VAR_7, -VAR_7, -VAR_7, -VAR_7,

            -VAR_7, -VAR_7, -VAR_7, -VAR_7

          };

      register vector short VAR_13, qmulv, qaddv, nqaddv, temp1;

      register vector VAR_14 short VAR_15, VAR_16;

      register short VAR_17 = VAR_1[0];

      register int VAR_18 = 0;

      

      qmulv = vec_ld(0, VAR_10);

      qaddv = vec_ld(0, VAR_11);

      nqaddv = vec_ld(0, VAR_12);



#if 0 

      

      for(VAR_18 = 0; (VAR_18 <= VAR_8) && ((((unsigned long)VAR_1) + (VAR_18 << 1)) & 0x0000000F) ; VAR_18++) {

        VAR_5 = VAR_1[VAR_18];

        if (VAR_5) {

          if (VAR_5 < 0) {

                VAR_5 = VAR_5 * VAR_6 - VAR_7;

            } else {

                VAR_5 = VAR_5 * VAR_6 + VAR_7;

            }

            VAR_1[VAR_18] = VAR_5;

        }

      }

#endif

      

      

      

      for(; (VAR_18 + 7) <= VAR_8 ; VAR_18+=8)

      {

        VAR_13 = vec_ld(VAR_18 << 1, VAR_1);

        VAR_16 = vec_cmplt(VAR_13, VAR_9);

        VAR_15 = vec_cmpeq(VAR_13, VAR_9);

        

        temp1 = vec_sel(qaddv, nqaddv, VAR_16);

        

        temp1 = vec_mladd(VAR_13, qmulv, temp1);

        

        VAR_13 = vec_sel(temp1, VAR_13, VAR_15);

        vec_st(VAR_13, VAR_18 << 1, VAR_1);

      }



      

      

      

      

      for(; VAR_18 <= VAR_8 ; VAR_18++) {

        VAR_5 = VAR_1[VAR_18];

        if (VAR_5) {

          if (VAR_5 < 0) {

                VAR_5 = VAR_5 * VAR_6 - VAR_7;

            } else {

                VAR_5 = VAR_5 * VAR_6 + VAR_7;

            }

            VAR_1[VAR_18] = VAR_5;

        }

      }

      

      if (VAR_4 == 1)

      { 

        VAR_1[0] = VAR_17;

      }

    }

#endif 



POWERPC_TBL_STOP_COUNT(altivec_dct_unquantize_h263_num, VAR_8 == 63);

}

void FUNC_0(MpegEncContext *VAR_0,
DCTELEM *VAR_1, int VAR_2, int VAR_3)
{ POWERPC_TBL_DECLARE(altivec_dct_unquantize_h263_num, 1); int VAR_4, VAR_5, VAR_6, VAR_7; int VAR_8; assert(VAR_0->block_last_index[VAR_2]>=0); POWERPC_TBL_START_COUNT(altivec_dct_unquantize_h263_num, 1); VAR_7 = (VAR_3 - 1) | 1; VAR_6 = VAR_3 << 1; if (VAR_0->mb_intra) { if (!VAR_0->h263_aic) { if (VAR_2 < 4)
VAR_1[0] = VAR_1[0] * VAR_0->y_dc_scale; else
VAR_1[0] = VAR_1[0] * VAR_0->c_dc_scale; }else VAR_7 = 0; VAR_4 = 1; VAR_8= 63; } else { VAR_4 = 0; VAR_8= VAR_0->intra_scantable.raster_end[ VAR_0->block_last_index[VAR_2] ]; } #ifdef ALTIVEC_USE_REFERENCE_C_CODE
for(;VAR_4<=VAR_8;VAR_4++) { VAR_5 = VAR_1[VAR_4]; if (VAR_5) { if (VAR_5 < 0) { VAR_5 = VAR_5 * VAR_6 - VAR_7; } else { VAR_5 = VAR_5 * VAR_6 + VAR_7; } VAR_1[VAR_4] = VAR_5; } } #else
{ register const vector short VAR_9 = (const vector short)vec_splat_s16(0); short __attribute__ ((aligned(16))) VAR_10[] =
{ VAR_6, VAR_6, VAR_6, VAR_6,
VAR_6, VAR_6, VAR_6, VAR_6
}; short __attribute__ ((aligned(16))) VAR_11[] =
{ VAR_7, VAR_7, VAR_7, VAR_7,
VAR_7, VAR_7, VAR_7, VAR_7
}; short __attribute__ ((aligned(16))) VAR_12[] =
{ -VAR_7, -VAR_7, -VAR_7, -VAR_7,
-VAR_7, -VAR_7, -VAR_7, -VAR_7
}; register vector short VAR_13, qmulv, qaddv, nqaddv, temp1; register vector VAR_14 short VAR_15, VAR_16; register short VAR_17 = VAR_1[0]; register int VAR_18 = 0; qmulv = vec_ld(0, VAR_10); qaddv = vec_ld(0, VAR_11); nqaddv = vec_ld(0, VAR_12); #if 0
for(VAR_18 = 0; (VAR_18 <= VAR_8) && ((((unsigned long)VAR_1) + (VAR_18 << 1)) & 0x0000000F) ; VAR_18++) { VAR_5 = VAR_1[VAR_18]; if (VAR_5) { if (VAR_5 < 0) { VAR_5 = VAR_5 * VAR_6 - VAR_7; } else { VAR_5 = VAR_5 * VAR_6 + VAR_7; } VAR_1[VAR_18] = VAR_5; } } #endif
for(; (VAR_18 + 7) <= VAR_8 ; VAR_18+=8) { VAR_13 = vec_ld(VAR_18 << 1, VAR_1); VAR_16 = vec_cmplt(VAR_13, VAR_9); VAR_15 = vec_cmpeq(VAR_13, VAR_9); temp1 = vec_sel(qaddv, nqaddv, VAR_16); temp1 = vec_mladd(VAR_13, qmulv, temp1); VAR_13 = vec_sel(temp1, VAR_13, VAR_15); vec_st(VAR_13, VAR_18 << 1, VAR_1); } for(; VAR_18 <= VAR_8 ; VAR_18++) { VAR_5 = VAR_1[VAR_18]; if (VAR_5) { if (VAR_5 < 0) { VAR_5 = VAR_5 * VAR_6 - VAR_7; } else { VAR_5 = VAR_5 * VAR_6 + VAR_7; } VAR_1[VAR_18] = VAR_5; } } if (VAR_4 == 1)
{ VAR_1[0] = VAR_17; } } #endif
POWERPC_TBL_STOP_COUNT(altivec_dct_unquantize_h263_num, VAR_8 == 63); }