Statistics
| Branch: | Revision:

ffmpeg / libavcodec / bfin / dsputil_bfin.c @ be449fca

History | View | Annotate | Download (11.7 KB)

1 5ca030fe Michael Benjamin
/*
2 67fd620c Marc Hoffman
 * BlackFin DSPUTILS
3
 *
4
 * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
5
 * Copyright (c) 2006 Michael Benjamin <michael.benjamin@analog.com>
6 5ca030fe Michael Benjamin
 *
7 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
8
 *
9
 * FFmpeg is free software; you can redistribute it and/or
10 5ca030fe Michael Benjamin
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
13 5ca030fe Michael Benjamin
 *
14 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
15 5ca030fe Michael Benjamin
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
21 5ca030fe Michael Benjamin
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
 */
23
24 67fd620c Marc Hoffman
#include <unistd.h>
25 245976da Diego Biurrun
#include "libavcodec/avcodec.h"
26
#include "libavcodec/dsputil.h"
27 bd92f4f3 Marc Hoffman
#include "dsputil_bfin.h"
28 5ca030fe Michael Benjamin
29 67fd620c Marc Hoffman
int off;
30
31
32 bd92f4f3 Marc Hoffman
extern void ff_bfin_idct (DCTELEM *block) attribute_l1_text;
33
extern void ff_bfin_fdct (DCTELEM *block) attribute_l1_text;
34 b9dc3279 Marc Hoffman
extern void ff_bfin_vp3_idct (DCTELEM *block);
35
extern void ff_bfin_vp3_idct_put (uint8_t *dest, int line_size, DCTELEM *block);
36
extern void ff_bfin_vp3_idct_add (uint8_t *dest, int line_size, DCTELEM *block);
37 bd92f4f3 Marc Hoffman
extern void ff_bfin_add_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text;
38
extern void ff_bfin_put_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text;
39
extern void ff_bfin_diff_pixels (DCTELEM *block, uint8_t *s1, uint8_t *s2, int stride)  attribute_l1_text;
40
extern void ff_bfin_get_pixels  (DCTELEM *restrict block, const uint8_t *pixels, int line_size) attribute_l1_text;
41
extern int  ff_bfin_pix_norm1  (uint8_t * pix, int line_size) attribute_l1_text;
42
extern int  ff_bfin_z_sad8x8   (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text;
43
extern int  ff_bfin_z_sad16x16 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text;
44 67fd620c Marc Hoffman
45 bd92f4f3 Marc Hoffman
extern void ff_bfin_z_put_pixels16_xy2     (uint8_t *block, const uint8_t *s0, int dest_size, int line_size, int h) attribute_l1_text;
46
extern void ff_bfin_z_put_pixels8_xy2      (uint8_t *block, const uint8_t *s0, int dest_size, int line_size, int h) attribute_l1_text;
47
extern void ff_bfin_put_pixels16_xy2_nornd (uint8_t *block, const uint8_t *s0, int line_size, int h) attribute_l1_text;
48
extern void ff_bfin_put_pixels8_xy2_nornd  (uint8_t *block, const uint8_t *s0, int line_size, int h) attribute_l1_text;
49 67fd620c Marc Hoffman
50
51 bd92f4f3 Marc Hoffman
extern int  ff_bfin_pix_sum (uint8_t *p, int stride) attribute_l1_text;
52 67fd620c Marc Hoffman
53 bd92f4f3 Marc Hoffman
extern void ff_bfin_put_pixels8uc        (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int dest_size, int line_size, int h) attribute_l1_text;
54
extern void ff_bfin_put_pixels16uc       (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int dest_size, int line_size, int h) attribute_l1_text;
55
extern void ff_bfin_put_pixels8uc_nornd  (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int line_size, int h) attribute_l1_text;
56
extern void ff_bfin_put_pixels16uc_nornd (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int line_size, int h) attribute_l1_text;
57 67fd620c Marc Hoffman
58 bd92f4f3 Marc Hoffman
extern int ff_bfin_sse4  (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text;
59
extern int ff_bfin_sse8  (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text;
60
extern int ff_bfin_sse16 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text;
61 67fd620c Marc Hoffman
62
63
static void bfin_idct_add (uint8_t *dest, int line_size, DCTELEM *block)
64
{
65
    ff_bfin_idct (block);
66
    ff_bfin_add_pixels_clamped (block, dest, line_size);
67
}
68
69
static void bfin_idct_put (uint8_t *dest, int line_size, DCTELEM *block)
70
{
71
    ff_bfin_idct (block);
72
    ff_bfin_put_pixels_clamped (block, dest, line_size);
73
}
74
75
76
static void bfin_clear_blocks (DCTELEM *blocks)
77
{
78
    // This is just a simple memset.
79
    //
80 be449fca Diego Pettenò
    __asm__("P0=192; "
81 67fd620c Marc Hoffman
        "I0=%0;  "
82
        "R0=0;   "
83
        "LSETUP(clear_blocks_blkfn_lab,clear_blocks_blkfn_lab)LC0=P0;"
84
        "clear_blocks_blkfn_lab:"
85
        "[I0++]=R0;"
86
        ::"a" (blocks):"P0","I0","R0");
87
}
88
89
90
91
static void bfin_put_pixels8 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
92
{
93
    ff_bfin_put_pixels8uc (block, pixels, pixels, line_size, line_size, h);
94
}
95
96
static void bfin_put_pixels8_x2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
97
{
98
    ff_bfin_put_pixels8uc (block, pixels, pixels+1, line_size, line_size, h);
99
}
100
101
static void bfin_put_pixels8_y2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
102
{
103
    ff_bfin_put_pixels8uc (block, pixels, pixels+line_size, line_size, line_size, h);
104
}
105
106
static void bfin_put_pixels8_xy2 (uint8_t *block, const uint8_t *s0, int line_size, int h)
107
{
108
    ff_bfin_z_put_pixels8_xy2 (block,s0,line_size, line_size, h);
109
}
110
111
static void bfin_put_pixels16 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
112
{
113
    ff_bfin_put_pixels16uc (block, pixels, pixels, line_size, line_size, h);
114
}
115
116
static void bfin_put_pixels16_x2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
117
{
118
    ff_bfin_put_pixels16uc (block, pixels, pixels+1, line_size, line_size, h);
119
}
120
121
static void bfin_put_pixels16_y2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
122
{
123
    ff_bfin_put_pixels16uc (block, pixels, pixels+line_size, line_size, line_size, h);
124
}
125
126
static void bfin_put_pixels16_xy2 (uint8_t *block, const uint8_t *s0, int line_size, int h)
127
{
128
    ff_bfin_z_put_pixels16_xy2 (block,s0,line_size, line_size, h);
129
}
130
131
void bfin_put_pixels8_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
132
{
133
    ff_bfin_put_pixels8uc_nornd (block, pixels, pixels, line_size, h);
134
}
135
136
static void bfin_put_pixels8_x2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
137
{
138
    ff_bfin_put_pixels8uc_nornd (block, pixels, pixels+1, line_size, h);
139
}
140
141
static void bfin_put_pixels8_y2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
142
{
143
    ff_bfin_put_pixels8uc_nornd (block, pixels, pixels+line_size, line_size, h);
144 5ca030fe Michael Benjamin
}
145
146 67fd620c Marc Hoffman
147
void bfin_put_pixels16_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
148
{
149
    ff_bfin_put_pixels16uc_nornd (block, pixels, pixels, line_size, h);
150
}
151
152
static void bfin_put_pixels16_x2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
153
{
154
    ff_bfin_put_pixels16uc_nornd (block, pixels, pixels+1, line_size, h);
155
}
156
157
static void bfin_put_pixels16_y2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
158
{
159
    ff_bfin_put_pixels16uc_nornd (block, pixels, pixels+line_size, line_size, h);
160
}
161
162
static int bfin_pix_abs16 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
163
{
164
    return ff_bfin_z_sad16x16 (blk1,blk2,line_size,line_size,h);
165
}
166
167 584a3ac9 Marc Hoffman
static int bfin_vsad_intra16 (void *c, uint8_t *blk1, uint8_t *dummy, int stride, int h) {
168
    return ff_bfin_z_sad16x16 (blk1,blk1+stride,stride<<1,stride<<1,h);
169
}
170
171
static int bfin_vsad (void *c, uint8_t *blk1, uint8_t *blk2, int stride, int h) {
172
    return ff_bfin_z_sad16x16 (blk1,blk1+stride,stride<<1,stride<<1,h)
173
        + ff_bfin_z_sad16x16 (blk2,blk2+stride,stride<<1,stride<<1,h);
174
}
175
176 e44d7c65 Mike Frysinger
static uint8_t vtmp_blk[256] attribute_l1_data_b;
177 67fd620c Marc Hoffman
178
static int bfin_pix_abs16_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
179
{
180
    ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+1, 16, line_size, h);
181
    return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
182
}
183
184
static int bfin_pix_abs16_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
185
{
186
    ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+line_size, 16, line_size, h);
187
    return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
188
}
189
190
static int bfin_pix_abs16_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
191
{
192
    ff_bfin_z_put_pixels16_xy2 (vtmp_blk, blk2, 16, line_size, h);
193
    return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
194
}
195
196
static int bfin_pix_abs8 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
197
{
198
    return ff_bfin_z_sad8x8 (blk1,blk2,line_size,line_size, h);
199
}
200
201
static int bfin_pix_abs8_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
202
{
203
    ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+1, 8, line_size, h);
204
    return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
205
}
206
207
static int bfin_pix_abs8_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
208
{
209
    ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+line_size, 8, line_size, h);
210
    return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
211
}
212
213
static int bfin_pix_abs8_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
214
{
215
    ff_bfin_z_put_pixels8_xy2 (vtmp_blk, blk2, 8, line_size, h);
216
    return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
217
}
218
219
220
/*
221
  decoder optimization
222
  start on 2/11 100 frames of 352x240@25 compiled with no optimization -g debugging
223
  9.824s ~ 2.44x off
224
  6.360s ~ 1.58x off with -O2
225
  5.740s ~ 1.43x off with idcts
226

227
  2.64s    2/20 same sman.mp4 decode only
228

229
*/
230
231 5ca030fe Michael Benjamin
void dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx )
232
{
233 67fd620c Marc Hoffman
    c->get_pixels         = ff_bfin_get_pixels;
234
    c->diff_pixels        = ff_bfin_diff_pixels;
235
    c->put_pixels_clamped = ff_bfin_put_pixels_clamped;
236
    c->add_pixels_clamped = ff_bfin_add_pixels_clamped;
237
238
    c->clear_blocks       = bfin_clear_blocks;
239
    c->pix_sum            = ff_bfin_pix_sum;
240
    c->pix_norm1          = ff_bfin_pix_norm1;
241
242
    c->sad[0]             = bfin_pix_abs16;
243
    c->sad[1]             = bfin_pix_abs8;
244
245 584a3ac9 Marc Hoffman
    c->vsad[0]            = bfin_vsad;
246
    c->vsad[4]            = bfin_vsad_intra16;
247
248 67fd620c Marc Hoffman
    /* TODO [0] 16  [1] 8 */
249
    c->pix_abs[0][0] = bfin_pix_abs16;
250
    c->pix_abs[0][1] = bfin_pix_abs16_x2;
251
    c->pix_abs[0][2] = bfin_pix_abs16_y2;
252
    c->pix_abs[0][3] = bfin_pix_abs16_xy2;
253
254
    c->pix_abs[1][0] = bfin_pix_abs8;
255
    c->pix_abs[1][1] = bfin_pix_abs8_x2;
256
    c->pix_abs[1][2] = bfin_pix_abs8_y2;
257
    c->pix_abs[1][3] = bfin_pix_abs8_xy2;
258
259
260
    c->sse[0] = ff_bfin_sse16;
261
    c->sse[1] = ff_bfin_sse8;
262
    c->sse[2] = ff_bfin_sse4;
263
264
265
    /**
266
     * Halfpel motion compensation with rounding (a+b+1)>>1.
267
     * This is an array[4][4] of motion compensation functions for 4
268
     * horizontal blocksizes (8,16) and the 4 halfpel positions
269
     * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
270
     * @param block destination where the result is stored
271
     * @param pixels source
272
     * @param line_size number of bytes in a horizontal line of block
273
     * @param h height
274
     */
275
276
    c->put_pixels_tab[0][0] = bfin_put_pixels16;
277
    c->put_pixels_tab[0][1] = bfin_put_pixels16_x2;
278
    c->put_pixels_tab[0][2] = bfin_put_pixels16_y2;
279
    c->put_pixels_tab[0][3] = bfin_put_pixels16_xy2;
280
281
    c->put_pixels_tab[1][0] = bfin_put_pixels8;
282
    c->put_pixels_tab[1][1] = bfin_put_pixels8_x2;
283
    c->put_pixels_tab[1][2] = bfin_put_pixels8_y2;
284
    c->put_pixels_tab[1][3] = bfin_put_pixels8_xy2;
285
286
    c->put_no_rnd_pixels_tab[1][0] = bfin_put_pixels8_nornd;
287
    c->put_no_rnd_pixels_tab[1][1] = bfin_put_pixels8_x2_nornd;
288
    c->put_no_rnd_pixels_tab[1][2] = bfin_put_pixels8_y2_nornd;
289
    c->put_no_rnd_pixels_tab[1][3] = ff_bfin_put_pixels8_xy2_nornd;
290
291
    c->put_no_rnd_pixels_tab[0][0] = bfin_put_pixels16_nornd;
292
    c->put_no_rnd_pixels_tab[0][1] = bfin_put_pixels16_x2_nornd;
293
    c->put_no_rnd_pixels_tab[0][2] = bfin_put_pixels16_y2_nornd;
294
    c->put_no_rnd_pixels_tab[0][3] = ff_bfin_put_pixels16_xy2_nornd;
295
296 ea6ad30c Marc Hoffman
    c->idct_permutation_type = FF_NO_IDCT_PERM;
297 345bb2ad Marc Hoffman
    c->fdct                  = ff_bfin_fdct;
298 b9dc3279 Marc Hoffman
    if (avctx->idct_algo==FF_IDCT_VP3) {
299
        c->idct               = ff_bfin_vp3_idct;
300
        c->idct_add           = ff_bfin_vp3_idct_add;
301
        c->idct_put           = ff_bfin_vp3_idct_put;
302
    } else {
303 345bb2ad Marc Hoffman
        c->idct               = ff_bfin_idct;
304
        c->idct_add           = bfin_idct_add;
305
        c->idct_put           = bfin_idct_put;
306
    }
307 5ca030fe Michael Benjamin
}
308 67fd620c Marc Hoffman
309