2 * iWMMXt optimized DSP utils
3 * Copyright (c) 2004 AGAWA Koji
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "../dsputil.h"
24 #define DEF(x, y) x ## _no_rnd_ ## y ##_iwmmxt
25 #define SET_RND(regd) __asm__ __volatile__ ("mov r12, #1 \n\t tbcsth " #regd ", r12":::"r12");
26 #define WAVG2B "wavg2b"
27 #include "dsputil_iwmmxt_rnd.h"
32 #define DEF(x, y) x ## _ ## y ##_iwmmxt
33 #define SET_RND(regd) __asm__ __volatile__ ("mov r12, #2 \n\t tbcsth " #regd ", r12":::"r12");
34 #define WAVG2B "wavg2br"
35 #include "dsputil_iwmmxt_rnd.h"
44 "and r12, %[pixels], #7 \n\t" \
45 "bic %[pixels], %[pixels], #7 \n\t" \
46 "tmcr wcgr1, r12 \n\t" \
48 "wldrd wr0, [%[pixels]] \n\t" \
49 "wldrd wr1, [%[pixels], #8] \n\t" \
50 "add %[pixels], %[pixels], %[line_size] \n\t" \
51 "walignr1 wr4, wr0, wr1 \n\t" \
55 "wldrd wr2, [%[pixels]] \n\t" \
56 "wldrd wr3, [%[pixels], #8] \n\t" \
57 "add %[pixels], %[pixels], %[line_size] \n\t" \
58 "pld [%[pixels]] \n\t" \
59 "walignr1 wr5, wr2, wr3 \n\t" \
60 AVG " wr6, wr4, wr5 \n\t" \
61 "wstrd wr6, [%[block]] \n\t" \
62 "add %[block], %[block], %[line_size] \n\t" \
64 "wldrd wr0, [%[pixels]] \n\t" \
65 "wldrd wr1, [%[pixels], #8] \n\t" \
66 "add %[pixels], %[pixels], %[line_size] \n\t" \
67 "walignr1 wr4, wr0, wr1 \n\t" \
68 "pld [%[pixels]] \n\t" \
69 AVG " wr6, wr4, wr5 \n\t" \
70 "wstrd wr6, [%[block]] \n\t" \
71 "add %[block], %[block], %[line_size] \n\t" \
73 "subs %[h], %[h], #2 \n\t" \
75 : [block]"+r"(block), [pixels]"+r"(pixels), [h]"+r"(h) \
76 : [line_size]"r"(line_size) \
78 void put_pixels8_y2_iwmmxt(uint8_t *block, const uint8_t *pixels, const int line_size, int h)
82 void put_no_rnd_pixels8_y2_iwmmxt(uint8_t *block, const uint8_t *pixels, const int line_size, int h)
88 void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_size)
90 uint8_t *pixels2 = pixels + line_size;
92 __asm__ __volatile__ (
95 "pld [%[pixels], %[line_size2]] \n\t"
96 "pld [%[pixels2], %[line_size2]] \n\t"
97 "wldrd wr4, [%[pixels]] \n\t"
98 "wldrd wr5, [%[pixels2]] \n\t"
99 "pld [%[block], #32] \n\t"
100 "wunpckelub wr6, wr4 \n\t"
101 "wldrd wr0, [%[block]] \n\t"
102 "wunpckehub wr7, wr4 \n\t"
103 "wldrd wr1, [%[block], #8] \n\t"
104 "wunpckelub wr8, wr5 \n\t"
105 "wldrd wr2, [%[block], #16] \n\t"
106 "wunpckehub wr9, wr5 \n\t"
107 "wldrd wr3, [%[block], #24] \n\t"
108 "add %[block], %[block], #32 \n\t"
109 "waddhss wr10, wr0, wr6 \n\t"
110 "waddhss wr11, wr1, wr7 \n\t"
111 "waddhss wr12, wr2, wr8 \n\t"
112 "waddhss wr13, wr3, wr9 \n\t"
113 "wpackhus wr14, wr10, wr11 \n\t"
114 "wpackhus wr15, wr12, wr13 \n\t"
115 "wstrd wr14, [%[pixels]] \n\t"
116 "add %[pixels], %[pixels], %[line_size2] \n\t"
117 "subs r12, r12, #1 \n\t"
118 "wstrd wr15, [%[pixels2]] \n\t"
119 "add %[pixels2], %[pixels2], %[line_size2] \n\t"
121 : [block]"+r"(block), [pixels]"+r"(pixels), [pixels2]"+r"(pixels2)
122 : [line_size2]"r"(line_size << 1)
123 : "cc", "memory", "r12");
126 static void nop(uint8_t *block, const uint8_t *pixels, int line_size, int h)
131 int mm_flags; /* multimedia extension flags */
135 return 0; /* TODO, implement proper detection */
138 void dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx)
140 mm_flags = mm_support();
142 if (avctx->dsp_mask) {
143 if (avctx->dsp_mask & FF_MM_FORCE)
144 mm_flags |= (avctx->dsp_mask & 0xffff);
146 mm_flags &= ~(avctx->dsp_mask & 0xffff);
149 if (!(mm_flags & MM_IWMMXT)) return;
151 c->add_pixels_clamped = add_pixels_clamped_iwmmxt;
153 c->put_pixels_tab[0][0] = put_pixels16_iwmmxt;
154 c->put_pixels_tab[0][1] = put_pixels16_x2_iwmmxt;
155 c->put_pixels_tab[0][2] = put_pixels16_y2_iwmmxt;
156 c->put_pixels_tab[0][3] = put_pixels16_xy2_iwmmxt;
157 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_iwmmxt;
158 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_iwmmxt;
159 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_iwmmxt;
160 c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_iwmmxt;
162 c->put_pixels_tab[1][0] = put_pixels8_iwmmxt;
163 c->put_pixels_tab[1][1] = put_pixels8_x2_iwmmxt;
164 c->put_pixels_tab[1][2] = put_pixels8_y2_iwmmxt;
165 c->put_pixels_tab[1][3] = put_pixels8_xy2_iwmmxt;
166 c->put_no_rnd_pixels_tab[1][0] = put_pixels8_iwmmxt;
167 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_iwmmxt;
168 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_iwmmxt;
169 c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_iwmmxt;
171 c->avg_pixels_tab[0][0] = avg_pixels16_iwmmxt;
172 c->avg_pixels_tab[0][1] = avg_pixels16_x2_iwmmxt;
173 c->avg_pixels_tab[0][2] = avg_pixels16_y2_iwmmxt;
174 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_iwmmxt;
175 c->avg_no_rnd_pixels_tab[0][0] = avg_pixels16_iwmmxt;
176 c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_iwmmxt;
177 c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_iwmmxt;
178 c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_iwmmxt;
180 c->avg_pixels_tab[1][0] = avg_pixels8_iwmmxt;
181 c->avg_pixels_tab[1][1] = avg_pixels8_x2_iwmmxt;
182 c->avg_pixels_tab[1][2] = avg_pixels8_y2_iwmmxt;
183 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_iwmmxt;
184 c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_iwmmxt;
185 c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_iwmmxt;
186 c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_iwmmxt;
187 c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_iwmmxt;