Statistics
| Branch: | Revision:

ffmpeg / libavcodec / bfin / dsputil_bfin.c @ 345bb2ad

History | View | Annotate | Download (10.8 KB)

1
/*
2
 * BlackFin DSPUTILS
3
 *
4
 * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
5
 * Copyright (c) 2006 Michael Benjamin <michael.benjamin@analog.com>
6
 *
7
 * This file is part of FFmpeg.
8
 *
9
 * FFmpeg is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * FFmpeg is distributed in the hope that it will be useful,
15
 * 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
 * License along with FFmpeg; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
 */
23

    
24
#include <unistd.h>
25
#include "avcodec.h"
26
#include "dsputil.h"
27
#include "dsputil_bfin.h"
28

    
29
int off;
30

    
31

    
32
extern void ff_bfin_idct (DCTELEM *block) attribute_l1_text;
33
extern void ff_bfin_fdct (DCTELEM *block) attribute_l1_text;
34
extern void ff_bfin_add_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text;
35
extern void ff_bfin_put_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text;
36
extern void ff_bfin_diff_pixels (DCTELEM *block, uint8_t *s1, uint8_t *s2, int stride)  attribute_l1_text;
37
extern void ff_bfin_get_pixels  (DCTELEM *restrict block, const uint8_t *pixels, int line_size) attribute_l1_text;
38
extern int  ff_bfin_pix_norm1  (uint8_t * pix, int line_size) attribute_l1_text;
39
extern int  ff_bfin_z_sad8x8   (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text;
40
extern int  ff_bfin_z_sad16x16 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text;
41

    
42
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;
43
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;
44
extern void ff_bfin_put_pixels16_xy2_nornd (uint8_t *block, const uint8_t *s0, int line_size, int h) attribute_l1_text;
45
extern void ff_bfin_put_pixels8_xy2_nornd  (uint8_t *block, const uint8_t *s0, int line_size, int h) attribute_l1_text;
46

    
47

    
48
extern int  ff_bfin_pix_sum (uint8_t *p, int stride) attribute_l1_text;
49

    
50
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;
51
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;
52
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;
53
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;
54

    
55
extern int ff_bfin_sse4  (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text;
56
extern int ff_bfin_sse8  (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text;
57
extern int ff_bfin_sse16 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text;
58

    
59

    
60
static void bfin_idct_add (uint8_t *dest, int line_size, DCTELEM *block)
61
{
62
    ff_bfin_idct (block);
63
    ff_bfin_add_pixels_clamped (block, dest, line_size);
64
}
65

    
66
static void bfin_idct_put (uint8_t *dest, int line_size, DCTELEM *block)
67
{
68
    ff_bfin_idct (block);
69
    ff_bfin_put_pixels_clamped (block, dest, line_size);
70
}
71

    
72

    
73
static void bfin_clear_blocks (DCTELEM *blocks)
74
{
75
    // This is just a simple memset.
76
    //
77
    asm("P0=192; "
78
        "I0=%0;  "
79
        "R0=0;   "
80
        "LSETUP(clear_blocks_blkfn_lab,clear_blocks_blkfn_lab)LC0=P0;"
81
        "clear_blocks_blkfn_lab:"
82
        "[I0++]=R0;"
83
        ::"a" (blocks):"P0","I0","R0");
84
}
85

    
86

    
87

    
88
static void bfin_put_pixels8 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
89
{
90
    ff_bfin_put_pixels8uc (block, pixels, pixels, line_size, line_size, h);
91
}
92

    
93
static void bfin_put_pixels8_x2(uint8_t *block, const uint8_t *pixels, int line_size, int h)
94
{
95
    ff_bfin_put_pixels8uc (block, pixels, pixels+1, line_size, line_size, h);
96
}
97

    
98
static void bfin_put_pixels8_y2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
99
{
100
    ff_bfin_put_pixels8uc (block, pixels, pixels+line_size, line_size, line_size, h);
101
}
102

    
103
static void bfin_put_pixels8_xy2 (uint8_t *block, const uint8_t *s0, int line_size, int h)
104
{
105
    ff_bfin_z_put_pixels8_xy2 (block,s0,line_size, line_size, h);
106
}
107

    
108
static void bfin_put_pixels16 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
109
{
110
    ff_bfin_put_pixels16uc (block, pixels, pixels, line_size, line_size, h);
111
}
112

    
113
static void bfin_put_pixels16_x2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
114
{
115
    ff_bfin_put_pixels16uc (block, pixels, pixels+1, line_size, line_size, h);
116
}
117

    
118
static void bfin_put_pixels16_y2 (uint8_t *block, const uint8_t *pixels, int line_size, int h)
119
{
120
    ff_bfin_put_pixels16uc (block, pixels, pixels+line_size, line_size, line_size, h);
121
}
122

    
123
static void bfin_put_pixels16_xy2 (uint8_t *block, const uint8_t *s0, int line_size, int h)
124
{
125
    ff_bfin_z_put_pixels16_xy2 (block,s0,line_size, line_size, h);
126
}
127

    
128
void bfin_put_pixels8_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
129
{
130
    ff_bfin_put_pixels8uc_nornd (block, pixels, pixels, line_size, h);
131
}
132

    
133
static void bfin_put_pixels8_x2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
134
{
135
    ff_bfin_put_pixels8uc_nornd (block, pixels, pixels+1, line_size, h);
136
}
137

    
138
static void bfin_put_pixels8_y2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
139
{
140
    ff_bfin_put_pixels8uc_nornd (block, pixels, pixels+line_size, line_size, h);
141
}
142

    
143

    
144
void bfin_put_pixels16_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
145
{
146
    ff_bfin_put_pixels16uc_nornd (block, pixels, pixels, line_size, h);
147
}
148

    
149
static void bfin_put_pixels16_x2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
150
{
151
    ff_bfin_put_pixels16uc_nornd (block, pixels, pixels+1, line_size, h);
152
}
153

    
154
static void bfin_put_pixels16_y2_nornd (uint8_t *block, const uint8_t *pixels, int line_size, int h)
155
{
156
    ff_bfin_put_pixels16uc_nornd (block, pixels, pixels+line_size, line_size, h);
157
}
158

    
159
static int bfin_pix_abs16 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
160
{
161
    return ff_bfin_z_sad16x16 (blk1,blk2,line_size,line_size,h);
162
}
163

    
164
static uint8_t vtmp_blk[256] __attribute__((l1_data_B));
165

    
166
static int bfin_pix_abs16_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
167
{
168
    ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+1, 16, line_size, h);
169
    return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
170
}
171

    
172
static int bfin_pix_abs16_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
173
{
174
    ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+line_size, 16, line_size, h);
175
    return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
176
}
177

    
178
static int bfin_pix_abs16_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
179
{
180
    ff_bfin_z_put_pixels16_xy2 (vtmp_blk, blk2, 16, line_size, h);
181
    return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
182
}
183

    
184
static int bfin_pix_abs8 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
185
{
186
    return ff_bfin_z_sad8x8 (blk1,blk2,line_size,line_size, h);
187
}
188

    
189
static int bfin_pix_abs8_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
190
{
191
    ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+1, 8, line_size, h);
192
    return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
193
}
194

    
195
static int bfin_pix_abs8_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
196
{
197
    ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+line_size, 8, line_size, h);
198
    return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
199
}
200

    
201
static int bfin_pix_abs8_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
202
{
203
    ff_bfin_z_put_pixels8_xy2 (vtmp_blk, blk2, 8, line_size, h);
204
    return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
205
}
206

    
207

    
208
/*
209
  decoder optimization
210
  start on 2/11 100 frames of 352x240@25 compiled with no optimization -g debugging
211
  9.824s ~ 2.44x off
212
  6.360s ~ 1.58x off with -O2
213
  5.740s ~ 1.43x off with idcts
214

215
  2.64s    2/20 same sman.mp4 decode only
216

217
*/
218

    
219
void dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx )
220
{
221
    c->get_pixels         = ff_bfin_get_pixels;
222
    c->diff_pixels        = ff_bfin_diff_pixels;
223
    c->put_pixels_clamped = ff_bfin_put_pixels_clamped;
224
    c->add_pixels_clamped = ff_bfin_add_pixels_clamped;
225

    
226
    c->clear_blocks       = bfin_clear_blocks;
227
    c->pix_sum            = ff_bfin_pix_sum;
228
    c->pix_norm1          = ff_bfin_pix_norm1;
229

    
230
    c->sad[0]             = bfin_pix_abs16;
231
    c->sad[1]             = bfin_pix_abs8;
232

    
233
    /* TODO [0] 16  [1] 8 */
234
    c->pix_abs[0][0] = bfin_pix_abs16;
235
    c->pix_abs[0][1] = bfin_pix_abs16_x2;
236
    c->pix_abs[0][2] = bfin_pix_abs16_y2;
237
    c->pix_abs[0][3] = bfin_pix_abs16_xy2;
238

    
239
    c->pix_abs[1][0] = bfin_pix_abs8;
240
    c->pix_abs[1][1] = bfin_pix_abs8_x2;
241
    c->pix_abs[1][2] = bfin_pix_abs8_y2;
242
    c->pix_abs[1][3] = bfin_pix_abs8_xy2;
243

    
244

    
245
    c->sse[0] = ff_bfin_sse16;
246
    c->sse[1] = ff_bfin_sse8;
247
    c->sse[2] = ff_bfin_sse4;
248

    
249

    
250
    /**
251
     * Halfpel motion compensation with rounding (a+b+1)>>1.
252
     * This is an array[4][4] of motion compensation functions for 4
253
     * horizontal blocksizes (8,16) and the 4 halfpel positions
254
     * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
255
     * @param block destination where the result is stored
256
     * @param pixels source
257
     * @param line_size number of bytes in a horizontal line of block
258
     * @param h height
259
     */
260

    
261
    c->put_pixels_tab[0][0] = bfin_put_pixels16;
262
    c->put_pixels_tab[0][1] = bfin_put_pixels16_x2;
263
    c->put_pixels_tab[0][2] = bfin_put_pixels16_y2;
264
    c->put_pixels_tab[0][3] = bfin_put_pixels16_xy2;
265

    
266
    c->put_pixels_tab[1][0] = bfin_put_pixels8;
267
    c->put_pixels_tab[1][1] = bfin_put_pixels8_x2;
268
    c->put_pixels_tab[1][2] = bfin_put_pixels8_y2;
269
    c->put_pixels_tab[1][3] = bfin_put_pixels8_xy2;
270

    
271
    c->put_no_rnd_pixels_tab[1][0] = bfin_put_pixels8_nornd;
272
    c->put_no_rnd_pixels_tab[1][1] = bfin_put_pixels8_x2_nornd;
273
    c->put_no_rnd_pixels_tab[1][2] = bfin_put_pixels8_y2_nornd;
274
    c->put_no_rnd_pixels_tab[1][3] = ff_bfin_put_pixels8_xy2_nornd;
275

    
276
    c->put_no_rnd_pixels_tab[0][0] = bfin_put_pixels16_nornd;
277
    c->put_no_rnd_pixels_tab[0][1] = bfin_put_pixels16_x2_nornd;
278
    c->put_no_rnd_pixels_tab[0][2] = bfin_put_pixels16_y2_nornd;
279
    c->put_no_rnd_pixels_tab[0][3] = ff_bfin_put_pixels16_xy2_nornd;
280

    
281
    c->idct_permutation_type = FF_NO_IDCT_PERM;
282
    c->fdct                  = ff_bfin_fdct;
283
    if (avctx->idct_algo!=FF_IDCT_VP3) {
284
        c->idct               = ff_bfin_idct;
285
        c->idct_add           = bfin_idct_add;
286
        c->idct_put           = bfin_idct_put;
287
    }
288
}
289

    
290

    
291