FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dsputil_init.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 <stdint.h>
25 
26 #include "config.h"
27 #include "libavutil/attributes.h"
29 #include "libavcodec/avcodec.h"
30 #include "libavcodec/dsputil.h"
31 #include "libavcodec/mpegvideo.h"
32 
33 void ff_bfin_idct(int16_t *block) attribute_l1_text;
34 void ff_bfin_fdct(int16_t *block) attribute_l1_text;
35 
36 void ff_bfin_add_pixels_clamped(const int16_t *block, uint8_t *dest,
37  int line_size) attribute_l1_text;
38 void ff_bfin_put_pixels_clamped(const int16_t *block, uint8_t *dest,
39  int line_size) attribute_l1_text;
40 
41 void ff_bfin_diff_pixels(int16_t *block, const uint8_t *s1, const uint8_t *s2,
43 void ff_bfin_get_pixels(int16_t *restrict block, const uint8_t *pixels,
44  int line_size) attribute_l1_text;
45 
46 int ff_bfin_pix_norm1(uint8_t *pix, int line_size) attribute_l1_text;
48 
49 int ff_bfin_z_sad8x8(uint8_t *blk1, uint8_t *blk2, int dsz,
50  int line_size, int h) attribute_l1_text;
51 int ff_bfin_z_sad16x16(uint8_t *blk1, uint8_t *blk2, int dsz,
52  int line_size, int h) attribute_l1_text;
53 
54 int ff_bfin_sse4(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
55  int line_size, int h) attribute_l1_text;
56 int ff_bfin_sse8(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
57  int line_size, int h) attribute_l1_text;
58 int ff_bfin_sse16(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
59  int line_size, int h) attribute_l1_text;
60 
61 static void bfin_idct_add(uint8_t *dest, int line_size, int16_t *block)
62 {
63  ff_bfin_idct(block);
64  ff_bfin_add_pixels_clamped(block, dest, line_size);
65 }
66 
67 static void bfin_idct_put(uint8_t *dest, int line_size, int16_t *block)
68 {
69  ff_bfin_idct(block);
70  ff_bfin_put_pixels_clamped(block, dest, line_size);
71 }
72 
73 static void bfin_clear_blocks(int16_t *blocks)
74 {
75  // This is just a simple memset.
76  __asm__ ("P0=192; "
77  "I0=%0; "
78  "R0=0; "
79  "LSETUP(clear_blocks_blkfn_lab,clear_blocks_blkfn_lab)LC0=P0;"
80  "clear_blocks_blkfn_lab:"
81  "[I0++]=R0;"
82  ::"a" (blocks) : "P0", "I0", "R0");
83 }
84 
85 static int bfin_pix_abs16(MpegEncContext *c, uint8_t *blk1, uint8_t *blk2,
86  int line_size, int h)
87 {
88  return ff_bfin_z_sad16x16(blk1, blk2, line_size, line_size, h);
89 }
90 
91 static uint8_t vtmp_blk[256] attribute_l1_data_b;
92 
93 static int bfin_pix_abs16_x2(MpegEncContext *c, uint8_t *blk1, uint8_t *blk2,
94  int line_size, int h)
95 {
96  ff_bfin_put_pixels16uc(vtmp_blk, blk2, blk2 + 1, 16, line_size, h);
97  return ff_bfin_z_sad16x16(blk1, vtmp_blk, line_size, 16, h);
98 }
99 
101  int line_size, int h)
102 {
103  ff_bfin_put_pixels16uc(vtmp_blk, blk2, blk2 + line_size, 16, line_size, h);
104  return ff_bfin_z_sad16x16(blk1, vtmp_blk, line_size, 16, h);
105 }
106 
108  int line_size, int h)
109 {
110  ff_bfin_z_put_pixels16_xy2(vtmp_blk, blk2, 16, line_size, h);
111  return ff_bfin_z_sad16x16(blk1, vtmp_blk, line_size, 16, h);
112 }
113 
114 static int bfin_pix_abs8(MpegEncContext *c, uint8_t *blk1, uint8_t *blk2,
115  int line_size, int h)
116 {
117  return ff_bfin_z_sad8x8(blk1, blk2, line_size, line_size, h);
118 }
119 
120 static int bfin_pix_abs8_x2(MpegEncContext *c, uint8_t *blk1, uint8_t *blk2,
121  int line_size, int h)
122 {
123  ff_bfin_put_pixels8uc(vtmp_blk, blk2, blk2 + 1, 8, line_size, h);
124  return ff_bfin_z_sad8x8(blk1, vtmp_blk, line_size, 8, h);
125 }
126 
127 static int bfin_pix_abs8_y2(MpegEncContext *c, uint8_t *blk1, uint8_t *blk2,
128  int line_size, int h)
129 {
130  ff_bfin_put_pixels8uc(vtmp_blk, blk2, blk2 + line_size, 8, line_size, h);
131  return ff_bfin_z_sad8x8(blk1, vtmp_blk, line_size, 8, h);
132 }
133 
135  int line_size, int h)
136 {
137  ff_bfin_z_put_pixels8_xy2(vtmp_blk, blk2, 8, line_size, h);
138  return ff_bfin_z_sad8x8(blk1, vtmp_blk, line_size, 8, h);
139 }
140 
141 /*
142  * decoder optimization
143  * start on 2/11 100 frames of 352x240@25 compiled with no optimization -g debugging
144  * 9.824s ~ 2.44x off
145  * 6.360s ~ 1.58x off with -O2
146  * 5.740s ~ 1.43x off with idcts
147  *
148  * 2.64s 2/20 same sman.mp4 decode only
149  */
150 
152  unsigned high_bit_depth)
153 {
155 
158 
160 
163 
164  c->sad[0] = bfin_pix_abs16;
165  c->sad[1] = bfin_pix_abs8;
166 
167  /* TODO [0] 16 [1] 8 */
168  c->pix_abs[0][0] = bfin_pix_abs16;
169  c->pix_abs[0][1] = bfin_pix_abs16_x2;
170  c->pix_abs[0][2] = bfin_pix_abs16_y2;
171  c->pix_abs[0][3] = bfin_pix_abs16_xy2;
172 
173  c->pix_abs[1][0] = bfin_pix_abs8;
174  c->pix_abs[1][1] = bfin_pix_abs8_x2;
175  c->pix_abs[1][2] = bfin_pix_abs8_y2;
176  c->pix_abs[1][3] = bfin_pix_abs8_xy2;
177 
178  c->sse[0] = ff_bfin_sse16;
179  c->sse[1] = ff_bfin_sse8;
180  c->sse[2] = ff_bfin_sse4;
181 
182  if (!high_bit_depth) {
184 
185  if (avctx->dct_algo == FF_DCT_AUTO)
186  c->fdct = ff_bfin_fdct;
187 
188  if (avctx->idct_algo == FF_IDCT_AUTO) {
190  c->idct = ff_bfin_idct;
191  c->idct_add = bfin_idct_add;
192  c->idct_put = bfin_idct_put;
193  }
194  }
195 }