dsputil_bfin.c
Go to the documentation of this file.
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 "libavutil/attributes.h"
25 #include "libavcodec/avcodec.h"
26 #include "libavcodec/dsputil.h"
27 #include "dsputil_bfin.h"
28 
29 int off;
30 
31 static void bfin_idct_add (uint8_t *dest, int line_size, int16_t *block)
32 {
33  ff_bfin_idct (block);
34  ff_bfin_add_pixels_clamped (block, dest, line_size);
35 }
36 
37 static void bfin_idct_put (uint8_t *dest, int line_size, int16_t *block)
38 {
39  ff_bfin_idct (block);
40  ff_bfin_put_pixels_clamped (block, dest, line_size);
41 }
42 
43 
44 static void bfin_clear_blocks (int16_t *blocks)
45 {
46  // This is just a simple memset.
47  //
48  __asm__("P0=192; "
49  "I0=%0; "
50  "R0=0; "
51  "LSETUP(clear_blocks_blkfn_lab,clear_blocks_blkfn_lab)LC0=P0;"
52  "clear_blocks_blkfn_lab:"
53  "[I0++]=R0;"
54  ::"a" (blocks):"P0","I0","R0");
55 }
56 
57 static int bfin_pix_abs16 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
58 {
59  return ff_bfin_z_sad16x16 (blk1,blk2,line_size,line_size,h);
60 }
61 
62 static int bfin_vsad_intra16 (void *c, uint8_t *blk1, uint8_t *dummy, int stride, int h) {
63  return ff_bfin_z_sad16x16 (blk1,blk1+stride,stride<<1,stride<<1,h);
64 }
65 
66 static int bfin_vsad (void *c, uint8_t *blk1, uint8_t *blk2, int stride, int h) {
67  return ff_bfin_z_sad16x16 (blk1,blk1+stride,stride<<1,stride<<1,h)
68  + ff_bfin_z_sad16x16 (blk2,blk2+stride,stride<<1,stride<<1,h);
69 }
70 
71 static uint8_t vtmp_blk[256] attribute_l1_data_b;
72 
73 static int bfin_pix_abs16_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
74 {
75  ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+1, 16, line_size, h);
76  return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
77 }
78 
79 static int bfin_pix_abs16_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
80 {
81  ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+line_size, 16, line_size, h);
82  return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
83 }
84 
85 static int bfin_pix_abs16_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
86 {
87  ff_bfin_z_put_pixels16_xy2 (vtmp_blk, blk2, 16, line_size, h);
88  return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
89 }
90 
91 static int bfin_pix_abs8 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
92 {
93  return ff_bfin_z_sad8x8 (blk1,blk2,line_size,line_size, h);
94 }
95 
96 static int bfin_pix_abs8_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
97 {
98  ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+1, 8, line_size, h);
99  return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
100 }
101 
102 static int bfin_pix_abs8_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
103 {
104  ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+line_size, 8, line_size, h);
105  return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
106 }
107 
108 static int bfin_pix_abs8_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
109 {
110  ff_bfin_z_put_pixels8_xy2 (vtmp_blk, blk2, 8, line_size, h);
111  return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
112 }
113 
114 
115 /*
116  decoder optimization
117  start on 2/11 100 frames of 352x240@25 compiled with no optimization -g debugging
118  9.824s ~ 2.44x off
119  6.360s ~ 1.58x off with -O2
120  5.740s ~ 1.43x off with idcts
121 
122  2.64s 2/20 same sman.mp4 decode only
123 
124 */
125 
127 {
128  const int high_bit_depth = avctx->bits_per_raw_sample > 8;
129 
133 
134  if (!high_bit_depth)
139 
140  c->sad[0] = bfin_pix_abs16;
141  c->sad[1] = bfin_pix_abs8;
142 
143 /* c->vsad[0] = bfin_vsad; */
144 /* c->vsad[4] = bfin_vsad_intra16; */
145 
146  /* TODO [0] 16 [1] 8 */
147  c->pix_abs[0][0] = bfin_pix_abs16;
148  c->pix_abs[0][1] = bfin_pix_abs16_x2;
149  c->pix_abs[0][2] = bfin_pix_abs16_y2;
150  c->pix_abs[0][3] = bfin_pix_abs16_xy2;
151 
152  c->pix_abs[1][0] = bfin_pix_abs8;
153  c->pix_abs[1][1] = bfin_pix_abs8_x2;
154  c->pix_abs[1][2] = bfin_pix_abs8_y2;
155  c->pix_abs[1][3] = bfin_pix_abs8_xy2;
156 
157 
158  c->sse[0] = ff_bfin_sse16;
159  c->sse[1] = ff_bfin_sse8;
160  c->sse[2] = ff_bfin_sse4;
161 
162  if (avctx->bits_per_raw_sample <= 8) {
163  if (avctx->dct_algo == FF_DCT_AUTO)
164  c->fdct = ff_bfin_fdct;
165 
166  if (avctx->idct_algo == FF_IDCT_AUTO) {
168  c->idct = ff_bfin_idct;
169  c->idct_add = bfin_idct_add;
170  c->idct_put = bfin_idct_put;
171  }
172  }
173 }
int dct_algo
DCT algorithm, see FF_DCT_* below.
me_cmp_func sse[6]
Definition: dsputil.h:152
static int bfin_pix_abs16(void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil_bfin.c:57
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
void(* fdct)(int16_t *block)
Definition: dsputil.h:218
int stride
Definition: mace.c:144
static int bfin_vsad(void *c, uint8_t *blk1, uint8_t *blk2, int stride, int h)
Definition: dsputil_bfin.c:66
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
Macro definitions for various function/variable attributes.
void(* get_pixels)(int16_t *block, const uint8_t *pixels, int line_size)
Definition: dsputil.h:129
static int bfin_pix_abs8_x2(void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil_bfin.c:96
static int bfin_pix_abs16_xy2(void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil_bfin.c:85
uint8_t
#define av_cold
Definition: attributes.h:78
void ff_bfin_fdct(int16_t *block) attribute_l1_text
int(* pix_sum)(uint8_t *pix, int line_size)
Definition: dsputil.h:147
static int bfin_pix_abs8(void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil_bfin.c:91
int ff_bfin_sse16(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text
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
static int bfin_pix_abs8_xy2(void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil_bfin.c:108
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
void(* clear_blocks)(int16_t *blocks)
Definition: dsputil.h:146
external API header
int off
Definition: dsputil_bfin.c:29
#define FF_DCT_AUTO
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
int ff_bfin_pix_norm1(uint8_t *pix, int line_size) attribute_l1_text
void(* put_pixels_clamped)(const int16_t *block, uint8_t *pixels, int line_size)
Definition: dsputil.h:131
#define FF_NO_IDCT_PERM
Definition: dsputil.h:251
static uint8_t vtmp_blk[256] attribute_l1_data_b
Definition: dsputil_bfin.c:71
int ff_bfin_sse4(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text
void(* add_pixels_clamped)(const int16_t *block, uint8_t *pixels, int line_size)
Definition: dsputil.h:133
static void bfin_idct_add(uint8_t *dest, int line_size, int16_t *block)
Definition: dsputil_bfin.c:31
#define FF_IDCT_AUTO
dest
Definition: start.py:60
int ff_bfin_z_sad8x8(uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text
void ff_bfin_get_pixels(int16_t *restrict block, const uint8_t *pixels, int line_size) attribute_l1_text
static void bfin_clear_blocks(int16_t *blocks)
Definition: dsputil_bfin.c:44
int idct_permutation_type
Definition: dsputil.h:250
void(* idct_add)(uint8_t *dest, int line_size, int16_t *block)
block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
Definition: dsputil.h:235
main external API structure.
static void bfin_idct_put(uint8_t *dest, int line_size, int16_t *block)
Definition: dsputil_bfin.c:37
int(* pix_norm1)(uint8_t *pix, int line_size)
Definition: dsputil.h:148
void ff_bfin_idct(int16_t *block) attribute_l1_text
int ff_bfin_sse8(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text
static int bfin_pix_abs16_x2(void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil_bfin.c:73
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
static int bfin_pix_abs16_y2(void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil_bfin.c:79
static int bfin_pix_abs8_y2(void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
Definition: dsputil_bfin.c:102
void ff_bfin_put_pixels_clamped(const int16_t *block, uint8_t *dest, int line_size) attribute_l1_text
av_cold void ff_dsputil_init_bfin(DSPContext *c, AVCodecContext *avctx)
Definition: dsputil_bfin.c:126
void(* idct)(int16_t *block)
Definition: dsputil.h:222
static double c[64]
me_cmp_func sad[6]
Definition: dsputil.h:151
DSP utils.
void(* idct_put)(uint8_t *dest, int line_size, int16_t *block)
block -> idct -> clip to unsigned 8 bit -> dest.
Definition: dsputil.h:229
void ff_bfin_add_pixels_clamped(const int16_t *block, uint8_t *dest, int line_size) attribute_l1_text
static int bfin_vsad_intra16(void *c, uint8_t *blk1, uint8_t *dummy, int stride, int h)
Definition: dsputil_bfin.c:62
void ff_bfin_diff_pixels(int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride) attribute_l1_text
int ff_bfin_pix_sum(uint8_t *p, int stride) attribute_l1_text
int ff_bfin_z_sad16x16(uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text
int dummy
Definition: motion-test.c:64
void(* diff_pixels)(int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride)
Definition: dsputil.h:130
me_cmp_func pix_abs[2][4]
Definition: dsputil.h:194
DSPContext.
Definition: dsputil.h:127