• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/arm/dsputil_iwmmxt.c

Go to the documentation of this file.
00001 /*
00002  * iWMMXt optimized DSP utils
00003  * Copyright (c) 2004 AGAWA Koji
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "libavutil/cpu.h"
00023 #include "libavcodec/dsputil.h"
00024 
00025 #define DEF(x, y) x ## _no_rnd_ ## y ##_iwmmxt
00026 #define SET_RND(regd)  __asm__ volatile ("mov r12, #1 \n\t tbcsth " #regd ", r12":::"r12");
00027 #define WAVG2B "wavg2b"
00028 #include "dsputil_iwmmxt_rnd_template.c"
00029 #undef DEF
00030 #undef SET_RND
00031 #undef WAVG2B
00032 
00033 #define DEF(x, y) x ## _ ## y ##_iwmmxt
00034 #define SET_RND(regd)  __asm__ volatile ("mov r12, #2 \n\t tbcsth " #regd ", r12":::"r12");
00035 #define WAVG2B "wavg2br"
00036 #include "dsputil_iwmmxt_rnd_template.c"
00037 #undef DEF
00038 #undef SET_RND
00039 #undef WAVG2BR
00040 
00041 // need scheduling
00042 #define OP(AVG)                                         \
00043     __asm__ volatile (                                      \
00044         /* alignment */                                 \
00045         "and r12, %[pixels], #7 \n\t"                   \
00046         "bic %[pixels], %[pixels], #7 \n\t"             \
00047         "tmcr wcgr1, r12 \n\t"                          \
00048                                                         \
00049         "wldrd wr0, [%[pixels]] \n\t"                   \
00050         "wldrd wr1, [%[pixels], #8] \n\t"               \
00051         "add %[pixels], %[pixels], %[line_size] \n\t"   \
00052         "walignr1 wr4, wr0, wr1 \n\t"                   \
00053                                                         \
00054         "1: \n\t"                                       \
00055                                                         \
00056         "wldrd wr2, [%[pixels]] \n\t"                   \
00057         "wldrd wr3, [%[pixels], #8] \n\t"               \
00058         "add %[pixels], %[pixels], %[line_size] \n\t"   \
00059         "pld [%[pixels]] \n\t"                          \
00060         "walignr1 wr5, wr2, wr3 \n\t"                   \
00061         AVG " wr6, wr4, wr5 \n\t"                       \
00062         "wstrd wr6, [%[block]] \n\t"                    \
00063         "add %[block], %[block], %[line_size] \n\t"     \
00064                                                         \
00065         "wldrd wr0, [%[pixels]] \n\t"                   \
00066         "wldrd wr1, [%[pixels], #8] \n\t"               \
00067         "add %[pixels], %[pixels], %[line_size] \n\t"   \
00068         "walignr1 wr4, wr0, wr1 \n\t"                   \
00069         "pld [%[pixels]] \n\t"                          \
00070         AVG " wr6, wr4, wr5 \n\t"                       \
00071         "wstrd wr6, [%[block]] \n\t"                    \
00072         "add %[block], %[block], %[line_size] \n\t"     \
00073                                                         \
00074         "subs %[h], %[h], #2 \n\t"                      \
00075         "bne 1b \n\t"                                   \
00076         : [block]"+r"(block), [pixels]"+r"(pixels), [h]"+r"(h)  \
00077         : [line_size]"r"(line_size) \
00078         : "memory", "r12");
00079 void put_pixels8_y2_iwmmxt(uint8_t *block, const uint8_t *pixels, const int line_size, int h)
00080 {
00081     OP("wavg2br");
00082 }
00083 void put_no_rnd_pixels8_y2_iwmmxt(uint8_t *block, const uint8_t *pixels, const int line_size, int h)
00084 {
00085     OP("wavg2b");
00086 }
00087 #undef OP
00088 
00089 void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_size)
00090 {
00091     uint8_t *pixels2 = pixels + line_size;
00092 
00093     __asm__ volatile (
00094         "mov            r12, #4                 \n\t"
00095         "1:                                     \n\t"
00096         "pld            [%[pixels], %[line_size2]]              \n\t"
00097         "pld            [%[pixels2], %[line_size2]]             \n\t"
00098         "wldrd          wr4, [%[pixels]]        \n\t"
00099         "wldrd          wr5, [%[pixels2]]       \n\t"
00100         "pld            [%[block], #32]         \n\t"
00101         "wunpckelub     wr6, wr4                \n\t"
00102         "wldrd          wr0, [%[block]]         \n\t"
00103         "wunpckehub     wr7, wr4                \n\t"
00104         "wldrd          wr1, [%[block], #8]     \n\t"
00105         "wunpckelub     wr8, wr5                \n\t"
00106         "wldrd          wr2, [%[block], #16]    \n\t"
00107         "wunpckehub     wr9, wr5                \n\t"
00108         "wldrd          wr3, [%[block], #24]    \n\t"
00109         "add            %[block], %[block], #32 \n\t"
00110         "waddhss        wr10, wr0, wr6          \n\t"
00111         "waddhss        wr11, wr1, wr7          \n\t"
00112         "waddhss        wr12, wr2, wr8          \n\t"
00113         "waddhss        wr13, wr3, wr9          \n\t"
00114         "wpackhus       wr14, wr10, wr11        \n\t"
00115         "wpackhus       wr15, wr12, wr13        \n\t"
00116         "wstrd          wr14, [%[pixels]]       \n\t"
00117         "add            %[pixels], %[pixels], %[line_size2]     \n\t"
00118         "subs           r12, r12, #1            \n\t"
00119         "wstrd          wr15, [%[pixels2]]      \n\t"
00120         "add            %[pixels2], %[pixels2], %[line_size2]   \n\t"
00121         "bne            1b                      \n\t"
00122         : [block]"+r"(block), [pixels]"+r"(pixels), [pixels2]"+r"(pixels2)
00123         : [line_size2]"r"(line_size << 1)
00124         : "cc", "memory", "r12");
00125 }
00126 
00127 static void clear_blocks_iwmmxt(DCTELEM *blocks)
00128 {
00129     __asm__ volatile(
00130                 "wzero wr0                      \n\t"
00131                 "mov r1, #(128 * 6 / 32)        \n\t"
00132                 "1:                             \n\t"
00133                 "wstrd wr0, [%0]                \n\t"
00134                 "wstrd wr0, [%0, #8]            \n\t"
00135                 "wstrd wr0, [%0, #16]           \n\t"
00136                 "wstrd wr0, [%0, #24]           \n\t"
00137                 "subs r1, r1, #1                \n\t"
00138                 "add %0, %0, #32                \n\t"
00139                 "bne 1b                         \n\t"
00140                 : "+r"(blocks)
00141                 :
00142                 : "r1"
00143         );
00144 }
00145 
00146 static void nop(uint8_t *block, const uint8_t *pixels, int line_size, int h)
00147 {
00148     return;
00149 }
00150 
00151 /* A run time test is not simple. If this file is compiled in
00152  * then we should install the functions
00153  */
00154 
00155 void ff_dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx)
00156 {
00157     int mm_flags = AV_CPU_FLAG_IWMMXT; /* multimedia extension flags */
00158     const int high_bit_depth = avctx->codec_id == CODEC_ID_H264 && avctx->bits_per_raw_sample > 8;
00159 
00160     if (avctx->dsp_mask) {
00161         if (avctx->dsp_mask & AV_CPU_FLAG_FORCE)
00162             mm_flags |= (avctx->dsp_mask & 0xffff);
00163         else
00164             mm_flags &= ~(avctx->dsp_mask & 0xffff);
00165     }
00166 
00167     if (!(mm_flags & AV_CPU_FLAG_IWMMXT)) return;
00168 
00169     c->add_pixels_clamped = add_pixels_clamped_iwmmxt;
00170 
00171     if (!high_bit_depth) {
00172     c->clear_blocks = clear_blocks_iwmmxt;
00173 
00174     c->put_pixels_tab[0][0] = put_pixels16_iwmmxt;
00175     c->put_pixels_tab[0][1] = put_pixels16_x2_iwmmxt;
00176     c->put_pixels_tab[0][2] = put_pixels16_y2_iwmmxt;
00177     c->put_pixels_tab[0][3] = put_pixels16_xy2_iwmmxt;
00178     c->put_no_rnd_pixels_tab[0][0] = put_pixels16_iwmmxt;
00179     c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_iwmmxt;
00180     c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_iwmmxt;
00181     c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_iwmmxt;
00182 
00183     c->put_pixels_tab[1][0] = put_pixels8_iwmmxt;
00184     c->put_pixels_tab[1][1] = put_pixels8_x2_iwmmxt;
00185     c->put_pixels_tab[1][2] = put_pixels8_y2_iwmmxt;
00186     c->put_pixels_tab[1][3] = put_pixels8_xy2_iwmmxt;
00187     c->put_no_rnd_pixels_tab[1][0] = put_pixels8_iwmmxt;
00188     c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_iwmmxt;
00189     c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_iwmmxt;
00190     c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_iwmmxt;
00191 
00192     c->avg_pixels_tab[0][0] = avg_pixels16_iwmmxt;
00193     c->avg_pixels_tab[0][1] = avg_pixels16_x2_iwmmxt;
00194     c->avg_pixels_tab[0][2] = avg_pixels16_y2_iwmmxt;
00195     c->avg_pixels_tab[0][3] = avg_pixels16_xy2_iwmmxt;
00196     c->avg_no_rnd_pixels_tab[0][0] = avg_pixels16_iwmmxt;
00197     c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_iwmmxt;
00198     c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_iwmmxt;
00199     c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_iwmmxt;
00200 
00201     c->avg_pixels_tab[1][0] = avg_pixels8_iwmmxt;
00202     c->avg_pixels_tab[1][1] = avg_pixels8_x2_iwmmxt;
00203     c->avg_pixels_tab[1][2] = avg_pixels8_y2_iwmmxt;
00204     c->avg_pixels_tab[1][3] = avg_pixels8_xy2_iwmmxt;
00205     c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_iwmmxt;
00206     c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_iwmmxt;
00207     c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_iwmmxt;
00208     c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_iwmmxt;
00209     }
00210 }

Generated on Fri Feb 22 2013 07:24:25 for FFmpeg by  doxygen 1.7.1