2 * BlackFin MPEGVIDEO OPTIMIZATIONS
4 * Copyright (C) 2007 Marc Hoffman <mmh@pleasantst.com>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavcodec/avcodec.h"
24 #include "libavcodec/dsputil.h"
25 #include "libavcodec/mpegvideo.h"
26 #include "dsputil_bfin.h"
28 static int dct_quantize_bfin (MpegEncContext *s,
29 DCTELEM *block, int n,
30 int qscale, int *overflow)
32 int last_non_zero, q, start_i;
35 const uint8_t *scantable= s->intra_scantable.scantable;
45 s->denoise_dct(s, block);
57 /* For AIC we skip quant/dequant of INTRADC */
60 /* note: block[0] is assumed to be positive */
61 dc = block[0] = (block[0] + (q >> 1)) / q;
65 bias = s->q_intra_matrix16[qscale][1];
66 qmat = s->q_intra_matrix16[qscale][0];
68 bias = s->q_chroma_intra_matrix16[qscale][1];
69 qmat = s->q_chroma_intra_matrix16[qscale][0];
75 bias = s->q_inter_matrix16[qscale][1];
76 qmat = s->q_inter_matrix16[qscale][0];
83 /* for(i=start_i; i<64; i++) { */
84 /* sign = (block[i]>>15)|1; */
85 /* level = ((abs(block[i])+bias[0])*qmat[i])>>16; */
86 /* if (level < 0) level = 0; */
88 /* level = level * sign; */
89 /* block[i] = level; */
95 "r0=r1>>>15 (v); \n\t"
96 "lsetup (0f,1f) lc0=%3; \n\t"
98 " r1=abs r1 (v) || r2=[%2++];\n\t"
100 " r1=max(r1,%6) (v); \n\t"
101 " r1.h=(a1 =r1.h*r2.h), r1.l=(a0 =r1.l*r2.l) (tfu); \n\t"
103 " r0.h=(a1 =r1.h*r0.h), r0.l=(a0 =r1.l*r0.l) (is) || r1=[%1++];\n\t"
104 "1: r0=r1>>>15 (v) || [i2++]=r0;\n\t"
109 : "b" (block), "b" (qmat), "a" (32), "d" (0x00010001), "d" (bias[0]*0x10001), "d" (0)
110 : "R0","R1","R2", "I2");
111 if (start_i == 1) block[0] = dc;
119 ("r0=b[%1--] (x); \n\t"
120 "lsetup (0f,1f) lc0=%3; \n\t" /* for(i=63; i>=start_i; i--) { */
121 "0: p0=r0; \n\t" /* j = scantable[i]; */
122 " p0=%2+(p0<<1); \n\t" /* if (block[j]) { */
123 " r0=w[p0]; \n\t" /* last_non_zero = i; */
124 " cc=r0==0; \n\t" /* break; */
125 " if !cc jump 2f; \n\t" /* } */
126 "1: r0=b[%1--] (x); \n\t" /* } */
132 : "=d" (last_non_zero)
133 : "a" (scantable+63), "a" (block), "a" (63), "d" (last_non_zero)
138 *overflow= s->max_qcoeff < max; //overflow might have happened
142 /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
143 if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
144 ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
146 return last_non_zero;
149 void ff_MPV_common_init_bfin (MpegEncContext *s)
151 /* s->dct_quantize= dct_quantize_bfin; */